mirror of
https://github.com/HoshinoSuzumi/rayine-ui.git
synced 2025-04-10 04:58:51 +08:00
✨ docs(interactive): add slot code rendering
This commit is contained in:
parent
049739db91
commit
70d1af3d2f
@ -24,7 +24,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
slots: {
|
slots: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: null,
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
type: Array as PropType<{ name: string, values: string[], restriction: 'expected' | 'included' | 'excluded' | 'only' }[]>,
|
type: Array as PropType<{ name: string, values: string[], restriction: 'expected' | 'included' | 'excluded' | 'only' }[]>,
|
||||||
@ -119,7 +119,22 @@ const code = computed(() => {
|
|||||||
code += ` ${(typeof v === 'boolean' && (k === 'modelValue' || v !== true)) || typeof v === 'number' || typeof v === 'object' ? ':' : ''}${k === 'modelValue' ? 'model-value' : kebabCase(k)}${k !== 'modelValue' && typeof v === 'boolean' && !!v ? '' : `="${typeof v === 'object' ? renderObject(v) : v}"`}`
|
code += ` ${(typeof v === 'boolean' && (k === 'modelValue' || v !== true)) || typeof v === 'number' || typeof v === 'object' ? ':' : ''}${k === 'modelValue' ? 'model-value' : kebabCase(k)}${k !== 'modelValue' && typeof v === 'boolean' && !!v ? '' : `="${typeof v === 'object' ? renderObject(v) : v}"`}`
|
||||||
}
|
}
|
||||||
|
|
||||||
code += `/>\n</template>
|
if (props.slots) {
|
||||||
|
code += `>
|
||||||
|
${Object.entries(props.slots).map(([key, value]) => {
|
||||||
|
return key === 'default'
|
||||||
|
? value
|
||||||
|
: `<template #${key}>
|
||||||
|
${value}
|
||||||
|
</template>`
|
||||||
|
}).join('\n ')}
|
||||||
|
</${componentName}>`
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
code += ' />'
|
||||||
|
}
|
||||||
|
|
||||||
|
code += `\n</template>
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`
|
`
|
||||||
return code
|
return code
|
||||||
@ -176,11 +191,12 @@ const { data: codeRender } = await useAsyncData(`${componentName}-code-renderer-
|
|||||||
v-else
|
v-else
|
||||||
:id="`${prop.name}-prop`"
|
:id="`${prop.name}-prop`"
|
||||||
:model-value="componentProps[prop.name]"
|
:model-value="componentProps[prop.name]"
|
||||||
:type="prop.type === 'number' ? 'number' : 'text'"
|
:type="prop.type.includes('number') ? 'number' : 'text'"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
:padded="false"
|
:padded="false"
|
||||||
:ui="{ rounded: 'rounded-none' }"
|
:ui="{ rounded: 'rounded-none' }"
|
||||||
placeholder="type something..."
|
:placeholder="prop.type"
|
||||||
|
autocomplete="off"
|
||||||
@update:model-value="val => componentProps[prop.name] = prop.type === 'number' ? Number(val) : val"
|
@update:model-value="val => componentProps[prop.name] = prop.type === 'number' ? Number(val) : val"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user