@primitiv-ui/react 0.1.0 → 0.1.2
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.
- package/LICENSE +21 -0
- package/package.json +2 -1
- package/src/AccessibleIcon/AccessibleIcon.tsx +6 -2
- package/src/AccessibleIcon/__tests__/AccessibleIcon.test.tsx +1 -1
- package/src/AccessibleIcon/types.ts +4 -0
- package/src/Accordion/Accordion.tsx +34 -12
- package/src/Accordion/AccordionContext.ts +1 -1
- package/src/Accordion/__tests__/Accordion.reading-direction.test.tsx +1 -1
- package/src/Accordion/hooks/useAccordionItem.ts +1 -1
- package/src/Accordion/hooks/useAccordionRoot.ts +1 -1
- package/src/Accordion/hooks/useAccordionTrigger.ts +2 -2
- package/src/Accordion/index.ts +2 -1
- package/src/Accordion/types.ts +55 -13
- package/src/Alert/Alert.tsx +9 -2
- package/src/Alert/__tests__/Alert.test.tsx +1 -1
- package/src/Alert/types.ts +1 -0
- package/src/Avatar/Avatar.tsx +20 -7
- package/src/Avatar/AvatarContext.ts +12 -6
- package/src/Breadcrumb/Breadcrumb.tsx +32 -10
- package/src/Button/Button.tsx +5 -2
- package/src/Button/types.ts +4 -0
- package/src/Carousel/Carousel.tsx +30 -14
- package/src/Carousel/CarouselContext.ts +7 -3
- package/src/Carousel/__tests__/Carousel.asChild.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.auto-play.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.basic-rendering.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.controlled-state.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.error-handling.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.ids.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.imperative-api.test.tsx +2 -2
- package/src/Carousel/__tests__/Carousel.indicators.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.intersection-observer.test.tsx +2 -2
- package/src/Carousel/__tests__/Carousel.keyboard-navigation.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.play-pause.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.prev-next.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.reduced-motion.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.refresh-progress.test.tsx +2 -2
- package/src/Carousel/__tests__/Carousel.scroll-snap-change.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.scroll-sync.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.slides-per-move.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.slides-per-page.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.touch-interaction.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.transition-modes.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.translations.test.tsx +1 -1
- package/src/Carousel/__tests__/Carousel.uncontrolled-state.test.tsx +1 -1
- package/src/Carousel/types.ts +8 -0
- package/src/Checkbox/Checkbox.tsx +11 -6
- package/src/Checkbox/CheckboxContext.ts +1 -1
- package/src/Checkbox/hooks/useCheckboxRoot.ts +1 -1
- package/src/Checkbox/index.ts +1 -0
- package/src/Checkbox/types.ts +30 -3
- package/src/CheckboxCard/CheckboxCard.tsx +13 -11
- package/src/CheckboxCard/CheckboxCardContext.ts +19 -6
- package/src/CheckboxCard/hooks/useCheckboxCardRoot.ts +2 -2
- package/src/CheckboxCard/types.ts +21 -5
- package/src/Collapsible/Collapsible.tsx +37 -21
- package/src/Collapsible/CollapsibleContext.ts +1 -1
- package/src/Collapsible/hooks/useCollapsibleRoot.ts +1 -1
- package/src/Collapsible/hooks/useCollapsibleTrigger.ts +1 -1
- package/src/Collapsible/index.ts +1 -0
- package/src/Collapsible/types.ts +45 -12
- package/src/ContextMenu/ContextMenu.tsx +60 -34
- package/src/ContextMenu/ContextMenuContext.ts +2 -2
- package/src/ContextMenu/ContextMenuSubContext.ts +1 -1
- package/src/ContextMenu/__tests__/ContextMenu.reading-direction.test.tsx +1 -1
- package/src/ContextMenu/index.ts +2 -1
- package/src/ContextMenu/types.ts +160 -17
- package/src/DirectionProvider/DirectionProvider.tsx +7 -1
- package/src/DirectionProvider/__tests__/DirectionProvider.test.tsx +1 -1
- package/src/DirectionProvider/types.ts +1 -0
- package/src/Divider/Divider.tsx +4 -1
- package/src/Divider/__tests__/Divider.test.tsx +1 -1
- package/src/Divider/index.ts +2 -1
- package/src/Divider/types.ts +5 -0
- package/src/Dropdown/Dropdown.tsx +60 -34
- package/src/Dropdown/DropdownContext.ts +2 -2
- package/src/Dropdown/DropdownSubContext.ts +1 -1
- package/src/Dropdown/__tests__/Dropdown.reading-direction.test.tsx +1 -1
- package/src/Dropdown/hooks/useDropdownContent.ts +1 -1
- package/src/Dropdown/hooks/useDropdownItem.ts +1 -1
- package/src/Dropdown/hooks/useDropdownRoot.ts +2 -2
- package/src/Dropdown/hooks/useDropdownTrigger.ts +1 -1
- package/src/Dropdown/index.ts +2 -1
- package/src/Dropdown/types.ts +153 -25
- package/src/EmptyState/EmptyState.tsx +34 -20
- package/src/EmptyState/__tests__/EmptyState.Actions.test.tsx +1 -1
- package/src/EmptyState/__tests__/EmptyState.Description.test.tsx +1 -1
- package/src/EmptyState/__tests__/EmptyState.Media.test.tsx +1 -1
- package/src/EmptyState/__tests__/EmptyState.Root.test.tsx +1 -1
- package/src/EmptyState/__tests__/EmptyState.Title.test.tsx +1 -1
- package/src/EmptyState/types.ts +2 -1
- package/src/Field/Field.tsx +24 -10
- package/src/Field/FieldContext.ts +1 -1
- package/src/Field/types.ts +4 -0
- package/src/Fieldset/Fieldset.tsx +26 -10
- package/src/Fieldset/types.ts +2 -0
- package/src/Input/Input.tsx +6 -3
- package/src/Input/__tests__/Input.field-integration.test.tsx +1 -1
- package/src/Input/types.ts +4 -0
- package/src/InputGroup/InputGroup.tsx +15 -8
- package/src/InputGroup/types.ts +9 -0
- package/src/MillerColumns/MillerColumns.tsx +28 -8
- package/src/MillerColumns/MillerColumnsContext.ts +1 -1
- package/src/MillerColumns/hooks/useMillerColumnsItem.ts +2 -2
- package/src/MillerColumns/hooks/useMillerColumnsRoot.ts +0 -0
- package/src/MillerColumns/index.ts +1 -1
- package/src/MillerColumns/types.ts +67 -14
- package/src/MillerColumns/useMillerColumnsSelection.ts +1 -1
- package/src/Modal/Modal.tsx +25 -11
- package/src/Modal/ModalContext.ts +14 -7
- package/src/Modal/hooks/useModalRoot.ts +1 -1
- package/src/Modal/hooks/useModalTrigger.ts +2 -2
- package/src/Modal/types.ts +51 -2
- package/src/Portal/Portal.tsx +3 -1
- package/src/Portal/types.ts +4 -0
- package/src/Progress/Progress.tsx +12 -7
- package/src/Progress/ProgressContext.ts +18 -6
- package/src/RadioCard/RadioCard.tsx +17 -11
- package/src/RadioCard/RadioCardContext.ts +17 -5
- package/src/RadioCard/RadioCardItemContext.ts +18 -5
- package/src/RadioCard/__tests__/RadioCard.reading-direction.test.tsx +1 -1
- package/src/RadioCard/hooks/useRadioCardRoot.ts +1 -1
- package/src/RadioCard/types.ts +24 -3
- package/src/RadioGroup/RadioGroup.tsx +17 -11
- package/src/RadioGroup/RadioGroupContext.ts +1 -1
- package/src/RadioGroup/RadioGroupItemContext.ts +1 -1
- package/src/RadioGroup/__tests__/RadioGroup.reading-direction.test.tsx +1 -1
- package/src/RadioGroup/hooks/useRadioGroupRoot.ts +1 -1
- package/src/RadioGroup/index.ts +1 -0
- package/src/RadioGroup/types.ts +34 -3
- package/src/Select/Select.tsx +23 -8
- package/src/Select/__tests__/Select.field-integration.test.tsx +1 -1
- package/src/Select/index.ts +1 -1
- package/src/Select/types.ts +18 -3
- package/src/SkipNav/SkipNav.tsx +7 -2
- package/src/SkipNav/__tests__/SkipNav.ids.test.tsx +1 -1
- package/src/Slider/Slider.tsx +26 -11
- package/src/Slider/SliderContext.ts +13 -6
- package/src/Slider/__tests__/Slider.reading-direction.test.tsx +1 -1
- package/src/Slider/hooks/useSliderRoot.ts +1 -1
- package/src/Slider/types.ts +12 -3
- package/src/Status/Status.tsx +9 -2
- package/src/Status/__tests__/Status.test.tsx +1 -1
- package/src/Status/types.ts +4 -0
- package/src/Switch/Switch.tsx +16 -6
- package/src/Switch/SwitchContext.ts +13 -5
- package/src/Switch/hooks/useSwitchRoot.ts +1 -1
- package/src/Switch/types.ts +24 -3
- package/src/Table/Table.tsx +51 -25
- package/src/Table/__tests__/Table.Body.test.tsx +1 -1
- package/src/Table/__tests__/Table.Caption.test.tsx +1 -1
- package/src/Table/__tests__/Table.Cell.test.tsx +1 -1
- package/src/Table/__tests__/Table.Footer.test.tsx +1 -1
- package/src/Table/__tests__/Table.Head.test.tsx +1 -1
- package/src/Table/__tests__/Table.Header.test.tsx +1 -1
- package/src/Table/__tests__/Table.Root.test.tsx +1 -1
- package/src/Table/__tests__/Table.Row.test.tsx +1 -1
- package/src/Table/__tests__/Table.ScrollArea.test.tsx +1 -1
- package/src/Table/index.ts +2 -1
- package/src/Tabs/Tabs.tsx +30 -10
- package/src/Tabs/TabsContext.ts +15 -7
- package/src/Tabs/__tests__/Tabs.asChild.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.basic-rendering.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.change-event-callbacks.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.controlled-state.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.error-handling.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.imperative-api.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.keyboard-interaction.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.lazy-mount.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.mouse-interaction.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.reading-direction.test.tsx +1 -1
- package/src/Tabs/__tests__/Tabs.uncontrolled-state.test.tsx +1 -1
- package/src/Tabs/hooks/useTabsContent.ts +1 -1
- package/src/Tabs/hooks/useTabsRoot.ts +1 -1
- package/src/Tabs/hooks/useTabsTrigger.ts +1 -1
- package/src/Tabs/types.ts +35 -1
- package/src/Tabs/utils.ts +1 -1
- package/src/Textarea/Textarea.tsx +6 -3
- package/src/Textarea/__tests__/Textarea.field-integration.test.tsx +1 -1
- package/src/Textarea/types.ts +4 -0
- package/src/Toggle/Toggle.tsx +11 -4
- package/src/Toggle/types.ts +7 -3
- package/src/ToggleGroup/ToggleGroup.tsx +23 -13
- package/src/ToggleGroup/ToggleGroupContext.ts +1 -1
- package/src/ToggleGroup/__tests__/ToggleGroup.reading-direction.test.tsx +1 -1
- package/src/ToggleGroup/hooks/useToggleGroupRoot.ts +1 -1
- package/src/ToggleGroup/types.ts +45 -5
- package/src/Tooltip/Tooltip.tsx +46 -15
- package/src/Tooltip/TooltipContext.ts +1 -1
- package/src/Tooltip/hooks/useTooltipContent.ts +1 -1
- package/src/Tooltip/hooks/useTooltipRoot.ts +1 -1
- package/src/Tooltip/hooks/useTooltipTrigger.ts +1 -1
- package/src/Tooltip/index.ts +1 -0
- package/src/Tooltip/types.ts +50 -2
- package/src/Tree/Tree.tsx +58 -12
- package/src/Tree/TreeContext.ts +1 -1
- package/src/Tree/__tests__/Tree.selection-path.test.tsx +2 -2
- package/src/Tree/hooks/useTreeItemKeyboard.ts +1 -1
- package/src/Tree/hooks/useTreeRoot.ts +1 -1
- package/src/Tree/index.ts +1 -1
- package/src/Tree/types.ts +39 -7
- package/src/VisuallyHidden/VisuallyHidden.tsx +4 -2
- package/src/VisuallyHidden/__tests__/VisuallyHidden.test.tsx +1 -1
- package/src/VisuallyHidden/types.ts +4 -0
- package/src/index.ts +39 -38
- package/src/types.ts +1 -0
- package/src/utils/createStrictContext.ts +9 -5
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
|
|
3
|
-
import { useCheckboxRoot } from "../Checkbox/hooks";
|
|
4
|
-
import { useDirection } from "../DirectionProvider";
|
|
5
|
-
import { useRadioGroupRoot } from "../RadioGroup/hooks";
|
|
6
|
-
import { composeEventHandlers, Slot } from "../Slot";
|
|
4
|
+
import { useCheckboxRoot } from "../Checkbox/hooks/index.ts";
|
|
5
|
+
import { useDirection } from "../DirectionProvider/index.ts";
|
|
6
|
+
import { useRadioGroupRoot } from "../RadioGroup/hooks/index.ts";
|
|
7
|
+
import { composeEventHandlers, Slot } from "../Slot/index.ts";
|
|
7
8
|
|
|
8
9
|
import { DropdownContext } from "./DropdownContext";
|
|
9
10
|
import { DropdownContentContext } from "./DropdownContentContext";
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
useDropdownRoot,
|
|
22
23
|
useDropdownSubContext,
|
|
23
24
|
useDropdownTrigger,
|
|
24
|
-
} from "./hooks";
|
|
25
|
+
} from "./hooks/index.ts";
|
|
25
26
|
import {
|
|
26
27
|
DropdownCheckboxItemProps,
|
|
27
28
|
DropdownContentProps,
|
|
@@ -84,13 +85,13 @@ import { MENUITEM_SELECTOR } from "./constants";
|
|
|
84
85
|
* </Dropdown.Root>
|
|
85
86
|
* ```
|
|
86
87
|
*/
|
|
87
|
-
function DropdownRoot({
|
|
88
|
+
export function DropdownRoot({
|
|
88
89
|
defaultOpen,
|
|
89
90
|
open,
|
|
90
91
|
onOpenChange,
|
|
91
92
|
dir,
|
|
92
93
|
children,
|
|
93
|
-
}: DropdownRootProps) {
|
|
94
|
+
}: DropdownRootProps): ReactElement {
|
|
94
95
|
const inheritedDir = useDirection();
|
|
95
96
|
const { contextValue } = useDropdownRoot({
|
|
96
97
|
defaultOpen,
|
|
@@ -106,6 +107,7 @@ function DropdownRoot({
|
|
|
106
107
|
);
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
/** @internal */
|
|
109
111
|
DropdownRoot.displayName = "DropdownRoot";
|
|
110
112
|
|
|
111
113
|
/**
|
|
@@ -126,12 +128,12 @@ DropdownRoot.displayName = "DropdownRoot";
|
|
|
126
128
|
* </Dropdown.Trigger>
|
|
127
129
|
* ```
|
|
128
130
|
*/
|
|
129
|
-
function DropdownTrigger({
|
|
131
|
+
export function DropdownTrigger({
|
|
130
132
|
children,
|
|
131
133
|
onClick,
|
|
132
134
|
asChild = false,
|
|
133
135
|
...rest
|
|
134
|
-
}: DropdownTriggerProps) {
|
|
136
|
+
}: DropdownTriggerProps): ReactElement {
|
|
135
137
|
const { triggerProps } = useDropdownTrigger({ onClick, restProps: rest });
|
|
136
138
|
|
|
137
139
|
if (asChild) {
|
|
@@ -145,6 +147,7 @@ function DropdownTrigger({
|
|
|
145
147
|
);
|
|
146
148
|
}
|
|
147
149
|
|
|
150
|
+
/** @internal */
|
|
148
151
|
DropdownTrigger.displayName = "DropdownTrigger";
|
|
149
152
|
|
|
150
153
|
/**
|
|
@@ -178,12 +181,12 @@ DropdownTrigger.displayName = "DropdownTrigger";
|
|
|
178
181
|
* lands on the next sibling item in the parent rather than getting
|
|
179
182
|
* stuck on a non-focusable item inside a closed sub-popover.
|
|
180
183
|
*/
|
|
181
|
-
function DropdownContent({
|
|
184
|
+
export function DropdownContent({
|
|
182
185
|
children,
|
|
183
186
|
onKeyDown,
|
|
184
187
|
asChild = false,
|
|
185
188
|
...rest
|
|
186
|
-
}: DropdownContentProps) {
|
|
189
|
+
}: DropdownContentProps): ReactElement {
|
|
187
190
|
const { contentContextValue, contentProps } = useDropdownContent({
|
|
188
191
|
onKeyDown,
|
|
189
192
|
restProps: rest,
|
|
@@ -200,6 +203,7 @@ function DropdownContent({
|
|
|
200
203
|
);
|
|
201
204
|
}
|
|
202
205
|
|
|
206
|
+
/** @internal */
|
|
203
207
|
DropdownContent.displayName = "DropdownContent";
|
|
204
208
|
|
|
205
209
|
/**
|
|
@@ -215,14 +219,14 @@ DropdownContent.displayName = "DropdownContent";
|
|
|
215
219
|
* Disabled items receive `aria-disabled="true"` and are skipped by arrow
|
|
216
220
|
* navigation, typeahead, and activation handlers.
|
|
217
221
|
*/
|
|
218
|
-
function DropdownItem({
|
|
222
|
+
export function DropdownItem({
|
|
219
223
|
children,
|
|
220
224
|
onClick,
|
|
221
225
|
onSelect,
|
|
222
226
|
disabled,
|
|
223
227
|
asChild = false,
|
|
224
228
|
...rest
|
|
225
|
-
}: DropdownItemProps) {
|
|
229
|
+
}: DropdownItemProps): ReactElement {
|
|
226
230
|
const { itemProps } = useDropdownItem({
|
|
227
231
|
disabled,
|
|
228
232
|
onClick,
|
|
@@ -237,6 +241,7 @@ function DropdownItem({
|
|
|
237
241
|
return <li {...itemProps}>{children}</li>;
|
|
238
242
|
}
|
|
239
243
|
|
|
244
|
+
/** @internal */
|
|
240
245
|
DropdownItem.displayName = "DropdownItem";
|
|
241
246
|
|
|
242
247
|
/**
|
|
@@ -244,11 +249,11 @@ DropdownItem.displayName = "DropdownItem";
|
|
|
244
249
|
* by default; pass `asChild` to render any element with separator semantics.
|
|
245
250
|
* Non-interactive — skipped by focus, arrow navigation, and typeahead.
|
|
246
251
|
*/
|
|
247
|
-
function DropdownSeparator({
|
|
252
|
+
export function DropdownSeparator({
|
|
248
253
|
asChild = false,
|
|
249
254
|
children,
|
|
250
255
|
...rest
|
|
251
|
-
}: DropdownSeparatorProps) {
|
|
256
|
+
}: DropdownSeparatorProps): ReactElement {
|
|
252
257
|
const separatorProps = { ...rest, role: "separator" as const };
|
|
253
258
|
|
|
254
259
|
if (asChild) {
|
|
@@ -258,6 +263,7 @@ function DropdownSeparator({
|
|
|
258
263
|
return <li {...separatorProps} />;
|
|
259
264
|
}
|
|
260
265
|
|
|
266
|
+
/** @internal */
|
|
261
267
|
DropdownSeparator.displayName = "DropdownSeparator";
|
|
262
268
|
|
|
263
269
|
/**
|
|
@@ -270,11 +276,11 @@ DropdownSeparator.displayName = "DropdownSeparator";
|
|
|
270
276
|
* first child to provide the accessible name; screen readers will announce
|
|
271
277
|
* the group when arrowing into it.
|
|
272
278
|
*/
|
|
273
|
-
function DropdownGroup({
|
|
279
|
+
export function DropdownGroup({
|
|
274
280
|
children,
|
|
275
281
|
asChild = false,
|
|
276
282
|
...rest
|
|
277
|
-
}: DropdownGroupProps) {
|
|
283
|
+
}: DropdownGroupProps): ReactElement {
|
|
278
284
|
const { contextValue, groupProps } = useDropdownGroup({ restProps: rest });
|
|
279
285
|
|
|
280
286
|
return (
|
|
@@ -290,6 +296,7 @@ function DropdownGroup({
|
|
|
290
296
|
);
|
|
291
297
|
}
|
|
292
298
|
|
|
299
|
+
/** @internal */
|
|
293
300
|
DropdownGroup.displayName = "DropdownGroup";
|
|
294
301
|
|
|
295
302
|
/**
|
|
@@ -301,12 +308,12 @@ DropdownGroup.displayName = "DropdownGroup";
|
|
|
301
308
|
* Renders a `<li>` by default; pass `asChild` to render any element. A
|
|
302
309
|
* caller-supplied `id` takes precedence over the auto-generated one.
|
|
303
310
|
*/
|
|
304
|
-
function DropdownLabel({
|
|
311
|
+
export function DropdownLabel({
|
|
305
312
|
id,
|
|
306
313
|
children,
|
|
307
314
|
asChild = false,
|
|
308
315
|
...rest
|
|
309
|
-
}: DropdownLabelProps) {
|
|
316
|
+
}: DropdownLabelProps): ReactElement {
|
|
310
317
|
const { labelProps } = useDropdownLabel({ id, restProps: rest });
|
|
311
318
|
|
|
312
319
|
if (asChild) {
|
|
@@ -315,6 +322,7 @@ function DropdownLabel({
|
|
|
315
322
|
return <li {...labelProps}>{children}</li>;
|
|
316
323
|
}
|
|
317
324
|
|
|
325
|
+
/** @internal */
|
|
318
326
|
DropdownLabel.displayName = "DropdownLabel";
|
|
319
327
|
|
|
320
328
|
/**
|
|
@@ -343,7 +351,7 @@ DropdownLabel.displayName = "DropdownLabel";
|
|
|
343
351
|
*
|
|
344
352
|
* Disabled items receive `aria-disabled="true"` and no-op on activation.
|
|
345
353
|
*/
|
|
346
|
-
function DropdownCheckboxItem({
|
|
354
|
+
export function DropdownCheckboxItem({
|
|
347
355
|
children,
|
|
348
356
|
onClick,
|
|
349
357
|
onSelect,
|
|
@@ -353,7 +361,7 @@ function DropdownCheckboxItem({
|
|
|
353
361
|
onCheckedChange,
|
|
354
362
|
asChild = false,
|
|
355
363
|
...rest
|
|
356
|
-
}: DropdownCheckboxItemProps) {
|
|
364
|
+
}: DropdownCheckboxItemProps): ReactElement {
|
|
357
365
|
const { setOpen, triggerRef } = useDropdownContext();
|
|
358
366
|
const closeSiblingSub = useCloseSiblingSub();
|
|
359
367
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -403,6 +411,7 @@ function DropdownCheckboxItem({
|
|
|
403
411
|
);
|
|
404
412
|
}
|
|
405
413
|
|
|
414
|
+
/** @internal */
|
|
406
415
|
DropdownCheckboxItem.displayName = "DropdownCheckboxItem";
|
|
407
416
|
|
|
408
417
|
/**
|
|
@@ -417,14 +426,14 @@ DropdownCheckboxItem.displayName = "DropdownCheckboxItem";
|
|
|
417
426
|
* Optional `onValueChange` observes selections.
|
|
418
427
|
* - **Controlled** — pass `value` *and* `onValueChange` together.
|
|
419
428
|
*/
|
|
420
|
-
function DropdownRadioGroup({
|
|
429
|
+
export function DropdownRadioGroup({
|
|
421
430
|
defaultValue,
|
|
422
431
|
value: controlledValue,
|
|
423
432
|
onValueChange,
|
|
424
433
|
children,
|
|
425
434
|
asChild = false,
|
|
426
435
|
...rest
|
|
427
|
-
}: DropdownRadioGroupProps) {
|
|
436
|
+
}: DropdownRadioGroupProps): ReactElement {
|
|
428
437
|
const { value, select } = useRadioGroupRoot({
|
|
429
438
|
defaultValue,
|
|
430
439
|
value: controlledValue,
|
|
@@ -445,6 +454,7 @@ function DropdownRadioGroup({
|
|
|
445
454
|
);
|
|
446
455
|
}
|
|
447
456
|
|
|
457
|
+
/** @internal */
|
|
448
458
|
DropdownRadioGroup.displayName = "DropdownRadioGroup";
|
|
449
459
|
|
|
450
460
|
/**
|
|
@@ -467,7 +477,7 @@ DropdownRadioGroup.displayName = "DropdownRadioGroup";
|
|
|
467
477
|
*
|
|
468
478
|
* Disabled items receive `aria-disabled="true"` and no-op on activation.
|
|
469
479
|
*/
|
|
470
|
-
function DropdownRadioItem({
|
|
480
|
+
export function DropdownRadioItem({
|
|
471
481
|
children,
|
|
472
482
|
onClick,
|
|
473
483
|
onSelect,
|
|
@@ -475,7 +485,7 @@ function DropdownRadioItem({
|
|
|
475
485
|
value: itemValue,
|
|
476
486
|
asChild = false,
|
|
477
487
|
...rest
|
|
478
|
-
}: DropdownRadioItemProps) {
|
|
488
|
+
}: DropdownRadioItemProps): ReactElement {
|
|
479
489
|
const { setOpen, triggerRef } = useDropdownContext();
|
|
480
490
|
const closeSiblingSub = useCloseSiblingSub();
|
|
481
491
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -525,6 +535,7 @@ function DropdownRadioItem({
|
|
|
525
535
|
);
|
|
526
536
|
}
|
|
527
537
|
|
|
538
|
+
/** @internal */
|
|
528
539
|
DropdownRadioItem.displayName = "DropdownRadioItem";
|
|
529
540
|
|
|
530
541
|
/**
|
|
@@ -554,12 +565,12 @@ DropdownRadioItem.displayName = "DropdownRadioItem";
|
|
|
554
565
|
* </Dropdown.CheckboxItem>
|
|
555
566
|
* ```
|
|
556
567
|
*/
|
|
557
|
-
function DropdownItemIndicator({
|
|
568
|
+
export function DropdownItemIndicator({
|
|
558
569
|
children,
|
|
559
570
|
asChild = false,
|
|
560
571
|
forceMount = false,
|
|
561
572
|
...rest
|
|
562
|
-
}: DropdownItemIndicatorProps) {
|
|
573
|
+
}: DropdownItemIndicatorProps): ReactElement | null {
|
|
563
574
|
const context = useContext(DropdownItemIndicatorContext);
|
|
564
575
|
if (!context) {
|
|
565
576
|
throw new Error(
|
|
@@ -581,6 +592,7 @@ function DropdownItemIndicator({
|
|
|
581
592
|
return <span {...indicatorProps}>{children}</span>;
|
|
582
593
|
}
|
|
583
594
|
|
|
595
|
+
/** @internal */
|
|
584
596
|
DropdownItemIndicator.displayName = "DropdownItemIndicator";
|
|
585
597
|
|
|
586
598
|
/**
|
|
@@ -608,12 +620,12 @@ DropdownItemIndicator.displayName = "DropdownItemIndicator";
|
|
|
608
620
|
* </Dropdown.Root>
|
|
609
621
|
* ```
|
|
610
622
|
*/
|
|
611
|
-
function DropdownSub({
|
|
623
|
+
export function DropdownSub({
|
|
612
624
|
defaultOpen,
|
|
613
625
|
open: controlledOpen,
|
|
614
626
|
onOpenChange,
|
|
615
627
|
children,
|
|
616
|
-
}: DropdownSubProps) {
|
|
628
|
+
}: DropdownSubProps): ReactElement {
|
|
617
629
|
const { open, setOpen } = useDropdownRoot({
|
|
618
630
|
defaultOpen,
|
|
619
631
|
open: controlledOpen,
|
|
@@ -650,6 +662,7 @@ function DropdownSub({
|
|
|
650
662
|
);
|
|
651
663
|
}
|
|
652
664
|
|
|
665
|
+
/** @internal */
|
|
653
666
|
DropdownSub.displayName = "DropdownSub";
|
|
654
667
|
|
|
655
668
|
/**
|
|
@@ -671,14 +684,14 @@ DropdownSub.displayName = "DropdownSub";
|
|
|
671
684
|
* Disabled triggers receive `aria-disabled="true"` and ignore both click
|
|
672
685
|
* and the open arrow key.
|
|
673
686
|
*/
|
|
674
|
-
function DropdownSubTrigger({
|
|
687
|
+
export function DropdownSubTrigger({
|
|
675
688
|
children,
|
|
676
689
|
onClick,
|
|
677
690
|
onKeyDown,
|
|
678
691
|
disabled,
|
|
679
692
|
asChild = false,
|
|
680
693
|
...rest
|
|
681
|
-
}: DropdownSubTriggerProps) {
|
|
694
|
+
}: DropdownSubTriggerProps): ReactElement {
|
|
682
695
|
const sub = useDropdownSubContext();
|
|
683
696
|
const { dir } = useDropdownContext();
|
|
684
697
|
const openKey = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
@@ -720,6 +733,7 @@ function DropdownSubTrigger({
|
|
|
720
733
|
return <li {...subTriggerProps}>{children}</li>;
|
|
721
734
|
}
|
|
722
735
|
|
|
736
|
+
/** @internal */
|
|
723
737
|
DropdownSubTrigger.displayName = "DropdownSubTrigger";
|
|
724
738
|
|
|
725
739
|
/**
|
|
@@ -736,12 +750,12 @@ DropdownSubTrigger.displayName = "DropdownSubTrigger";
|
|
|
736
750
|
* to the parent {@link DropdownContent | `Dropdown.Content`} so arrow
|
|
737
751
|
* navigation and typeahead apply to the submenu's items.
|
|
738
752
|
*/
|
|
739
|
-
function DropdownSubContent({
|
|
753
|
+
export function DropdownSubContent({
|
|
740
754
|
children,
|
|
741
755
|
onKeyDown,
|
|
742
756
|
asChild = false,
|
|
743
757
|
...rest
|
|
744
|
-
}: DropdownSubContentProps) {
|
|
758
|
+
}: DropdownSubContentProps): ReactElement {
|
|
745
759
|
const sub = useDropdownSubContext();
|
|
746
760
|
const { dir } = useDropdownContext();
|
|
747
761
|
const closeKey = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
@@ -801,9 +815,11 @@ function DropdownSubContent({
|
|
|
801
815
|
);
|
|
802
816
|
}
|
|
803
817
|
|
|
818
|
+
/** @internal */
|
|
804
819
|
DropdownSubContent.displayName = "DropdownSubContent";
|
|
805
820
|
|
|
806
|
-
|
|
821
|
+
/** Type of the {@link Dropdown} compound: the root callable plus its attached sub-components. */
|
|
822
|
+
export type TDropdownCompound = typeof DropdownRoot & {
|
|
807
823
|
Root: typeof DropdownRoot;
|
|
808
824
|
Trigger: typeof DropdownTrigger;
|
|
809
825
|
Content: typeof DropdownContent;
|
|
@@ -820,6 +836,15 @@ type TDropdownCompound = typeof DropdownRoot & {
|
|
|
820
836
|
SubContent: typeof DropdownSubContent;
|
|
821
837
|
};
|
|
822
838
|
|
|
839
|
+
/**
|
|
840
|
+
* Headless, accessible **Dropdown** menu — a compound component implementing the
|
|
841
|
+
* [WAI-ARIA menu-button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/)
|
|
842
|
+
* with submenus, checkbox and radio items, groups, labels and separators. Zero
|
|
843
|
+
* styles ship.
|
|
844
|
+
*
|
|
845
|
+
* The default export is the `Root`; sub-components are attached as static
|
|
846
|
+
* properties (`Dropdown.Trigger`, `Dropdown.Content`, …).
|
|
847
|
+
*/
|
|
823
848
|
const DropdownCompound: TDropdownCompound = Object.assign(DropdownRoot, {
|
|
824
849
|
Root: DropdownRoot,
|
|
825
850
|
Trigger: DropdownTrigger,
|
|
@@ -837,6 +862,7 @@ const DropdownCompound: TDropdownCompound = Object.assign(DropdownRoot, {
|
|
|
837
862
|
SubContent: DropdownSubContent,
|
|
838
863
|
});
|
|
839
864
|
|
|
865
|
+
/** @internal */
|
|
840
866
|
DropdownCompound.displayName = "Dropdown";
|
|
841
867
|
|
|
842
868
|
export { DropdownCompound as Dropdown };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
2
|
|
|
3
|
-
import { Direction } from "../DirectionProvider";
|
|
4
|
-
import { createStrictContext } from "../utils";
|
|
3
|
+
import { Direction } from "../DirectionProvider/index.ts";
|
|
4
|
+
import { createStrictContext } from "../utils/index.ts";
|
|
5
5
|
|
|
6
6
|
export type DropdownContextValue = {
|
|
7
7
|
open: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { render, screen } from "@testing-library/react";
|
|
2
2
|
import userEvent from "@testing-library/user-event";
|
|
3
3
|
|
|
4
|
-
import { DirectionProvider } from "../../DirectionProvider";
|
|
4
|
+
import { DirectionProvider } from "../../DirectionProvider/index.ts";
|
|
5
5
|
import { Dropdown } from "../Dropdown";
|
|
6
6
|
|
|
7
7
|
describe("Dropdown reading direction", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef, useEffect, useMemo, KeyboardEventHandler } from "react";
|
|
2
|
-
import { composeEventHandlers } from "../../Slot";
|
|
2
|
+
import { composeEventHandlers } from "../../Slot/index.ts";
|
|
3
3
|
import { MENUITEM_SELECTOR, TYPEAHEAD_RESET_MS } from "../constants";
|
|
4
4
|
import { useDropdownContext } from "./useDropdownContext";
|
|
5
5
|
import { DropdownContentProps } from "../types";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MouseEventHandler, useState } from "react";
|
|
2
|
-
import { composeEventHandlers, SlotProps } from "../../Slot";
|
|
2
|
+
import { composeEventHandlers, SlotProps } from "../../Slot/index.ts";
|
|
3
3
|
import { useCloseSiblingSub } from "./useCloseSiblingSub";
|
|
4
4
|
import { useDropdownContext } from "./useDropdownContext";
|
|
5
5
|
import { DropdownItemProps } from "../types";
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
useRef,
|
|
7
7
|
} from "react";
|
|
8
8
|
|
|
9
|
-
import { Direction } from "../../DirectionProvider";
|
|
10
|
-
import { useControllableState } from "../../hooks";
|
|
9
|
+
import { Direction } from "../../DirectionProvider/index.ts";
|
|
10
|
+
import { useControllableState } from "../../hooks/index.ts";
|
|
11
11
|
|
|
12
12
|
type UseDropdownRootArgs = {
|
|
13
13
|
defaultOpen?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MouseEventHandler } from "react";
|
|
2
|
-
import { composeEventHandlers } from "../../Slot";
|
|
2
|
+
import { composeEventHandlers } from "../../Slot/index.ts";
|
|
3
3
|
import { DropdownTriggerProps } from "../types";
|
|
4
4
|
import { useDropdownContext } from "./useDropdownContext";
|
|
5
5
|
|
package/src/Dropdown/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./Dropdown";
|
|
2
|
+
export * from "./types";
|