Manageable, conditional, flexible class names in React.
npm install @reactory/class-name---
A simple, lightweight yet powerful JavaScript utility function for React
to easily manage CSS classes via the className attribute.
---
- 1.: simplified and flexible CSS class management in React
- 2.: multiple, combinable, conditional, and fault tolerant class names from strings, objects, arrays, and functions
- 3.: handles deeply nested arrays, objects, and functions
- 4.: handles class names with leading dots (e.g.: '.class-name' => 'class-name')
```
npm i @reactory/class-name
`jsx
import React from 'react'
import className from '@reactory/class-name'
// Regular use cases
export function Container (props) {
return (
/**
* Built-in deduplication
*
* Classes will be excluded or included from the class list
* based on their falsy or truthy values.
*/
export function Button (props) {
return (
className={className(
// if true, btn-hover class will be added to the class list
{ 'btn-hover': props.isHover },
// ...
// then later, btn-hover will be removed from the class list
{ 'btn-hover': !props.disabled },
// ...
// then again, later will be added again to the class list
{ 'btn-hover': props.isHoverEnforced },
)}
>
{props.label}
)
}
``
---
---
Any contribution is highly appreciated. To get going, check out the [contribution guidelines][url-contrib-doc].
Thank you!
[MIT][url-license-doc] @ Richard King
[url-license-doc]: https://github.com/reactory/class-name/blob/main/LICENSE
[url-contrib-doc]: https://github.com/reactory/class-name/blob/main/.github/CONTRIBUTING.md