From b3de942696bdf27a3202a19dc661bd8e6a645875 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 4 Sep 2024 10:20:01 +0200 Subject: [PATCH] docs(ComponentProps): display schema default in description --- .../components/content/ComponentPropsSchema.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/app/components/content/ComponentPropsSchema.vue b/docs/app/components/content/ComponentPropsSchema.vue index 19b34af0..20ca0305 100644 --- a/docs/app/components/content/ComponentPropsSchema.vue +++ b/docs/app/components/content/ComponentPropsSchema.vue @@ -18,7 +18,20 @@ function getSchemaProps(schema: PropertyMeta['schema']) { return (Array.isArray(schema.schema) ? schema.schema : Object.values(schema.schema)).flatMap(getSchemaProps) } -const schemaProps = computed(() => getSchemaProps(props.prop.schema)) +const schemaProps = computed(() => { + return getSchemaProps(props.prop.schema).map((prop) => { + const defaultValue = prop.default ?? prop.tags?.find(tag => tag.name === 'defaultValue')?.text + let description = prop.description + if (defaultValue) { + description = description ? `${description} Defaults to \`${defaultValue}\`{lang="ts-type"}.` : `Defaults to \`${defaultValue}\`{lang="ts-type"}.` + } + + return { + ...prop, + description + } + }) +})