@itwin/itwinui-react 5.0.0-alpha.7 → 5.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +6 -6
  4. package/dist/DEV/bricks/Anchor.js +4 -9
  5. package/dist/DEV/bricks/Avatar.js +2 -2
  6. package/dist/DEV/bricks/Badge.js +2 -2
  7. package/dist/DEV/bricks/Button.js +10 -3
  8. package/dist/DEV/bricks/Checkbox.js +4 -2
  9. package/dist/DEV/bricks/Chip.js +2 -2
  10. package/dist/DEV/bricks/Divider.js +3 -2
  11. package/dist/DEV/bricks/DropdownMenu.js +83 -33
  12. package/dist/DEV/bricks/Field.js +21 -17
  13. package/dist/DEV/bricks/Icon.js +5 -5
  14. package/dist/DEV/bricks/IconButton.js +14 -6
  15. package/dist/DEV/bricks/Kbd.internal.js +19 -0
  16. package/dist/DEV/bricks/Kbd.js +3 -18
  17. package/dist/DEV/bricks/Label.js +2 -2
  18. package/dist/DEV/bricks/Radio.js +4 -2
  19. package/dist/DEV/bricks/Root.js +35 -4
  20. package/dist/DEV/bricks/Select.js +3 -3
  21. package/dist/DEV/bricks/Spinner.js +2 -2
  22. package/dist/DEV/bricks/Switch.js +4 -2
  23. package/dist/DEV/bricks/Table.js +7 -7
  24. package/dist/DEV/bricks/Tabs.js +5 -5
  25. package/dist/DEV/bricks/Text.js +2 -2
  26. package/dist/DEV/bricks/TextBox.js +8 -7
  27. package/dist/DEV/bricks/Tooltip.js +11 -22
  28. package/dist/DEV/bricks/Tree.js +8 -202
  29. package/dist/DEV/bricks/TreeItem.js +219 -0
  30. package/dist/DEV/bricks/VisuallyHidden.js +2 -2
  31. package/dist/DEV/bricks/styles.css.js +2 -2
  32. package/dist/DEV/bricks/~hooks.js +31 -0
  33. package/dist/DEV/bricks/~utils.GhostAligner.js +13 -0
  34. package/dist/DEV/bricks/{ListItem.js → ~utils.ListItem.js} +6 -4
  35. package/dist/DEV/foundations/styles.css.js +2 -2
  36. package/dist/bricks/Anchor.js +4 -9
  37. package/dist/bricks/Avatar.js +2 -2
  38. package/dist/bricks/Badge.js +2 -2
  39. package/dist/bricks/Button.js +10 -3
  40. package/dist/bricks/Checkbox.d.ts +2 -2
  41. package/dist/bricks/Checkbox.js +4 -2
  42. package/dist/bricks/Chip.js +2 -2
  43. package/dist/bricks/Divider.d.ts +2 -2
  44. package/dist/bricks/Divider.js +3 -2
  45. package/dist/bricks/DropdownMenu.d.ts +38 -23
  46. package/dist/bricks/DropdownMenu.js +81 -33
  47. package/dist/bricks/Field.d.ts +5 -5
  48. package/dist/bricks/Field.js +21 -17
  49. package/dist/bricks/Icon.js +5 -5
  50. package/dist/bricks/IconButton.d.ts +20 -4
  51. package/dist/bricks/IconButton.js +14 -6
  52. package/dist/bricks/Kbd.d.ts +2 -17
  53. package/dist/bricks/Kbd.internal.d.ts +17 -0
  54. package/dist/bricks/Kbd.internal.js +19 -0
  55. package/dist/bricks/Kbd.js +3 -18
  56. package/dist/bricks/Label.js +2 -2
  57. package/dist/bricks/Radio.d.ts +2 -2
  58. package/dist/bricks/Radio.js +4 -2
  59. package/dist/bricks/Root.js +35 -4
  60. package/dist/bricks/Select.d.ts +1 -2
  61. package/dist/bricks/Select.js +3 -3
  62. package/dist/bricks/Spinner.js +2 -2
  63. package/dist/bricks/Switch.d.ts +2 -2
  64. package/dist/bricks/Switch.js +4 -2
  65. package/dist/bricks/Table.js +7 -7
  66. package/dist/bricks/Tabs.d.ts +4 -4
  67. package/dist/bricks/Tabs.js +5 -5
  68. package/dist/bricks/Text.d.ts +1 -1
  69. package/dist/bricks/Text.js +2 -2
  70. package/dist/bricks/TextBox.js +8 -7
  71. package/dist/bricks/Tooltip.d.ts +2 -2
  72. package/dist/bricks/Tooltip.js +11 -22
  73. package/dist/bricks/Tree.d.ts +3 -108
  74. package/dist/bricks/Tree.js +8 -196
  75. package/dist/bricks/TreeItem.d.ts +123 -0
  76. package/dist/bricks/TreeItem.js +214 -0
  77. package/dist/bricks/VisuallyHidden.js +2 -2
  78. package/dist/bricks/styles.css.js +2 -2
  79. package/dist/bricks/~hooks.d.ts +31 -1
  80. package/dist/bricks/~hooks.js +31 -0
  81. package/dist/bricks/~utils.GhostAligner.d.ts +22 -0
  82. package/dist/bricks/~utils.GhostAligner.js +13 -0
  83. package/dist/bricks/{ListItem.d.ts → ~utils.ListItem.d.ts} +6 -6
  84. package/dist/bricks/{ListItem.js → ~utils.ListItem.js} +6 -4
  85. package/dist/bricks/~utils.d.ts +6 -3
  86. package/dist/foundations/styles.css.js +2 -2
  87. package/package.json +4 -4
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- import * as Ariakit from "@ariakit/react";
2
+ import * as AkTab from "@ariakit/react/tab";
3
3
  import { type FocusableProps, type BaseProps } from "./~utils.js";
4
- interface TabsProps extends Pick<Ariakit.TabProviderProps, "defaultSelectedId" | "selectedId" | "setSelectedId" | "selectOnMove" | "children"> {
4
+ interface TabsProps extends Pick<AkTab.TabProviderProps, "defaultSelectedId" | "selectedId" | "setSelectedId" | "selectOnMove" | "children"> {
5
5
  }
6
6
  /**
7
7
  * A set of tabs that can be used to switch between different views.
@@ -53,7 +53,7 @@ interface TabListProps extends BaseProps {
53
53
  * ```
54
54
  */
55
55
  declare const TabList: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
56
- interface TabProps extends FocusableProps<"button">, Pick<Ariakit.TabProps, "id"> {
56
+ interface TabProps extends FocusableProps<"button">, Pick<AkTab.TabProps, "id"> {
57
57
  }
58
58
  /**
59
59
  * An individual tab button that switches the selected tab panel when clicked.
@@ -67,7 +67,7 @@ interface TabProps extends FocusableProps<"button">, Pick<Ariakit.TabProps, "id"
67
67
  * ```
68
68
  */
69
69
  declare const Tab: React.ForwardRefExoticComponent<TabProps & React.RefAttributes<HTMLElement | HTMLButtonElement>>;
70
- interface TabPanelProps extends FocusableProps<"div">, Pick<Ariakit.TabPanelProps, "tabId" | "unmountOnHide" | "focusable"> {
70
+ interface TabPanelProps extends FocusableProps<"div">, Pick<AkTab.TabPanelProps, "tabId" | "unmountOnHide" | "focusable"> {
71
71
  }
72
72
  /**
73
73
  * The actual content of a tab, shown when the tab is selected. Should be used as a child of `Tabs.Root`.
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import * as ReactDOM from "react-dom";
4
4
  import cx from "classnames";
5
- import * as Ariakit from "@ariakit/react";
5
+ import * as AkTab from "@ariakit/react/tab";
6
6
  import { useControlledState } from "./~hooks.js";
7
7
  import { forwardRef } from "./~utils.js";
8
8
  function Tabs(props) {
@@ -19,7 +19,7 @@ function Tabs(props) {
19
19
  setSelectedIdProp
20
20
  );
21
21
  return /* @__PURE__ */ jsx(
22
- Ariakit.TabProvider,
22
+ AkTab.TabProvider,
23
23
  {
24
24
  selectedId,
25
25
  setSelectedId: React.useCallback(
@@ -45,7 +45,7 @@ const TabList = forwardRef((props, forwardedRef) => {
45
45
  const { tone = "neutral", ...rest } = props;
46
46
  const viewTransitionName = `\u{1F95D}active-stripe-${React.useId().replaceAll(":", "_")}`;
47
47
  return /* @__PURE__ */ jsx(
48
- Ariakit.TabList,
48
+ AkTab.TabList,
49
49
  {
50
50
  ...rest,
51
51
  "data-kiwi-tone": tone,
@@ -60,7 +60,7 @@ const TabList = forwardRef((props, forwardedRef) => {
60
60
  });
61
61
  const Tab = forwardRef((props, forwardedRef) => {
62
62
  return /* @__PURE__ */ jsx(
63
- Ariakit.Tab,
63
+ AkTab.Tab,
64
64
  {
65
65
  accessibleWhenDisabled: true,
66
66
  ...props,
@@ -71,7 +71,7 @@ const Tab = forwardRef((props, forwardedRef) => {
71
71
  });
72
72
  const TabPanel = forwardRef((props, forwardedRef) => {
73
73
  return /* @__PURE__ */ jsx(
74
- Ariakit.TabPanel,
74
+ AkTab.TabPanel,
75
75
  {
76
76
  ...props,
77
77
  className: cx("\u{1F95D}-tab-panel", props.className),
@@ -3,7 +3,7 @@ interface TextProps extends BaseProps {
3
3
  /**
4
4
  * The typography variant to use.
5
5
  */
6
- variant?: "display-lg" | "display-md" | "display-sm" | "headline-lg" | "headline-md" | "headline-sm" | "body-lg" | "body-md" | "body-sm" | "caption-lg" | "caption-md" | "caption-sm" | "mono-sm";
6
+ variant: "display-lg" | "display-md" | "display-sm" | "headline-lg" | "headline-md" | "headline-sm" | "body-lg" | "body-md" | "body-sm" | "caption-lg" | "caption-md" | "caption-sm" | "mono-sm";
7
7
  }
8
8
  /**
9
9
  * An element with text styles applied. Useful for paragraphs, headings, and other text content.
@@ -1,11 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import * as Ariakit from "@ariakit/react";
2
+ import { Role } from "@ariakit/react/role";
3
3
  import cx from "classnames";
4
4
  import { forwardRef } from "./~utils.js";
5
5
  const Text = forwardRef((props, forwardedRef) => {
6
6
  const { variant, ...rest } = props;
7
7
  return /* @__PURE__ */ jsx(
8
- Ariakit.Role,
8
+ Role,
9
9
  {
10
10
  ...rest,
11
11
  className: cx("\u{1F95D}-text", props.className),
@@ -1,6 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import * as Ariakit from "@ariakit/react";
3
+ import { Role } from "@ariakit/react/role";
4
+ import { Focusable } from "@ariakit/react/focusable";
4
5
  import cx from "classnames";
5
6
  import { FieldControl } from "./Field.js";
6
7
  import { Icon } from "./Icon.js";
@@ -20,14 +21,14 @@ const TextBoxInput = forwardRef(
20
21
  type: "textlike",
21
22
  id,
22
23
  render: /* @__PURE__ */ jsx(
23
- Ariakit.Role.input,
24
+ Role.input,
24
25
  {
25
26
  readOnly: props.disabled,
26
27
  ...rest,
27
28
  className: cx({ "\u{1F95D}-text-box": !rootContext }, props.className),
28
29
  placeholder: props.placeholder ?? " ",
29
30
  render: /* @__PURE__ */ jsx(
30
- Ariakit.Focusable,
31
+ Focusable,
31
32
  {
32
33
  accessibleWhenDisabled: true,
33
34
  render: props.render || /* @__PURE__ */ jsx("input", {})
@@ -49,14 +50,14 @@ const TextBoxTextarea = forwardRef(
49
50
  type: "textlike",
50
51
  id,
51
52
  render: /* @__PURE__ */ jsx(
52
- Ariakit.Role.textarea,
53
+ Role.textarea,
53
54
  {
54
55
  readOnly: props.disabled,
55
56
  ...rest,
56
57
  className: cx("\u{1F95D}-text-box", props.className),
57
58
  placeholder: props.placeholder ?? " ",
58
59
  render: /* @__PURE__ */ jsx(
59
- Ariakit.Focusable,
60
+ Focusable,
60
61
  {
61
62
  accessibleWhenDisabled: true,
62
63
  render: props.render || /* @__PURE__ */ jsx("textarea", {})
@@ -78,7 +79,7 @@ const TextBoxRoot = forwardRef(
78
79
  {
79
80
  value: React.useMemo(() => ({ setDisabled, inputRef }), []),
80
81
  children: /* @__PURE__ */ jsx(
81
- Ariakit.Role.div,
82
+ Role.div,
82
83
  {
83
84
  ...props,
84
85
  "data-kiwi-disabled": disabled,
@@ -113,7 +114,7 @@ const TextBoxIcon = forwardRef(
113
114
  const TextBoxText = forwardRef(
114
115
  (props, forwardedRef) => {
115
116
  return /* @__PURE__ */ jsx(
116
- Ariakit.Role.span,
117
+ Role.span,
117
118
  {
118
119
  ...props,
119
120
  className: cx("\u{1F95D}-text-box-decoration", props.className),
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- import * as Ariakit from "@ariakit/react";
2
+ import * as AkTooltip from "@ariakit/react/tooltip";
3
3
  import { type FocusableProps } from "./~utils.js";
4
- interface TooltipProps extends Omit<FocusableProps<"div">, "content">, Pick<Ariakit.TooltipProps, "open" | "unmountOnHide">, Pick<Ariakit.TooltipProviderProps, "defaultOpen" | "setOpen"> {
4
+ interface TooltipProps extends Omit<FocusableProps<"div">, "content">, Pick<AkTooltip.TooltipProps, "open" | "unmountOnHide">, Pick<AkTooltip.TooltipProviderProps, "defaultOpen" | "setOpen"> {
5
5
  /**
6
6
  * The content to be displayed inside the tooltip when the trigger element is hovered or focused.
7
7
  */
@@ -1,8 +1,9 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import cx from "classnames";
4
- import * as Ariakit from "@ariakit/react";
5
- import { forwardRef, supportsPopover } from "./~utils.js";
4
+ import * as AkTooltip from "@ariakit/react/tooltip";
5
+ import { forwardRef } from "./~utils.js";
6
+ import { usePopoverApi } from "./~hooks.js";
6
7
  const Tooltip = forwardRef(
7
8
  (props, forwardedRef) => {
8
9
  const generatedId = React.useId();
@@ -17,22 +18,10 @@ const Tooltip = forwardRef(
17
18
  unmountOnHide = type === "none",
18
19
  ...rest
19
20
  } = props;
20
- const store = Ariakit.useTooltipStore();
21
- const open = Ariakit.useStoreState(store, (state) => state.open);
22
- const popover = Ariakit.useStoreState(
23
- store,
24
- (state) => state.popoverElement
25
- );
26
- React.useEffect(
27
- function syncPopoverWithOpenState() {
28
- if (popover?.isConnected) {
29
- popover?.togglePopover?.(open);
30
- }
31
- },
32
- [open, popover]
33
- );
21
+ const store = AkTooltip.useTooltipStore();
22
+ const popover = usePopoverApi(store);
34
23
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
35
- Ariakit.TooltipProvider,
24
+ AkTooltip.TooltipProvider,
36
25
  {
37
26
  store,
38
27
  defaultOpen: defaultOpenProp,
@@ -40,7 +29,7 @@ const Tooltip = forwardRef(
40
29
  setOpen: setOpenProp,
41
30
  children: [
42
31
  /* @__PURE__ */ jsx(
43
- Ariakit.TooltipAnchor,
32
+ AkTooltip.TooltipAnchor,
44
33
  {
45
34
  render: children,
46
35
  ...type === "description" && { "aria-describedby": id },
@@ -48,7 +37,7 @@ const Tooltip = forwardRef(
48
37
  }
49
38
  ),
50
39
  /* @__PURE__ */ jsx(
51
- Ariakit.Tooltip,
40
+ AkTooltip.Tooltip,
52
41
  {
53
42
  "aria-hidden": "true",
54
43
  ...rest,
@@ -57,11 +46,11 @@ const Tooltip = forwardRef(
57
46
  ref: forwardedRef,
58
47
  id,
59
48
  style: {
60
- zIndex: supportsPopover ? void 0 : 9999,
49
+ ...popover.style,
61
50
  ...props.style
62
51
  },
63
- wrapperProps: { popover: "manual" },
64
- portal: !supportsPopover,
52
+ wrapperProps: popover.wrapperProps,
53
+ portal: popover.portal,
65
54
  children: content
66
55
  }
67
56
  )
@@ -1,6 +1,5 @@
1
- import * as React from "react";
2
- import { IconButton } from "./IconButton.js";
3
1
  import { type BaseProps } from "./~utils.js";
2
+ import { Root as TreeItemRoot, Action as TreeItemAction } from "./TreeItem.js";
4
3
  interface TreeProps extends BaseProps {
5
4
  }
6
5
  /**
@@ -19,109 +18,5 @@ interface TreeProps extends BaseProps {
19
18
  * </Tree.Root>
20
19
  * ```
21
20
  */
22
- declare const Tree: React.ForwardRefExoticComponent<TreeProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
23
- interface TreeItemProps extends Omit<BaseProps, "content"> {
24
- /** Specifies the nesting level of the tree item. Nesting levels start at 1. */
25
- "aria-level": number;
26
- /** Defines tree item position in the current level of tree items. Integer greater than or equal to 1. */
27
- "aria-posinset": number;
28
- /** Defines tree item set size of the current level. */
29
- "aria-setsize": number;
30
- /**
31
- * Specifies if the tree item is selected.
32
- *
33
- * If `undefined`, the tree item is not selectable.
34
- *
35
- * @default undefined
36
- */
37
- selected?: boolean;
38
- /**
39
- * Callback fired when the tree item is selected.
40
- *
41
- * Should be used with the `selected` prop.
42
- */
43
- onSelectedChange?: (selected: boolean) => void;
44
- /**
45
- * Specifies if the tree item is expanded.
46
- *
47
- * Used to determine if a tree item is a parent node. If `undefined`, it is a leaf node (i.e. not expandable).
48
- *
49
- * @default undefined
50
- * */
51
- expanded?: boolean;
52
- /**
53
- * Callback fired when the tree item is expanded.
54
- *
55
- * Should be used with the `expanded` prop.
56
- */
57
- onExpandedChange?: (expanded: boolean) => void;
58
- /**
59
- * Icon to be displayed inside the tree item.
60
- *
61
- * Can be a URL of an SVG from the `kiwi-icons` package, or a JSX element.
62
- */
63
- icon?: string | React.JSX.Element;
64
- /**
65
- * The primary label that identifies the tree item and is displayed inside it.
66
- */
67
- label?: React.ReactNode;
68
- /**
69
- * The actions available for the tree item. Must be a list of `Tree.ItemAction` components.
70
- *
71
- * Example:
72
- * ```tsx
73
- * actions={[
74
- * <Tree.ItemAction key={…} icon={…} label={…} />,
75
- * <Tree.ItemAction key={…} icon={…} label={…} />,
76
- * ]}
77
- * ```
78
- */
79
- actions?: React.ReactNode[];
80
- }
81
- /**
82
- * A treeitem is a node in a tree structure that may be expanded or collapsed to reveal or hide its descendants.
83
- *
84
- * `Tree.Item`s can be rendered inside a `Tree.Root`. Additional properties are specified to the `Tree.Item`s to create a hierarchical tree structure.
85
- *
86
- * Example:
87
- * ```tsx
88
- * <Tree.Root>
89
- * <Tree.Item label="Parent" aria-level={1} aria-posinset={1} aria-setsize={1} />
90
- * <Tree.Item label="Child 1" aria-level={2} aria-posinset={1} aria-setsize={2} />
91
- * <Tree.Item label="Child 2" aria-level={2} aria-posinset={2} aria-setsize={2} />
92
- * </Tree.Root>
93
- * ```
94
- *
95
- * The `label` and `icon` props can be used to specify the treeitem's own content.
96
- *
97
- * The `aria-level` prop is used to specify the nesting level of the treeitem. Nesting levels start at 1.
98
- *
99
- * The `aria-posinset` and `aria-setsize` props are used to define the treeitem's position in the current level of tree items.
100
- *
101
- * The `expanded` and `onExpandedChange` props can be used to control the expansion state of a treeitem.
102
- *
103
- * The `selected` and `onSelectedChange` props can be used to control the selection state of a treeitem.
104
- *
105
- * Secondary actions can be passed into the `actions` prop.
106
- */
107
- declare const TreeItem: React.ForwardRefExoticComponent<TreeItemProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
108
- type IconButtonProps = React.ComponentProps<typeof IconButton>;
109
- interface TreeItemActionProps extends BaseProps<"button">, Pick<IconButtonProps, "label" | "icon"> {
110
- /**
111
- * Controls the visibility of the action.
112
- *
113
- * If `true`, the action is always visible.
114
- * If `false`, the action is hidden and becomes inaccessible, but still occupies space.
115
- *
116
- * By default, the action is shown only when the treeitem receives hover/focus.
117
- */
118
- visible?: boolean;
119
- }
120
- /**
121
- * A secondary action for `<Tree.Item>`, to be passed into the `actions` prop. The action is typically
122
- * displayed as an icon-button on the right end of the treeitem.
123
- *
124
- * By default, the action appears only on hover/focus. This can be controlled by the `visible` prop.
125
- */
126
- declare const TreeItemAction: React.ForwardRefExoticComponent<TreeItemActionProps & React.RefAttributes<HTMLElement | HTMLButtonElement>>;
127
- export { Tree as Root, TreeItem as Item, TreeItemAction as ItemAction };
21
+ declare const Tree: import("react").ForwardRefExoticComponent<TreeProps & import("react").RefAttributes<HTMLElement | HTMLDivElement>>;
22
+ export { Tree as Root, TreeItemRoot as Item, TreeItemAction as ItemAction };
@@ -1,213 +1,25 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import * as React from "react";
1
+ import { jsx } from "react/jsx-runtime";
3
2
  import cx from "classnames";
4
- import * as Ariakit from "@ariakit/react";
5
- import * as ListItem from "./ListItem.js";
6
- import { IconButton } from "./IconButton.js";
7
- import { Icon } from "./Icon.js";
3
+ import { Role } from "@ariakit/react/role";
4
+ import { useCompositeStore, Composite } from "@ariakit/react/composite";
8
5
  import { forwardRef } from "./~utils.js";
9
- import { useEventHandlers } from "./~hooks.js";
6
+ import { Root as TreeItemRoot, Action as TreeItemAction } from "./TreeItem.js";
10
7
  const Tree = forwardRef((props, forwardedRef) => {
11
- const composite = Ariakit.useCompositeStore({ orientation: "vertical" });
8
+ const composite = useCompositeStore({ orientation: "vertical" });
12
9
  return /* @__PURE__ */ jsx(
13
- Ariakit.Role.div,
10
+ Role.div,
14
11
  {
15
12
  role: "tree",
16
13
  ...props,
17
- render: /* @__PURE__ */ jsx(Ariakit.Composite, { store: composite }),
14
+ render: /* @__PURE__ */ jsx(Composite, { store: composite }),
18
15
  className: cx("\u{1F95D}-tree", props.className),
19
16
  ref: forwardedRef,
20
17
  children: props.children
21
18
  }
22
19
  );
23
20
  });
24
- const TreeItem = forwardRef((props, forwardedRef) => {
25
- const {
26
- "aria-level": level,
27
- selected,
28
- children,
29
- expanded,
30
- icon,
31
- label,
32
- actions,
33
- onSelectedChange,
34
- onExpandedChange,
35
- onClick: onClickProp,
36
- onKeyDown: onKeyDownProp,
37
- ...rest
38
- } = props;
39
- const handleClick = (event) => {
40
- if (selected === void 0) return;
41
- event.stopPropagation();
42
- onSelectedChange?.(!selected);
43
- };
44
- const handleKeyDown = (event) => {
45
- if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
46
- return;
47
- }
48
- if (expanded === void 0) return;
49
- if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
50
- event.preventDefault();
51
- onExpandedChange?.(event.key === "ArrowRight");
52
- }
53
- };
54
- const contentId = React.useId();
55
- return /* @__PURE__ */ jsx(
56
- TreeItemContext.Provider,
57
- {
58
- value: React.useMemo(
59
- () => ({
60
- level,
61
- expanded,
62
- selected,
63
- contentId
64
- }),
65
- [level, expanded, selected, contentId]
66
- ),
67
- children: /* @__PURE__ */ jsx(
68
- Ariakit.CompositeItem,
69
- {
70
- render: /* @__PURE__ */ jsx(Ariakit.Role, { ...rest }),
71
- onClick: useEventHandlers(
72
- onClickProp,
73
- handleClick
74
- ),
75
- onKeyDown: useEventHandlers(
76
- onKeyDownProp,
77
- handleKeyDown
78
- ),
79
- role: "treeitem",
80
- "aria-expanded": expanded,
81
- "aria-selected": selected,
82
- "aria-labelledby": contentId,
83
- "aria-level": level,
84
- className: cx("\u{1F95D}-tree-item", props.className),
85
- ref: forwardedRef,
86
- children: /* @__PURE__ */ jsxs(
87
- ListItem.Root,
88
- {
89
- "data-kiwi-expanded": expanded,
90
- "data-kiwi-selected": selected,
91
- className: "\u{1F95D}-tree-item-node",
92
- style: { "--\u{1F95D}tree-item-level": level },
93
- role: void 0,
94
- children: [
95
- /* @__PURE__ */ jsxs(ListItem.Decoration, { children: [
96
- /* @__PURE__ */ jsx(
97
- TreeItemExpander,
98
- {
99
- onClick: () => {
100
- if (expanded === void 0) return;
101
- onExpandedChange?.(!expanded);
102
- }
103
- }
104
- ),
105
- typeof icon === "string" ? /* @__PURE__ */ jsx(Icon, { href: icon }) : icon
106
- ] }),
107
- /* @__PURE__ */ jsx(TreeItemContent, { label }),
108
- /* @__PURE__ */ jsx(
109
- ListItem.Decoration,
110
- {
111
- render: /* @__PURE__ */ jsx(TreeItemActions, { children: actions })
112
- }
113
- )
114
- ]
115
- }
116
- )
117
- }
118
- )
119
- }
120
- );
121
- });
122
- const TreeItemContent = forwardRef(
123
- (props, forwardedRef) => {
124
- const { label, ...rest } = props;
125
- const { contentId } = React.useContext(TreeItemContext) ?? {};
126
- return /* @__PURE__ */ jsx(
127
- ListItem.Content,
128
- {
129
- ...rest,
130
- id: contentId,
131
- className: cx("\u{1F95D}-tree-item-content", props.className),
132
- ref: forwardedRef,
133
- children: label
134
- }
135
- );
136
- }
137
- );
138
- const TreeItemActions = forwardRef((props, forwardedRef) => {
139
- return /* @__PURE__ */ jsx(
140
- Ariakit.Toolbar,
141
- {
142
- ...props,
143
- onClick: useEventHandlers(props.onClick, (e) => e.stopPropagation()),
144
- className: cx("\u{1F95D}-tree-item-actions", props.className),
145
- ref: forwardedRef,
146
- children: props.children
147
- }
148
- );
149
- });
150
- const TreeItemAction = forwardRef(
151
- (props, forwardedRef) => {
152
- const { visible, ...rest } = props;
153
- return /* @__PURE__ */ jsx(
154
- IconButton,
155
- {
156
- inert: visible === false ? true : void 0,
157
- ...rest,
158
- variant: "ghost",
159
- className: cx("\u{1F95D}-tree-item-action", props.className),
160
- "data-kiwi-visible": visible,
161
- ref: forwardedRef
162
- }
163
- );
164
- }
165
- );
166
- const TreeItemExpander = forwardRef(
167
- (props, forwardedRef) => {
168
- return /* @__PURE__ */ jsx(
169
- IconButton,
170
- {
171
- tabIndex: -1,
172
- "aria-hidden": "true",
173
- icon: /* @__PURE__ */ jsx(TreeChevron, {}),
174
- label: "Toggle",
175
- ...props,
176
- onClick: useEventHandlers(props.onClick, (e) => e.stopPropagation()),
177
- className: cx("\u{1F95D}-tree-item-expander", props.className),
178
- variant: "ghost",
179
- labelVariant: "visually-hidden",
180
- ref: forwardedRef
181
- }
182
- );
183
- }
184
- );
185
- const TreeChevron = forwardRef(
186
- (props, forwardedRef) => {
187
- return /* @__PURE__ */ jsx(
188
- Icon,
189
- {
190
- ...props,
191
- render: /* @__PURE__ */ jsx(
192
- Ariakit.Role.svg,
193
- {
194
- width: "16",
195
- height: "16",
196
- fill: "currentColor",
197
- viewBox: "0 0 16 16",
198
- render: props.render,
199
- children: /* @__PURE__ */ jsx("path", { d: "M4.146 6.146a.5.5 0 0 1 .708 0L8 9.293l3.146-3.147a.5.5 0 0 1 .708.708l-3.5 3.5a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 0 1 0-.708Z" })
200
- }
201
- ),
202
- className: cx("\u{1F95D}-tree-chevron", props.className),
203
- ref: forwardedRef
204
- }
205
- );
206
- }
207
- );
208
- const TreeItemContext = React.createContext(void 0);
209
21
  export {
210
- TreeItem as Item,
22
+ TreeItemRoot as Item,
211
23
  TreeItemAction as ItemAction,
212
24
  Tree as Root
213
25
  };