@umbrellio/prefix-classnames

This library allows adding prefixes to classes attributes of html elements.
Install
$ yarn add @umbrellio/prefix-classnames
Usage
Imported from the library function takes one argument which will be the prefix for classes. Returns function which takes any number of arguments which can be a string, an object or an array and returns the string with the prefix.
classnames(prefix: String): (...args: String | Object | Array): String => result
import classnames from "@umbrellio/prefix-classnames"
classnames(prefix: String): (...args: String | Object | Array): String => result
const cn = classnames("prefix__")
cn("foo", "bar")
cn("foo", { bar: true })
cn({ "foo-bar": true })
cn({ "foo-bar": false })
cn({ foo: true }, { bar: true })
cn({ foo: true, bar: true })
cn(["cat", { foo: true, bar: false }, "duck"])
cn("foo", { bar: true, duck: false }, "baz", { quux: true });
cn(null, false, "bar", undefined, 0, 123, { baz: null }, "");
Usage with React component
import classnames from "@umbrellio/prefix-classnames"
const cn = classnames("super-prefix__");
class Button extends React.Component {
render () {
const btnClass = cn({
btn: true,
"btn-pressed": this.state.isPressed,
"btn-over": !this.state.isPressed && this.state.isHovered
});
return <button className={btnClass}>{this.props.label}</button>;
}
}