docs(ComponentCard): show all props for the code (#797)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
KeJun
2023-10-15 23:52:20 +08:00
committed by GitHub
parent 9f4d88e0aa
commit 8867936e01
16 changed files with 157 additions and 99 deletions

View File

@@ -41,7 +41,7 @@
<ContentSlot v-if="$slots.default" :use="$slots.default" />
<template v-for="slot in Object.keys(slots || {})" :key="slot" #[slot]>
<ContentSlot :name="slot" />
<ContentSlot :name="slot" unwrap="p" />
</template>
</component>
</div>
@@ -113,6 +113,7 @@ const props = defineProps({
const baseProps = reactive({ ...props.baseProps })
const componentProps = reactive({ ...props.props })
const { $prettier } = useNuxtApp()
const appConfig = useAppConfig()
const route = useRoute()
// eslint-disable-next-line vue/no-dupe-keys
@@ -124,7 +125,7 @@ const meta = await fetchComponentMeta(name)
// Computed
const fullProps = computed(() => ({ ...baseProps, ...componentProps }))
const fullProps = computed(() => ({ ...componentProps, ...baseProps }))
const vModel = computed({
get: () => baseProps.modelValue,
set: (value) => {
@@ -186,7 +187,7 @@ const propsToSelect = computed(() => Object.keys(componentProps).map((key) => {
const code = computed(() => {
let code = `\`\`\`html
<${name}`
for (const [key, value] of Object.entries(componentProps)) {
for (const [key, value] of Object.entries(fullProps.value)) {
if (value === 'undefined' || value === null) {
continue
}
@@ -206,7 +207,7 @@ const code = computed(() => {
code += `>
${props.code}</${name}>`
} else {
code += `>${props.code}</${name}>`
code += `>${props.code.endsWith('>') ? `${props.code}\n` : props.code}</${name}>`
}
} else {
code += ' />'
@@ -235,16 +236,27 @@ function renderObject (obj: any) {
const shikiHighlighter = useShikiHighlighter({})
const codeHighlighter = async (code: string, lang: string, theme: any, highlights: number[]) => shikiHighlighter.getHighlightedAST(code, lang, theme, { highlights })
const { data: ast } = await useAsyncData(`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots })}`, () => transformContent('content:_markdown.md', code.value, {
markdown: {
highlight: {
highlighter: codeHighlighter,
theme: {
light: 'material-theme-lighter',
default: 'material-theme',
dark: 'material-theme-palenight'
}
const { data: ast } = await useAsyncData(
`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots })}`,
async () => {
let formatted = ''
try {
formatted = await $prettier.format(code.value) || code.value
} catch (error) {
formatted = code.value
}
}
}), { watch: [code] })
return transformContent('content:_markdown.md', formatted, {
markdown: {
highlight: {
highlighter: codeHighlighter,
theme: {
light: 'material-theme-lighter',
default: 'material-theme',
dark: 'material-theme-palenight'
}
}
}
})
}, { watch: [code] })
</script>

View File

@@ -5,8 +5,9 @@
</template>
<template #error="{ error }">
<UAlert v-if="error" icon="i-heroicons-exclamation-triangle-20-solid" :title="error" color="red" />
<UAlert v-else icon="i-heroicons-check-circle-20-solid" title="Your email is valid" color="green" />
<span :class="[error ? 'text-red-500 dark:text-red-400' : 'text-primary-500 dark:text-primary-400']">
{{ error ? error : 'Your email is valid' }}
</span>
</template>
</UFormGroup>
</template>