/* eslint-disable space-infix-ops */ /** * Create a helper function for accessing a component's class name. * * @param {Object} styles Dictionary of style -> postcss generated class name. * @param {String} prefix Component name prefix dasherized * @returns {Function} * @throws {TypeError} If the style is not found. * * @example * ```jsx * import styles from './progress-bar.module.less; * import createStyler from './styler'; * const style = createStyler('progress-bar'); * * const render = (props) => { * return ( *
*
*
{props.message}
*
*
* ); * }; * ``` */ export default function styler(styles: Record, prefix: string) { // eslint-disable-next-line camelcase return function get_style_for_component(what = '') { const k = `${prefix}${what !== '' ? '-' + what : ''}`; const def = styles[k]; if (!def) { throw new TypeError(`Style does not exist for ${k}`); } return def; }; }