mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 19:30:37 +01:00
docs(ComponentCode): handle custom items
This commit is contained in:
@@ -5,6 +5,7 @@ import * as theme from '#build/ui'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
ignore?: string[]
|
ignore?: string[]
|
||||||
|
items?: { [key: string]: string[] }
|
||||||
props?: { [key: string]: any }
|
props?: { [key: string]: any }
|
||||||
slots?: { [key: string]: any }
|
slots?: { [key: string]: any }
|
||||||
}>()
|
}>()
|
||||||
@@ -24,14 +25,18 @@ const options = computed(() => Object.keys(props.props || {}).filter((key) => {
|
|||||||
return !props.ignore?.includes(key)
|
return !props.ignore?.includes(key)
|
||||||
}).map((key) => {
|
}).map((key) => {
|
||||||
const prop = meta?.meta?.props?.find((prop: any) => prop.name === key)
|
const prop = meta?.meta?.props?.find((prop: any) => prop.name === key)
|
||||||
const variants = Object.keys(componentTheme.variants?.[key] || {})
|
const items = props.items?.[key]?.length
|
||||||
const items = prop?.type === 'boolean'
|
? props.items[key].map(item => ({
|
||||||
? [{ value: true, label: 'true' }, { value: false, label: 'false' }]
|
value: item,
|
||||||
: variants.map(variant => ({
|
label: item
|
||||||
value: variant,
|
}))
|
||||||
label: variant,
|
: prop?.type === 'boolean'
|
||||||
chip: key === 'color' ? { color: variant } : undefined
|
? [{ value: true, label: 'true' }, { value: false, label: 'false' }]
|
||||||
})).filter(variant => key === 'color' ? !['error'].includes(variant.value) : true)
|
: Object.keys(componentTheme.variants?.[key] || {}).map(variant => ({
|
||||||
|
value: variant,
|
||||||
|
label: variant,
|
||||||
|
chip: key === 'color' ? { color: variant } : undefined
|
||||||
|
})).filter(variant => key === 'color' ? !['error'].includes(variant.value) : true)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: key,
|
name: key,
|
||||||
|
|||||||
Reference in New Issue
Block a user