feat(module): handle variants with dynamic colors

This commit is contained in:
Benjamin Canac
2022-06-30 17:16:22 +02:00
parent f98253c255
commit 5a8b078d65
5 changed files with 474 additions and 457 deletions

View File

@@ -1,22 +1,18 @@
export const safeColors = [
'primary',
'rose',
'pink',
'fuchsia',
'purple',
'violet',
'indigo',
'blue',
'sky',
'cyan',
'teal',
'emerald',
'green',
'lime',
'yellow',
'amber',
'orange',
'red'
import { omit, kebabCase } from './index'
export const colorsToExclude = [
'inherit',
'transparent',
'current',
'white',
'black',
'slate',
'gray',
'zinc',
'neutral',
'stone'
]
export const safeColorsAsRegex = safeColors.join('|')
export const excludeColors = (colors: object) => Object.keys(omit(colors, colorsToExclude)).map(color => kebabCase(color))
export const colorsAsRegex = (colors: string[]) => colors.join('|')

View File

@@ -3,3 +3,16 @@ export * from './popper'
export function classNames (...classes: any[string]) {
return classes.filter(Boolean).join(' ')
}
export const kebabCase = (str: string) => {
return str
?.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
?.map(x => x.toLowerCase())
?.join('-')
}
export const omit = (obj: object, keys: string[]) => {
return Object.fromEntries(
Object.entries(obj).filter(([key]) => !keys.includes(key))
)
}