docs(ComponentExample): add iframe prop

This commit is contained in:
Benjamin Canac
2024-12-11 12:13:37 +01:00
parent 52e2a4d68f
commit a0b8b93a5a
2 changed files with 11 additions and 3 deletions

View File

@@ -5,6 +5,11 @@ import { get, set } from '#ui/utils'
const props = withDefaults(defineProps<{
name: string
class?: any
/**
* Whether to render the component in an iframe
* @defaultValue false
*/
iframe?: boolean | { [key: string]: any }
props?: { [key: string]: any }
/**
* Whether to format the code with Prettier
@@ -112,6 +117,8 @@ const optionsValues = ref(props.options?.reduce((acc, option) => {
}
return acc
}, {} as Record<string, any>) || {})
const urlSearchParams = computed(() => new URLSearchParams(optionsValues.value).toString())
</script>
<template>
@@ -170,7 +177,8 @@ const optionsValues = ref(props.options?.reduce((acc, option) => {
</div>
<div class="flex justify-center p-4" :class="props.class">
<component :is="camelName" v-bind="{ ...componentProps, ...optionsValues }" />
<iframe v-if="iframe" v-bind="typeof iframe === 'object' ? iframe : {}" :src="`/examples/${name}?${urlSearchParams}`" class="w-full" />
<component :is="camelName" v-else v-bind="{ ...componentProps, ...optionsValues }" />
</div>
</div>
</template>

View File

@@ -5,7 +5,7 @@ const name = route.params.slug?.[0]
</script>
<template>
<div class="p-4 flex flex-col justify-center h-screen overflow-auto">
<component :is="name" />
<div class="flex flex-col justify-center items-center h-screen">
<component :is="name" v-bind="route.query" />
</div>
</template>