@itwin/itwinui-react 5.0.0-alpha.0 → 5.0.0-alpha.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/DEV/bricks/Anchor.js +20 -22
  3. package/dist/DEV/bricks/Button.js +17 -15
  4. package/dist/DEV/bricks/Checkbox.js +19 -15
  5. package/dist/DEV/bricks/Chip.js +21 -0
  6. package/dist/DEV/bricks/Description.js +27 -0
  7. package/dist/DEV/bricks/Divider.js +14 -16
  8. package/dist/DEV/bricks/DropdownMenu.js +60 -44
  9. package/dist/DEV/bricks/Field.js +66 -16
  10. package/dist/DEV/bricks/Icon.js +45 -44
  11. package/dist/DEV/bricks/IconButton.js +24 -19
  12. package/dist/DEV/bricks/Kbd.js +46 -16
  13. package/dist/DEV/bricks/Label.js +2 -2
  14. package/dist/DEV/bricks/ListItem.js +16 -16
  15. package/dist/DEV/bricks/Radio.js +5 -3
  16. package/dist/DEV/bricks/Root.js +45 -43
  17. package/dist/DEV/bricks/Select.js +57 -0
  18. package/dist/DEV/bricks/Spinner.js +40 -0
  19. package/dist/DEV/bricks/Switch.js +20 -16
  20. package/dist/DEV/bricks/Tabs.js +15 -16
  21. package/dist/DEV/bricks/Text.js +20 -0
  22. package/dist/DEV/bricks/TextBox.js +55 -46
  23. package/dist/DEV/bricks/Textarea.js +25 -21
  24. package/dist/DEV/bricks/Tooltip.js +65 -57
  25. package/dist/DEV/bricks/Tree.js +133 -66
  26. package/dist/DEV/bricks/VisuallyHidden.js +6 -4
  27. package/dist/DEV/bricks/index.js +12 -0
  28. package/dist/DEV/bricks/styles.css.js +1 -1
  29. package/dist/DEV/bricks/~hooks.js +13 -0
  30. package/dist/DEV/bricks/~utils.js +3 -0
  31. package/dist/DEV/foundations/styles.css.js +1 -1
  32. package/dist/bricks/Anchor.d.ts +12 -3
  33. package/dist/bricks/Anchor.js +20 -22
  34. package/dist/bricks/Button.d.ts +27 -4
  35. package/dist/bricks/Button.js +17 -15
  36. package/dist/bricks/Checkbox.d.ts +17 -3
  37. package/dist/bricks/Checkbox.js +19 -15
  38. package/dist/bricks/Chip.d.ts +22 -0
  39. package/dist/bricks/Chip.js +20 -0
  40. package/dist/bricks/Description.d.ts +20 -0
  41. package/dist/bricks/Description.js +27 -0
  42. package/dist/bricks/Divider.d.ts +3 -4
  43. package/dist/bricks/Divider.js +14 -16
  44. package/dist/bricks/DropdownMenu.d.ts +60 -10
  45. package/dist/bricks/DropdownMenu.js +60 -44
  46. package/dist/bricks/Field.d.ts +30 -2
  47. package/dist/bricks/Field.js +66 -16
  48. package/dist/bricks/Icon.d.ts +4 -4
  49. package/dist/bricks/Icon.js +44 -43
  50. package/dist/bricks/IconButton.d.ts +4 -4
  51. package/dist/bricks/IconButton.js +24 -19
  52. package/dist/bricks/Kbd.d.ts +32 -3
  53. package/dist/bricks/Kbd.js +39 -16
  54. package/dist/bricks/Label.d.ts +22 -3
  55. package/dist/bricks/Label.js +2 -2
  56. package/dist/bricks/ListItem.d.ts +2 -3
  57. package/dist/bricks/ListItem.js +15 -15
  58. package/dist/bricks/Radio.d.ts +17 -3
  59. package/dist/bricks/Radio.js +5 -3
  60. package/dist/bricks/Root.d.ts +11 -2
  61. package/dist/bricks/Root.js +45 -43
  62. package/dist/bricks/Select.d.ts +45 -0
  63. package/dist/bricks/Select.js +57 -0
  64. package/dist/bricks/Spinner.d.ts +31 -0
  65. package/dist/bricks/Spinner.js +39 -0
  66. package/dist/bricks/Switch.d.ts +17 -3
  67. package/dist/bricks/Switch.js +20 -16
  68. package/dist/bricks/Tabs.d.ts +66 -5
  69. package/dist/bricks/Tabs.js +15 -16
  70. package/dist/bricks/Text.d.ts +22 -0
  71. package/dist/bricks/Text.js +19 -0
  72. package/dist/bricks/TextBox.d.ts +39 -9
  73. package/dist/bricks/TextBox.js +55 -46
  74. package/dist/bricks/Textarea.d.ts +14 -4
  75. package/dist/bricks/Textarea.js +25 -21
  76. package/dist/bricks/Tooltip.d.ts +11 -4
  77. package/dist/bricks/Tooltip.js +65 -57
  78. package/dist/bricks/Tree.d.ts +79 -16
  79. package/dist/bricks/Tree.js +128 -62
  80. package/dist/bricks/VisuallyHidden.d.ts +15 -3
  81. package/dist/bricks/VisuallyHidden.js +6 -4
  82. package/dist/bricks/index.d.ts +6 -0
  83. package/dist/bricks/index.js +12 -0
  84. package/dist/bricks/styles.css.js +1 -1
  85. package/dist/bricks/~hooks.d.ts +15 -0
  86. package/dist/bricks/~hooks.js +13 -0
  87. package/dist/bricks/~utils.d.ts +20 -0
  88. package/dist/bricks/~utils.js +3 -0
  89. package/dist/foundations/styles.css.js +1 -1
  90. package/package.json +2 -2
@@ -4,8 +4,9 @@ import cx from "classnames";
4
4
  import * as Ariakit from "@ariakit/react";
5
5
  import * as ListItem from "./ListItem.js";
6
6
  import { Button } from "./Button.js";
7
+ import { Kbd } from "./Kbd.js";
7
8
  import { DisclosureArrow } from "./Icon.js";
8
- import { supportsPopover } from "./~utils.js";
9
+ import { forwardRef, supportsPopover } from "./~utils.js";
9
10
  function DropdownMenu(props) {
10
11
  const {
11
12
  children,
@@ -15,8 +16,8 @@ function DropdownMenu(props) {
15
16
  defaultOpen: defaultOpenProp
16
17
  } = props;
17
18
  const store = Ariakit.useMenuStore();
18
- const open = Ariakit.useStoreState(store, (store2) => store2.open);
19
- const popover = Ariakit.useStoreState(store, (store2) => store2.popoverElement);
19
+ const open = Ariakit.useStoreState(store, (state) => state.open);
20
+ const popover = Ariakit.useStoreState(store, (state) => state.popoverElement);
20
21
  React.useEffect(
21
22
  function syncPopoverWithOpenState() {
22
23
  if (popover?.isConnected) {
@@ -37,47 +38,62 @@ function DropdownMenu(props) {
37
38
  }
38
39
  );
39
40
  }
40
- const DropdownMenuContent = React.forwardRef((props, forwardedRef) => {
41
- return /* @__PURE__ */ jsx(
42
- Ariakit.Menu,
43
- {
44
- portal: !supportsPopover,
45
- unmountOnHide: true,
46
- ...props,
47
- style: { zIndex: supportsPopover ? void 0 : 9999, ...props.style },
48
- wrapperProps: { popover: "manual" },
49
- className: cx("\u{1F95D}-dropdown-menu", props.className),
50
- ref: forwardedRef
51
- }
52
- );
53
- });
54
- const DropdownMenuButton = React.forwardRef((props, forwardedRef) => {
55
- const { accessibleWhenDisabled = true, children, ...rest } = props;
56
- return /* @__PURE__ */ jsx(
57
- Ariakit.MenuButton,
58
- {
59
- accessibleWhenDisabled: true,
60
- render: /* @__PURE__ */ jsxs(Button, { accessibleWhenDisabled, children: [
61
- children,
62
- /* @__PURE__ */ jsx(DisclosureArrow, {})
63
- ] }),
64
- ...rest,
65
- className: cx("\u{1F95D}-dropdown-menu-button", props.className),
66
- ref: forwardedRef
67
- }
68
- );
69
- });
70
- const DropdownMenuItem = React.forwardRef((props, forwardedRef) => {
71
- return /* @__PURE__ */ jsx(
72
- Ariakit.MenuItem,
73
- {
74
- accessibleWhenDisabled: true,
75
- ...props,
76
- render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
77
- ref: forwardedRef
78
- }
79
- );
80
- });
41
+ const DropdownMenuContent = forwardRef(
42
+ (props, forwardedRef) => {
43
+ return /* @__PURE__ */ jsx(
44
+ Ariakit.Menu,
45
+ {
46
+ portal: !supportsPopover,
47
+ unmountOnHide: true,
48
+ ...props,
49
+ style: { zIndex: supportsPopover ? void 0 : 9999, ...props.style },
50
+ wrapperProps: { popover: "manual" },
51
+ className: cx("\u{1F95D}-dropdown-menu", props.className),
52
+ ref: forwardedRef
53
+ }
54
+ );
55
+ }
56
+ );
57
+ const DropdownMenuButton = forwardRef(
58
+ (props, forwardedRef) => {
59
+ const { accessibleWhenDisabled = true, children, ...rest } = props;
60
+ return /* @__PURE__ */ jsx(
61
+ Ariakit.MenuButton,
62
+ {
63
+ accessibleWhenDisabled: true,
64
+ render: /* @__PURE__ */ jsxs(Button, { accessibleWhenDisabled, children: [
65
+ children,
66
+ /* @__PURE__ */ jsx(DisclosureArrow, {})
67
+ ] }),
68
+ ...rest,
69
+ className: cx("\u{1F95D}-dropdown-menu-button", props.className),
70
+ ref: forwardedRef
71
+ }
72
+ );
73
+ }
74
+ );
75
+ const DropdownMenuItem = forwardRef(
76
+ (props, forwardedRef) => {
77
+ const { shortcuts, ...rest } = props;
78
+ const shortcutKeys = React.useMemo(() => {
79
+ return typeof shortcuts === "string" ? shortcuts.split("+").map((key) => key.trim()) : [];
80
+ }, [shortcuts]);
81
+ const hasShortcuts = shortcutKeys.length > 0;
82
+ return /* @__PURE__ */ jsxs(
83
+ Ariakit.MenuItem,
84
+ {
85
+ accessibleWhenDisabled: true,
86
+ ...rest,
87
+ render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
88
+ ref: forwardedRef,
89
+ children: [
90
+ /* @__PURE__ */ jsx(ListItem.Content, { children: props.children }),
91
+ hasShortcuts && /* @__PURE__ */ jsx("span", { className: "\u{1F95D}-dropdown-menu-item-shortcuts", children: shortcutKeys.map((key, index) => /* @__PURE__ */ jsx(Kbd, { variant: "ghost", children: key }, `${key + index}`)) })
92
+ ]
93
+ }
94
+ );
95
+ }
96
+ );
81
97
  export {
82
98
  DropdownMenuButton as Button,
83
99
  DropdownMenuContent as Content,
@@ -1,11 +1,39 @@
1
1
  import * as React from "react";
2
- import type { BaseProps } from "./~utils.js";
2
+ import { type BaseProps } from "./~utils.js";
3
3
  interface FieldProps extends BaseProps {
4
4
  /**
5
5
  * Allows overriding the default block layout for text controls.
6
6
  */
7
7
  layout?: "inline";
8
8
  }
9
- export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>>;
9
+ /**
10
+ * A container for form controls. It manages ID associations provides a consistent layout and spacing.
11
+ *
12
+ * Example:
13
+ * ```tsx
14
+ * <Field>
15
+ * <Label>Label</Label>
16
+ * <TextBox.Input />
17
+ * </Field>
18
+ * ```
19
+ *
20
+ * Supports a `layout` prop, which can be set to `inline` to align the label and control horizontally.
21
+ *
22
+ * Should contain a `Label` component paired with a form control. Supported form controls include:
23
+ * - `TextBox.Input`
24
+ * - `TextBox.Textarea`
25
+ * - `Checkbox`
26
+ * - `Radio`
27
+ * - `Switch`
28
+ */
29
+ export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
30
+ /**
31
+ * Use the description IDs for a field.
32
+ */
33
+ export declare function useFieldDescribedBy(ariaDescribedByProp?: string): string | undefined;
34
+ /**
35
+ * Registers a description for an associated control.
36
+ */
37
+ export declare function useFieldRegisterDescribedBy(id: string): void;
10
38
  export declare function useFieldId(): string | undefined;
11
39
  export {};
@@ -2,26 +2,76 @@ import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import * as Ariakit from "@ariakit/react";
4
4
  import cx from "classnames";
5
- const Field = React.forwardRef(
6
- (props, forwardedRef) => {
7
- const fieldId = React.useId();
8
- const { className, layout, ...rest } = props;
9
- return /* @__PURE__ */ jsx(FieldIdContext.Provider, { value: fieldId, children: /* @__PURE__ */ jsx(
10
- Ariakit.Role,
11
- {
12
- ...rest,
13
- className: cx("\u{1F95D}-field", className),
14
- "data-kiwi-layout": layout,
15
- ref: forwardedRef
16
- }
17
- ) });
18
- }
19
- );
5
+ import { forwardRef } from "./~utils.js";
6
+ const Field = forwardRef((props, forwardedRef) => {
7
+ const fieldId = React.useId();
8
+ const { layout, ...rest } = props;
9
+ return /* @__PURE__ */ jsx(FieldIdContext.Provider, { value: fieldId, children: /* @__PURE__ */ jsx(FieldDescribedByProvider, { children: /* @__PURE__ */ jsx(
10
+ Ariakit.Role,
11
+ {
12
+ ...rest,
13
+ className: cx("\u{1F95D}-field", props.className),
14
+ "data-kiwi-layout": layout,
15
+ ref: forwardedRef
16
+ }
17
+ ) }) });
18
+ });
19
+ const FieldDescribedByContext = React.createContext(void 0);
20
+ function FieldDescribedByProvider(props) {
21
+ const [describedBy, setDescribedBy] = React.useState(/* @__PURE__ */ new Set());
22
+ const register = React.useCallback((id) => {
23
+ setDescribedBy((describedBy2) => {
24
+ const updated = new Set(describedBy2);
25
+ updated.add(id);
26
+ return updated;
27
+ });
28
+ }, []);
29
+ const unregister = React.useCallback((id) => {
30
+ setDescribedBy((describedBy2) => {
31
+ const updated = new Set(describedBy2);
32
+ updated.delete(id);
33
+ return updated;
34
+ });
35
+ }, []);
36
+ return /* @__PURE__ */ jsx(
37
+ FieldDescribedByContext.Provider,
38
+ {
39
+ value: React.useMemo(
40
+ () => ({
41
+ describedBy,
42
+ register,
43
+ unregister
44
+ }),
45
+ [describedBy, register, unregister]
46
+ ),
47
+ children: props.children
48
+ }
49
+ );
50
+ }
51
+ function useFieldDescribedBy(ariaDescribedByProp) {
52
+ const describedBySet = React.useContext(FieldDescribedByContext)?.describedBy;
53
+ return React.useMemo(
54
+ () => !describedBySet || describedBySet.size === 0 ? ariaDescribedByProp : [...describedBySet, ariaDescribedByProp].filter(Boolean).join(" "),
55
+ [describedBySet, ariaDescribedByProp]
56
+ );
57
+ }
58
+ function useFieldRegisterDescribedBy(id) {
59
+ const context = React.useContext(FieldDescribedByContext);
60
+ const register = context?.register;
61
+ const unregister = context?.unregister;
62
+ React.useEffect(() => {
63
+ if (!register || !unregister) return;
64
+ register(id);
65
+ return () => unregister(id);
66
+ }, [id, register, unregister]);
67
+ }
20
68
  const FieldIdContext = React.createContext(void 0);
21
69
  function useFieldId() {
22
70
  return React.useContext(FieldIdContext);
23
71
  }
24
72
  export {
25
73
  Field,
26
- useFieldId
74
+ useFieldDescribedBy,
75
+ useFieldId,
76
+ useFieldRegisterDescribedBy
27
77
  };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import type { BaseProps } from "./~utils.js";
2
+ import { type BaseProps } from "./~utils.js";
3
3
  interface IconProps extends Omit<BaseProps<"svg">, "children"> {
4
4
  /** URL of the symbol sprite. */
5
5
  href?: string;
@@ -11,7 +11,7 @@ interface IconProps extends Omit<BaseProps<"svg">, "children"> {
11
11
  * It uses an external symbol sprite to render the icon based on the specified `size`.
12
12
  *
13
13
  * ```tsx
14
- * const arrowIcon = new URL("@itwin/itwinui-icons/icons/arrow.svg", import.meta.url).href;
14
+ * const arrowIcon = new URL("@itwin/itwinui-icons/arrow.svg", import.meta.url).href;
15
15
  * <Icon href={arrowIcon} />
16
16
  * ```
17
17
  *
@@ -23,7 +23,7 @@ interface IconProps extends Omit<BaseProps<"svg">, "children"> {
23
23
  *
24
24
  * **Note**: This component is meant to be used with decorative icons, so it adds `aria-hidden` by default.
25
25
  */
26
- export declare const Icon: React.ForwardRefExoticComponent<IconProps & React.RefAttributes<SVGSVGElement>>;
26
+ export declare const Icon: React.ForwardRefExoticComponent<IconProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
27
27
  interface DisclosureArrowProps extends Omit<BaseProps<"svg">, "children"> {
28
28
  /**
29
29
  * Which direction should the arrow point towards?
@@ -31,5 +31,5 @@ interface DisclosureArrowProps extends Omit<BaseProps<"svg">, "children"> {
31
31
  */
32
32
  direction?: "down" | "right";
33
33
  }
34
- export declare const DisclosureArrow: React.ForwardRefExoticComponent<DisclosureArrowProps & React.RefAttributes<SVGSVGElement>>;
34
+ export declare const DisclosureArrow: React.ForwardRefExoticComponent<DisclosureArrowProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
35
35
  export {};
@@ -2,57 +2,58 @@ import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import cx from "classnames";
4
4
  import * as Ariakit from "@ariakit/react";
5
- const Icon = React.forwardRef(
5
+ import { forwardRef } from "./~utils.js";
6
+ const Icon = forwardRef((props, forwardedRef) => {
7
+ const { href, size = "regular", ...rest } = props;
8
+ const iconId = toIconId(size);
9
+ return /* @__PURE__ */ jsx(
10
+ Ariakit.Role.svg,
11
+ {
12
+ "aria-hidden": true,
13
+ ...rest,
14
+ "data-kiwi-size": size,
15
+ className: cx("\u{1F95D}-icon", props.className),
16
+ ref: forwardedRef,
17
+ children: /* @__PURE__ */ jsx("use", { href: `${props.href}#${iconId}` })
18
+ }
19
+ );
20
+ });
21
+ function toIconId(size) {
22
+ if (size === "large") return "icon-large";
23
+ return "icon";
24
+ }
25
+ const DisclosureArrow = forwardRef(
6
26
  (props, forwardedRef) => {
7
- const { href, size = "regular", ...rest } = props;
8
- const iconId = toIconId(size);
27
+ const { direction = "down", ...rest } = props;
28
+ const path = React.useMemo(() => {
29
+ switch (direction) {
30
+ case "down":
31
+ return /* @__PURE__ */ jsx("path", { d: "M8 10 5 7h6l-3 3Z" });
32
+ case "right":
33
+ return /* @__PURE__ */ jsx("path", { d: "M7 11V5l3 3-3 3Z" });
34
+ }
35
+ }, [direction]);
9
36
  return /* @__PURE__ */ jsx(
10
- Ariakit.Role.svg,
37
+ Icon,
11
38
  {
12
- "data-kiwi-size": size,
13
- "aria-hidden": true,
14
39
  ...rest,
15
- className: cx("\u{1F95D}-icon", props.className),
16
- ref: forwardedRef,
17
- children: /* @__PURE__ */ jsx("use", { href: `${props.href}#${iconId}` })
40
+ render: /* @__PURE__ */ jsx(
41
+ Ariakit.Role.svg,
42
+ {
43
+ width: "16",
44
+ height: "16",
45
+ fill: "currentColor",
46
+ viewBox: "0 0 16 16",
47
+ render: props.render,
48
+ children: path
49
+ }
50
+ ),
51
+ className: cx("\u{1F95D}-disclosure-arrow", props.className),
52
+ ref: forwardedRef
18
53
  }
19
54
  );
20
55
  }
21
56
  );
22
- function toIconId(size) {
23
- if (size === "large") return "icon-large";
24
- return "icon";
25
- }
26
- const DisclosureArrow = React.forwardRef((props, forwardedRef) => {
27
- const { direction = "down", ...rest } = props;
28
- const path = React.useMemo(() => {
29
- switch (direction) {
30
- case "down":
31
- return /* @__PURE__ */ jsx("path", { d: "M8 10 5 7h6l-3 3Z" });
32
- case "right":
33
- return /* @__PURE__ */ jsx("path", { d: "M7 11V5l3 3-3 3Z" });
34
- }
35
- }, [direction]);
36
- return /* @__PURE__ */ jsx(
37
- Icon,
38
- {
39
- ...rest,
40
- render: /* @__PURE__ */ jsx(
41
- Ariakit.Role.svg,
42
- {
43
- width: "16",
44
- height: "16",
45
- fill: "currentColor",
46
- viewBox: "0 0 16 16",
47
- render: props.render,
48
- children: path
49
- }
50
- ),
51
- className: cx("\u{1F95D}-disclosure-arrow", props.className),
52
- ref: forwardedRef
53
- }
54
- );
55
- });
56
57
  export {
57
58
  DisclosureArrow,
58
59
  Icon
@@ -1,4 +1,3 @@
1
- import * as React from "react";
2
1
  import { Button } from "./Button.js";
3
2
  interface IconButtonBaseProps extends Omit<React.ComponentProps<typeof Button>, "children" | "tone"> {
4
3
  /**
@@ -32,7 +31,7 @@ interface IconButtonBaseProps extends Omit<React.ComponentProps<typeof Button>,
32
31
  * ```tsx
33
32
  * <IconButton
34
33
  * label="Reveal full content"
35
- * icon={new URL("@itwin/itwinui-icons/icons/arrow.svg", import.meta.url).href}
34
+ * icon={new URL("@itwin/itwinui-icons/arrow.svg", import.meta.url).href}
36
35
  * />
37
36
  * ```
38
37
  *
@@ -55,8 +54,9 @@ interface IconButtonBaseProps extends Omit<React.ComponentProps<typeof Button>,
55
54
  * isActive={isActive}
56
55
  * onClick={() => setIsActive(!isActive)}
57
56
  * />
57
+ * ```
58
58
  */
59
- export declare const IconButton: React.ForwardRefExoticComponent<(Omit<IconButtonBaseProps & {
59
+ export declare const IconButton: import("react").ForwardRefExoticComponent<(Omit<IconButtonBaseProps & {
60
60
  variant: "ghost";
61
61
  /**
62
62
  * Whether the button is in a toggled state and currently "active" (toggled on).
@@ -75,5 +75,5 @@ export declare const IconButton: React.ForwardRefExoticComponent<(Omit<IconButto
75
75
  }, "ref"> | Omit<IconButtonBaseProps & {
76
76
  variant?: Omit<React.ComponentProps<typeof Button>["variant"], "ghost">;
77
77
  isActive?: never;
78
- }, "ref">) & React.RefAttributes<HTMLButtonElement>>;
78
+ }, "ref">) & import("react").RefAttributes<HTMLElement | HTMLButtonElement>>;
79
79
  export {};
@@ -1,30 +1,35 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import * as React from "react";
3
2
  import cx from "classnames";
3
+ import * as Ariakit from "@ariakit/react";
4
4
  import { Button } from "./Button.js";
5
5
  import { VisuallyHidden } from "./VisuallyHidden.js";
6
6
  import { Icon } from "./Icon.js";
7
7
  import { Tooltip } from "./Tooltip.js";
8
- const IconButton = React.forwardRef((props, forwardedRef) => {
9
- const { label, icon, isActive, labelVariant, ...rest } = props;
10
- const button = /* @__PURE__ */ jsxs(
11
- Button,
12
- {
13
- "aria-pressed": isActive,
14
- ...rest,
15
- className: cx("\u{1F95D}-icon-button", props.className),
16
- ref: forwardedRef,
17
- children: [
18
- /* @__PURE__ */ jsx(VisuallyHidden, { children: label }),
19
- typeof icon === "string" ? /* @__PURE__ */ jsx(Icon, { href: icon }) : icon
20
- ]
8
+ import { forwardRef } from "./~utils.js";
9
+ const IconButton = forwardRef(
10
+ (props, forwardedRef) => {
11
+ const { label, icon, isActive, labelVariant, ...rest } = props;
12
+ const toolbar = Ariakit.useToolbarContext();
13
+ const button = /* @__PURE__ */ jsxs(
14
+ Button,
15
+ {
16
+ "aria-pressed": isActive,
17
+ ...rest,
18
+ render: toolbar ? /* @__PURE__ */ jsx(Ariakit.ToolbarItem, { render: props.render }) : props.render,
19
+ className: cx("\u{1F95D}-icon-button", props.className),
20
+ ref: forwardedRef,
21
+ children: [
22
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: label }),
23
+ typeof icon === "string" ? /* @__PURE__ */ jsx(Icon, { href: icon }) : icon
24
+ ]
25
+ }
26
+ );
27
+ if (labelVariant === "visually-hidden") {
28
+ return button;
21
29
  }
22
- );
23
- if (labelVariant === "visually-hidden") {
24
- return button;
30
+ return /* @__PURE__ */ jsx(Tooltip, { content: label, type: "none", children: button });
25
31
  }
26
- return /* @__PURE__ */ jsx(Tooltip, { content: label, type: "none", children: button });
27
- });
32
+ );
28
33
  export {
29
34
  IconButton
30
35
  };
@@ -1,8 +1,33 @@
1
- import * as React from "react";
2
- import type { BaseProps } from "./~utils.js";
1
+ import { type BaseProps } from "./~utils.js";
2
+ declare const predefinedSymbols: {
3
+ readonly Backspace: "⌫";
4
+ readonly Command: "⌘";
5
+ readonly Control: "Ctrl";
6
+ readonly Down: "↓";
7
+ readonly Eject: "⏏";
8
+ readonly Enter: "↵";
9
+ readonly Escape: "Esc";
10
+ readonly Left: "←";
11
+ readonly Option: "⌥";
12
+ readonly Right: "→";
13
+ readonly Shift: "⇧";
14
+ readonly Space: "␣";
15
+ readonly Tab: "Tab";
16
+ readonly Up: "↑";
17
+ };
3
18
  interface KbdProps extends BaseProps<"kbd"> {
4
19
  /** @default "solid" */
5
20
  variant?: "solid" | "muted" | "ghost";
21
+ /**
22
+ * Display a specific key symbol from a predefined list. This is useful for
23
+ * displaying modifier keys or special keys, such as `Control`, `Shift`, `Enter`, etc.
24
+ *
25
+ * Example:
26
+ * ```tsx
27
+ * <Kbd symbol="Control" />
28
+ * ```
29
+ */
30
+ symbol?: keyof typeof predefinedSymbols;
6
31
  }
7
32
  /**
8
33
  * A styled wrapper over the HTML `<kbd>` element. This is typically
@@ -11,6 +36,10 @@ interface KbdProps extends BaseProps<"kbd"> {
11
36
  * ```tsx
12
37
  * <Kbd>Ctrl</Kbd> <Kbd>S</Kbd>
13
38
  * ```
39
+ *
40
+ * ```tsx
41
+ * <Kbd symbol="Control" />
42
+ * ```
14
43
  */
15
- export declare const Kbd: React.ForwardRefExoticComponent<KbdProps & React.RefAttributes<HTMLElement>>;
44
+ export declare const Kbd: import("react").ForwardRefExoticComponent<KbdProps & import("react").RefAttributes<HTMLElement>>;
16
45
  export {};
@@ -1,22 +1,45 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import * as React from "react";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
2
  import cx from "classnames";
4
3
  import * as Ariakit from "@ariakit/react";
5
- const Kbd = React.forwardRef(
6
- (props, forwardedRef) => {
7
- const { variant = "solid", ...rest } = props;
8
- return /* @__PURE__ */ jsx(
9
- Ariakit.Role,
10
- {
11
- "data-kiwi-variant": variant,
12
- ...rest,
13
- className: cx("\u{1F95D}-kbd", props.className),
14
- render: props.render || /* @__PURE__ */ jsx("kbd", {}),
15
- ref: forwardedRef
16
- }
17
- );
4
+ import { forwardRef } from "./~utils.js";
5
+ import { VisuallyHidden } from "./VisuallyHidden.js";
6
+ const predefinedSymbols = {
7
+ Backspace: "\u232B",
8
+ Command: "\u2318",
9
+ Control: "Ctrl",
10
+ Down: "\u2193",
11
+ Eject: "\u23CF",
12
+ Enter: "\u21B5",
13
+ Escape: "Esc",
14
+ Left: "\u2190",
15
+ Option: "\u2325",
16
+ Right: "\u2192",
17
+ Shift: "\u21E7",
18
+ Space: "\u2423",
19
+ Tab: "Tab",
20
+ Up: "\u2191"
21
+ };
22
+ const Kbd = forwardRef((props, forwardedRef) => {
23
+ const { variant = "solid", symbol, children, ...rest } = props;
24
+ let content = children;
25
+ if (symbol) {
26
+ content = /* @__PURE__ */ jsxs(Fragment, { children: [
27
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: predefinedSymbols[symbol] }),
28
+ children || /* @__PURE__ */ jsx(VisuallyHidden, { children: symbol })
29
+ ] });
18
30
  }
19
- );
31
+ return /* @__PURE__ */ jsx(
32
+ Ariakit.Role,
33
+ {
34
+ ...rest,
35
+ "data-kiwi-variant": variant,
36
+ className: cx("\u{1F95D}-kbd", props.className),
37
+ render: props.render || /* @__PURE__ */ jsx("kbd", {}),
38
+ ref: forwardedRef,
39
+ children: content
40
+ }
41
+ );
42
+ });
20
43
  export {
21
44
  Kbd
22
45
  };
@@ -1,6 +1,25 @@
1
- import * as React from "react";
2
- import type { BaseProps } from "./~utils.js";
1
+ import { type BaseProps } from "./~utils.js";
3
2
  interface LabelProps extends BaseProps<"label"> {
4
3
  }
5
- export declare const Label: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLLabelElement>>;
4
+ /**
5
+ * A styled wrapper over the HTML `<label>` element, used for labelling form controls.
6
+ *
7
+ * Can be used standalone:
8
+
9
+ * ```tsx
10
+ * <Label htmlFor="my-input">Label</Label>
11
+ * <TextBox.Input id="my-input" />
12
+ * ```
13
+ *
14
+ * Or within a `Field` component to automatically manage ID associations:
15
+ *
16
+ * ```tsx
17
+ * <Field>
18
+ * <Label>Label</Label>
19
+ * <TextBox.Input />
20
+ * </Field>
21
+ * ```
22
+ *
23
+ */
24
+ export declare const Label: import("react").ForwardRefExoticComponent<LabelProps & import("react").RefAttributes<HTMLElement | HTMLLabelElement>>;
6
25
  export {};
@@ -1,9 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
2
  import cx from "classnames";
4
3
  import * as Ariakit from "@ariakit/react";
5
4
  import { useFieldId } from "./Field.js";
6
- const Label = React.forwardRef((props, forwardedRef) => {
5
+ import { forwardRef } from "./~utils.js";
6
+ const Label = forwardRef((props, forwardedRef) => {
7
7
  const fieldId = useFieldId();
8
8
  return /* @__PURE__ */ jsx(
9
9
  Ariakit.Role.label,
@@ -1,11 +1,10 @@
1
- import * as React from "react";
2
1
  import * as Ariakit from "@ariakit/react";
3
2
  interface ListItemProps extends Ariakit.RoleProps<"div"> {
4
3
  }
5
4
  /** @internal */
6
- declare const ListItem: React.ForwardRefExoticComponent<Omit<ListItemProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
+ declare const ListItem: import("react").ForwardRefExoticComponent<Omit<ListItemProps, "ref"> & import("react").RefAttributes<HTMLElement | HTMLDivElement>>;
7
6
  interface ListItemContentProps extends Ariakit.RoleProps<"span"> {
8
7
  }
9
8
  /** @internal */
10
- declare const ListItemContent: React.ForwardRefExoticComponent<Omit<ListItemContentProps, "ref"> & React.RefAttributes<HTMLSpanElement>>;
9
+ declare const ListItemContent: import("react").ForwardRefExoticComponent<Omit<ListItemContentProps, "ref"> & import("react").RefAttributes<HTMLElement | HTMLSpanElement>>;
11
10
  export { ListItem as Root, ListItemContent as Content };