@itwin/itwinui-react 5.0.0-alpha.0 → 5.0.0-alpha.10

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 (118) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/DEV/bricks/Anchor.js +16 -23
  4. package/dist/DEV/bricks/Avatar.js +24 -0
  5. package/dist/DEV/bricks/Badge.js +22 -0
  6. package/dist/DEV/bricks/Button.js +25 -16
  7. package/dist/DEV/bricks/Checkbox.js +26 -16
  8. package/dist/DEV/bricks/Chip.js +42 -0
  9. package/dist/DEV/bricks/Description.js +29 -0
  10. package/dist/DEV/bricks/Divider.js +16 -17
  11. package/dist/DEV/bricks/DropdownMenu.js +143 -48
  12. package/dist/DEV/bricks/Field.js +120 -20
  13. package/dist/DEV/bricks/Icon.js +108 -45
  14. package/dist/DEV/bricks/IconButton.js +31 -18
  15. package/dist/DEV/bricks/Kbd.internal.js +19 -0
  16. package/dist/DEV/bricks/Kbd.js +32 -17
  17. package/dist/DEV/bricks/Label.js +13 -10
  18. package/dist/DEV/bricks/ProgressBar.js +25 -0
  19. package/dist/DEV/bricks/Radio.js +19 -11
  20. package/dist/DEV/bricks/Root.js +78 -45
  21. package/dist/DEV/bricks/Select.js +61 -0
  22. package/dist/DEV/bricks/Skeleton.js +24 -0
  23. package/dist/DEV/bricks/Spinner.js +40 -0
  24. package/dist/DEV/bricks/Switch.js +27 -17
  25. package/dist/DEV/bricks/Table.js +114 -0
  26. package/dist/DEV/bricks/Tabs.js +19 -20
  27. package/dist/DEV/bricks/Text.js +20 -0
  28. package/dist/DEV/bricks/TextBox.js +95 -50
  29. package/dist/DEV/bricks/Tooltip.js +58 -58
  30. package/dist/DEV/bricks/Tree.js +16 -102
  31. package/dist/DEV/bricks/TreeItem.js +224 -0
  32. package/dist/DEV/bricks/VisuallyHidden.js +7 -5
  33. package/dist/DEV/bricks/index.js +20 -0
  34. package/dist/DEV/bricks/styles.css.js +2 -2
  35. package/dist/DEV/bricks/~hooks.js +55 -3
  36. package/dist/DEV/bricks/~utils.GhostAligner.js +13 -0
  37. package/dist/DEV/bricks/~utils.ListItem.js +49 -0
  38. package/dist/DEV/bricks/~utils.js +3 -0
  39. package/dist/DEV/foundations/styles.css.js +2 -2
  40. package/dist/bricks/Anchor.d.ts +12 -3
  41. package/dist/bricks/Anchor.js +16 -23
  42. package/dist/bricks/Avatar.d.ts +47 -0
  43. package/dist/bricks/Avatar.js +23 -0
  44. package/dist/bricks/Badge.d.ts +28 -0
  45. package/dist/bricks/Badge.js +21 -0
  46. package/dist/bricks/Button.d.ts +27 -4
  47. package/dist/bricks/Button.js +25 -16
  48. package/dist/bricks/Checkbox.d.ts +19 -5
  49. package/dist/bricks/Checkbox.js +26 -16
  50. package/dist/bricks/Chip.d.ts +31 -0
  51. package/dist/bricks/Chip.js +41 -0
  52. package/dist/bricks/Description.d.ts +19 -0
  53. package/dist/bricks/Description.js +29 -0
  54. package/dist/bricks/Divider.d.ts +5 -6
  55. package/dist/bricks/Divider.js +16 -17
  56. package/dist/bricks/DropdownMenu.d.ts +92 -15
  57. package/dist/bricks/DropdownMenu.js +138 -46
  58. package/dist/bricks/Field.d.ts +45 -3
  59. package/dist/bricks/Field.js +120 -20
  60. package/dist/bricks/Icon.d.ts +38 -7
  61. package/dist/bricks/Icon.js +105 -44
  62. package/dist/bricks/IconButton.d.ts +20 -4
  63. package/dist/bricks/IconButton.js +31 -18
  64. package/dist/bricks/Kbd.d.ts +17 -3
  65. package/dist/bricks/Kbd.internal.d.ts +17 -0
  66. package/dist/bricks/Kbd.internal.js +19 -0
  67. package/dist/bricks/Kbd.js +25 -17
  68. package/dist/bricks/Label.d.ts +22 -3
  69. package/dist/bricks/Label.js +13 -10
  70. package/dist/bricks/ProgressBar.d.ts +31 -0
  71. package/dist/bricks/ProgressBar.js +24 -0
  72. package/dist/bricks/Radio.d.ts +19 -5
  73. package/dist/bricks/Radio.js +19 -11
  74. package/dist/bricks/Root.d.ts +11 -2
  75. package/dist/bricks/Root.js +78 -45
  76. package/dist/bricks/Select.d.ts +51 -0
  77. package/dist/bricks/Select.js +61 -0
  78. package/dist/bricks/Skeleton.d.ts +25 -0
  79. package/dist/bricks/Skeleton.js +23 -0
  80. package/dist/bricks/Spinner.d.ts +31 -0
  81. package/dist/bricks/Spinner.js +39 -0
  82. package/dist/bricks/Switch.d.ts +19 -5
  83. package/dist/bricks/Switch.js +27 -17
  84. package/dist/bricks/Table.d.ts +115 -0
  85. package/dist/bricks/Table.js +108 -0
  86. package/dist/bricks/Tabs.d.ts +69 -8
  87. package/dist/bricks/Tabs.js +19 -20
  88. package/dist/bricks/Text.d.ts +22 -0
  89. package/dist/bricks/Text.js +19 -0
  90. package/dist/bricks/TextBox.d.ts +62 -11
  91. package/dist/bricks/TextBox.js +94 -50
  92. package/dist/bricks/Tooltip.d.ts +13 -6
  93. package/dist/bricks/Tooltip.js +58 -58
  94. package/dist/bricks/Tree.d.ts +20 -21
  95. package/dist/bricks/Tree.js +15 -97
  96. package/dist/bricks/TreeItem.d.ts +123 -0
  97. package/dist/bricks/TreeItem.js +219 -0
  98. package/dist/bricks/VisuallyHidden.d.ts +15 -3
  99. package/dist/bricks/VisuallyHidden.js +7 -5
  100. package/dist/bricks/index.d.ts +10 -0
  101. package/dist/bricks/index.js +20 -0
  102. package/dist/bricks/styles.css.js +2 -2
  103. package/dist/bricks/~hooks.d.ts +55 -0
  104. package/dist/bricks/~hooks.js +55 -3
  105. package/dist/bricks/~utils.GhostAligner.d.ts +22 -0
  106. package/dist/bricks/~utils.GhostAligner.js +13 -0
  107. package/dist/bricks/~utils.ListItem.d.ts +14 -0
  108. package/dist/bricks/~utils.ListItem.js +46 -0
  109. package/dist/bricks/~utils.d.ts +26 -3
  110. package/dist/bricks/~utils.js +3 -0
  111. package/dist/foundations/styles.css.js +2 -2
  112. package/package.json +14 -13
  113. package/dist/DEV/bricks/ListItem.js +0 -33
  114. package/dist/DEV/bricks/Textarea.js +0 -28
  115. package/dist/bricks/ListItem.d.ts +0 -11
  116. package/dist/bricks/ListItem.js +0 -31
  117. package/dist/bricks/Textarea.d.ts +0 -14
  118. package/dist/bricks/Textarea.js +0 -27
@@ -0,0 +1,19 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Role } from "@ariakit/react/role";
3
+ import cx from "classnames";
4
+ import { forwardRef } from "./~utils.js";
5
+ const Text = forwardRef((props, forwardedRef) => {
6
+ const { variant, ...rest } = props;
7
+ return /* @__PURE__ */ jsx(
8
+ Role,
9
+ {
10
+ ...rest,
11
+ className: cx("\u{1F95D}-text", props.className),
12
+ "data-kiwi-text-variant": variant,
13
+ ref: forwardedRef
14
+ }
15
+ );
16
+ });
17
+ export {
18
+ Text
19
+ };
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Icon } from "./Icon.js";
3
- import { Textarea } from "./Textarea.js";
4
- import type { FocusableProps, BaseProps } from "./~utils.js";
3
+ import { type FocusableProps, type BaseProps } from "./~utils.js";
5
4
  interface BaseInputProps extends FocusableProps<"input"> {
6
5
  }
7
6
  interface TextBoxInputProps extends Omit<BaseInputProps, "children" | "type"> {
@@ -16,7 +15,7 @@ interface TextBoxInputProps extends Omit<BaseInputProps, "children" | "type"> {
16
15
  type?: Extract<BaseInputProps["type"], "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "date">;
17
16
  }
18
17
  /**
19
- * Input component that allows users to enter text based values.
18
+ * An input component that allows users to enter text based values.
20
19
  *
21
20
  * Example usage:
22
21
  * ```tsx
@@ -24,26 +23,78 @@ interface TextBoxInputProps extends Omit<BaseInputProps, "children" | "type"> {
24
23
  * ```
25
24
  *
26
25
  * To add additional decorations, see `TextBox.Root` component.
26
+ *
27
+ * Works well with the `Field` and `Label` components.
28
+ * ```tsx
29
+ * <Field>
30
+ * <Label>Enter your name</Label>
31
+ * <TextBox.Input />
32
+ * </Field>
33
+ * ```
34
+ *
35
+ * Underneath, it's an HTML input, i.e. `<input>`, so it supports the same props, including
36
+ * `value`, `defaultValue`, `onChange`, and `disabled`.
37
+ *
38
+ * For a multiline text input, use the `TextBox.Textarea` component.
27
39
  */
28
- declare const TextBoxInput: React.ForwardRefExoticComponent<TextBoxInputProps & React.RefAttributes<HTMLInputElement>>;
40
+ declare const TextBoxInput: React.ForwardRefExoticComponent<TextBoxInputProps & React.RefAttributes<HTMLElement | HTMLInputElement>>;
41
+ interface TextareaProps extends FocusableProps<"textarea"> {
42
+ }
43
+ /**
44
+ * A styled textarea element that allows users to enter multiline text values.
45
+ *
46
+ * Example usage:
47
+ * ```tsx
48
+ * <TextBox.Textarea defaultValue="Hello" />
49
+ * ```
50
+ *
51
+ * Works well with the `Field` and `Label` components.
52
+ * ```tsx
53
+ * <Field>
54
+ * <Label>Leave a comment, be kind</Label>
55
+ * <TextBox.Textarea />
56
+ * </Field>
57
+ * ```
58
+ *
59
+ * Underneath, it's an HTML textarea, i.e. `<textarea>`, so it supports the same props, including
60
+ * `value`, `defaultValue`, `onChange`, and `disabled`.
61
+ */
62
+ declare const TextBoxTextarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLElement | HTMLTextAreaElement>>;
29
63
  interface TextBoxRootProps extends BaseProps {
30
64
  }
31
65
  /**
32
- * Root component allows adding additional decorations to text based inputs.
66
+ * Compound component for a text input. Allows adding additional decorations.
33
67
  *
34
68
  * Example usage to add an end icon:
35
69
  * ```tsx
36
70
  * <TextBox.Root>
37
- * <TextBox.Input defaultValue="Hello" />
38
- * <TextBox.Icon href={...} />
71
+ * <TextBox.Input defaultValue="Hello" />
72
+ * <TextBox.Icon href={...} />
39
73
  * </TextBox.Root>
40
74
  * ```
75
+ *
76
+ * Works well with the `Field` and `Label` components.
77
+ * ```tsx
78
+ * <Field>
79
+ * <Label>Enter your name</Label>
80
+ * <TextBox.Root>
81
+ * <TextBox.Input />
82
+ * <TextBox.Icon href={…} />
83
+ * </TextBox.Root>
84
+ * </Field>
85
+ * ```
41
86
  */
42
- declare const TextBoxRoot: React.ForwardRefExoticComponent<TextBoxRootProps & React.RefAttributes<HTMLDivElement>>;
87
+ declare const TextBoxRoot: React.ForwardRefExoticComponent<TextBoxRootProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
43
88
  interface TextBoxIconProps extends React.ComponentProps<typeof Icon> {
44
89
  }
45
- declare const TextBoxIcon: React.ForwardRefExoticComponent<Omit<TextBoxIconProps, "ref"> & React.RefAttributes<SVGSVGElement>>;
90
+ /**
91
+ * A static icon decoration for the `TextBox.Root` component. Can be added before or after the `TextBox.Input`.
92
+ */
93
+ declare const TextBoxIcon: React.ForwardRefExoticComponent<Omit<TextBoxIconProps, "ref"> & React.RefAttributes<HTMLElement | SVGSVGElement>>;
46
94
  interface TextBoxTextProps extends BaseProps<"span"> {
47
95
  }
48
- declare const TextBoxText: React.ForwardRefExoticComponent<TextBoxTextProps & React.RefAttributes<HTMLSpanElement>>;
49
- export { TextBoxRoot as Root, TextBoxInput as Input, Textarea, TextBoxIcon as Icon, TextBoxText as Text, };
96
+ /**
97
+ * A static text decoration for the `TextBox.Root` component. Can be added before or after the `TextBox.Input`.
98
+ */
99
+ declare const TextBoxText: React.ForwardRefExoticComponent<TextBoxTextProps & React.RefAttributes<HTMLElement | HTMLSpanElement>>;
100
+ export { TextBoxRoot as Root, TextBoxInput as Input, TextBoxTextarea as Textarea, TextBoxIcon as Icon, TextBoxText as Text, };
@@ -1,36 +1,76 @@
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
- import { useFieldId } from "./Field.js";
6
+ import { FieldControl } from "./Field.js";
6
7
  import { Icon } from "./Icon.js";
7
- import { Textarea } from "./Textarea.js";
8
8
  import { useMergedRefs } from "./~hooks.js";
9
- const TextBoxInput = React.forwardRef((props, forwardedRef) => {
10
- const fieldId = useFieldId();
11
- const rootContext = React.useContext(TextBoxRootContext);
12
- const setDisabled = rootContext?.setDisabled;
13
- React.useEffect(() => {
14
- setDisabled?.(props.disabled);
15
- }, [setDisabled, props.disabled]);
16
- return /* @__PURE__ */ jsx(
17
- Ariakit.Role.input,
18
- {
19
- id: fieldId,
20
- ...props,
21
- className: cx({ "\u{1F95D}-text-box": !rootContext }, props.className),
22
- render: /* @__PURE__ */ jsx(
23
- Ariakit.Focusable,
24
- {
25
- accessibleWhenDisabled: true,
26
- render: props.render || /* @__PURE__ */ jsx("input", {})
27
- }
28
- ),
29
- ref: useMergedRefs(rootContext?.inputRef, forwardedRef)
30
- }
31
- );
32
- });
33
- const TextBoxRoot = React.forwardRef(
9
+ import { forwardRef } from "./~utils.js";
10
+ const TextBoxInput = forwardRef(
11
+ (props, forwardedRef) => {
12
+ const { id, ...rest } = props;
13
+ const rootContext = React.useContext(TextBoxRootContext);
14
+ const setDisabled = rootContext?.setDisabled;
15
+ React.useEffect(() => {
16
+ setDisabled?.(props.disabled);
17
+ }, [setDisabled, props.disabled]);
18
+ return /* @__PURE__ */ jsx(
19
+ FieldControl,
20
+ {
21
+ type: "textlike",
22
+ id,
23
+ render: /* @__PURE__ */ jsx(
24
+ Role.input,
25
+ {
26
+ readOnly: props.disabled,
27
+ ...rest,
28
+ className: cx({ "\u{1F95D}-text-box": !rootContext }, props.className),
29
+ placeholder: props.placeholder ?? " ",
30
+ render: /* @__PURE__ */ jsx(
31
+ Focusable,
32
+ {
33
+ accessibleWhenDisabled: true,
34
+ render: props.render || /* @__PURE__ */ jsx("input", {})
35
+ }
36
+ ),
37
+ ref: useMergedRefs(rootContext?.inputRef, forwardedRef)
38
+ }
39
+ )
40
+ }
41
+ );
42
+ }
43
+ );
44
+ const TextBoxTextarea = forwardRef(
45
+ (props, forwardedRef) => {
46
+ const { id, ...rest } = props;
47
+ return /* @__PURE__ */ jsx(
48
+ FieldControl,
49
+ {
50
+ type: "textlike",
51
+ id,
52
+ render: /* @__PURE__ */ jsx(
53
+ Role.textarea,
54
+ {
55
+ readOnly: props.disabled,
56
+ ...rest,
57
+ className: cx("\u{1F95D}-text-box", props.className),
58
+ placeholder: props.placeholder ?? " ",
59
+ render: /* @__PURE__ */ jsx(
60
+ Focusable,
61
+ {
62
+ accessibleWhenDisabled: true,
63
+ render: props.render || /* @__PURE__ */ jsx("textarea", {})
64
+ }
65
+ ),
66
+ ref: forwardedRef
67
+ }
68
+ )
69
+ }
70
+ );
71
+ }
72
+ );
73
+ const TextBoxRoot = forwardRef(
34
74
  (props, forwardedRef) => {
35
75
  const inputRef = React.useRef(null);
36
76
  const [disabled, setDisabled] = React.useState();
@@ -39,7 +79,7 @@ const TextBoxRoot = React.forwardRef(
39
79
  {
40
80
  value: React.useMemo(() => ({ setDisabled, inputRef }), []),
41
81
  children: /* @__PURE__ */ jsx(
42
- Ariakit.Role.div,
82
+ Role.div,
43
83
  {
44
84
  ...props,
45
85
  "data-kiwi-disabled": disabled,
@@ -59,31 +99,35 @@ const TextBoxRoot = React.forwardRef(
59
99
  );
60
100
  }
61
101
  );
62
- const TextBoxIcon = React.forwardRef((props, forwardedRef) => {
63
- return /* @__PURE__ */ jsx(
64
- Icon,
65
- {
66
- ...props,
67
- className: cx("\u{1F95D}-text-box-decoration", props.className),
68
- ref: forwardedRef
69
- }
70
- );
71
- });
72
- const TextBoxText = React.forwardRef((props, forwardedRef) => {
73
- return /* @__PURE__ */ jsx(
74
- Ariakit.Role.span,
75
- {
76
- ...props,
77
- className: cx("\u{1F95D}-text-box-decoration", props.className),
78
- ref: forwardedRef
79
- }
80
- );
81
- });
102
+ const TextBoxIcon = forwardRef(
103
+ (props, forwardedRef) => {
104
+ return /* @__PURE__ */ jsx(
105
+ Icon,
106
+ {
107
+ ...props,
108
+ className: cx("\u{1F95D}-text-box-decoration", props.className),
109
+ ref: forwardedRef
110
+ }
111
+ );
112
+ }
113
+ );
114
+ const TextBoxText = forwardRef(
115
+ (props, forwardedRef) => {
116
+ return /* @__PURE__ */ jsx(
117
+ Role.span,
118
+ {
119
+ ...props,
120
+ className: cx("\u{1F95D}-text-box-decoration", props.className),
121
+ ref: forwardedRef
122
+ }
123
+ );
124
+ }
125
+ );
82
126
  const TextBoxRootContext = React.createContext(void 0);
83
127
  export {
84
128
  TextBoxIcon as Icon,
85
129
  TextBoxInput as Input,
86
130
  TextBoxRoot as Root,
87
131
  TextBoxText as Text,
88
- Textarea
132
+ TextBoxTextarea as Textarea
89
133
  };
@@ -1,14 +1,18 @@
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
- * The content to be displayed inside the tooltip.
6
+ * The content to be displayed inside the tooltip when the trigger element is hovered or focused.
7
7
  */
8
8
  content: React.ReactNode;
9
9
  /**
10
10
  * The element that will trigger the tooltip when hovered or focused.
11
11
  * Common examples include buttons, links, or form controls.
12
+ *
13
+ * **Note**: The trigger must be a single interactive element. Do not add a
14
+ * tooltip to a non-interactive static element (such as a `<div>` or `<svg>`). Also,
15
+ * the trigger element must forward its ref and spread its props.
12
16
  */
13
17
  children: React.ReactElement;
14
18
  /**
@@ -23,7 +27,7 @@ interface TooltipProps extends Omit<FocusableProps<"div">, "content">, Pick<Aria
23
27
  type?: "description" | "label" | "none";
24
28
  }
25
29
  /**
26
- * Tooltip component that provides additional information or context for a trigger element.
30
+ * A tooltip component that provides additional information or context for an interactive trigger element.
27
31
  *
28
32
  * Example usage:
29
33
  *
@@ -33,7 +37,10 @@ interface TooltipProps extends Omit<FocusableProps<"div">, "content">, Pick<Aria
33
37
  * </Tooltip>
34
38
  * ```
35
39
  *
36
- * **Note**: If `type` is set to `"none"`, the tooltip will not use ARIA attributes and will unmount when hidden.
40
+ * **Note**: The trigger element must be a single interactive element, such as a button or link. Do not add a
41
+ * tooltip to a non-interactive static element (such as a `<div>` or `<svg>`).
42
+ *
43
+ * **Note**: If `type` is set to `"none"`, the tooltip will not use ARIA attributes.
37
44
  */
38
- export declare const Tooltip: React.ForwardRefExoticComponent<TooltipProps & React.RefAttributes<HTMLDivElement>>;
45
+ export declare const Tooltip: React.ForwardRefExoticComponent<TooltipProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
39
46
  export {};
@@ -1,67 +1,67 @@
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 { supportsPopover } from "./~utils.js";
6
- const Tooltip = React.forwardRef((props, forwardedRef) => {
7
- const {
8
- content,
9
- children,
10
- className,
11
- type = "description",
12
- id = React.useId(),
13
- defaultOpen: defaultOpenProp,
14
- open: openProp,
15
- setOpen: setOpenProp,
16
- unmountOnHide = type === "none",
17
- ...rest
18
- } = props;
19
- const store = Ariakit.useTooltipStore();
20
- const open = Ariakit.useStoreState(store, (state) => state.open);
21
- const popover = Ariakit.useStoreState(store, (state) => state.popoverElement);
22
- React.useEffect(
23
- function syncPopoverWithOpenState() {
24
- if (popover?.isConnected) {
25
- popover?.togglePopover?.(open);
26
- }
27
- },
28
- [open, popover]
29
- );
30
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
31
- Ariakit.TooltipProvider,
32
- {
33
- store,
4
+ import * as AkTooltip from "@ariakit/react/tooltip";
5
+ import { useStoreState } from "@ariakit/react/store";
6
+ import { forwardRef } from "./~utils.js";
7
+ import { usePopoverApi } from "./~hooks.js";
8
+ const Tooltip = forwardRef(
9
+ (props, forwardedRef) => {
10
+ const generatedId = React.useId();
11
+ const {
12
+ content,
13
+ children,
14
+ type = "description",
15
+ id = generatedId,
34
16
  defaultOpen: defaultOpenProp,
35
17
  open: openProp,
36
18
  setOpen: setOpenProp,
37
- children: [
38
- /* @__PURE__ */ jsx(
39
- Ariakit.TooltipAnchor,
40
- {
41
- render: children,
42
- ...type === "description" && { "aria-describedby": id },
43
- ...type === "label" && { "aria-labelledby": id }
44
- }
45
- ),
46
- /* @__PURE__ */ jsx(
47
- Ariakit.Tooltip,
48
- {
49
- "aria-hidden": "true",
50
- ...rest,
51
- unmountOnHide,
52
- className: cx("\u{1F95D}-tooltip", className),
53
- ref: forwardedRef,
54
- id,
55
- style: { zIndex: supportsPopover ? void 0 : 9999, ...props.style },
56
- wrapperProps: { popover: "manual" },
57
- portal: !supportsPopover,
58
- children: content
59
- }
60
- )
61
- ]
62
- }
63
- ) });
64
- });
19
+ unmountOnHide = type === "none",
20
+ ...rest
21
+ } = props;
22
+ const store = AkTooltip.useTooltipStore();
23
+ const open = useStoreState(store, (store2) => store2.open);
24
+ const popover = usePopoverApi(store);
25
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
26
+ AkTooltip.TooltipProvider,
27
+ {
28
+ store,
29
+ defaultOpen: defaultOpenProp,
30
+ open: openProp,
31
+ setOpen: setOpenProp,
32
+ children: [
33
+ /* @__PURE__ */ jsx(
34
+ AkTooltip.TooltipAnchor,
35
+ {
36
+ render: children,
37
+ "data-has-popover-open": open || void 0,
38
+ ...type === "description" && { "aria-describedby": id },
39
+ ...type === "label" && { "aria-labelledby": id }
40
+ }
41
+ ),
42
+ /* @__PURE__ */ jsx(
43
+ AkTooltip.Tooltip,
44
+ {
45
+ "aria-hidden": "true",
46
+ ...rest,
47
+ unmountOnHide,
48
+ className: cx("\u{1F95D}-tooltip", props.className),
49
+ ref: forwardedRef,
50
+ id,
51
+ style: {
52
+ ...popover.style,
53
+ ...props.style
54
+ },
55
+ wrapperProps: popover.wrapperProps,
56
+ portal: popover.portal,
57
+ children: content
58
+ }
59
+ )
60
+ ]
61
+ }
62
+ ) });
63
+ }
64
+ );
65
65
  export {
66
66
  Tooltip
67
67
  };
@@ -1,23 +1,22 @@
1
- import * as React from "react";
2
- import { IconButton } from "./IconButton.js";
3
- import type { BaseProps } from "./~utils.js";
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
- declare const Tree: React.ForwardRefExoticComponent<TreeProps & React.RefAttributes<HTMLDivElement>>;
7
- interface TreeItemProps extends Omit<BaseProps, "content"> {
8
- content?: React.ReactNode;
9
- selected?: boolean;
10
- /** Specifies if the tree item is expanded. Used to determine if a tree item is a parent node. Defaults to `undefined`. */
11
- expanded?: boolean;
12
- }
13
- declare const TreeItem: React.ForwardRefExoticComponent<TreeItemProps & React.RefAttributes<HTMLDivElement>>;
14
- interface TreeItemContentProps extends BaseProps<"span"> {
15
- }
16
- declare const TreeItemContent: React.ForwardRefExoticComponent<TreeItemContentProps & React.RefAttributes<HTMLSpanElement>>;
17
- type IconButtonProps = React.ComponentProps<typeof IconButton>;
18
- interface TreeItemExpanderProps extends Omit<IconButtonProps, "variant" | "label" | "icon"> {
19
- label?: IconButtonProps["label"];
20
- icon?: IconButtonProps["icon"];
21
- }
22
- declare const TreeItemExpander: React.ForwardRefExoticComponent<Omit<TreeItemExpanderProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
23
- export { Tree as Root, TreeItem as Item, TreeItemExpander as Expander, TreeItemContent as Content, };
5
+ /**
6
+ * A tree is a hierarchical list of items that can be expanded or collapsed, or optionally selected.
7
+ *
8
+ * `Tree.Root` is the root component for a tree. `Tree.Item`s are rendered as a flat list in the `Tree.Root` component to create a hierarchical tree structure.
9
+ *
10
+ * Example:
11
+ * ```tsx
12
+ * <Tree.Root>
13
+ * <Tree.Item label="Parent 1" aria-level={1} aria-posinset={1} aria-setsize={2} />
14
+ * <Tree.Item label="Child 1.1" aria-level={2} aria-posinset={1} aria-setsize={2} />
15
+ * <Tree.Item label="Child 1.2" aria-level={2} aria-posinset={2} aria-setsize={2} />
16
+ * <Tree.Item label="Parent 2" aria-level={1} aria-posinset={2} aria-setsize={2} />
17
+ * <Tree.Item label="Child 2.1" aria-level={2} aria-posinset={1} aria-setsize={1} />
18
+ * </Tree.Root>
19
+ * ```
20
+ */
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,107 +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";
8
- const Tree = React.forwardRef(
9
- (props, forwardedRef) => {
10
- return /* @__PURE__ */ jsx(Ariakit.Role.div, { ...props, role: "list", ref: forwardedRef, children: props.children });
11
- }
12
- );
13
- const TreeItem = React.forwardRef(
14
- (props, forwardedRef) => {
15
- const { selected, content, children, className, expanded, style, ...rest } = props;
16
- const parentContext = React.useContext(TreeItemContext);
17
- const level = parentContext ? parentContext.level + 1 : 1;
18
- return /* @__PURE__ */ jsx(
19
- TreeItemContext.Provider,
20
- {
21
- value: React.useMemo(
22
- () => ({
23
- level,
24
- expanded
25
- }),
26
- [level, expanded]
27
- ),
28
- children: /* @__PURE__ */ jsxs("div", { role: "listitem", children: [
29
- /* @__PURE__ */ jsx(
30
- ListItem.Root,
31
- {
32
- ...rest,
33
- "data-kiwi-expanded": expanded,
34
- "data-kiwi-selected": selected,
35
- className: cx("\u{1F95D}-tree-item", className),
36
- style: {
37
- ...style,
38
- "--\u{1F95D}tree-item-level": level
39
- },
40
- ref: forwardedRef,
41
- role: void 0,
42
- children: content
43
- }
44
- ),
45
- children && /* @__PURE__ */ jsx("div", { role: "list", children })
46
- ] })
47
- }
48
- );
49
- }
50
- );
51
- const TreeItemContent = React.forwardRef((props, forwardedRef) => {
3
+ import { Role } from "@ariakit/react/role";
4
+ import { useCompositeStore, Composite } from "@ariakit/react/composite";
5
+ import { forwardRef } from "./~utils.js";
6
+ import { Root as TreeItemRoot, Action as TreeItemAction } from "./TreeItem.js";
7
+ const Tree = forwardRef((props, forwardedRef) => {
8
+ const composite = useCompositeStore({ orientation: "vertical" });
52
9
  return /* @__PURE__ */ jsx(
53
- ListItem.Content,
10
+ Role.div,
54
11
  {
12
+ role: "tree",
55
13
  ...props,
56
- className: cx("\u{1F95D}-tree-item-content", props.className),
57
- ref: forwardedRef
14
+ render: /* @__PURE__ */ jsx(Composite, { store: composite }),
15
+ className: cx("\u{1F95D}-tree", props.className),
16
+ ref: forwardedRef,
17
+ children: props.children
58
18
  }
59
19
  );
60
20
  });
61
- const TreeItemExpander = React.forwardRef((props, forwardedRef) => {
62
- const context = React.useContext(TreeItemContext);
63
- const expanded = context?.expanded;
64
- return /* @__PURE__ */ jsx(
65
- IconButton,
66
- {
67
- icon: /* @__PURE__ */ jsx(TreeChevron, {}),
68
- label: "Toggle",
69
- "aria-expanded": expanded === void 0 ? void 0 : expanded,
70
- ...props,
71
- className: cx("\u{1F95D}-tree-item-expander", props.className),
72
- variant: "ghost",
73
- labelVariant: "visually-hidden",
74
- ref: forwardedRef
75
- }
76
- );
77
- });
78
- const TreeChevron = React.forwardRef(
79
- (props, forwardedRef) => {
80
- return /* @__PURE__ */ jsx(
81
- Icon,
82
- {
83
- ...props,
84
- render: /* @__PURE__ */ jsx(
85
- Ariakit.Role.svg,
86
- {
87
- width: "16",
88
- height: "16",
89
- fill: "currentColor",
90
- viewBox: "0 0 16 16",
91
- render: props.render,
92
- 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" })
93
- }
94
- ),
95
- className: cx("\u{1F95D}-tree-chevron", props.className),
96
- ref: forwardedRef
97
- }
98
- );
99
- }
100
- );
101
- const TreeItemContext = React.createContext(void 0);
102
21
  export {
103
- TreeItemContent as Content,
104
- TreeItemExpander as Expander,
105
- TreeItem as Item,
22
+ TreeItemRoot as Item,
23
+ TreeItemAction as ItemAction,
106
24
  Tree as Root
107
25
  };