Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created January 26, 2018 20:30
Show Gist options
  • Save inxilpro/1849451f3479edb097530e342c1cd371 to your computer and use it in GitHub Desktop.
Save inxilpro/1849451f3479edb097530e342c1cd371 to your computer and use it in GitHub Desktop.
import cx from 'classnames';
const defaultPrefix = 'ais';
let classMapper = className => className;
const defaultFormatter = (block, elements) => ({
className: cx(
elements
.filter(element => element !== undefined && element !== false)
.map(element => `${prefix}-${block}__${element}`)
.map(classMap)
),
});
let prefix = defaultPrefix;
let formatter = defaultFormatter;
export function setPrefix(newPrefix) {
prefix = newPrefix;
}
export function setFormatter(newFormatter) {
formatter = newFormatter;
}
export function setClassMapper(newClassMapper) {
classMapper = newClassMapper;
}
export default function classNames(block) {
return (...elements) => formatter(block, elements);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment