Files
ui/docs/app/components/content/ComponentPropsSchema.vue
2024-07-17 11:55:19 +02:00

32 lines
891 B
Vue

<script setup lang="ts">
import type { PropertyMeta } from 'vue-component-meta'
const props = defineProps<{
prop: PropertyMeta
}>()
function getSchemaProps(schema: PropertyMeta['schema']) {
if (!schema || typeof schema === 'string' || !schema.schema) {
return []
}
if (schema.kind === 'object') {
return Object.values(schema.schema)
}
return (Array.isArray(schema.schema) ? schema.schema : Object.values(schema.schema)).flatMap(getSchemaProps)
}
const schemaProps = computed(() => getSchemaProps(props.prop.schema))
</script>
<template>
<Collapsible v-if="schemaProps?.length" class="mt-1">
<ProseUl>
<ProseLi v-for="schemaProp in schemaProps" :key="schemaProp.name">
<HighlightInlineType :type="`${schemaProp.name}${schemaProp.required === false ? '?' : ''}: ${schemaProp.type}`" />
</ProseLi>
</ProseUl>
</Collapsible>
</template>