Skip to content

Commit ed675cd

Browse files
committed
refactor: update documentation and examples for form components
1 parent 1cc87a0 commit ed675cd

File tree

12 files changed

+25
-128
lines changed

12 files changed

+25
-128
lines changed

packages/ui/src/components/form/caption.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ interface CaptionProps extends PropsWithChildren {
1010
/**
1111
* Caption component that renders supplementary text below form inputs.
1212
* Used to provide additional context or hints for form fields.
13-
*
14-
* @param {CaptionProps} props - The properties for the Caption component.
15-
* @param {React.ReactNode} props.children - The content to be displayed as the caption text.
16-
* @param {string} [props.className] - Optional additional class names for styling.
17-
* @returns {JSX.Element} The rendered Caption component.
13+
* @example
14+
* <Caption>This is a caption</Caption>
1815
*/
1916
export function Caption({ children, className }: CaptionProps) {
2017
return (

packages/ui/src/components/form/checkbox.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ interface CheckboxProps extends ComponentPropsWithoutRef<typeof CheckboxPrimitiv
99
/**
1010
* Checkbox component that provides a customizable, accessible checkbox input.
1111
* Built on top of Radix UI Checkbox primitive with additional styling.
12-
*
13-
* @param {CheckboxProps} props - The properties for the Checkbox component.
14-
* @param {string} [props.className] - Optional additional class names for styling.
15-
* @param {React.Ref<HTMLButtonElement>} ref - Forward ref for the checkbox element.
16-
* @returns {JSX.Element} The rendered Checkbox component.
12+
* @example
13+
* <Checkbox id="checkbox" checked={checkboxValue} onCheckedChange={checkboxChange} />
1714
*/
1815
const Checkbox = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
1916
({ className, ...props }, ref) => (
2017
<div className={cn('flex gap-x-2.5', className)}>
2118
<CheckboxPrimitive.Root
2219
ref={ref}
23-
className="peer size-4 shrink-0 rounded-sm border border-icons-1 shadow hover:border-icons-3 disabled:cursor-not-allowed disabled:border-icons-4 data-[state=checked]:border-icons-2 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground"
20+
className="border-icons-1 hover:border-icons-3 disabled:border-icons-4 data-[state=checked]:border-icons-2 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer size-4 shrink-0 rounded-sm border shadow disabled:cursor-not-allowed"
2421
{...props}
2522
>
2623
<CheckboxPrimitive.Indicator className={cn('flex items-center justify-center text-current')}>

packages/ui/src/components/form/control-group.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ interface ControlGroupProps extends HTMLAttributes<HTMLDivElement> {
88

99
/**
1010
* A container component that groups form control elements together.
11-
*
12-
* @param props.type - Specifies the type of control group ('button' or 'input').
13-
* Affects spacing and ARIA labels.
14-
* @param props.children - The form control elements to be grouped (Label, Input/Button,
15-
* ErrorMessage, Caption, etc.).
16-
* @param props.className - Additional CSS classes to apply to the control group.
11+
* @example
12+
* <ControlGroup type="button">
13+
* <Button>Button</Button>
14+
* </ControlGroup>
1715
*/
1816
export function ControlGroup({ children, type, className, ...props }: ControlGroupProps) {
1917
return (

packages/ui/src/components/form/fieldset.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ interface FieldsetProps extends HTMLAttributes<HTMLFieldSetElement> {
99

1010
/**
1111
* A form fieldset component that groups related form elements.
12-
* @component
13-
* @param {FieldsetProps} props - The component props
14-
* @param {ReactNode} props.children - The content to be rendered inside the fieldset
15-
* @param {boolean} [props.box] - When true, adds border and padding to create a box around the fieldset
16-
* @param {boolean} [props.shaded] - When true, adds a subtle background color to the fieldset
17-
* @param {string} [props.className] - Additional CSS classes to apply to the fieldset
18-
* @returns {JSX.Element} A styled fieldset element
12+
* @example
13+
* <Fieldset box shaded>
14+
* <div>Form elements</div>
15+
* </Fieldset>
1916
*/
2017
export function Fieldset({ children, box, shaded, className, ...props }: FieldsetProps) {
2118
return (

packages/ui/src/components/form/input.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export interface BaseInputProps
88
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>,
99
VariantProps<typeof inputVariants> {}
1010

11-
const inputVariants = cva('bg-transparent px-2.5 py-1 text-foreground-1 disabled:cursor-not-allowed', {
11+
const inputVariants = cva('text-foreground-1 bg-transparent px-2.5 py-1 disabled:cursor-not-allowed', {
1212
variants: {
1313
variant: {
1414
default:
15-
'flex w-full rounded border text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-4 focus-visible:rounded focus-visible:outline-none',
15+
'placeholder:text-foreground-4 flex w-full rounded border text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:rounded focus-visible:outline-none',
1616
extended: 'grow border-none focus-visible:outline-none'
1717
},
1818
size: {
@@ -56,20 +56,6 @@ interface InputProps extends BaseInputProps {
5656

5757
/**
5858
* A form input component with support for labels, captions, and error messages.
59-
*
60-
* @component
61-
* @param {Object} props - The component props
62-
* @param {string} [props.label] - Optional label text displayed above the input
63-
* @param {ReactNode} [props.caption] - Optional caption text displayed below the input
64-
* @param {InputError} [props.error] - Error configuration object containing theme and message
65-
* @param {string} [props.id] - Input element ID, used for label association
66-
* @param {MessageTheme} [props.theme] - Visual theme of the input
67-
* @param {boolean} [props.disabled] - Whether the input is disabled
68-
* @param {boolean} [props.optional] - Indicates if the field is optional, displays "(Optional)" in the label
69-
* @param {string} [props.className] - Optional additional class names for the input element
70-
* @param {string} [props.wrapperClassName] - Optional additional class names for the wrapper element
71-
* @param {BaseInputProps} props.rest - All other props are passed to the underlying input element
72-
*
7359
* @example
7460
* <Input
7561
* label="Email"

packages/ui/src/components/form/label.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,13 @@ interface LabelProps extends VariantProps<typeof labelVariants>, PropsWithChildr
4141
/**
4242
* A Label component that wraps the Radix UI LabelPrimitive.Root component.
4343
* It supports variant and color styling through class-variance-authority.
44-
*
45-
* @param {Object} props - The properties object.
46-
* @param {string} [props.htmlFor] - The id of the element this label is associated with.
47-
* @param {boolean} [props.optional] - If true, renders "(optional)" next to the label text.
48-
* @param {string} [props.color] - The color variant of the label.
49-
* @param {string} [props.variant] - The style variant of the label.
50-
* @param {React.ReactNode} props.children - The content of the label.
51-
* @param {string} [props.className] - Additional class names to apply to the label.
52-
* @returns {JSX.Element} The rendered label component.
44+
* @example
45+
* <Label htmlFor="label" optional>Label</Label>
5346
*/
5447
const Label = ({ htmlFor, optional, color, variant, children, className }: LabelProps) => {
5548
return (
5649
<LabelRoot htmlFor={htmlFor} variant={variant} color={color} className={className}>
57-
{children} {optional && <span className="align-top text-foreground-7">(optional)</span>}
50+
{children} {optional && <span className="text-foreground-7 align-top">(optional)</span>}
5851
</LabelRoot>
5952
)
6053
}

packages/ui/src/components/form/legend.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@ interface LegendProps {
1111
/**
1212
* Legend component for form fieldsets
1313
*
14-
* @component
1514
* @example
16-
* ```tsx
1715
* <Legend
1816
* title="Personal Information"
1917
* description="Please fill in your details below"
2018
* />
21-
* ```
22-
*
23-
* @param {object} props - Component props
24-
* @param {ReactNode} props.title - The main title text or element
25-
* @param {ReactNode} [props.description] - Optional description text or element
26-
* @param {string} [props.className] - Optional CSS class name for custom styling
27-
* @returns {JSX.Element} A legend component with title and optional description
2819
*/
2920
export function Legend({ title, description, className }: LegendProps) {
3021
return (

packages/ui/src/components/form/message.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,16 @@ const themeClassMap: Record<MessageTheme, string> = {
2323

2424
/**
2525
* Message component for displaying status or error messages with different themes.
26-
*
2726
* This component is typically used in forms to provide feedback to users, such as success, warning, or error messages.
2827
*
29-
* @component
30-
* @param {MessageProps} props - The properties for the Message component.
31-
* @param {MessageTheme} props.theme - The visual theme of the message (success, warning, error, or default).
32-
* This also affects accessibility attributes.
33-
* @param {React.ReactNode} props.children - The content of the message to display.
34-
* @param {string} [props.className] - Additional CSS classes to apply to the message container.
35-
*
36-
* @returns {JSX.Element} The rendered Message component.
37-
*
3828
* @example
39-
* ```tsx
4029
* <Message theme={MessageTheme.ERROR}>
4130
* This field is required
4231
* </Message>
4332
*
4433
* <Message theme={MessageTheme.SUCCESS}>
4534
* Changes saved successfully
4635
* </Message>
47-
* ```
48-
*
49-
* @remarks
50-
* - Uses appropriate ARIA roles ('alert' for errors, 'status' for other themes).
51-
* - Sets aria-live appropriately ('assertive' for errors, 'polite' for other themes).
52-
* - Applies theme-specific text colors through Tailwind classes.
5336
*/
5437
export function Message({ children, theme, className }: MessageProps) {
5538
const textClass = themeClassMap[theme]

packages/ui/src/components/form/option.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,17 @@ import { cn } from '@utils/cn'
55

66
type ControlType = ReactElement<typeof RadioButton> | ReactElement<typeof Checkbox>
77

8-
/**
9-
* Interface for Option component props
10-
*/
118
interface OptionProps {
12-
/** The radio button or checkbox control element */
139
control: ControlType
14-
/** Unique identifier for the input */
1510
id: string
16-
/** Label text for the input */
1711
label?: string
18-
/** Optional description text or node below the label */
1912
description?: string | ReactNode
20-
/** Additional CSS classes */
2113
className?: string
22-
/** Indicates if the item is currently selected */
2314
ariaSelected?: boolean
2415
}
2516

2617
/**
2718
* Individual item that contains a control (radio button or checkbox) with optional label and description
28-
* @component
2919
* @example
3020
* <Option
3121
* control={<RadioButton value="option1" />}

packages/ui/src/components/form/select.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,21 @@ interface SelectError {
1212
message?: string
1313
}
1414

15-
/**
16-
* Props for the Select component
17-
* @interface SelectProps
18-
* @extends {PropsWithChildren}
19-
* @extends {SelectPrimitive.SelectProps}
20-
*/
2115
interface SelectProps extends PropsWithChildren, SelectPrimitive.SelectProps {
22-
/** Label text displayed above the select */
2316
label?: string
24-
/** Error state configuration */
2517
error?: SelectError
26-
/** Optional caption text displayed below the select */
2718
caption?: ReactNode
28-
/** Whether the select is disabled */
2919
disabled?: boolean
30-
/** Placeholder text shown when no option is selected */
3120
placeholder: string
3221
}
3322

3423
/**
3524
* A customizable select component that supports labels, error states, and captions
36-
* @param {SelectProps} props - The component props
37-
* @returns {JSX.Element} The Select component
25+
* @example
26+
* <Select name="select" label="Select an option" placeholder="Select an option">
27+
* <SelectItem value="option1">Option 1</SelectItem>
28+
* <SelectItem value="option2">Option 2</SelectItem>
29+
* </Select>
3830
*/
3931
const Select: FC<SelectProps> = ({
4032
name,
@@ -72,8 +64,6 @@ const SelectValue = SelectPrimitive.Value
7264

7365
/**
7466
* The trigger button for the select dropdown
75-
* @param {ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & { iconClassName?: string }} props - The component props
76-
* @returns {JSX.Element} The SelectTrigger component
7767
*/
7868
const SelectTrigger = forwardRef<
7969
ElementRef<typeof SelectPrimitive.Trigger>,
@@ -97,8 +87,6 @@ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
9787

9888
/**
9989
* The content container for the select dropdown
100-
* @param {ComponentPropsWithoutRef<typeof SelectPrimitive.Content>} props - The component props
101-
* @returns {JSX.Element} The SelectContent component
10290
*/
10391
const SelectContent = forwardRef<
10492
ElementRef<typeof SelectPrimitive.Content>,
@@ -132,8 +120,6 @@ SelectContent.displayName = SelectPrimitive.Content.displayName
132120

133121
/**
134122
* A label component for grouping select items
135-
* @param {ComponentPropsWithoutRef<typeof SelectPrimitive.Label>} props - The component props
136-
* @returns {JSX.Element} The SelectLabel component
137123
*/
138124
const SelectLabel = forwardRef<
139125
ElementRef<typeof SelectPrimitive.Label>,
@@ -145,8 +131,6 @@ SelectLabel.displayName = SelectPrimitive.Label.displayName
145131

146132
/**
147133
* An individual selectable item within the dropdown
148-
* @param {ComponentPropsWithoutRef<typeof SelectPrimitive.Item>} props - The component props
149-
* @returns {JSX.Element} The SelectItem component
150134
*/
151135
const SelectItem = forwardRef<
152136
ElementRef<typeof SelectPrimitive.Item>,
@@ -172,8 +156,6 @@ SelectItem.displayName = SelectPrimitive.Item.displayName
172156

173157
/**
174158
* A visual separator between select items
175-
* @param {ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>} props - The component props
176-
* @returns {JSX.Element} The SelectSeparator component
177159
*/
178160
const SelectSeparator = forwardRef<
179161
ElementRef<typeof SelectPrimitive.Separator>,

0 commit comments

Comments
 (0)