Socket
Socket
Sign inDemoInstall

@codecademy/variance

Package Overview
Dependencies
64
Maintainers
1
Versions
547
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @codecademy/variance

Constraint based CSS in JS for building scalable design systems


Version published
Weekly downloads
5.2K
increased by38.71%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@codecademy/variance

This is an experimental package for creating dynamic and typesafe style props.

Usage

Configure your props with a simple configuration object. The keys of your object become your prop names and their values describe their responsibilities and valid types.

import styled from '@emotion/styled';
import { variance } from '@codecademy/variance';

const Container = styled.div(
  variance.create({
    w: { property: 'width' },
    p: { property: 'padding', scale: 'spacing' },
  })
);

<Container w="100%" p={[16, 24]}>
  Contained!
</Container>;

Composition

You can compose props that you've created seperately to create new prop functions.

import { variance } from '@codecademy/variance';

const spacing = variance.create({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const dimensions = variance.create({
  w: { property: 'width' },
  h: { property: 'height' },
});

const combinedProps = variance.compose(spacing, dimensions);

const Box = styled.div(combinedProps);

Static CSS

import styled from '@emotion/styled';
import { variance } from '@codecademy/variance';

const css = variance.createCss({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const MyCoolThing = styled.div(
  css({
    width: '100%',
    height: '500px',
    p: [32, , 64],
  })
);

const variant = variance.createVariant({
  m: { property: 'padding', scale: 'margin' },
  p: { property: 'padding', scale: 'spacing' },
});

const MyCoolThing = styled.div(
  variant({
    base: { width: '100%' },
    variants: {
      big: {
        height: '500px',
        p: [32, , 64],
      },
      small: {
        height: '250px',
        p: [16, , 32],
      },
    },
  })
);

Keywords

FAQs

Last updated on 01 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc