@primitiv-ui/react 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +2 -1
  3. package/src/AccessibleIcon/AccessibleIcon.tsx +1 -0
  4. package/src/AccessibleIcon/types.ts +4 -0
  5. package/src/Accordion/Accordion.tsx +23 -0
  6. package/src/Accordion/index.ts +2 -1
  7. package/src/Accordion/types.ts +55 -13
  8. package/src/Alert/Alert.tsx +1 -0
  9. package/src/Alert/types.ts +1 -0
  10. package/src/Avatar/Avatar.tsx +8 -4
  11. package/src/Avatar/AvatarContext.ts +2 -0
  12. package/src/Breadcrumb/Breadcrumb.tsx +15 -7
  13. package/src/Button/Button.tsx +1 -0
  14. package/src/Button/types.ts +4 -0
  15. package/src/Carousel/Carousel.tsx +9 -0
  16. package/src/Carousel/CarouselContext.ts +5 -2
  17. package/src/Carousel/types.ts +8 -0
  18. package/src/Checkbox/Checkbox.tsx +7 -3
  19. package/src/Checkbox/index.ts +1 -0
  20. package/src/Checkbox/types.ts +30 -3
  21. package/src/CheckboxCard/CheckboxCard.tsx +9 -8
  22. package/src/CheckboxCard/CheckboxCardContext.ts +9 -1
  23. package/src/CheckboxCard/hooks/useCheckboxCardRoot.ts +1 -1
  24. package/src/CheckboxCard/types.ts +21 -5
  25. package/src/Collapsible/Collapsible.tsx +15 -0
  26. package/src/Collapsible/index.ts +1 -0
  27. package/src/Collapsible/types.ts +45 -12
  28. package/src/ContextMenu/ContextMenu.tsx +40 -15
  29. package/src/ContextMenu/index.ts +2 -1
  30. package/src/ContextMenu/types.ts +159 -16
  31. package/src/DirectionProvider/DirectionProvider.tsx +1 -0
  32. package/src/DirectionProvider/types.ts +1 -0
  33. package/src/Divider/Divider.tsx +1 -0
  34. package/src/Divider/index.ts +2 -1
  35. package/src/Divider/types.ts +5 -0
  36. package/src/Dropdown/Dropdown.tsx +40 -15
  37. package/src/Dropdown/index.ts +2 -1
  38. package/src/Dropdown/types.ts +152 -24
  39. package/src/EmptyState/EmptyState.tsx +26 -14
  40. package/src/EmptyState/types.ts +2 -1
  41. package/src/Field/Field.tsx +14 -5
  42. package/src/Field/types.ts +4 -0
  43. package/src/Fieldset/Fieldset.tsx +17 -10
  44. package/src/Fieldset/types.ts +2 -0
  45. package/src/Input/Input.tsx +1 -0
  46. package/src/Input/types.ts +4 -0
  47. package/src/InputGroup/InputGroup.tsx +9 -4
  48. package/src/InputGroup/types.ts +9 -0
  49. package/src/MillerColumns/MillerColumns.tsx +19 -0
  50. package/src/MillerColumns/index.ts +1 -1
  51. package/src/MillerColumns/types.ts +67 -14
  52. package/src/Modal/Modal.tsx +1 -0
  53. package/src/Modal/ModalContext.ts +5 -2
  54. package/src/Modal/types.ts +51 -2
  55. package/src/Portal/Portal.tsx +1 -0
  56. package/src/Portal/types.ts +4 -0
  57. package/src/Progress/Progress.tsx +7 -3
  58. package/src/Progress/ProgressContext.ts +7 -0
  59. package/src/RadioCard/RadioCard.tsx +9 -4
  60. package/src/RadioCard/RadioCardContext.ts +7 -0
  61. package/src/RadioCard/RadioCardItemContext.ts +8 -0
  62. package/src/RadioCard/types.ts +24 -3
  63. package/src/RadioGroup/RadioGroup.tsx +9 -4
  64. package/src/RadioGroup/index.ts +1 -0
  65. package/src/RadioGroup/types.ts +34 -3
  66. package/src/Select/Select.tsx +16 -5
  67. package/src/Select/index.ts +1 -1
  68. package/src/Select/types.ts +18 -3
  69. package/src/Slider/Slider.tsx +10 -5
  70. package/src/Slider/SliderContext.ts +3 -0
  71. package/src/Slider/types.ts +12 -3
  72. package/src/Status/Status.tsx +1 -0
  73. package/src/Status/types.ts +4 -0
  74. package/src/Switch/Switch.tsx +8 -3
  75. package/src/Switch/SwitchContext.ts +4 -0
  76. package/src/Switch/types.ts +24 -3
  77. package/src/Table/Table.tsx +44 -24
  78. package/src/Table/index.ts +2 -1
  79. package/src/Tabs/Tabs.tsx +7 -2
  80. package/src/Tabs/TabsContext.ts +7 -2
  81. package/src/Tabs/types.ts +35 -1
  82. package/src/Textarea/Textarea.tsx +1 -0
  83. package/src/Textarea/types.ts +4 -0
  84. package/src/Toggle/Toggle.tsx +1 -0
  85. package/src/Toggle/types.ts +7 -3
  86. package/src/ToggleGroup/ToggleGroup.tsx +9 -3
  87. package/src/ToggleGroup/types.ts +45 -5
  88. package/src/Tooltip/Tooltip.tsx +25 -7
  89. package/src/Tooltip/index.ts +1 -0
  90. package/src/Tooltip/types.ts +50 -2
  91. package/src/Tree/Tree.tsx +46 -1
  92. package/src/Tree/index.ts +1 -1
  93. package/src/Tree/types.ts +39 -7
  94. package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
  95. package/src/VisuallyHidden/types.ts +4 -0
  96. package/src/index.ts +1 -0
  97. package/src/types.ts +1 -0
@@ -10,30 +10,48 @@ export type RadioCardOrientation = "horizontal" | "vertical" | "both";
10
10
  /** Reading direction — swaps the horizontal arrow pair when `"rtl"`. */
11
11
  export type RadioCardReadingDirection = "ltr" | "rtl";
12
12
 
13
- type RadioCardRootBaseProps = Omit<ComponentProps<"div">, "role"> & {
13
+ /** Props shared by both controlled and uncontrolled `RadioCard.Root` usage.
14
+ * Extends the native `<div>` props (minus `role`). */
15
+ export type RadioCardRootBaseProps = Omit<ComponentProps<"div">, "role"> & {
14
16
  children?: ReactNode;
17
+ /** Ref to the rendered root element. */
15
18
  ref?: Ref<HTMLDivElement>;
19
+ /** Render the child element instead of the default `<div>`. */
16
20
  asChild?: boolean;
21
+ /** Which arrow keys navigate the group. */
17
22
  orientation?: RadioCardOrientation;
23
+ /** Reading direction for horizontal arrow navigation. */
18
24
  dir?: RadioCardReadingDirection;
19
25
  };
20
26
 
21
- type RadioCardRootUncontrolledProps = RadioCardRootBaseProps & {
27
+ /** Uncontrolled `RadioCard.Root` props: the component owns the selection,
28
+ * seeded by an optional `defaultValue`. */
29
+ export type RadioCardRootUncontrolledProps = RadioCardRootBaseProps & {
30
+ /** Value selected on first render. */
22
31
  defaultValue?: string;
23
32
  value?: never;
33
+ /** Called with the value when the selection changes. */
24
34
  onValueChange?: (value: string) => void;
25
35
  };
26
36
 
27
- type RadioCardRootControlledProps = RadioCardRootBaseProps & {
37
+ /** Controlled `RadioCard.Root` props: the caller owns the selection via
38
+ * `value` and is notified through the required `onValueChange`. */
39
+ export type RadioCardRootControlledProps = RadioCardRootBaseProps & {
28
40
  defaultValue?: never;
41
+ /** Value of the currently selected card. */
29
42
  value: string;
43
+ /** Called with the value when the user selects a card. */
30
44
  onValueChange: (value: string) => void;
31
45
  };
32
46
 
47
+ /** Props for `RadioCard.Root` — resolves to either the controlled or
48
+ * uncontrolled prop shape. */
33
49
  export type RadioCardRootProps =
34
50
  | RadioCardRootUncontrolledProps
35
51
  | RadioCardRootControlledProps;
36
52
 
53
+ /** Props for `RadioCard.Item` — a selectable card rendered as a
54
+ * `role="radio"` button, identified by its required `value`. */
37
55
  export type RadioCardItemProps = Omit<
38
56
  ComponentProps<"button">,
39
57
  "type" | "role" | "aria-checked" | "value"
@@ -44,6 +62,9 @@ export type RadioCardItemProps = Omit<
44
62
  asChild?: boolean;
45
63
  };
46
64
 
65
+ /** Props for `RadioCard.Indicator` — the visual marker rendered inside the
66
+ * selected item. By default it renders only when its item is checked; set
67
+ * `forceMount` to keep it mounted for exit transitions. */
47
68
  export type RadioCardIndicatorProps = ComponentProps<"span"> & {
48
69
  children?: ReactNode;
49
70
  forceMount?: boolean;
@@ -74,7 +74,7 @@ import {
74
74
  * </RadioGroup.Root>
75
75
  * ```
76
76
  */
77
- function RadioGroupRoot({
77
+ export function RadioGroupRoot({
78
78
  defaultValue,
79
79
  value: controlledValue,
80
80
  onValueChange,
@@ -130,6 +130,7 @@ function RadioGroupRoot({
130
130
  );
131
131
  }
132
132
 
133
+ /** @internal */
133
134
  RadioGroupRoot.displayName = "RadioGroupRoot";
134
135
 
135
136
  /**
@@ -164,7 +165,7 @@ RadioGroupRoot.displayName = "RadioGroupRoot";
164
165
  *
165
166
  * @throws if rendered outside a `RadioGroup.Root`.
166
167
  */
167
- function RadioGroupItem({
168
+ export function RadioGroupItem({
168
169
  value,
169
170
  children,
170
171
  onClick,
@@ -238,6 +239,7 @@ function RadioGroupItem({
238
239
  );
239
240
  }
240
241
 
242
+ /** @internal */
241
243
  RadioGroupItem.displayName = "RadioGroupItem";
242
244
 
243
245
  /**
@@ -278,7 +280,7 @@ RadioGroupItem.displayName = "RadioGroupItem";
278
280
  *
279
281
  * @throws if rendered outside a `RadioGroup.Item`.
280
282
  */
281
- function RadioGroupIndicator({
283
+ export function RadioGroupIndicator({
282
284
  children,
283
285
  forceMount,
284
286
  asChild = false,
@@ -297,9 +299,11 @@ function RadioGroupIndicator({
297
299
  return <span {...indicatorProps}>{children}</span>;
298
300
  }
299
301
 
302
+ /** @internal */
300
303
  RadioGroupIndicator.displayName = "RadioGroupIndicator";
301
304
 
302
- type TRadioGroupCompound = typeof RadioGroupRoot & {
305
+ /** Type of the {@link RadioGroup} compound: the root callable plus its attached sub-components. */
306
+ export type TRadioGroupCompound = typeof RadioGroupRoot & {
303
307
  Root: typeof RadioGroupRoot;
304
308
  Item: typeof RadioGroupItem;
305
309
  Indicator: typeof RadioGroupIndicator;
@@ -349,6 +353,7 @@ const RadioGroupCompound: TRadioGroupCompound = Object.assign(RadioGroupRoot, {
349
353
  Indicator: RadioGroupIndicator,
350
354
  });
351
355
 
356
+ /** @internal */
352
357
  RadioGroupCompound.displayName = "RadioGroup";
353
358
 
354
359
  export { RadioGroupCompound as RadioGroup };
@@ -1 +1,2 @@
1
1
  export * from "./RadioGroup";
2
+ export * from "./types";
@@ -10,7 +10,12 @@ export type RadioGroupOrientation = "horizontal" | "vertical" | "both";
10
10
  /** Reading direction — swaps the horizontal arrow pair when `"rtl"`. */
11
11
  export type RadioGroupReadingDirection = "ltr" | "rtl";
12
12
 
13
- type RadioGroupRootBaseProps = Omit<ComponentProps<"div">, "role"> & {
13
+ /**
14
+ * Shared base for both {@link RadioGroupRootProps} variants — the native
15
+ * `<div>` attributes (minus `role`) plus the `asChild` escape hatch,
16
+ * orientation, reading direction, and a typed `ref`.
17
+ */
18
+ export type RadioGroupRootBaseProps = Omit<ComponentProps<"div">, "role"> & {
14
19
  children?: ReactNode;
15
20
  ref?: Ref<HTMLDivElement>;
16
21
  asChild?: boolean;
@@ -18,22 +23,43 @@ type RadioGroupRootBaseProps = Omit<ComponentProps<"div">, "role"> & {
18
23
  dir?: RadioGroupReadingDirection;
19
24
  };
20
25
 
21
- type RadioGroupRootUncontrolledProps = RadioGroupRootBaseProps & {
26
+ /**
27
+ * Uncontrolled variant of {@link RadioGroupRootProps}: the component owns
28
+ * the selected value. Pass `defaultValue` (or omit it); `onValueChange` is
29
+ * optional and `value` is forbidden.
30
+ */
31
+ export type RadioGroupRootUncontrolledProps = RadioGroupRootBaseProps & {
22
32
  defaultValue?: string;
23
33
  value?: never;
24
34
  onValueChange?: (value: string) => void;
25
35
  };
26
36
 
27
- type RadioGroupRootControlledProps = RadioGroupRootBaseProps & {
37
+ /**
38
+ * Controlled variant of {@link RadioGroupRootProps}: the parent owns the
39
+ * selected value. Pass `value` and `onValueChange` together; `defaultValue`
40
+ * is forbidden.
41
+ */
42
+ export type RadioGroupRootControlledProps = RadioGroupRootBaseProps & {
28
43
  defaultValue?: never;
29
44
  value: string;
30
45
  onValueChange: (value: string) => void;
31
46
  };
32
47
 
48
+ /**
49
+ * Props for {@link RadioGroup.Root}. A discriminated union of
50
+ * {@link RadioGroupRootUncontrolledProps} and
51
+ * {@link RadioGroupRootControlledProps}, so TypeScript accepts exactly one
52
+ * state mode.
53
+ */
33
54
  export type RadioGroupRootProps =
34
55
  | RadioGroupRootUncontrolledProps
35
56
  | RadioGroupRootControlledProps;
36
57
 
58
+ /**
59
+ * Props for {@link RadioGroup.Item} — the radio button. `value` identifies
60
+ * the option; all native `<button>` attributes (minus the component-owned
61
+ * ones) plus the `asChild` escape hatch and a typed `ref` are passed through.
62
+ */
37
63
  export type RadioGroupItemProps = Omit<
38
64
  ComponentProps<"button">,
39
65
  "type" | "role" | "aria-checked" | "value"
@@ -44,6 +70,11 @@ export type RadioGroupItemProps = Omit<
44
70
  asChild?: boolean;
45
71
  };
46
72
 
73
+ /**
74
+ * Props for {@link RadioGroup.Indicator} — all `<span>` attributes plus
75
+ * `forceMount` (keep mounted while unselected for exit animations) and the
76
+ * `asChild` escape hatch.
77
+ */
47
78
  export type RadioGroupIndicatorProps = ComponentProps<"span"> & {
48
79
  children?: ReactNode;
49
80
  forceMount?: boolean;
@@ -52,7 +52,7 @@ function hasPlaceholderChild(children: ReactNode): boolean {
52
52
  * ids first, then field-supplied description / error ids). Outside a
53
53
  * `<Field.Root>`, behaviour is unchanged.
54
54
  */
55
- function SelectRoot({
55
+ export function SelectRoot({
56
56
  children,
57
57
  asChild = false,
58
58
  onChange,
@@ -96,6 +96,7 @@ function SelectRoot({
96
96
  return <select {...rootProps}>{children}</select>;
97
97
  }
98
98
 
99
+ /** @internal */
99
100
  SelectRoot.displayName = "SelectRoot";
100
101
 
101
102
  /**
@@ -105,10 +106,14 @@ SelectRoot.displayName = "SelectRoot";
105
106
  * Native `<option>` only renders text; rich content (icons, descriptions)
106
107
  * is not supported.
107
108
  */
108
- function SelectOption({ children, ...rest }: SelectOptionProps): ReactElement {
109
+ export function SelectOption({
110
+ children,
111
+ ...rest
112
+ }: SelectOptionProps): ReactElement {
109
113
  return <option {...rest}>{children}</option>;
110
114
  }
111
115
 
116
+ /** @internal */
112
117
  SelectOption.displayName = "SelectOption";
113
118
 
114
119
  /**
@@ -116,10 +121,14 @@ SelectOption.displayName = "SelectOption";
116
121
  * native `<optgroup>` element. The `label` is shown by the browser as a
117
122
  * non-selectable heading and is announced as the group's accessible name.
118
123
  */
119
- function SelectGroup({ children, ...rest }: SelectGroupProps): ReactElement {
124
+ export function SelectGroup({
125
+ children,
126
+ ...rest
127
+ }: SelectGroupProps): ReactElement {
120
128
  return <optgroup {...rest}>{children}</optgroup>;
121
129
  }
122
130
 
131
+ /** @internal */
123
132
  SelectGroup.displayName = "SelectGroup";
124
133
 
125
134
  /**
@@ -132,7 +141,7 @@ SelectGroup.displayName = "SelectGroup";
132
141
  * Pair with `required` on {@link Select.Root} to make the browser's
133
142
  * native form validation catch an unchosen value at submission.
134
143
  */
135
- function SelectPlaceholder({
144
+ export function SelectPlaceholder({
136
145
  children,
137
146
  ...rest
138
147
  }: SelectPlaceholderProps): ReactElement {
@@ -143,9 +152,11 @@ function SelectPlaceholder({
143
152
  );
144
153
  }
145
154
 
155
+ /** @internal */
146
156
  SelectPlaceholder.displayName = "SelectPlaceholder";
147
157
 
148
- type TSelectCompound = typeof SelectRoot & {
158
+ /** Type of the {@link Select} compound: the root callable plus its attached sub-components. */
159
+ export type TSelectCompound = typeof SelectRoot & {
149
160
  Root: typeof SelectRoot;
150
161
  Option: typeof SelectOption;
151
162
  Group: typeof SelectGroup;
@@ -1,2 +1,2 @@
1
- export { Select } from "./Select";
1
+ export * from "./Select";
2
2
  export * from "./types";
@@ -1,6 +1,11 @@
1
1
  import { ChangeEventHandler, ComponentProps, ReactNode, Ref } from "react";
2
2
 
3
- type SelectRootBaseProps = Omit<
3
+ /**
4
+ * Shared base for both {@link SelectRootProps} variants — the native
5
+ * `<select>` attributes (minus the state-owning ones), the `asChild`
6
+ * escape hatch, and the raw `onChange` passthrough.
7
+ */
8
+ export type SelectRootBaseProps = Omit<
4
9
  ComponentProps<"select">,
5
10
  "value" | "defaultValue" | "multiple" | "onChange"
6
11
  > & {
@@ -22,13 +27,23 @@ type SelectRootBaseProps = Omit<
22
27
  asChild?: boolean;
23
28
  };
24
29
 
25
- type SelectRootUncontrolledProps = SelectRootBaseProps & {
30
+ /**
31
+ * Uncontrolled variant of {@link SelectRootProps}: the browser owns the
32
+ * selection. Pass `defaultValue` (or omit it); `onValueChange` is optional
33
+ * and `value` is forbidden.
34
+ */
35
+ export type SelectRootUncontrolledProps = SelectRootBaseProps & {
26
36
  defaultValue?: string;
27
37
  value?: never;
28
38
  onValueChange?: (value: string) => void;
29
39
  };
30
40
 
31
- type SelectRootControlledProps = SelectRootBaseProps & {
41
+ /**
42
+ * Controlled variant of {@link SelectRootProps}: the parent owns the
43
+ * selection. Pass `value` and `onValueChange` together; `defaultValue` is
44
+ * forbidden.
45
+ */
46
+ export type SelectRootControlledProps = SelectRootBaseProps & {
32
47
  defaultValue?: never;
33
48
  value: string;
34
49
  onValueChange: (value: string) => void;
@@ -74,7 +74,7 @@ import { getRangeStyle } from "./utils";
74
74
  * </Slider.Root>
75
75
  * ```
76
76
  */
77
- function SliderRoot({
77
+ export function SliderRoot({
78
78
  min = 0,
79
79
  max = 100,
80
80
  step = 1,
@@ -142,6 +142,7 @@ function SliderRoot({
142
142
  );
143
143
  }
144
144
 
145
+ /** @internal */
145
146
  SliderRoot.displayName = "SliderRoot";
146
147
 
147
148
  /**
@@ -153,7 +154,7 @@ SliderRoot.displayName = "SliderRoot";
153
154
  *
154
155
  * @throws if rendered outside a `Slider.Root`.
155
156
  */
156
- function SliderTrack({
157
+ export function SliderTrack({
157
158
  children,
158
159
  asChild = false,
159
160
  ...rest
@@ -171,6 +172,7 @@ function SliderTrack({
171
172
  );
172
173
  }
173
174
 
175
+ /** @internal */
174
176
  SliderTrack.displayName = "SliderTrack";
175
177
 
176
178
  /**
@@ -183,7 +185,7 @@ SliderTrack.displayName = "SliderTrack";
183
185
  *
184
186
  * @throws if rendered outside a `Slider.Root`.
185
187
  */
186
- function SliderRange({
188
+ export function SliderRange({
187
189
  style,
188
190
  asChild = false,
189
191
  children,
@@ -207,6 +209,7 @@ function SliderRange({
207
209
  );
208
210
  }
209
211
 
212
+ /** @internal */
210
213
  SliderRange.displayName = "SliderRange";
211
214
 
212
215
  /**
@@ -230,7 +233,7 @@ SliderRange.displayName = "SliderRange";
230
233
  *
231
234
  * @throws if rendered outside a `Slider.Root`.
232
235
  */
233
- function SliderThumb({
236
+ export function SliderThumb({
234
237
  style,
235
238
  ref: forwardedRef,
236
239
  onKeyDown,
@@ -270,9 +273,11 @@ function SliderThumb({
270
273
  );
271
274
  }
272
275
 
276
+ /** @internal */
273
277
  SliderThumb.displayName = "SliderThumb";
274
278
 
275
- type TSliderCompound = typeof SliderRoot & {
279
+ /** Static-property shape of the compound {@link Slider} export: the callable {@link SliderRoot} plus its namespaced sub-components. */
280
+ export type TSliderCompound = typeof SliderRoot & {
276
281
  Root: typeof SliderRoot;
277
282
  Track: typeof SliderTrack;
278
283
  Range: typeof SliderRange;
@@ -3,6 +3,7 @@ import { createStrictContext } from "../utils/index.ts";
3
3
 
4
4
  import type { SliderDirection, SliderOrientation } from "./types";
5
5
 
6
+ /** Shared state published by `Slider.Root` to its sub-components: the current values, range/step bounds, orientation and direction, thumb registration, and value-commit callbacks. */
6
7
  export type SliderContextValue = {
7
8
  values: number[];
8
9
  min: number;
@@ -23,6 +24,8 @@ const sliderContextPair = createStrictContext<SliderContextValue>(
23
24
  "SliderContext",
24
25
  );
25
26
 
27
+ /** React context carrying the {@link SliderContextValue} shared by the slider's sub-components. */
26
28
  export const SliderContext: Context<SliderContextValue | null> =
27
29
  sliderContextPair[0];
30
+ /** Hook returning the {@link SliderContextValue}; throws when used outside a `<Slider.Root>`. */
28
31
  export const useSliderContext: () => SliderContextValue = sliderContextPair[1];
@@ -1,9 +1,12 @@
1
1
  import type { ComponentProps } from "react";
2
2
 
3
+ /** Layout axis of the slider track. */
3
4
  export type SliderOrientation = "horizontal" | "vertical";
5
+ /** Reading direction of the slider, affecting which end is the minimum. */
4
6
  export type SliderDirection = "ltr" | "rtl";
5
7
 
6
- type SliderRootSharedProps = Omit<
8
+ /** Props common to both controlled and uncontrolled `Slider.Root`: range/step bounds, orientation, direction, and the native `<span>` attributes. */
9
+ export type SliderRootSharedProps = Omit<
7
10
  ComponentProps<"span">,
8
11
  "defaultValue" | "dir"
9
12
  > & {
@@ -19,30 +22,36 @@ type SliderRootSharedProps = Omit<
19
22
  asChild?: boolean;
20
23
  };
21
24
 
22
- type SliderRootUncontrolledProps = SliderRootSharedProps & {
25
+ /** Uncontrolled `Slider.Root` props: seed with `defaultValue`; `value` is disallowed. */
26
+ export type SliderRootUncontrolledProps = SliderRootSharedProps & {
23
27
  defaultValue?: number[];
24
28
  value?: never;
25
29
  onValueChange?: (value: number[]) => void;
26
30
  onValueCommit?: (value: number[]) => void;
27
31
  };
28
32
 
29
- type SliderRootControlledProps = SliderRootSharedProps & {
33
+ /** Controlled `Slider.Root` props: drive with `value`; `defaultValue` is disallowed. */
34
+ export type SliderRootControlledProps = SliderRootSharedProps & {
30
35
  defaultValue?: never;
31
36
  value: number[];
32
37
  onValueChange?: (value: number[]) => void;
33
38
  onValueCommit?: (value: number[]) => void;
34
39
  };
35
40
 
41
+ /** Props for `Slider.Root` — the discriminated union of controlled ({@link SliderRootControlledProps}) and uncontrolled ({@link SliderRootUncontrolledProps}) modes. */
36
42
  export type SliderRootProps =
37
43
  | SliderRootUncontrolledProps
38
44
  | SliderRootControlledProps;
39
45
 
46
+ /** Props for `Slider.Track` — the full-length rail; native `<span>` props plus `asChild`. */
40
47
  export type SliderTrackProps = ComponentProps<"span"> & {
41
48
  asChild?: boolean;
42
49
  };
50
+ /** Props for `Slider.Range` — the filled segment between the minimum and the active thumb; native `<span>` props plus `asChild`. */
43
51
  export type SliderRangeProps = ComponentProps<"span"> & {
44
52
  asChild?: boolean;
45
53
  };
54
+ /** Props for `Slider.Thumb` — a draggable handle; native `<span>` props plus `asChild`. */
46
55
  export type SliderThumbProps = ComponentProps<"span"> & {
47
56
  asChild?: boolean;
48
57
  };
@@ -47,4 +47,5 @@ export function Status({
47
47
  return <div {...rootProps}>{children}</div>;
48
48
  }
49
49
 
50
+ /** @internal */
50
51
  Status.displayName = "Status";
@@ -1,5 +1,9 @@
1
1
  import { ComponentProps } from "react";
2
2
 
3
+ /**
4
+ * Props for {@link Status} — all native `<div>` attributes plus the
5
+ * `asChild` escape hatch.
6
+ */
3
7
  export type StatusProps = ComponentProps<"div"> & {
4
8
  asChild?: boolean;
5
9
  };
@@ -49,7 +49,7 @@ import { SwitchRootProps, SwitchThumbProps } from "./types";
49
49
  * </Switch.Root>
50
50
  * ```
51
51
  */
52
- function SwitchRoot({
52
+ export function SwitchRoot({
53
53
  defaultChecked,
54
54
  checked,
55
55
  onCheckedChange,
@@ -89,6 +89,7 @@ function SwitchRoot({
89
89
  );
90
90
  }
91
91
 
92
+ /** @internal */
92
93
  SwitchRoot.displayName = "SwitchRoot";
93
94
 
94
95
  /**
@@ -112,7 +113,7 @@ SwitchRoot.displayName = "SwitchRoot";
112
113
  *
113
114
  * @throws if rendered outside a `Switch.Root`.
114
115
  */
115
- function SwitchThumb({
116
+ export function SwitchThumb({
116
117
  children,
117
118
  asChild = false,
118
119
  ...rest
@@ -129,10 +130,14 @@ function SwitchThumb({
129
130
  return <span {...thumbProps}>{children}</span>;
130
131
  }
131
132
 
133
+ /** @internal */
132
134
  SwitchThumb.displayName = "SwitchThumb";
133
135
 
134
- type TSwitchCompound = typeof SwitchRoot & {
136
+ /** Type of the {@link Switch} compound — the Root callable plus its sub-components. */
137
+ export type TSwitchCompound = typeof SwitchRoot & {
138
+ /** The root toggle button, owning checked state and context. */
135
139
  Root: typeof SwitchRoot;
140
+ /** The sliding thumb indicator. */
136
141
  Thumb: typeof SwitchThumb;
137
142
  };
138
143
 
@@ -1,7 +1,9 @@
1
1
  import type { Context } from "react";
2
2
  import { createStrictContext } from "../utils/index.ts";
3
3
 
4
+ /** Value shared from `Switch.Root` to `Switch.Thumb` through context. */
4
5
  export type SwitchContextValue = {
6
+ /** Whether the switch is currently checked. */
5
7
  checked: boolean;
6
8
  };
7
9
 
@@ -9,6 +11,8 @@ const switchContextPair = createStrictContext<SwitchContextValue>(
9
11
  "Switch.Thumb must be rendered inside a <Switch.Root>.",
10
12
  );
11
13
 
14
+ /** React context carrying the {@link SwitchContextValue} for `Switch.Thumb`. */
12
15
  export const SwitchContext: Context<SwitchContextValue | null> =
13
16
  switchContextPair[0];
17
+ /** Read the nearest {@link SwitchContextValue}; throws outside `Switch.Root`. */
14
18
  export const useSwitchContext: () => SwitchContextValue = switchContextPair[1];
@@ -1,25 +1,43 @@
1
1
  import { ButtonHTMLAttributes, ComponentProps, ReactNode, Ref } from "react";
2
2
 
3
- type SwitchRootBaseProps = Omit<
3
+ /** Props common to both controlled and uncontrolled `Switch.Root` modes. */
4
+ export type SwitchRootBaseProps = Omit<
4
5
  ButtonHTMLAttributes<HTMLButtonElement>,
5
6
  "type" | "role" | "aria-checked"
6
7
  > & {
8
+ /** Render the child element instead of the default `<button>`. */
7
9
  asChild?: boolean;
10
+ /** Ref to the rendered `<button>` element. */
8
11
  ref?: Ref<HTMLButtonElement>;
9
12
  };
10
13
 
11
- type SwitchRootUncontrolledProps = SwitchRootBaseProps & {
14
+ /**
15
+ * Props for `Switch.Root` in uncontrolled mode — the component owns the checked
16
+ * state. Pass `defaultChecked` to set the initial value; `checked` is forbidden.
17
+ */
18
+ export type SwitchRootUncontrolledProps = SwitchRootBaseProps & {
19
+ /** Initial checked state when uncontrolled. */
12
20
  defaultChecked?: boolean;
21
+ /** Forbidden in uncontrolled mode. */
13
22
  checked?: never;
23
+ /** Called whenever the checked state changes. */
14
24
  onCheckedChange?: (checked: boolean) => void;
15
25
  };
16
26
 
17
- type SwitchRootControlledProps = SwitchRootBaseProps & {
27
+ /**
28
+ * Props for `Switch.Root` in controlled mode — the parent owns the checked
29
+ * value. Pass `checked` and `onCheckedChange` together.
30
+ */
31
+ export type SwitchRootControlledProps = SwitchRootBaseProps & {
32
+ /** Forbidden in controlled mode. */
18
33
  defaultChecked?: never;
34
+ /** The controlled checked state. */
19
35
  checked: boolean;
36
+ /** Called whenever the component requests a checked-state change. */
20
37
  onCheckedChange: (checked: boolean) => void;
21
38
  };
22
39
 
40
+ /** Props for `Switch.Root` — discriminated controlled/uncontrolled union. */
23
41
  export type SwitchRootProps =
24
42
  | SwitchRootUncontrolledProps
25
43
  | SwitchRootControlledProps;
@@ -31,7 +49,10 @@ export type SwitchRootProps =
31
49
  */
32
50
  export type SwitchProps = SwitchRootProps;
33
51
 
52
+ /** Props for `Switch.Thumb`, the sliding indicator inside the track. */
34
53
  export type SwitchThumbProps = ComponentProps<"span"> & {
54
+ /** Optional thumb content. */
35
55
  children?: ReactNode;
56
+ /** Render the child element instead of the default `<span>`. */
36
57
  asChild?: boolean;
37
58
  };