css-variants
Version:
A lightweight, flexible API for managing CSS class variants.
56 lines • 1.49 kB
JavaScript
;
// credit: https://github.com/lukeed/clsx
Object.defineProperty(exports, "__esModule", { value: true });
exports.cx = cx;
function toVal(input) {
if (typeof input === 'string') {
return input;
}
if (typeof input === 'number' || typeof input === 'bigint') {
return String(input);
}
if (input === null || input === undefined || typeof input === 'boolean') {
return '';
}
let result = '';
if (Array.isArray(input)) {
let i = 0;
let tmpClassValue;
let tmpClassName;
for (; i < input.length; i++) {
if ((tmpClassValue = input[i])) {
if ((tmpClassName = toVal(tmpClassValue))) {
if (result)
result += ' ';
result += tmpClassName;
}
}
}
return result;
}
for (const key in input) {
if (input[key]) {
result && (result += ' ');
result += key;
}
}
return result;
}
function cx(...args) {
let result = '';
let i = 0;
let tmpClassValue;
let tmpClassName;
for (; i < args.length; i++) {
if ((tmpClassValue = args[i])) {
if ((tmpClassName = toVal(tmpClassValue))) {
if (result)
result += ' ';
result += tmpClassName;
}
}
}
return result;
}
exports.default = cx;
//# sourceMappingURL=cx.js.map