UNPKG

css-variants

Version:

A lightweight, flexible API for managing CSS class variants.

53 lines 1.4 kB
// credit: https://github.com/lukeed/clsx 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; } export 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; } export default cx; //# sourceMappingURL=cx.js.map