@primitiv-ui/react 0.1.1 → 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 +1 -0
- package/src/AccessibleIcon/types.ts +4 -0
- package/src/Accordion/Accordion.tsx +23 -0
- package/src/Accordion/index.ts +2 -1
- package/src/Accordion/types.ts +55 -13
- package/src/Alert/Alert.tsx +1 -0
- package/src/Alert/types.ts +1 -0
- package/src/Avatar/Avatar.tsx +8 -4
- package/src/Avatar/AvatarContext.ts +2 -0
- package/src/Breadcrumb/Breadcrumb.tsx +15 -7
- package/src/Button/Button.tsx +1 -0
- package/src/Button/types.ts +4 -0
- package/src/Carousel/Carousel.tsx +9 -0
- package/src/Carousel/CarouselContext.ts +5 -2
- package/src/Carousel/types.ts +8 -0
- package/src/Checkbox/Checkbox.tsx +7 -3
- package/src/Checkbox/index.ts +1 -0
- package/src/Checkbox/types.ts +30 -3
- package/src/CheckboxCard/CheckboxCard.tsx +9 -8
- package/src/CheckboxCard/CheckboxCardContext.ts +9 -1
- package/src/CheckboxCard/hooks/useCheckboxCardRoot.ts +1 -1
- package/src/CheckboxCard/types.ts +21 -5
- package/src/Collapsible/Collapsible.tsx +15 -0
- package/src/Collapsible/index.ts +1 -0
- package/src/Collapsible/types.ts +45 -12
- package/src/ContextMenu/ContextMenu.tsx +40 -15
- package/src/ContextMenu/index.ts +2 -1
- package/src/ContextMenu/types.ts +159 -16
- package/src/DirectionProvider/DirectionProvider.tsx +1 -0
- package/src/DirectionProvider/types.ts +1 -0
- package/src/Divider/Divider.tsx +1 -0
- package/src/Divider/index.ts +2 -1
- package/src/Divider/types.ts +5 -0
- package/src/Dropdown/Dropdown.tsx +40 -15
- package/src/Dropdown/index.ts +2 -1
- package/src/Dropdown/types.ts +152 -24
- package/src/EmptyState/EmptyState.tsx +26 -14
- package/src/EmptyState/types.ts +2 -1
- package/src/Field/Field.tsx +14 -5
- package/src/Field/types.ts +4 -0
- package/src/Fieldset/Fieldset.tsx +17 -10
- package/src/Fieldset/types.ts +2 -0
- package/src/Input/Input.tsx +1 -0
- package/src/Input/types.ts +4 -0
- package/src/InputGroup/InputGroup.tsx +9 -4
- package/src/InputGroup/types.ts +9 -0
- package/src/MillerColumns/MillerColumns.tsx +19 -0
- package/src/MillerColumns/index.ts +1 -1
- package/src/MillerColumns/types.ts +67 -14
- package/src/Modal/Modal.tsx +1 -0
- package/src/Modal/ModalContext.ts +5 -2
- package/src/Modal/types.ts +51 -2
- package/src/Portal/Portal.tsx +1 -0
- package/src/Portal/types.ts +4 -0
- package/src/Progress/Progress.tsx +7 -3
- package/src/Progress/ProgressContext.ts +7 -0
- package/src/RadioCard/RadioCard.tsx +9 -4
- package/src/RadioCard/RadioCardContext.ts +7 -0
- package/src/RadioCard/RadioCardItemContext.ts +8 -0
- package/src/RadioCard/types.ts +24 -3
- package/src/RadioGroup/RadioGroup.tsx +9 -4
- package/src/RadioGroup/index.ts +1 -0
- package/src/RadioGroup/types.ts +34 -3
- package/src/Select/Select.tsx +16 -5
- package/src/Select/index.ts +1 -1
- package/src/Select/types.ts +18 -3
- package/src/Slider/Slider.tsx +10 -5
- package/src/Slider/SliderContext.ts +3 -0
- package/src/Slider/types.ts +12 -3
- package/src/Status/Status.tsx +1 -0
- package/src/Status/types.ts +4 -0
- package/src/Switch/Switch.tsx +8 -3
- package/src/Switch/SwitchContext.ts +4 -0
- package/src/Switch/types.ts +24 -3
- package/src/Table/Table.tsx +44 -24
- package/src/Table/index.ts +2 -1
- package/src/Tabs/Tabs.tsx +7 -2
- package/src/Tabs/TabsContext.ts +7 -2
- package/src/Tabs/types.ts +35 -1
- package/src/Textarea/Textarea.tsx +1 -0
- package/src/Textarea/types.ts +4 -0
- package/src/Toggle/Toggle.tsx +1 -0
- package/src/Toggle/types.ts +7 -3
- package/src/ToggleGroup/ToggleGroup.tsx +9 -3
- package/src/ToggleGroup/types.ts +45 -5
- package/src/Tooltip/Tooltip.tsx +25 -7
- package/src/Tooltip/index.ts +1 -0
- package/src/Tooltip/types.ts +50 -2
- package/src/Tree/Tree.tsx +46 -1
- package/src/Tree/index.ts +1 -1
- package/src/Tree/types.ts +39 -7
- package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
- package/src/VisuallyHidden/types.ts +4 -0
- package/src/index.ts +1 -0
- package/src/types.ts +1 -0
package/src/Checkbox/types.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
2
|
|
|
3
|
+
/** The checked value of a checkbox — `true`, `false`, or `"indeterminate"` (the tri-state). */
|
|
3
4
|
export type CheckedState = boolean | "indeterminate";
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Props for {@link Checkbox.Indicator} — all `<span>` attributes plus
|
|
8
|
+
* `forceMount` (keep mounted while unchecked for exit animations) and the
|
|
9
|
+
* `asChild` escape hatch.
|
|
10
|
+
*/
|
|
5
11
|
export type CheckboxIndicatorProps = ComponentProps<"span"> & {
|
|
6
12
|
children?: ReactNode;
|
|
7
13
|
forceMount?: boolean;
|
|
8
14
|
asChild?: boolean;
|
|
9
15
|
};
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Shared base for both {@link CheckboxRootProps} variants — the native
|
|
19
|
+
* `<button>` attributes (minus the ones the component owns) plus the
|
|
20
|
+
* `asChild` escape hatch and a typed `ref`.
|
|
21
|
+
*/
|
|
22
|
+
export type CheckboxRootBaseProps = Omit<
|
|
12
23
|
ComponentProps<"button">,
|
|
13
24
|
"type" | "role" | "aria-checked" | "defaultChecked"
|
|
14
25
|
> & {
|
|
@@ -16,18 +27,34 @@ type CheckboxRootBaseProps = Omit<
|
|
|
16
27
|
ref?: Ref<HTMLButtonElement>;
|
|
17
28
|
};
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Uncontrolled variant of {@link CheckboxRootProps}: the component owns the
|
|
32
|
+
* checked value. Pass `defaultChecked` (or omit it); `onCheckedChange` is
|
|
33
|
+
* optional and `checked` is forbidden.
|
|
34
|
+
*/
|
|
35
|
+
export type CheckboxRootUncontrolledProps = CheckboxRootBaseProps & {
|
|
20
36
|
defaultChecked?: CheckedState;
|
|
21
37
|
checked?: never;
|
|
22
38
|
onCheckedChange?: (checked: boolean) => void;
|
|
23
39
|
};
|
|
24
40
|
|
|
25
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Controlled variant of {@link CheckboxRootProps}: the parent owns the
|
|
43
|
+
* checked value. Pass `checked` and `onCheckedChange` together;
|
|
44
|
+
* `defaultChecked` is forbidden.
|
|
45
|
+
*/
|
|
46
|
+
export type CheckboxRootControlledProps = CheckboxRootBaseProps & {
|
|
26
47
|
defaultChecked?: never;
|
|
27
48
|
checked: CheckedState;
|
|
28
49
|
onCheckedChange: (checked: boolean) => void;
|
|
29
50
|
};
|
|
30
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Props for {@link Checkbox.Root}. A discriminated union of
|
|
54
|
+
* {@link CheckboxRootUncontrolledProps} and
|
|
55
|
+
* {@link CheckboxRootControlledProps}, so TypeScript accepts exactly one
|
|
56
|
+
* state mode.
|
|
57
|
+
*/
|
|
31
58
|
export type CheckboxRootProps =
|
|
32
59
|
| CheckboxRootUncontrolledProps
|
|
33
60
|
| CheckboxRootControlledProps;
|
|
@@ -5,11 +5,8 @@ import { Slot, composeEventHandlers } from "../Slot/index.ts";
|
|
|
5
5
|
|
|
6
6
|
import { CheckboxCardContext } from "./CheckboxCardContext";
|
|
7
7
|
import { useCheckboxCardContext, useCheckboxCardRoot } from "./hooks/index.ts";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
CheckboxCardRootProps,
|
|
11
|
-
CheckedState,
|
|
12
|
-
} from "./types";
|
|
8
|
+
import { CheckboxCardIndicatorProps, CheckboxCardRootProps } from "./types";
|
|
9
|
+
import type { CheckedState } from "../Checkbox/types";
|
|
13
10
|
|
|
14
11
|
function dataStateOf(checked: CheckedState) {
|
|
15
12
|
if (checked === "indeterminate") return "indeterminate" as const;
|
|
@@ -67,7 +64,7 @@ function dataStateOf(checked: CheckedState) {
|
|
|
67
64
|
* </CheckboxCard.Root>
|
|
68
65
|
* ```
|
|
69
66
|
*/
|
|
70
|
-
function CheckboxCardRoot(props: CheckboxCardRootProps): ReactElement {
|
|
67
|
+
export function CheckboxCardRoot(props: CheckboxCardRootProps): ReactElement {
|
|
71
68
|
const {
|
|
72
69
|
defaultChecked,
|
|
73
70
|
checked,
|
|
@@ -109,6 +106,7 @@ function CheckboxCardRoot(props: CheckboxCardRootProps): ReactElement {
|
|
|
109
106
|
);
|
|
110
107
|
}
|
|
111
108
|
|
|
109
|
+
/** @internal */
|
|
112
110
|
CheckboxCardRoot.displayName = "CheckboxCardRoot";
|
|
113
111
|
|
|
114
112
|
/**
|
|
@@ -137,7 +135,7 @@ CheckboxCardRoot.displayName = "CheckboxCardRoot";
|
|
|
137
135
|
*
|
|
138
136
|
* @throws if rendered outside a `CheckboxCard.Root`.
|
|
139
137
|
*/
|
|
140
|
-
function CheckboxCardIndicator({
|
|
138
|
+
export function CheckboxCardIndicator({
|
|
141
139
|
children,
|
|
142
140
|
forceMount,
|
|
143
141
|
asChild = false,
|
|
@@ -157,9 +155,12 @@ function CheckboxCardIndicator({
|
|
|
157
155
|
return <span {...indicatorProps}>{children}</span>;
|
|
158
156
|
}
|
|
159
157
|
|
|
158
|
+
/** @internal */
|
|
160
159
|
CheckboxCardIndicator.displayName = "CheckboxCardIndicator";
|
|
161
160
|
|
|
162
|
-
|
|
161
|
+
/** Type of the {@link CheckboxCard} compound: the callable `CheckboxCard.Root`
|
|
162
|
+
* component augmented with its sub-components as static properties. */
|
|
163
|
+
export type TCheckboxCardCompound = typeof CheckboxCardRoot & {
|
|
163
164
|
Root: typeof CheckboxCardRoot;
|
|
164
165
|
Indicator: typeof CheckboxCardIndicator;
|
|
165
166
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Context } from "react";
|
|
2
2
|
import { createStrictContext } from "../utils/index.ts";
|
|
3
3
|
|
|
4
|
-
import { CheckedState } from "
|
|
4
|
+
import type { CheckedState } from "../Checkbox/types";
|
|
5
5
|
|
|
6
|
+
/** The value shared by `CheckboxCard.Root` with its `CheckboxCard.Indicator`,
|
|
7
|
+
* exposing the current checked state. */
|
|
6
8
|
export type CheckboxCardContextValue = {
|
|
9
|
+
/** Current checked state of the card. */
|
|
7
10
|
checked: CheckedState;
|
|
8
11
|
};
|
|
9
12
|
|
|
@@ -11,7 +14,12 @@ const checkboxCardContextPair = createStrictContext<CheckboxCardContextValue>(
|
|
|
11
14
|
"CheckboxCard sub-components must be rendered inside a <CheckboxCard.Root>.",
|
|
12
15
|
);
|
|
13
16
|
|
|
17
|
+
/** Strict React context carrying the {@link CheckboxCardContextValue} from
|
|
18
|
+
* `CheckboxCard.Root` to its indicator. `null` when read outside a
|
|
19
|
+
* `CheckboxCard.Root`. */
|
|
14
20
|
export const CheckboxCardContext: Context<CheckboxCardContextValue | null> =
|
|
15
21
|
checkboxCardContextPair[0];
|
|
22
|
+
/** Reads the {@link CheckboxCardContextValue}; throws when used outside a
|
|
23
|
+
* `CheckboxCard.Root`. */
|
|
16
24
|
export const useCheckboxCardContext: () => CheckboxCardContextValue =
|
|
17
25
|
checkboxCardContextPair[1];
|
|
@@ -2,7 +2,7 @@ import { useCallback } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useControllableState } from "../../hooks/index.ts";
|
|
4
4
|
|
|
5
|
-
import { CheckedState } from "
|
|
5
|
+
import type { CheckedState } from "../../Checkbox/types";
|
|
6
6
|
|
|
7
7
|
type UseCheckboxCardRootArgs = {
|
|
8
8
|
defaultChecked?: CheckedState;
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
|
+
import type { CheckedState } from "../Checkbox/types";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/** Props for `CheckboxCard.Indicator` — the visual marker shown when the card
|
|
5
|
+
* is checked. By default it renders only while checked; set `forceMount` to
|
|
6
|
+
* keep it mounted for exit transitions. */
|
|
5
7
|
export type CheckboxCardIndicatorProps = ComponentProps<"span"> & {
|
|
6
8
|
children?: ReactNode;
|
|
7
9
|
forceMount?: boolean;
|
|
8
10
|
asChild?: boolean;
|
|
9
11
|
};
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/** Props shared by both controlled and uncontrolled `CheckboxCard.Root` usage.
|
|
14
|
+
* Extends the native `<button>` props (minus the checkbox-managed ones). */
|
|
15
|
+
export type CheckboxCardRootBaseProps = Omit<
|
|
12
16
|
ComponentProps<"button">,
|
|
13
17
|
"type" | "role" | "aria-checked" | "defaultChecked"
|
|
14
18
|
> & {
|
|
19
|
+
/** Render the child element instead of the default `<button>`. */
|
|
15
20
|
asChild?: boolean;
|
|
21
|
+
/** Ref to the rendered element. */
|
|
16
22
|
ref?: Ref<HTMLButtonElement>;
|
|
17
23
|
};
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
/** Uncontrolled `CheckboxCard.Root` props: the component owns the checked
|
|
26
|
+
* state, seeded by an optional `defaultChecked`. */
|
|
27
|
+
export type CheckboxCardRootUncontrolledProps = CheckboxCardRootBaseProps & {
|
|
28
|
+
/** Checked state on first render. */
|
|
20
29
|
defaultChecked?: CheckedState;
|
|
21
30
|
checked?: never;
|
|
31
|
+
/** Called with the new boolean checked state when it changes. */
|
|
22
32
|
onCheckedChange?: (checked: boolean) => void;
|
|
23
33
|
};
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
/** Controlled `CheckboxCard.Root` props: the caller owns the checked state via
|
|
36
|
+
* `checked` and is notified through the required `onCheckedChange`. */
|
|
37
|
+
export type CheckboxCardRootControlledProps = CheckboxCardRootBaseProps & {
|
|
26
38
|
defaultChecked?: never;
|
|
39
|
+
/** Current checked state. */
|
|
27
40
|
checked: CheckedState;
|
|
41
|
+
/** Called with the new boolean checked state when the user toggles. */
|
|
28
42
|
onCheckedChange: (checked: boolean) => void;
|
|
29
43
|
};
|
|
30
44
|
|
|
45
|
+
/** Props for `CheckboxCard.Root` — resolves to either the controlled or
|
|
46
|
+
* uncontrolled prop shape. */
|
|
31
47
|
export type CheckboxCardRootProps =
|
|
32
48
|
| CheckboxCardRootUncontrolledProps
|
|
33
49
|
| CheckboxCardRootControlledProps;
|
|
@@ -88,6 +88,7 @@ export function CollapsibleRoot({
|
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/** @internal */
|
|
91
92
|
CollapsibleRoot.displayName = "CollapsibleRoot";
|
|
92
93
|
|
|
93
94
|
/**
|
|
@@ -171,6 +172,7 @@ export function CollapsibleTrigger<T extends HTMLElement = HTMLButtonElement>({
|
|
|
171
172
|
);
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
/** @internal */
|
|
174
176
|
CollapsibleTrigger.displayName = "CollapsibleTrigger";
|
|
175
177
|
|
|
176
178
|
/**
|
|
@@ -241,6 +243,7 @@ export function CollapsibleContent({
|
|
|
241
243
|
);
|
|
242
244
|
}
|
|
243
245
|
|
|
246
|
+
/** @internal */
|
|
244
247
|
CollapsibleContent.displayName = "CollapsibleContent";
|
|
245
248
|
|
|
246
249
|
/**
|
|
@@ -293,15 +296,27 @@ export function CollapsibleTriggerIcon({
|
|
|
293
296
|
);
|
|
294
297
|
}
|
|
295
298
|
|
|
299
|
+
/** @internal */
|
|
296
300
|
CollapsibleTriggerIcon.displayName = "CollapsibleTriggerIcon";
|
|
297
301
|
|
|
302
|
+
/** Type of the {@link Collapsible} compound — the Root callable plus its sub-components. */
|
|
298
303
|
type CollapsibleCompound = typeof CollapsibleRoot & {
|
|
304
|
+
/** The root, owning open/closed state and context. */
|
|
299
305
|
Root: typeof CollapsibleRoot;
|
|
306
|
+
/** The button that toggles the panel. */
|
|
300
307
|
Trigger: typeof CollapsibleTrigger;
|
|
308
|
+
/** The collapsible panel. */
|
|
301
309
|
Content: typeof CollapsibleContent;
|
|
310
|
+
/** An aria-hidden icon wrapper with an open/closed `data-state` hook. */
|
|
302
311
|
TriggerIcon: typeof CollapsibleTriggerIcon;
|
|
303
312
|
};
|
|
304
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Collapsible — a single disclosure widget pairing a trigger with a panel
|
|
316
|
+
* that expands and collapses. Use as a namespace (`Collapsible.Root`,
|
|
317
|
+
* `Collapsible.Trigger`, `Collapsible.Content`, `Collapsible.TriggerIcon`);
|
|
318
|
+
* the default export is also callable as the Root.
|
|
319
|
+
*/
|
|
305
320
|
const CollapsibleCompound: CollapsibleCompound = Object.assign(
|
|
306
321
|
CollapsibleRoot,
|
|
307
322
|
{
|
package/src/Collapsible/index.ts
CHANGED
package/src/Collapsible/types.ts
CHANGED
|
@@ -1,48 +1,81 @@
|
|
|
1
1
|
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** Props common to both controlled and uncontrolled `Collapsible.Root` modes. */
|
|
4
|
+
export type CollapsibleRootBaseProps = Omit<
|
|
5
|
+
ComponentProps<"div">,
|
|
6
|
+
"onChange"
|
|
7
|
+
> & {
|
|
8
|
+
/** When `true`, disables the widget and short-circuits trigger activation. */
|
|
4
9
|
disabled?: boolean;
|
|
5
10
|
};
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Props for `Collapsible.Root` in uncontrolled mode — the component owns the
|
|
14
|
+
* open state. Pass `defaultOpen` to set the initial value; `open` is forbidden.
|
|
15
|
+
*/
|
|
16
|
+
export type CollapsibleRootUncontrolledProps = CollapsibleRootBaseProps & {
|
|
17
|
+
/** Initial open state when uncontrolled. Defaults to `false`. */
|
|
8
18
|
defaultOpen?: boolean;
|
|
19
|
+
/** Forbidden in uncontrolled mode. */
|
|
9
20
|
open?: never;
|
|
21
|
+
/** Called whenever the open state changes. */
|
|
10
22
|
onOpenChange?: (open: boolean) => void;
|
|
11
23
|
};
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Props for `Collapsible.Root` in controlled mode — the parent owns the open
|
|
27
|
+
* value. Pass `open` and `onOpenChange` together; `defaultOpen` is forbidden.
|
|
28
|
+
*/
|
|
29
|
+
export type CollapsibleRootControlledProps = CollapsibleRootBaseProps & {
|
|
30
|
+
/** The controlled open state. */
|
|
14
31
|
open: boolean;
|
|
32
|
+
/** Called whenever the component requests an open-state change. */
|
|
15
33
|
onOpenChange: (open: boolean) => void;
|
|
34
|
+
/** Forbidden in controlled mode. */
|
|
16
35
|
defaultOpen?: never;
|
|
17
36
|
};
|
|
18
37
|
|
|
38
|
+
/** Props for `Collapsible.Root` — discriminated controlled/uncontrolled union. */
|
|
19
39
|
export type CollapsibleRootProps =
|
|
20
40
|
| CollapsibleRootUncontrolledProps
|
|
21
41
|
| CollapsibleRootControlledProps;
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
/** Props for `Collapsible.Trigger`, the button that toggles the panel. */
|
|
44
|
+
export type CollapsibleTriggerProps<T extends HTMLElement = HTMLButtonElement> =
|
|
45
|
+
Omit<ComponentProps<"button">, "ref"> & {
|
|
46
|
+
/** Trigger content (label, icon, etc.). */
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
/** Render the child element instead of the default `<button>`. */
|
|
49
|
+
asChild?: boolean;
|
|
50
|
+
/** Ref to the rendered element. Defaults to `HTMLButtonElement`; when using
|
|
51
|
+
* `asChild`, specify the child's element type (e.g. `HTMLAnchorElement`). */
|
|
52
|
+
ref?: Ref<T>;
|
|
53
|
+
};
|
|
32
54
|
|
|
55
|
+
/** Props for `Collapsible.Content`, the panel revealed when open. */
|
|
33
56
|
export type CollapsibleContentProps = ComponentProps<"div"> & {
|
|
57
|
+
/** Panel content. */
|
|
34
58
|
children: ReactNode;
|
|
59
|
+
/** Keep the panel mounted when closed so transitions can be CSS-driven. */
|
|
35
60
|
forceMount?: boolean;
|
|
36
61
|
};
|
|
37
62
|
|
|
63
|
+
/** Props for `Collapsible.TriggerIcon`, the aria-hidden icon wrapper. */
|
|
38
64
|
export type CollapsibleTriggerIconProps = ComponentProps<"span"> & {
|
|
65
|
+
/** The icon to render (inline SVG or icon component). */
|
|
39
66
|
children: ReactNode;
|
|
40
67
|
};
|
|
41
68
|
|
|
69
|
+
/** Value shared through Collapsible context to all sub-components. */
|
|
42
70
|
export type CollapsibleContextValue = {
|
|
71
|
+
/** Whether the panel is currently open. */
|
|
43
72
|
open: boolean;
|
|
73
|
+
/** Whether the widget is disabled. */
|
|
44
74
|
disabled: boolean;
|
|
75
|
+
/** Toggle the open state. */
|
|
45
76
|
toggle: () => void;
|
|
77
|
+
/** Generated id linking trigger to content. */
|
|
46
78
|
triggerId: string;
|
|
79
|
+
/** Generated id of the content panel. */
|
|
47
80
|
contentId: string;
|
|
48
81
|
};
|
|
@@ -68,7 +68,7 @@ import { MENUITEM_SELECTOR, TYPEAHEAD_RESET_MS } from "./constants";
|
|
|
68
68
|
* keys (`ArrowRight` ↔ `ArrowLeft`). When omitted, the component reads
|
|
69
69
|
* the inherited {@link DirectionProvider} value, falling back to `"ltr"`.
|
|
70
70
|
*/
|
|
71
|
-
function ContextMenuRoot({
|
|
71
|
+
export function ContextMenuRoot({
|
|
72
72
|
defaultOpen = false,
|
|
73
73
|
open: controlledOpen,
|
|
74
74
|
onOpenChange,
|
|
@@ -119,6 +119,7 @@ function ContextMenuRoot({
|
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/** @internal */
|
|
122
123
|
ContextMenuRoot.displayName = "ContextMenuRoot";
|
|
123
124
|
|
|
124
125
|
/**
|
|
@@ -141,7 +142,7 @@ function useCloseSiblingSub() {
|
|
|
141
142
|
* the native menu is suppressed and the ContextMenu opens, positioned at
|
|
142
143
|
* the pointer.
|
|
143
144
|
*/
|
|
144
|
-
function ContextMenuTrigger({
|
|
145
|
+
export function ContextMenuTrigger({
|
|
145
146
|
children,
|
|
146
147
|
onContextMenu,
|
|
147
148
|
asChild = false,
|
|
@@ -172,6 +173,7 @@ function ContextMenuTrigger({
|
|
|
172
173
|
return <span {...triggerProps}>{children}</span>;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
/** @internal */
|
|
175
177
|
ContextMenuTrigger.displayName = "ContextMenuTrigger";
|
|
176
178
|
|
|
177
179
|
/**
|
|
@@ -196,7 +198,7 @@ ContextMenuTrigger.displayName = "ContextMenuTrigger";
|
|
|
196
198
|
* that flip the menu to the opposite side when it would overflow the
|
|
197
199
|
* viewport. Pass `asChild` to render any element with menu semantics.
|
|
198
200
|
*/
|
|
199
|
-
function ContextMenuContent({
|
|
201
|
+
export function ContextMenuContent({
|
|
200
202
|
children,
|
|
201
203
|
style,
|
|
202
204
|
onKeyDown,
|
|
@@ -374,6 +376,7 @@ function ContextMenuContent({
|
|
|
374
376
|
);
|
|
375
377
|
}
|
|
376
378
|
|
|
379
|
+
/** @internal */
|
|
377
380
|
ContextMenuContent.displayName = "ContextMenuContent";
|
|
378
381
|
|
|
379
382
|
/**
|
|
@@ -387,7 +390,7 @@ ContextMenuContent.displayName = "ContextMenuContent";
|
|
|
387
390
|
*
|
|
388
391
|
* Disabled items receive `aria-disabled="true"` and no-op on activation.
|
|
389
392
|
*/
|
|
390
|
-
function ContextMenuItem({
|
|
393
|
+
export function ContextMenuItem({
|
|
391
394
|
children,
|
|
392
395
|
onClick,
|
|
393
396
|
onSelect,
|
|
@@ -431,6 +434,7 @@ function ContextMenuItem({
|
|
|
431
434
|
return <li {...itemProps}>{children}</li>;
|
|
432
435
|
}
|
|
433
436
|
|
|
437
|
+
/** @internal */
|
|
434
438
|
ContextMenuItem.displayName = "ContextMenuItem";
|
|
435
439
|
|
|
436
440
|
/**
|
|
@@ -438,7 +442,7 @@ ContextMenuItem.displayName = "ContextMenuItem";
|
|
|
438
442
|
* by default. Non-interactive — skipped by focus, arrow navigation, and
|
|
439
443
|
* typeahead.
|
|
440
444
|
*/
|
|
441
|
-
function ContextMenuSeparator({
|
|
445
|
+
export function ContextMenuSeparator({
|
|
442
446
|
asChild = false,
|
|
443
447
|
children,
|
|
444
448
|
...rest
|
|
@@ -452,6 +456,7 @@ function ContextMenuSeparator({
|
|
|
452
456
|
return <li {...separatorProps} />;
|
|
453
457
|
}
|
|
454
458
|
|
|
459
|
+
/** @internal */
|
|
455
460
|
ContextMenuSeparator.displayName = "ContextMenuSeparator";
|
|
456
461
|
|
|
457
462
|
/**
|
|
@@ -462,7 +467,7 @@ ContextMenuSeparator.displayName = "ContextMenuSeparator";
|
|
|
462
467
|
* Generates a stable id for its accompanying {@link ContextMenuLabel |
|
|
463
468
|
* `ContextMenu.Label`}, wired automatically via `aria-labelledby`.
|
|
464
469
|
*/
|
|
465
|
-
function ContextMenuGroup({
|
|
470
|
+
export function ContextMenuGroup({
|
|
466
471
|
children,
|
|
467
472
|
asChild = false,
|
|
468
473
|
...rest
|
|
@@ -488,6 +493,7 @@ function ContextMenuGroup({
|
|
|
488
493
|
);
|
|
489
494
|
}
|
|
490
495
|
|
|
496
|
+
/** @internal */
|
|
491
497
|
ContextMenuGroup.displayName = "ContextMenuGroup";
|
|
492
498
|
|
|
493
499
|
/**
|
|
@@ -497,7 +503,7 @@ ContextMenuGroup.displayName = "ContextMenuGroup";
|
|
|
497
503
|
* consumers don't need to thread ids manually. A caller-supplied `id` takes
|
|
498
504
|
* precedence over the auto-generated one.
|
|
499
505
|
*/
|
|
500
|
-
function ContextMenuLabel({
|
|
506
|
+
export function ContextMenuLabel({
|
|
501
507
|
id,
|
|
502
508
|
children,
|
|
503
509
|
asChild = false,
|
|
@@ -513,6 +519,7 @@ function ContextMenuLabel({
|
|
|
513
519
|
return <li {...labelProps}>{children}</li>;
|
|
514
520
|
}
|
|
515
521
|
|
|
522
|
+
/** @internal */
|
|
516
523
|
ContextMenuLabel.displayName = "ContextMenuLabel";
|
|
517
524
|
|
|
518
525
|
/**
|
|
@@ -527,7 +534,7 @@ ContextMenuLabel.displayName = "ContextMenuLabel";
|
|
|
527
534
|
*
|
|
528
535
|
* Disabled items receive `aria-disabled="true"` and no-op on activation.
|
|
529
536
|
*/
|
|
530
|
-
function ContextMenuCheckboxItem({
|
|
537
|
+
export function ContextMenuCheckboxItem({
|
|
531
538
|
children,
|
|
532
539
|
onClick,
|
|
533
540
|
onSelect,
|
|
@@ -590,6 +597,7 @@ function ContextMenuCheckboxItem({
|
|
|
590
597
|
);
|
|
591
598
|
}
|
|
592
599
|
|
|
600
|
+
/** @internal */
|
|
593
601
|
ContextMenuCheckboxItem.displayName = "ContextMenuCheckboxItem";
|
|
594
602
|
|
|
595
603
|
/**
|
|
@@ -605,7 +613,7 @@ ContextMenuCheckboxItem.displayName = "ContextMenuCheckboxItem";
|
|
|
605
613
|
* {@link ContextMenuItemIndicatorProps.forceMount | `forceMount`} to keep
|
|
606
614
|
* the DOM node mounted in both states for animation use cases.
|
|
607
615
|
*/
|
|
608
|
-
function ContextMenuItemIndicator({
|
|
616
|
+
export function ContextMenuItemIndicator({
|
|
609
617
|
children,
|
|
610
618
|
asChild = false,
|
|
611
619
|
forceMount = false,
|
|
@@ -637,6 +645,7 @@ function ContextMenuItemIndicator({
|
|
|
637
645
|
return <span {...indicatorProps}>{children}</span>;
|
|
638
646
|
}
|
|
639
647
|
|
|
648
|
+
/** @internal */
|
|
640
649
|
ContextMenuItemIndicator.displayName = "ContextMenuItemIndicator";
|
|
641
650
|
|
|
642
651
|
/**
|
|
@@ -644,7 +653,7 @@ ContextMenuItemIndicator.displayName = "ContextMenuItemIndicator";
|
|
|
644
653
|
* {@link ContextMenuRadioItem | `ContextMenu.RadioItem`} elements. Renders a
|
|
645
654
|
* `<li role="group">` wrapping `<ul role="none">`.
|
|
646
655
|
*/
|
|
647
|
-
function ContextMenuRadioGroup({
|
|
656
|
+
export function ContextMenuRadioGroup({
|
|
648
657
|
defaultValue,
|
|
649
658
|
value: controlledValue,
|
|
650
659
|
onValueChange,
|
|
@@ -673,6 +682,7 @@ function ContextMenuRadioGroup({
|
|
|
673
682
|
);
|
|
674
683
|
}
|
|
675
684
|
|
|
685
|
+
/** @internal */
|
|
676
686
|
ContextMenuRadioGroup.displayName = "ContextMenuRadioGroup";
|
|
677
687
|
|
|
678
688
|
/**
|
|
@@ -687,7 +697,7 @@ ContextMenuRadioGroup.displayName = "ContextMenuRadioGroup";
|
|
|
687
697
|
* {@link ContextMenuRadioItemProps.onSelect | `onSelect`} with a cancellable
|
|
688
698
|
* `Event`. Call `event.preventDefault()` to keep the menu open.
|
|
689
699
|
*/
|
|
690
|
-
function ContextMenuRadioItem({
|
|
700
|
+
export function ContextMenuRadioItem({
|
|
691
701
|
children,
|
|
692
702
|
onClick,
|
|
693
703
|
onSelect,
|
|
@@ -748,6 +758,7 @@ function ContextMenuRadioItem({
|
|
|
748
758
|
);
|
|
749
759
|
}
|
|
750
760
|
|
|
761
|
+
/** @internal */
|
|
751
762
|
ContextMenuRadioItem.displayName = "ContextMenuRadioItem";
|
|
752
763
|
|
|
753
764
|
/**
|
|
@@ -757,7 +768,7 @@ ContextMenuRadioItem.displayName = "ContextMenuRadioItem";
|
|
|
757
768
|
* menu. Supports uncontrolled (`defaultOpen`) and controlled (`open` +
|
|
758
769
|
* `onOpenChange`) modes.
|
|
759
770
|
*/
|
|
760
|
-
function ContextMenuSub({
|
|
771
|
+
export function ContextMenuSub({
|
|
761
772
|
defaultOpen,
|
|
762
773
|
open: controlledOpen,
|
|
763
774
|
onOpenChange,
|
|
@@ -813,6 +824,7 @@ function ContextMenuSub({
|
|
|
813
824
|
);
|
|
814
825
|
}
|
|
815
826
|
|
|
827
|
+
/** @internal */
|
|
816
828
|
ContextMenuSub.displayName = "ContextMenuSub";
|
|
817
829
|
|
|
818
830
|
/**
|
|
@@ -828,7 +840,7 @@ ContextMenuSub.displayName = "ContextMenuSub";
|
|
|
828
840
|
* `ArrowRight` in `"ltr"`, `ArrowLeft` in `"rtl"`. Disabled triggers
|
|
829
841
|
* ignore both click and the open arrow key.
|
|
830
842
|
*/
|
|
831
|
-
function ContextMenuSubTrigger({
|
|
843
|
+
export function ContextMenuSubTrigger({
|
|
832
844
|
children,
|
|
833
845
|
onClick,
|
|
834
846
|
onKeyDown,
|
|
@@ -879,6 +891,7 @@ function ContextMenuSubTrigger({
|
|
|
879
891
|
return <li {...subTriggerProps}>{children}</li>;
|
|
880
892
|
}
|
|
881
893
|
|
|
894
|
+
/** @internal */
|
|
882
895
|
ContextMenuSubTrigger.displayName = "ContextMenuSubTrigger";
|
|
883
896
|
|
|
884
897
|
/**
|
|
@@ -890,7 +903,7 @@ ContextMenuSubTrigger.displayName = "ContextMenuSubTrigger";
|
|
|
890
903
|
* key closes the submenu and returns focus to the SubTrigger —
|
|
891
904
|
* `ArrowLeft` in `"ltr"`, `ArrowRight` in `"rtl"`.
|
|
892
905
|
*/
|
|
893
|
-
function ContextMenuSubContent({
|
|
906
|
+
export function ContextMenuSubContent({
|
|
894
907
|
children,
|
|
895
908
|
onKeyDown,
|
|
896
909
|
asChild = false,
|
|
@@ -961,9 +974,11 @@ function ContextMenuSubContent({
|
|
|
961
974
|
);
|
|
962
975
|
}
|
|
963
976
|
|
|
977
|
+
/** @internal */
|
|
964
978
|
ContextMenuSubContent.displayName = "ContextMenuSubContent";
|
|
965
979
|
|
|
966
|
-
|
|
980
|
+
/** Type of the {@link ContextMenu} compound: the root callable plus its attached sub-components. */
|
|
981
|
+
export type TContextMenuCompound = typeof ContextMenuRoot & {
|
|
967
982
|
Root: typeof ContextMenuRoot;
|
|
968
983
|
Trigger: typeof ContextMenuTrigger;
|
|
969
984
|
Content: typeof ContextMenuContent;
|
|
@@ -980,6 +995,15 @@ type TContextMenuCompound = typeof ContextMenuRoot & {
|
|
|
980
995
|
SubContent: typeof ContextMenuSubContent;
|
|
981
996
|
};
|
|
982
997
|
|
|
998
|
+
/**
|
|
999
|
+
* Headless, accessible **ContextMenu** — a compound component implementing the
|
|
1000
|
+
* [WAI-ARIA menu pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menu/) opened
|
|
1001
|
+
* by a right-click (or long-press) on its trigger, with submenus, checkbox and
|
|
1002
|
+
* radio items, groups, labels and separators. Zero styles ship.
|
|
1003
|
+
*
|
|
1004
|
+
* The default export is the `Root`; sub-components are attached as static
|
|
1005
|
+
* properties (`ContextMenu.Trigger`, `ContextMenu.Content`, …).
|
|
1006
|
+
*/
|
|
983
1007
|
const ContextMenuCompound: TContextMenuCompound = Object.assign(
|
|
984
1008
|
ContextMenuRoot,
|
|
985
1009
|
{
|
|
@@ -1000,6 +1024,7 @@ const ContextMenuCompound: TContextMenuCompound = Object.assign(
|
|
|
1000
1024
|
},
|
|
1001
1025
|
);
|
|
1002
1026
|
|
|
1027
|
+
/** @internal */
|
|
1003
1028
|
ContextMenuCompound.displayName = "ContextMenu";
|
|
1004
1029
|
|
|
1005
1030
|
export { ContextMenuCompound as ContextMenu };
|
package/src/ContextMenu/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./ContextMenu";
|
|
2
|
+
export * from "./types";
|