1.0.19 • Published 1 year ago

scn v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

scn - Simple class names

Simple class names utility that is the tiniest (75 bytes) and the fastest.

Now you can write conditional class names more easily and without getting into trouble 😼.

How to use?

Code Style 1: Logical operators

  • Use strings for normal class names.
  • Add logical operators for conditional classes.

Example

scn('hello', null, false && 'world', undefined); // 'hello'

Real world example

scn(
  'text-sm leading-4',
  isError && 'text-error bg-error-opacity',
  !isError && 'text-success bg-success-opacity'
); // 'text-sm leading-4 text-success bg-success-opacity'

Code Style 2: Tuples

  • Use strings for normal class names.
  • Use tuples for conditional styles, if the second value is falsy, the class name will not be included.

Examples

scn('hello', 'world'); // 'hello world'
scn(['hello', true], ['world', false]); // 'hello'
scn('one', 'two', ['three', undefined]); // 'one two'
scn('one', undefined, 'two', false, null, ['three', false]); // 'one two'

Real world example

scn(
  'text-sm leading-4',
  ['text-error bg-error-opacity', isError],
  ['text-success bg-success-opacity', !isError]
); // 'text-sm leading-4 text-success bg-success-opacity'

Example I love to mention

import scn from "scn";

interface IPropTypes {
  className?: string;
}

const Component = ({ className }: IPropTypes) => (
  <div className={scn("hello", className)} />
);

<Component className="world" /> // <div class="hello world" />

<Component /> // <div class="hello" />  -- No "undefined" class 🎉

Bundle Size comparison

image

License

MIT

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago