3.1.0 • Published 2 years ago

@shopify/css-utilities v3.1.0

Weekly downloads
51,806
License
MIT
Repository
github
Last release
2 years ago

@shopify/css-utilities

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

A set of CSS styling-related utilities.

Installation

$ yarn add @shopify/css-utilities

Both classNames and variationName are helper functions that are use to generate class names.

classNames

Is a straight export of classnames. It returns a classNames string that are conditionally joined together.

variationName

Is a utility that returns a camelCase string combining the name and value passed in.

Usage

Given this CSS file for a Square React component:

.Square {
  color: transparent;
}

.sizeSmall {
  height: 20px
  width: 20px
}

.sizeLarge {
  height: 44px
  width: 44px
}

.colorWhite {
  background-color: white;
}

.colorBlack {
  background-color: black;
}

The following can be use to generate different class names for the component based on its props:

type Size = 'small' | 'large';
type Color = 'white' | 'black';

interface Props {
  size: Size;
  color: Color;
}

function Square({size, color}: Props) {
  const className = classNames(
    styles.Square,
    styles[variationName<Color>('color', color)],
    styles[variationName<Size>('size', size)],
  );

  return <div className={className} />;
}
3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.9

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago