mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
docs(ComponentCard): show all props for the code (#797)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user