@appbuckets/react-ui
Version:
Just Another React UI Framework
71 lines (68 loc) • 1.49 kB
JavaScript
import { __rest } from 'tslib';
import clsx from 'clsx';
function classByPattern(value, pattern, replacer) {
if (replacer === void 0) {
replacer = '%value%';
}
if (typeof value === 'string' || typeof value === 'number') {
return pattern.replace(
new RegExp(replacer, 'g'),
value.toString().replace(/\s/g, '-')
);
}
return undefined;
}
function splitStateClassName(props) {
var _a = props,
appearance = _a.appearance,
danger = _a.danger,
info = _a.info,
primary = _a.primary,
secondary = _a.secondary,
success = _a.success,
warning = _a.warning,
rest = __rest(_a, [
'appearance',
'danger',
'info',
'primary',
'secondary',
'success',
'warning',
]);
var classes = clsx(
{
'is-danger': danger,
'is-info': info,
'is-primary': primary,
'is-secondary': secondary,
'is-success': success,
'is-warning': warning,
},
/** Apply manual color only if any other shorthand is falsy */
classByPattern(
!danger &&
!info &&
!primary &&
!secondary &&
!success &&
!warning &&
appearance,
'is-%value%'
)
);
return [
classes,
rest,
{
appearance: appearance,
danger: danger,
info: info,
primary: primary,
secondary: secondary,
success: success,
warning: warning,
},
];
}
export { splitStateClassName as default };