Skip to content

Commit 7031398

Browse files
committed
add ComponentProps support
1 parent c86144e commit 7031398

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed

app/components/ComponentProps.vue

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<script setup lang="ts">
2+
import {
3+
Table,
4+
TableBody,
5+
TableCell,
6+
TableHead,
7+
TableHeader,
8+
TableRow
9+
} from "@/components/table"
10+
import { type ComponentProp, type Meta } from "@app/types/globals"
11+
12+
defineProps<{
13+
props: ComponentProp[]
14+
meta: Meta
15+
}>()
16+
</script>
17+
18+
<template>
19+
<h2 class="mb-2 mt-8 text-2xl">Props</h2>
20+
21+
<Table>
22+
23+
<TableHeader>
24+
<TableRow>
25+
<TableHead class="w-[100px]"> Prop</TableHead>
26+
27+
<TableHead>Default</TableHead>
28+
29+
<TableHead>Type</TableHead>
30+
</TableRow>
31+
</TableHeader>
32+
33+
<TableBody>
34+
<TableRow v-for="(prop, index) in props" :key="index">
35+
<TableCell class="font-medium">
36+
{{ prop.name }}
37+
</TableCell>
38+
39+
<TableCell>
40+
<span v-if="prop.default" class="bg-muted px-2 py-1 font-mono">{{ prop.default }}</span>
41+
42+
<span v-else>-</span>
43+
</TableCell>
44+
45+
<TableCell>
46+
<div class="mb-4">
47+
<span class="bg-muted px-2 py-1 font-mono">
48+
<template v-if="typeof prop.type === 'string'">
49+
{{ prop.type }}
50+
</template>
51+
52+
<template v-else>
53+
{{ prop.type.join(" | ") }}
54+
</template>
55+
</span>
56+
</div>
57+
58+
{{ prop.description }}
59+
60+
</TableCell>
61+
</TableRow>
62+
</TableBody>
63+
</Table>
64+
</template>

app/components/ComponentSummary.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import { Button } from "@/components/button"
66
import { Heading } from "@"
77
import ShadcnLogo from "@app/components/ShadcnLogo.vue"
88
import CodingLabsLogo from "@app/components/CodingLabsLogo.vue"
9-
10-
type Meta = {
11-
layout: Component
12-
shadcn?: boolean | string
13-
modified?: boolean
14-
}
9+
import { type Meta } from "@app/types/globals"
1510
1611
const props = defineProps<{
1712
meta: Meta

app/pages/components/Toast.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { Ghost } from "lucide-vue-next"
33
import { Toaster, useToast } from "@/components/toast"
44
import { Button } from "@/components/button"
5+
import ComponentProps from "@app/components/ComponentProps.vue"
6+
import { type ComponentProp } from "@app/types/globals"
57
68
const { toast } = useToast()
79
@@ -20,6 +22,35 @@ function calculateDaysUntilHalloween() {
2022
2123
return Math.ceil(timeDiff / (1000 * 60 * 60 * 24))
2224
}
25+
26+
const componentProps: ComponentProp[] = [
27+
{
28+
name: "icon",
29+
type: ["string", "component"],
30+
description: "Icon component or URL to display in the toast"
31+
},
32+
{
33+
name: "iconClasses",
34+
type: "string",
35+
description: "CSS classes to apply to the icon"
36+
},
37+
{
38+
name: "title",
39+
type: "string",
40+
description: "Title text of the toast"
41+
},
42+
{
43+
name: "description",
44+
type: ["string", "object"],
45+
description: "Description text or object to display in the toast"
46+
},
47+
{
48+
name: "objectFormat",
49+
default: "value",
50+
type: "string",
51+
description: "Format for object descriptions: \"value\", \"key\", or \"both\""
52+
}
53+
]
2354
</script>
2455

2556
<template>
@@ -133,5 +164,9 @@ function calculateDaysUntilHalloween() {
133164
<li>Support for icon and iconClasses prop</li>
134165

135166
<li>Support for object descriptions (value only (default), key only, and key + value)</li>
167+
168+
<li>Emit a click event</li>
136169
</ul>
170+
171+
<ComponentProps :props="componentProps" :meta="$route.meta" />
137172
</template>

app/types/globals.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Component } from "vue"
2+
3+
export type Meta = {
4+
layout: Component
5+
shadcn?: boolean | string
6+
modified?: boolean
7+
}
8+
9+
export type ComponentProp = {
10+
name: string
11+
default?: string | boolean | null
12+
type: string | Array<string>
13+
description: string
14+
}

0 commit comments

Comments
 (0)