mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-17 13:38:07 +01:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
export function classNames (...classes: any[string]) {
|
|
return classes.filter(Boolean).join(' ')
|
|
}
|
|
|
|
export const hexToRgb = (hex: string) => {
|
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
|
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i
|
|
hex = hex.replace(shorthandRegex, function (_, r, g, b) {
|
|
return r + r + g + g + b + b
|
|
})
|
|
|
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
return result
|
|
? `${parseInt(result[1], 16)} ${parseInt(result[2], 16)} ${parseInt(result[3], 16)}`
|
|
: null
|
|
}
|
|
|
|
export const getSlotsChildren = (slots: any) => {
|
|
let children = slots.default?.()
|
|
if (children.length) {
|
|
children = children.flatMap(c => {
|
|
if (typeof c.type === 'symbol') {
|
|
if (typeof c.children === 'string') {
|
|
// `v-if="false"` or commented node
|
|
return
|
|
}
|
|
return c.children
|
|
} else if (c.type.name === 'ContentSlot') {
|
|
return c.ctx.slots.default?.()
|
|
}
|
|
return c
|
|
}).filter(Boolean)
|
|
}
|
|
return children
|
|
}
|