1.1.4 • Published 10 months ago

@brr-dev/classnames v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@brr-dev/classnames

Generate an HTML class attribute string... however you want.

Usage

Takes in a series of inputs to build a single class string. Different types of inputs are handled differently.

Input TypeHandling
stringadds the input string directly to the class string
numberadds the input number directly to the class string
arrayrecursively calls classnames with the array values, adds results to the class string
objectobject entries truthy values add their property names as a string to the class string

Here are some examples of what that looks like in practice:

// Simple use case
classnames("ui-button", "ui-active");
// => 'ui-button ui-active'

// Using a boolean flag to toggle a class
classnames("ui-button", isLoading && "ui-loading");
// => isLoading ? 'ui-button ui-loading' : 'ui-button'

// Nested array example
classnames("ui-button", ["ui-active", ["ui-loading"]]);
// => 'ui-button ui-active ui-loading'

// Object input, mapping state to class names example
classnames("ui-button", {
    "ui-loading": isLoading,
    "ui-hover": isHovered,
});
// => 'ui-button ui-loading ui-hovered' (if both are true)

// The export also has a short name if you prefer:
cn("ui-button", isActive && "ui-active");
1.1.4

10 months ago

1.1.1

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

0.1.0

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