@primitiv-ui/react 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/AccessibleIcon/AccessibleIcon.tsx +5 -2
- package/src/AccessibleIcon/__tests__/AccessibleIcon.test.tsx +1 -1
- package/src/Accordion/Accordion.tsx +11 -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/Alert/Alert.tsx +8 -2
- package/src/Alert/__tests__/Alert.test.tsx +1 -1
- package/src/Avatar/Avatar.tsx +14 -5
- package/src/Avatar/AvatarContext.ts +10 -6
- package/src/Breadcrumb/Breadcrumb.tsx +21 -7
- package/src/Button/Button.tsx +4 -2
- package/src/Carousel/Carousel.tsx +21 -14
- package/src/Carousel/CarouselContext.ts +3 -2
- 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/Checkbox/Checkbox.tsx +5 -4
- package/src/Checkbox/CheckboxContext.ts +1 -1
- package/src/Checkbox/hooks/useCheckboxRoot.ts +1 -1
- package/src/CheckboxCard/CheckboxCard.tsx +5 -4
- package/src/CheckboxCard/CheckboxCardContext.ts +10 -5
- package/src/CheckboxCard/hooks/useCheckboxCardRoot.ts +1 -1
- package/src/Collapsible/Collapsible.tsx +22 -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/ContextMenu/ContextMenu.tsx +20 -19
- 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/types.ts +1 -1
- package/src/DirectionProvider/DirectionProvider.tsx +6 -1
- package/src/DirectionProvider/__tests__/DirectionProvider.test.tsx +1 -1
- package/src/Divider/Divider.tsx +3 -1
- package/src/Divider/__tests__/Divider.test.tsx +1 -1
- package/src/Dropdown/Dropdown.tsx +20 -19
- 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/types.ts +1 -1
- package/src/EmptyState/EmptyState.tsx +8 -6
- 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/Field/Field.tsx +11 -6
- package/src/Field/FieldContext.ts +1 -1
- package/src/Fieldset/Fieldset.tsx +11 -2
- package/src/Input/Input.tsx +5 -3
- package/src/Input/__tests__/Input.field-integration.test.tsx +1 -1
- package/src/InputGroup/InputGroup.tsx +6 -4
- package/src/MillerColumns/MillerColumns.tsx +9 -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/useMillerColumnsSelection.ts +1 -1
- package/src/Modal/Modal.tsx +24 -11
- package/src/Modal/ModalContext.ts +10 -6
- package/src/Modal/hooks/useModalRoot.ts +1 -1
- package/src/Modal/hooks/useModalTrigger.ts +2 -2
- package/src/Portal/Portal.tsx +2 -1
- package/src/Progress/Progress.tsx +5 -4
- package/src/Progress/ProgressContext.ts +11 -6
- package/src/RadioCard/RadioCard.tsx +8 -7
- package/src/RadioCard/RadioCardContext.ts +10 -5
- package/src/RadioCard/RadioCardItemContext.ts +10 -5
- package/src/RadioCard/__tests__/RadioCard.reading-direction.test.tsx +1 -1
- package/src/RadioCard/hooks/useRadioCardRoot.ts +1 -1
- package/src/RadioGroup/RadioGroup.tsx +8 -7
- 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/Select/Select.tsx +10 -6
- package/src/Select/__tests__/Select.field-integration.test.tsx +1 -1
- package/src/SkipNav/SkipNav.tsx +7 -2
- package/src/SkipNav/__tests__/SkipNav.ids.test.tsx +1 -1
- package/src/Slider/Slider.tsx +17 -7
- package/src/Slider/SliderContext.ts +10 -6
- package/src/Slider/__tests__/Slider.reading-direction.test.tsx +1 -1
- package/src/Slider/hooks/useSliderRoot.ts +1 -1
- package/src/Status/Status.tsx +8 -2
- package/src/Status/__tests__/Status.test.tsx +1 -1
- package/src/Switch/Switch.tsx +9 -4
- package/src/Switch/SwitchContext.ts +9 -5
- package/src/Switch/hooks/useSwitchRoot.ts +1 -1
- package/src/Table/Table.tsx +15 -9
- 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/Tabs/Tabs.tsx +24 -9
- package/src/Tabs/TabsContext.ts +9 -6
- 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/utils.ts +1 -1
- package/src/Textarea/Textarea.tsx +5 -3
- package/src/Textarea/__tests__/Textarea.field-integration.test.tsx +1 -1
- package/src/Toggle/Toggle.tsx +10 -4
- package/src/ToggleGroup/ToggleGroup.tsx +14 -10
- 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/Tooltip/Tooltip.tsx +23 -10
- 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/Tree/Tree.tsx +12 -11
- 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/VisuallyHidden/VisuallyHidden.tsx +3 -2
- package/src/VisuallyHidden/__tests__/VisuallyHidden.test.tsx +1 -1
- package/src/index.ts +38 -38
- package/src/utils/createStrictContext.ts +9 -5
|
@@ -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 { Carousel } from "
|
|
4
|
+
import { Carousel } from "../index.ts";
|
|
5
5
|
|
|
6
6
|
describe("Carousel slidesPerPage", () => {
|
|
7
7
|
it("should mark every slide on the active page as active when slidesPerPage > 1", () => {
|
|
@@ -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 { Carousel } from "
|
|
4
|
+
import { Carousel } from "../index.ts";
|
|
5
5
|
|
|
6
6
|
describe("Carousel uncontrolled page state", () => {
|
|
7
7
|
it("should mark the slide at index 0 as active by default when no defaultPage is provided", () => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
|
|
3
|
-
import { Slot, composeEventHandlers } from "../Slot";
|
|
4
|
+
import { Slot, composeEventHandlers } from "../Slot/index.ts";
|
|
4
5
|
|
|
5
6
|
import { CheckboxContext } from "./CheckboxContext";
|
|
6
|
-
import { useCheckboxContext, useCheckboxRoot } from "./hooks";
|
|
7
|
+
import { useCheckboxContext, useCheckboxRoot } from "./hooks/index.ts";
|
|
7
8
|
import {
|
|
8
9
|
CheckboxIndicatorProps,
|
|
9
10
|
CheckboxRootProps,
|
|
@@ -76,7 +77,7 @@ function dataStateOf(checked: CheckedState) {
|
|
|
76
77
|
* </Checkbox.Root>
|
|
77
78
|
* ```
|
|
78
79
|
*/
|
|
79
|
-
function CheckboxRoot(props: CheckboxRootProps) {
|
|
80
|
+
function CheckboxRoot(props: CheckboxRootProps): ReactElement {
|
|
80
81
|
const {
|
|
81
82
|
defaultChecked,
|
|
82
83
|
checked,
|
|
@@ -169,7 +170,7 @@ function CheckboxIndicator({
|
|
|
169
170
|
forceMount,
|
|
170
171
|
asChild = false,
|
|
171
172
|
...rest
|
|
172
|
-
}: CheckboxIndicatorProps) {
|
|
173
|
+
}: CheckboxIndicatorProps): ReactElement | null {
|
|
173
174
|
const { checked } = useCheckboxContext();
|
|
174
175
|
const isVisible = checked !== false;
|
|
175
176
|
if (!isVisible && !forceMount) return null;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
|
|
3
|
-
import { Slot, composeEventHandlers } from "../Slot";
|
|
4
|
+
import { Slot, composeEventHandlers } from "../Slot/index.ts";
|
|
4
5
|
|
|
5
6
|
import { CheckboxCardContext } from "./CheckboxCardContext";
|
|
6
|
-
import { useCheckboxCardContext, useCheckboxCardRoot } from "./hooks";
|
|
7
|
+
import { useCheckboxCardContext, useCheckboxCardRoot } from "./hooks/index.ts";
|
|
7
8
|
import {
|
|
8
9
|
CheckboxCardIndicatorProps,
|
|
9
10
|
CheckboxCardRootProps,
|
|
@@ -66,7 +67,7 @@ function dataStateOf(checked: CheckedState) {
|
|
|
66
67
|
* </CheckboxCard.Root>
|
|
67
68
|
* ```
|
|
68
69
|
*/
|
|
69
|
-
function CheckboxCardRoot(props: CheckboxCardRootProps) {
|
|
70
|
+
function CheckboxCardRoot(props: CheckboxCardRootProps): ReactElement {
|
|
70
71
|
const {
|
|
71
72
|
defaultChecked,
|
|
72
73
|
checked,
|
|
@@ -141,7 +142,7 @@ function CheckboxCardIndicator({
|
|
|
141
142
|
forceMount,
|
|
142
143
|
asChild = false,
|
|
143
144
|
...rest
|
|
144
|
-
}: CheckboxCardIndicatorProps) {
|
|
145
|
+
}: CheckboxCardIndicatorProps): ReactElement | null {
|
|
145
146
|
const { checked } = useCheckboxCardContext();
|
|
146
147
|
const isVisible = checked !== false;
|
|
147
148
|
if (!isVisible && !forceMount) return null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Context } from "react";
|
|
2
|
+
import { createStrictContext } from "../utils/index.ts";
|
|
2
3
|
|
|
3
4
|
import { CheckedState } from "./types";
|
|
4
5
|
|
|
@@ -6,7 +7,11 @@ export type CheckboxCardContextValue = {
|
|
|
6
7
|
checked: CheckedState;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const checkboxCardContextPair = createStrictContext<CheckboxCardContextValue>(
|
|
11
|
+
"CheckboxCard sub-components must be rendered inside a <CheckboxCard.Root>.",
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const CheckboxCardContext: Context<CheckboxCardContextValue | null> =
|
|
15
|
+
checkboxCardContextPair[0];
|
|
16
|
+
export const useCheckboxCardContext: () => CheckboxCardContextValue =
|
|
17
|
+
checkboxCardContextPair[1];
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Ref } from "react";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
2
3
|
|
|
3
|
-
import { Slot } from "../Slot";
|
|
4
|
+
import { Slot } from "../Slot/index.ts";
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
CollapsibleContext,
|
|
8
|
+
useCollapsibleContext,
|
|
9
|
+
} from "./CollapsibleContext";
|
|
10
|
+
import { useCollapsibleRoot, useCollapsibleTrigger } from "./hooks/index.ts";
|
|
7
11
|
|
|
8
12
|
import type {
|
|
9
13
|
CollapsibleRootProps,
|
|
@@ -63,7 +67,7 @@ export function CollapsibleRoot({
|
|
|
63
67
|
onOpenChange,
|
|
64
68
|
disabled = false,
|
|
65
69
|
...rest
|
|
66
|
-
}: CollapsibleRootProps) {
|
|
70
|
+
}: CollapsibleRootProps): ReactElement {
|
|
67
71
|
const { contextValue } = useCollapsibleRoot(
|
|
68
72
|
controlledOpen,
|
|
69
73
|
defaultOpen,
|
|
@@ -140,16 +144,14 @@ CollapsibleRoot.displayName = "CollapsibleRoot";
|
|
|
140
144
|
* </Collapsible.Trigger>
|
|
141
145
|
* ```
|
|
142
146
|
*/
|
|
143
|
-
export function CollapsibleTrigger<
|
|
144
|
-
T extends HTMLElement = HTMLButtonElement,
|
|
145
|
-
>({
|
|
147
|
+
export function CollapsibleTrigger<T extends HTMLElement = HTMLButtonElement>({
|
|
146
148
|
ref,
|
|
147
149
|
children,
|
|
148
150
|
onClick,
|
|
149
151
|
onKeyDown,
|
|
150
152
|
asChild = false,
|
|
151
153
|
...rest
|
|
152
|
-
}: CollapsibleTriggerProps<T>) {
|
|
154
|
+
}: CollapsibleTriggerProps<T>): ReactElement {
|
|
153
155
|
const { triggerProps } = useCollapsibleTrigger({
|
|
154
156
|
ref: ref as Ref<HTMLButtonElement>,
|
|
155
157
|
onClick,
|
|
@@ -222,7 +224,7 @@ export function CollapsibleContent({
|
|
|
222
224
|
children,
|
|
223
225
|
forceMount = false,
|
|
224
226
|
...rest
|
|
225
|
-
}: CollapsibleContentProps) {
|
|
227
|
+
}: CollapsibleContentProps): ReactElement {
|
|
226
228
|
const { open, disabled, contentId } = useCollapsibleContext();
|
|
227
229
|
|
|
228
230
|
return (
|
|
@@ -281,15 +283,11 @@ CollapsibleContent.displayName = "CollapsibleContent";
|
|
|
281
283
|
export function CollapsibleTriggerIcon({
|
|
282
284
|
children,
|
|
283
285
|
...rest
|
|
284
|
-
}: CollapsibleTriggerIconProps) {
|
|
286
|
+
}: CollapsibleTriggerIconProps): ReactElement {
|
|
285
287
|
const { open } = useCollapsibleContext();
|
|
286
288
|
|
|
287
289
|
return (
|
|
288
|
-
<span
|
|
289
|
-
aria-hidden="true"
|
|
290
|
-
data-state={open ? "open" : "closed"}
|
|
291
|
-
{...rest}
|
|
292
|
-
>
|
|
290
|
+
<span aria-hidden="true" data-state={open ? "open" : "closed"} {...rest}>
|
|
293
291
|
{children}
|
|
294
292
|
</span>
|
|
295
293
|
);
|
|
@@ -304,12 +302,15 @@ type CollapsibleCompound = typeof CollapsibleRoot & {
|
|
|
304
302
|
TriggerIcon: typeof CollapsibleTriggerIcon;
|
|
305
303
|
};
|
|
306
304
|
|
|
307
|
-
const CollapsibleCompound: CollapsibleCompound = Object.assign(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
305
|
+
const CollapsibleCompound: CollapsibleCompound = Object.assign(
|
|
306
|
+
CollapsibleRoot,
|
|
307
|
+
{
|
|
308
|
+
Root: CollapsibleRoot,
|
|
309
|
+
Trigger: CollapsibleTrigger,
|
|
310
|
+
Content: CollapsibleContent,
|
|
311
|
+
TriggerIcon: CollapsibleTriggerIcon,
|
|
312
|
+
},
|
|
313
|
+
);
|
|
313
314
|
|
|
314
315
|
CollapsibleCompound.displayName = "Collapsible";
|
|
315
316
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, MouseEvent, KeyboardEvent } from "react";
|
|
2
2
|
|
|
3
|
-
import { composeRefs } from "../../Slot";
|
|
3
|
+
import { composeRefs } from "../../Slot/index.ts";
|
|
4
4
|
|
|
5
5
|
import { CollapsibleTriggerProps } from "../types";
|
|
6
6
|
import { useCollapsibleContext } from "../CollapsibleContext";
|
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
useRef,
|
|
8
8
|
useState,
|
|
9
9
|
} from "react";
|
|
10
|
+
import type { ReactElement } from "react";
|
|
10
11
|
|
|
11
|
-
import { useCheckboxRoot } from "../Checkbox/hooks";
|
|
12
|
-
import { useDirection } from "../DirectionProvider";
|
|
13
|
-
import { useRadioGroupRoot } from "../RadioGroup/hooks";
|
|
14
|
-
import { useControllableState } from "../hooks";
|
|
15
|
-
import { Slot, composeEventHandlers } from "../Slot";
|
|
12
|
+
import { useCheckboxRoot } from "../Checkbox/hooks/index.ts";
|
|
13
|
+
import { useDirection } from "../DirectionProvider/index.ts";
|
|
14
|
+
import { useRadioGroupRoot } from "../RadioGroup/hooks/index.ts";
|
|
15
|
+
import { useControllableState } from "../hooks/index.ts";
|
|
16
|
+
import { Slot, composeEventHandlers } from "../Slot/index.ts";
|
|
16
17
|
|
|
17
18
|
import {
|
|
18
19
|
ContextMenuContext,
|
|
@@ -73,7 +74,7 @@ function ContextMenuRoot({
|
|
|
73
74
|
onOpenChange,
|
|
74
75
|
dir,
|
|
75
76
|
children,
|
|
76
|
-
}: ContextMenuRootProps) {
|
|
77
|
+
}: ContextMenuRootProps): ReactElement {
|
|
77
78
|
const contentId = useId();
|
|
78
79
|
const triggerRef = useRef<HTMLElement | null>(null);
|
|
79
80
|
const [position, setPosition] = useState<ContextMenuPosition | null>(null);
|
|
@@ -146,7 +147,7 @@ function ContextMenuTrigger({
|
|
|
146
147
|
asChild = false,
|
|
147
148
|
disabled,
|
|
148
149
|
...rest
|
|
149
|
-
}: ContextMenuTriggerProps) {
|
|
150
|
+
}: ContextMenuTriggerProps): ReactElement {
|
|
150
151
|
const { setOpen, setPosition, triggerRef } = useContextMenuContext();
|
|
151
152
|
|
|
152
153
|
const handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
|
|
@@ -201,7 +202,7 @@ function ContextMenuContent({
|
|
|
201
202
|
onKeyDown,
|
|
202
203
|
asChild = false,
|
|
203
204
|
...rest
|
|
204
|
-
}: ContextMenuContentProps) {
|
|
205
|
+
}: ContextMenuContentProps): ReactElement {
|
|
205
206
|
const { open, setOpen, position, contentId, triggerRef } =
|
|
206
207
|
useContextMenuContext();
|
|
207
208
|
const menuRef = useRef<HTMLMenuElement | null>(null);
|
|
@@ -393,7 +394,7 @@ function ContextMenuItem({
|
|
|
393
394
|
disabled,
|
|
394
395
|
asChild = false,
|
|
395
396
|
...rest
|
|
396
|
-
}: ContextMenuItemProps) {
|
|
397
|
+
}: ContextMenuItemProps): ReactElement {
|
|
397
398
|
const { setOpen } = useContextMenuContext();
|
|
398
399
|
const closeSiblingSub = useCloseSiblingSub();
|
|
399
400
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -441,7 +442,7 @@ function ContextMenuSeparator({
|
|
|
441
442
|
asChild = false,
|
|
442
443
|
children,
|
|
443
444
|
...rest
|
|
444
|
-
}: ContextMenuSeparatorProps) {
|
|
445
|
+
}: ContextMenuSeparatorProps): ReactElement {
|
|
445
446
|
const separatorProps = { ...rest, role: "separator" as const };
|
|
446
447
|
|
|
447
448
|
if (asChild) {
|
|
@@ -465,7 +466,7 @@ function ContextMenuGroup({
|
|
|
465
466
|
children,
|
|
466
467
|
asChild = false,
|
|
467
468
|
...rest
|
|
468
|
-
}: ContextMenuGroupProps) {
|
|
469
|
+
}: ContextMenuGroupProps): ReactElement {
|
|
469
470
|
const labelId = useId();
|
|
470
471
|
const contextValue = useMemo(() => ({ labelId }), [labelId]);
|
|
471
472
|
const groupProps = {
|
|
@@ -501,7 +502,7 @@ function ContextMenuLabel({
|
|
|
501
502
|
children,
|
|
502
503
|
asChild = false,
|
|
503
504
|
...rest
|
|
504
|
-
}: ContextMenuLabelProps) {
|
|
505
|
+
}: ContextMenuLabelProps): ReactElement {
|
|
505
506
|
const group = useContext(ContextMenuGroupContext);
|
|
506
507
|
const labelProps = { ...rest, id: id ?? group?.labelId };
|
|
507
508
|
|
|
@@ -536,7 +537,7 @@ function ContextMenuCheckboxItem({
|
|
|
536
537
|
onCheckedChange,
|
|
537
538
|
asChild = false,
|
|
538
539
|
...rest
|
|
539
|
-
}: ContextMenuCheckboxItemProps) {
|
|
540
|
+
}: ContextMenuCheckboxItemProps): ReactElement {
|
|
540
541
|
const { setOpen } = useContextMenuContext();
|
|
541
542
|
const closeSiblingSub = useCloseSiblingSub();
|
|
542
543
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -609,7 +610,7 @@ function ContextMenuItemIndicator({
|
|
|
609
610
|
asChild = false,
|
|
610
611
|
forceMount = false,
|
|
611
612
|
...rest
|
|
612
|
-
}: ContextMenuItemIndicatorProps) {
|
|
613
|
+
}: ContextMenuItemIndicatorProps): ReactElement | null {
|
|
613
614
|
const context = useContext(ContextMenuItemIndicatorContext);
|
|
614
615
|
if (!context) {
|
|
615
616
|
throw new Error(
|
|
@@ -650,7 +651,7 @@ function ContextMenuRadioGroup({
|
|
|
650
651
|
children,
|
|
651
652
|
asChild = false,
|
|
652
653
|
...rest
|
|
653
|
-
}: ContextMenuRadioGroupProps) {
|
|
654
|
+
}: ContextMenuRadioGroupProps): ReactElement {
|
|
654
655
|
const { value, select } = useRadioGroupRoot({
|
|
655
656
|
defaultValue,
|
|
656
657
|
value: controlledValue,
|
|
@@ -694,7 +695,7 @@ function ContextMenuRadioItem({
|
|
|
694
695
|
value: itemValue,
|
|
695
696
|
asChild = false,
|
|
696
697
|
...rest
|
|
697
|
-
}: ContextMenuRadioItemProps) {
|
|
698
|
+
}: ContextMenuRadioItemProps): ReactElement {
|
|
698
699
|
const { setOpen } = useContextMenuContext();
|
|
699
700
|
const closeSiblingSub = useCloseSiblingSub();
|
|
700
701
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -761,7 +762,7 @@ function ContextMenuSub({
|
|
|
761
762
|
open: controlledOpen,
|
|
762
763
|
onOpenChange,
|
|
763
764
|
children,
|
|
764
|
-
}: ContextMenuSubProps) {
|
|
765
|
+
}: ContextMenuSubProps): ReactElement {
|
|
765
766
|
const contentId = useId();
|
|
766
767
|
const triggerRef = useRef<HTMLLIElement | null>(null);
|
|
767
768
|
const [open, setOpenBase] = useControllableState<boolean>(
|
|
@@ -834,7 +835,7 @@ function ContextMenuSubTrigger({
|
|
|
834
835
|
disabled,
|
|
835
836
|
asChild = false,
|
|
836
837
|
...rest
|
|
837
|
-
}: ContextMenuSubTriggerProps) {
|
|
838
|
+
}: ContextMenuSubTriggerProps): ReactElement {
|
|
838
839
|
const sub = useContextMenuSubContext();
|
|
839
840
|
const { dir } = useContextMenuContext();
|
|
840
841
|
const openKey = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
@@ -894,7 +895,7 @@ function ContextMenuSubContent({
|
|
|
894
895
|
onKeyDown,
|
|
895
896
|
asChild = false,
|
|
896
897
|
...rest
|
|
897
|
-
}: ContextMenuSubContentProps) {
|
|
898
|
+
}: ContextMenuSubContentProps): ReactElement {
|
|
898
899
|
const sub = useContextMenuSubContext();
|
|
899
900
|
const { dir } = useContextMenuContext();
|
|
900
901
|
const closeKey = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
@@ -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 ContextMenuPosition = { x: number; y: number };
|
|
7
7
|
|
|
@@ -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 { ContextMenu } from "../ContextMenu";
|
|
6
6
|
|
|
7
7
|
describe("ContextMenu reading direction", () => {
|
package/src/ContextMenu/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
2
|
|
|
3
3
|
import { CheckedState } from "../Checkbox/types";
|
|
4
|
-
import { Direction } from "../DirectionProvider";
|
|
4
|
+
import { Direction } from "../DirectionProvider/index.ts";
|
|
5
5
|
|
|
6
6
|
type ContextMenuRootBaseProps = {
|
|
7
7
|
children?: ReactNode;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
|
|
1
3
|
import { DirectionContext } from "./DirectionContext";
|
|
2
4
|
import { DirectionProviderProps } from "./types";
|
|
3
5
|
|
|
@@ -20,7 +22,10 @@ import { DirectionProviderProps } from "./types";
|
|
|
20
22
|
* </DirectionProvider>
|
|
21
23
|
* ```
|
|
22
24
|
*/
|
|
23
|
-
export function DirectionProvider({
|
|
25
|
+
export function DirectionProvider({
|
|
26
|
+
dir,
|
|
27
|
+
children,
|
|
28
|
+
}: DirectionProviderProps): ReactElement {
|
|
24
29
|
return (
|
|
25
30
|
<DirectionContext.Provider value={dir}>
|
|
26
31
|
{children}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { render, screen } from "@testing-library/react";
|
|
2
2
|
|
|
3
|
-
import { DirectionProvider, useDirection } from "
|
|
3
|
+
import { DirectionProvider, useDirection } from "../index.ts";
|
|
4
4
|
|
|
5
5
|
function DirectionProbe() {
|
|
6
6
|
return <span data-testid="probe">{useDirection()}</span>;
|
package/src/Divider/Divider.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
|
|
1
3
|
import { DividerProps } from "./types";
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -43,7 +45,7 @@ export function Divider({
|
|
|
43
45
|
orientation = "horizontal",
|
|
44
46
|
className = "",
|
|
45
47
|
...rest
|
|
46
|
-
}: DividerProps) {
|
|
48
|
+
}: DividerProps): ReactElement {
|
|
47
49
|
return (
|
|
48
50
|
<span
|
|
49
51
|
role="separator"
|
|
@@ -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,
|
|
@@ -90,7 +91,7 @@ function DropdownRoot({
|
|
|
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,
|
|
@@ -131,7 +132,7 @@ function DropdownTrigger({
|
|
|
131
132
|
onClick,
|
|
132
133
|
asChild = false,
|
|
133
134
|
...rest
|
|
134
|
-
}: DropdownTriggerProps) {
|
|
135
|
+
}: DropdownTriggerProps): ReactElement {
|
|
135
136
|
const { triggerProps } = useDropdownTrigger({ onClick, restProps: rest });
|
|
136
137
|
|
|
137
138
|
if (asChild) {
|
|
@@ -183,7 +184,7 @@ function DropdownContent({
|
|
|
183
184
|
onKeyDown,
|
|
184
185
|
asChild = false,
|
|
185
186
|
...rest
|
|
186
|
-
}: DropdownContentProps) {
|
|
187
|
+
}: DropdownContentProps): ReactElement {
|
|
187
188
|
const { contentContextValue, contentProps } = useDropdownContent({
|
|
188
189
|
onKeyDown,
|
|
189
190
|
restProps: rest,
|
|
@@ -222,7 +223,7 @@ function DropdownItem({
|
|
|
222
223
|
disabled,
|
|
223
224
|
asChild = false,
|
|
224
225
|
...rest
|
|
225
|
-
}: DropdownItemProps) {
|
|
226
|
+
}: DropdownItemProps): ReactElement {
|
|
226
227
|
const { itemProps } = useDropdownItem({
|
|
227
228
|
disabled,
|
|
228
229
|
onClick,
|
|
@@ -248,7 +249,7 @@ function DropdownSeparator({
|
|
|
248
249
|
asChild = false,
|
|
249
250
|
children,
|
|
250
251
|
...rest
|
|
251
|
-
}: DropdownSeparatorProps) {
|
|
252
|
+
}: DropdownSeparatorProps): ReactElement {
|
|
252
253
|
const separatorProps = { ...rest, role: "separator" as const };
|
|
253
254
|
|
|
254
255
|
if (asChild) {
|
|
@@ -274,7 +275,7 @@ function DropdownGroup({
|
|
|
274
275
|
children,
|
|
275
276
|
asChild = false,
|
|
276
277
|
...rest
|
|
277
|
-
}: DropdownGroupProps) {
|
|
278
|
+
}: DropdownGroupProps): ReactElement {
|
|
278
279
|
const { contextValue, groupProps } = useDropdownGroup({ restProps: rest });
|
|
279
280
|
|
|
280
281
|
return (
|
|
@@ -306,7 +307,7 @@ function DropdownLabel({
|
|
|
306
307
|
children,
|
|
307
308
|
asChild = false,
|
|
308
309
|
...rest
|
|
309
|
-
}: DropdownLabelProps) {
|
|
310
|
+
}: DropdownLabelProps): ReactElement {
|
|
310
311
|
const { labelProps } = useDropdownLabel({ id, restProps: rest });
|
|
311
312
|
|
|
312
313
|
if (asChild) {
|
|
@@ -353,7 +354,7 @@ function DropdownCheckboxItem({
|
|
|
353
354
|
onCheckedChange,
|
|
354
355
|
asChild = false,
|
|
355
356
|
...rest
|
|
356
|
-
}: DropdownCheckboxItemProps) {
|
|
357
|
+
}: DropdownCheckboxItemProps): ReactElement {
|
|
357
358
|
const { setOpen, triggerRef } = useDropdownContext();
|
|
358
359
|
const closeSiblingSub = useCloseSiblingSub();
|
|
359
360
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -424,7 +425,7 @@ function DropdownRadioGroup({
|
|
|
424
425
|
children,
|
|
425
426
|
asChild = false,
|
|
426
427
|
...rest
|
|
427
|
-
}: DropdownRadioGroupProps) {
|
|
428
|
+
}: DropdownRadioGroupProps): ReactElement {
|
|
428
429
|
const { value, select } = useRadioGroupRoot({
|
|
429
430
|
defaultValue,
|
|
430
431
|
value: controlledValue,
|
|
@@ -475,7 +476,7 @@ function DropdownRadioItem({
|
|
|
475
476
|
value: itemValue,
|
|
476
477
|
asChild = false,
|
|
477
478
|
...rest
|
|
478
|
-
}: DropdownRadioItemProps) {
|
|
479
|
+
}: DropdownRadioItemProps): ReactElement {
|
|
479
480
|
const { setOpen, triggerRef } = useDropdownContext();
|
|
480
481
|
const closeSiblingSub = useCloseSiblingSub();
|
|
481
482
|
const [highlighted, setHighlighted] = useState(false);
|
|
@@ -559,7 +560,7 @@ function DropdownItemIndicator({
|
|
|
559
560
|
asChild = false,
|
|
560
561
|
forceMount = false,
|
|
561
562
|
...rest
|
|
562
|
-
}: DropdownItemIndicatorProps) {
|
|
563
|
+
}: DropdownItemIndicatorProps): ReactElement | null {
|
|
563
564
|
const context = useContext(DropdownItemIndicatorContext);
|
|
564
565
|
if (!context) {
|
|
565
566
|
throw new Error(
|
|
@@ -613,7 +614,7 @@ function DropdownSub({
|
|
|
613
614
|
open: controlledOpen,
|
|
614
615
|
onOpenChange,
|
|
615
616
|
children,
|
|
616
|
-
}: DropdownSubProps) {
|
|
617
|
+
}: DropdownSubProps): ReactElement {
|
|
617
618
|
const { open, setOpen } = useDropdownRoot({
|
|
618
619
|
defaultOpen,
|
|
619
620
|
open: controlledOpen,
|
|
@@ -678,7 +679,7 @@ function DropdownSubTrigger({
|
|
|
678
679
|
disabled,
|
|
679
680
|
asChild = false,
|
|
680
681
|
...rest
|
|
681
|
-
}: DropdownSubTriggerProps) {
|
|
682
|
+
}: DropdownSubTriggerProps): ReactElement {
|
|
682
683
|
const sub = useDropdownSubContext();
|
|
683
684
|
const { dir } = useDropdownContext();
|
|
684
685
|
const openKey = dir === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
@@ -741,7 +742,7 @@ function DropdownSubContent({
|
|
|
741
742
|
onKeyDown,
|
|
742
743
|
asChild = false,
|
|
743
744
|
...rest
|
|
744
|
-
}: DropdownSubContentProps) {
|
|
745
|
+
}: DropdownSubContentProps): ReactElement {
|
|
745
746
|
const sub = useDropdownSubContext();
|
|
746
747
|
const { dir } = useDropdownContext();
|
|
747
748
|
const closeKey = dir === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
@@ -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;
|