1 # TSDoc: UI Components
2
3 UI component files live under `packages/design-system/ui/src/components/`. They export React components as named or default exports.
4
5 ## Rules
6
7 - Document the exported component with a 1-sentence description
8 - Document props inline inside the destructured parameter list
9 - For Radix UI-based components: reference the Radix primitive in the component doc
10 - For components that fully forward props to Radix without customization, document the component only — individual props come from Radix and don't need repeating
11 - Do NOT add `@param`, `@returns`, or `@since` to components (use `@since` only if version is in the prompt and component is new)
12
13 ## Component Description Format
14
15 **Standard component:**
16 ```typescript
17 /**
18 * A clickable button element with multiple visual styles and sizes.
19 */
20 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(...)
21 ```
22
23 **Radix UI-based component:**
24 ```typescript
25 /**
26 * This component is based on the [Radix UI Tabs](https://radix-ui.com/primitives/docs/components/tabs) primitive.
27 */
28 const TabsRoot = (props: React.ComponentPropsWithoutRef<typeof RadixTabs.Root>) => {
29 ```
30
31 ## Inline Prop Documentation
32
33 Document props as inline comments inside the destructured parameter list:
34
35 ```typescript
36 // ✅ correct — inline prop docs
37 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
38 (
39 {
40 /**
41 * The button's visual style.
42 */
43 variant = "primary",
44 /**
45 * The button's size.
46 */
47 size = "base",
48 /**
49 * Whether to render as the child element instead of a `button`.
50 */
51 asChild = false,
52 /**
53 * Whether to show a loading spinner.
54 */
55 isLoading = false,
56 disabled,
57 className,
58 children,
59 ...props
60 },
61 ref
62 ) => {
63 ```
64
65 ```typescript
66 // ❌ wrong — separate interface TSDoc for each prop
67 interface ButtonProps {
68 /** The button's visual style. */
69 variant?: string
70 // ... (document interface props separately only if the interface itself is exported)
71 }
72 ```
73
74 > **Note:** If the `Props` interface is exported, document it and its properties too. If it's internal to the file, inline documentation on destructured params is preferred.
75
76 ## Props Interface (if exported)
77
78 ```typescript
79 /**
80 * The props for the Button component.
81 */
82 export interface ButtonProps
83 extends React.ComponentPropsWithoutRef<"button">,
84 VariantProps<typeof buttonVariants> {
85 /**
86 * Whether to show a loading spinner and disable interaction.
87 */
88 isLoading?: boolean
89 /**
90 * Whether to render as the child element instead of a `button`.
91 */
92 asChild?: boolean
93 }
94 ```
95
96 ## Full Before/After Example
97
98 **Before:**
99 ```typescript
100 interface ButtonProps
101 extends React.ComponentPropsWithoutRef<"button">,
102 VariantProps<typeof buttonVariants> {
103 isLoading?: boolean
104 asChild?: boolean
105 }
106
107 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
108 ({ variant = "primary", size = "base", asChild = false, isLoading = false, ...props }, ref) => {
109 // ...
110 }
111 )
112 ```
113
114 **After:**
115 ```typescript
116 interface ButtonProps
117 extends React.ComponentPropsWithoutRef<"button">,
118 VariantProps<typeof buttonVariants> {
119 isLoading?: boolean
120 asChild?: boolean
121 }
122
123 /**
124 * This component is based on the `button` element and supports all of its props.
125 */
126 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
127 (
128 {
129 /**
130 * The button's visual style.
131 */
132 variant = "primary",
133 /**
134 * The button's size.
135 */
136 size = "base",
137 /**
138 * Whether to render as the child element instead of a `button`.
139 */
140 asChild = false,
141 /**
142 * Whether to show a loading spinner.
143 */
144 isLoading = false,
145 ...props
146 },
147 ref
148 ) => {
149 // ...
150 }
151 )
152 ```
153
154 ## @excludeExternal — Hiding Inherited Props
155
156 When a component's `Props` interface extends a native HTML element type (e.g. `React.ComponentPropsWithoutRef<"div">`) or a third-party component type, it inherits many props (`className`, `children`, `style`, `id`, etc.) that don't need to appear in the generated docs.
157
158 Add `@excludeExternal` to the component's TSDoc block to suppress those inherited external props:
159
160 ```typescript
161 // AlertProps extends React.ComponentPropsWithoutRef<"div">, which includes
162 // className, children, style, id, onClick, etc.
163 interface AlertProps extends React.ComponentPropsWithoutRef<"div"> {
164 variant?: "error" | "success" | "warning" | "info"
165 dismissible?: boolean
166 }
167
168 /**
169 * This component is based on the div element and supports all of its props
170 *
171 * @excludeExternal
172 */
173 export const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
174 (
175 {
176 /**
177 * The variant of the alert
178 */
179 variant = "info",
180 /**
181 * Whether the alert is dismissible
182 */
183 dismissible = false,
184 className,
185 children,
186 ...props
187 }: AlertProps,
188 ref
189 ) => {
190 ```
191
192 If the component's `Props` interface only contains custom props (no `extends` of an external type), `@excludeExternal` can be omitted.
193
194 ## @keep — Preserving Specific External Props
195
196 `@excludeExternal` hides ALL inherited props. Use `@keep` on individual external props that are meaningful for the user to know about — for example, `disabled` or event handlers with non-obvious behavior in this component.
197
198 Add `@keep` (and optionally `@defaultValue`) inline on the prop:
199
200 ```typescript
201 /**
202 * This component is based on the input element and supports all of its props
203 *
204 * @excludeExternal
205 */
206 const CurrencyInput = React.forwardRef<HTMLInputElement, CurrencyInputProps>(
207 (
208 {
209 /**
210 * The input's size.
211 */
212 size = "base",
213 /**
214 * Whether the input is disabled.
215 *
216 * @keep
217 * @defaultValue false
218 */
219 disabled,
220 /**
221 * A function that is triggered when the input is invalid.
222 *
223 * @keep
224 */
225 onInvalid,
226 ...props
227 }: CurrencyInputProps,
228 ref
229 ) => {
230 ```
231
232 > **When to use `@keep`:** On inherited props with non-obvious behavior in this component (e.g. `disabled` triggers a custom visual state, `onInvalid` is wired to internal validation). Do NOT `@keep` generic passthrough props like `className`, `style`, or `id`.
233
234 ## Radix-based Passthrough Components
235
236 For thin wrappers that only add styling and forward all Radix props:
237
238 ```typescript
239 /**
240 * This component is based on the [Radix UI Dialog](https://radix-ui.com/primitives/docs/components/dialog) primitive.
241 */
242 const DialogRoot = (
243 props: React.ComponentPropsWithoutRef<typeof RadixDialog.Root>
244 ) => {
245 return <RadixDialog.Root {...props} />
246 }
247 ```
248
249 No `@excludeExternal` needed here — there are no custom props and no individual prop docs.