svelte-ux
Version:
- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`
30 lines (29 loc) • 868 B
JavaScript
import clsx from 'clsx';
import { extendTailwindMerge } from 'tailwind-merge';
/**
* Convert object to style string
*/
export function objectToString(styleObj) {
return Object.entries(styleObj)
.map(([key, value]) => {
if (value) {
// Convert camelCase into kaboob-case (ex. (transformOrigin => transform-origin))
const propertyName = key.replace(/([A-Z])/g, '-$1').toLowerCase();
return `${propertyName}: ${value};`;
}
else {
return null;
}
})
.filter((x) => x)
.join(' ');
}
/**
* Wrapper around `tailwind-merge` and `clsx`
*/
const twMerge = extendTailwindMerge({
classGroups: {
shadow: ['shadow-border-l', 'shadow-border-r', 'shadow-border-t', 'shadow-border-b'],
},
});
export const cls = (...inputs) => twMerge(clsx(...inputs));