Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 1d2eab7

Browse files
committed
update properties components
1 parent 561c4ff commit 1d2eab7

File tree

3 files changed

+99
-47
lines changed

3 files changed

+99
-47
lines changed

src/components/Properties.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use client'
2+
3+
import { useState } from 'react'
4+
import { Button } from './ui/button'
5+
import { MinusCircleIcon, PlusCircleIcon } from '@heroicons/react/24/outline'
6+
import { Tag } from './Tag'
7+
import { cn } from '@/lib/utils'
8+
9+
export function Properties({
10+
children,
11+
nested,
12+
}: {
13+
children: React.ReactNode
14+
nested?: boolean
15+
}) {
16+
const [open, setOpen] = useState(false)
17+
18+
const content = (
19+
<ul
20+
role="list"
21+
className="m-0 max-w-[calc(theme(maxWidth.lg)-theme(spacing.8))] list-none divide-y divide-zinc-900/5 p-0 dark:divide-white/5"
22+
>
23+
{children}
24+
</ul>
25+
)
26+
27+
return nested ? (
28+
<li>
29+
<Button
30+
onClick={() => setOpen(!open)}
31+
variant="outline"
32+
className="mt-4 flex items-center gap-2"
33+
>
34+
{open ? (
35+
<MinusCircleIcon className="h-5 w-5" />
36+
) : (
37+
<PlusCircleIcon className="h-5 w-5" />
38+
)}
39+
{open ? 'Hide' : 'Show'} accepted values
40+
</Button>
41+
<div className={cn('mt-4 rounded-lg border p-4', !open && 'sr-only')}>
42+
{content}
43+
</div>
44+
</li>
45+
) : (
46+
<div className={'my-6'}>{content}</div>
47+
)
48+
}
49+
50+
interface PropertyProps {
51+
name: string
52+
type: string
53+
children: React.ReactNode
54+
required: boolean
55+
}
56+
57+
export function Property({ name, type, children, required }: PropertyProps) {
58+
return (
59+
<li className="m-0 px-0 py-4 first:pt-0 last:pb-0">
60+
<dl className="m-0 flex flex-wrap items-center gap-x-3 gap-y-2">
61+
<dt className="sr-only">Name</dt>
62+
<dd>
63+
<code>{name}</code>
64+
</dd>
65+
<dt className="sr-only">{required ? 'Required' : 'Optional'}</dt>
66+
<dd>
67+
{required ? (
68+
<Tag color="amber" className="rounded-md py-0.5 uppercase">
69+
Required
70+
</Tag>
71+
) : (
72+
<span className="mt-0.5 font-mono text-xs text-zinc-400 dark:text-zinc-500">
73+
Optional
74+
</span>
75+
)}
76+
</dd>
77+
<dt className="sr-only">Type</dt>
78+
<dd className="mt-0.5 flex font-mono text-xs text-zinc-400 dark:text-zinc-500">
79+
{type}
80+
</dd>
81+
<dt className="sr-only">Description</dt>
82+
<dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
83+
{children}
84+
</dd>
85+
</dl>
86+
</li>
87+
)
88+
}

src/components/Tag.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cn } from '@/lib/utils'
12
import clsx from 'clsx'
23

34
const variantStyles = {
@@ -43,18 +44,21 @@ const valueColorMap = {
4344
export function Tag({
4445
children,
4546
variant = 'medium',
46-
color = valueColorMap[children] ?? 'emerald',
47+
color = valueColorMap[children] ?? 'zinc',
48+
className = '',
4749
}: {
4850
children: keyof typeof valueColorMap & (string | {})
4951
variant?: keyof typeof variantStyles
5052
color?: keyof typeof colorStyles
53+
className?: string
5154
}) {
5255
return (
5356
<span
54-
className={clsx(
57+
className={cn(
5558
'font-mono text-[0.625rem] font-semibold leading-6',
5659
variantStyles[variant],
5760
colorStyles[color][variant],
61+
className,
5862
)}
5963
>
6064
{children}

src/components/mdx.tsx

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Link from 'next/link'
22
import clsx from 'clsx'
33
import { Table } from '@/components/ui/table'
4+
import { Tag } from './Tag'
5+
import { Button } from './ui/button'
6+
import { MinusCircleIcon, PlusCircleIcon } from '@heroicons/react/24/outline'
7+
import { useState } from 'react'
48

59
export {
610
TableHead as th,
@@ -92,51 +96,7 @@ export function Col({
9296
)
9397
}
9498

95-
export function Properties({ children }: { children: React.ReactNode }) {
96-
return (
97-
<div className="my-6">
98-
<ul
99-
role="list"
100-
className="m-0 max-w-[calc(theme(maxWidth.lg)-theme(spacing.8))] list-none divide-y divide-zinc-900/5 p-0 dark:divide-white/5"
101-
>
102-
{children}
103-
</ul>
104-
</div>
105-
)
106-
}
107-
108-
export function Property({
109-
name,
110-
children,
111-
type,
112-
}: {
113-
name: string
114-
children: React.ReactNode
115-
type?: string
116-
}) {
117-
return (
118-
<li className="m-0 px-0 py-4 first:pt-0 last:pb-0">
119-
<dl className="m-0 flex flex-wrap items-center gap-x-3 gap-y-2">
120-
<dt className="sr-only">Name</dt>
121-
<dd>
122-
<code>{name}</code>
123-
</dd>
124-
{type && (
125-
<>
126-
<dt className="sr-only">Type</dt>
127-
<dd className="font-mono text-xs text-zinc-400 dark:text-zinc-500">
128-
{type}
129-
</dd>
130-
</>
131-
)}
132-
<dt className="sr-only">Description</dt>
133-
<dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
134-
{children}
135-
</dd>
136-
</dl>
137-
</li>
138-
)
139-
}
99+
export { Properties, Property } from './Properties'
140100

141101
export { OSTabs } from '@/components/OSTabs'
142102

0 commit comments

Comments
 (0)