@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
@@ -1,11 +1,24 @@
1
1
  import { 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 * as ListItem from "./ListItem.js";
4
+ import * as ListItem from "./~utils.ListItem.js";
6
5
  import { Button } from "./Button.js";
7
- import { DisclosureArrow } from "./Icon.js";
8
- import { supportsPopover } from "./~utils.js";
6
+ import { Kbd } from "./Kbd.js";
7
+ import { Checkmark, DisclosureArrow, Icon } from "./Icon.js";
8
+ import {
9
+ forwardRef
10
+ } from "./~utils.js";
11
+ import { usePopoverApi } from "./~hooks.js";
12
+ import {
13
+ MenuProvider,
14
+ useMenuContext,
15
+ Menu,
16
+ MenuButton,
17
+ MenuItem,
18
+ MenuItemCheckbox
19
+ } from "@ariakit/react/menu";
20
+ import { useStoreState } from "@ariakit/react/store";
21
+ import { predefinedSymbols } from "./Kbd.internal.js";
9
22
  function DropdownMenu(props) {
10
23
  const {
11
24
  children,
@@ -14,21 +27,9 @@ function DropdownMenu(props) {
14
27
  setOpen: setOpenProp,
15
28
  defaultOpen: defaultOpenProp
16
29
  } = props;
17
- const store = Ariakit.useMenuStore();
18
- const open = Ariakit.useStoreState(store, (store2) => store2.open);
19
- const popover = Ariakit.useStoreState(store, (store2) => store2.popoverElement);
20
- React.useEffect(
21
- function syncPopoverWithOpenState() {
22
- if (popover?.isConnected) {
23
- popover?.togglePopover?.(open);
24
- }
25
- },
26
- [open, popover]
27
- );
28
30
  return /* @__PURE__ */ jsx(
29
- Ariakit.MenuProvider,
31
+ MenuProvider,
30
32
  {
31
- store,
32
33
  placement,
33
34
  defaultOpen: defaultOpenProp,
34
35
  open: openProp,
@@ -37,49 +38,140 @@ 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;
41
+ const DropdownMenuContent = forwardRef(
42
+ (props, forwardedRef) => {
43
+ const popover = usePopoverApi(useMenuContext());
44
+ return /* @__PURE__ */ jsx(
45
+ Menu,
46
+ {
47
+ portal: popover.portal,
48
+ unmountOnHide: true,
49
+ ...props,
50
+ gutter: 4,
51
+ style: { ...popover.style, ...props.style },
52
+ wrapperProps: popover.wrapperProps,
53
+ className: cx("\u{1F95D}-dropdown-menu", props.className),
54
+ ref: forwardedRef
55
+ }
56
+ );
57
+ }
58
+ );
59
+ const DropdownMenuButton = forwardRef(
60
+ (props, forwardedRef) => {
61
+ const { accessibleWhenDisabled = true, children, ...rest } = props;
62
+ const open = useStoreState(useMenuContext(), (state) => state?.open);
63
+ return /* @__PURE__ */ jsx(
64
+ MenuButton,
65
+ {
66
+ accessibleWhenDisabled: true,
67
+ render: /* @__PURE__ */ jsxs(Button, { accessibleWhenDisabled, children: [
68
+ children,
69
+ /* @__PURE__ */ jsx(DisclosureArrow, {})
70
+ ] }),
71
+ ...rest,
72
+ className: cx("\u{1F95D}-dropdown-menu-button", props.className),
73
+ "data-has-popover-open": open || void 0,
74
+ ref: forwardedRef
75
+ }
76
+ );
77
+ }
78
+ );
79
+ const DropdownMenuItem = forwardRef(
80
+ (props, forwardedRef) => {
81
+ const { label, shortcuts, icon, ...rest } = props;
82
+ return /* @__PURE__ */ jsxs(
83
+ MenuItem,
84
+ {
85
+ accessibleWhenDisabled: true,
86
+ ...rest,
87
+ render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
88
+ className: cx("\u{1F95D}-dropdown-menu-item", props.className),
89
+ ref: forwardedRef,
90
+ children: [
91
+ icon ? /* @__PURE__ */ jsx(DropdownMenuIcon, { icon }) : null,
92
+ /* @__PURE__ */ jsx(ListItem.Content, { children: label }),
93
+ shortcuts ? /* @__PURE__ */ jsx(DropdownMenuItemShortcuts, { shortcuts }) : null
94
+ ]
95
+ }
96
+ );
97
+ }
98
+ );
99
+ const DropdownMenuItemShortcuts = forwardRef((props, forwardedRef) => {
100
+ const { shortcuts, ...rest } = props;
101
+ const shortcutKeys = React.useMemo(() => {
102
+ return shortcuts.split("+").map((key) => ({
103
+ key: key.trim(),
104
+ isSymbol: key in predefinedSymbols
105
+ }));
106
+ }, [shortcuts]);
56
107
  return /* @__PURE__ */ jsx(
57
- Ariakit.MenuButton,
108
+ ListItem.Decoration,
58
109
  {
59
- accessibleWhenDisabled: true,
60
- render: /* @__PURE__ */ jsxs(Button, { accessibleWhenDisabled, children: [
61
- children,
62
- /* @__PURE__ */ jsx(DisclosureArrow, {})
63
- ] }),
64
110
  ...rest,
65
- className: cx("\u{1F95D}-dropdown-menu-button", props.className),
66
- ref: forwardedRef
111
+ className: cx("\u{1F95D}-dropdown-menu-item-shortcuts", props.className),
112
+ ref: forwardedRef,
113
+ children: shortcutKeys.map(({ key, isSymbol }, index) => {
114
+ if (isSymbol) {
115
+ return /* @__PURE__ */ jsx(
116
+ Kbd,
117
+ {
118
+ variant: "ghost",
119
+ symbol: key
120
+ },
121
+ `${key + index}`
122
+ );
123
+ }
124
+ return /* @__PURE__ */ jsx(Kbd, { variant: "ghost", children: key }, `${key + index}`);
125
+ })
67
126
  }
68
127
  );
69
128
  });
70
- const DropdownMenuItem = React.forwardRef((props, forwardedRef) => {
71
- return /* @__PURE__ */ jsx(
72
- Ariakit.MenuItem,
129
+ const DropdownMenuIcon = forwardRef(
130
+ (props, forwardedRef) => {
131
+ const { icon, ...rest } = props;
132
+ return /* @__PURE__ */ jsx(
133
+ ListItem.Decoration,
134
+ {
135
+ render: /* @__PURE__ */ jsx(
136
+ Icon,
137
+ {
138
+ href: typeof icon === "string" ? icon : void 0,
139
+ render: React.isValidElement(icon) ? icon : void 0
140
+ }
141
+ ),
142
+ ...rest,
143
+ ref: forwardedRef
144
+ }
145
+ );
146
+ }
147
+ );
148
+ const DropdownMenuCheckboxItem = forwardRef((props, forwardedRef) => {
149
+ const { label, icon, ...rest } = props;
150
+ return /* @__PURE__ */ jsxs(
151
+ MenuItemCheckbox,
73
152
  {
74
153
  accessibleWhenDisabled: true,
75
- ...props,
154
+ value: props.defaultChecked ? "on" : void 0,
155
+ ...rest,
76
156
  render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
77
- ref: forwardedRef
157
+ className: cx("\u{1F95D}-dropdown-menu-item", props.className),
158
+ ref: forwardedRef,
159
+ children: [
160
+ icon ? /* @__PURE__ */ jsx(DropdownMenuIcon, { icon }) : null,
161
+ /* @__PURE__ */ jsx(ListItem.Content, { children: label }),
162
+ /* @__PURE__ */ jsx(
163
+ ListItem.Decoration,
164
+ {
165
+ render: /* @__PURE__ */ jsx(Checkmark, { className: "\u{1F95D}-dropdown-menu-checkmark" })
166
+ }
167
+ )
168
+ ]
78
169
  }
79
170
  );
80
171
  });
81
172
  export {
82
173
  DropdownMenuButton as Button,
174
+ DropdownMenuCheckboxItem as CheckboxItem,
83
175
  DropdownMenuContent as Content,
84
176
  DropdownMenuItem as Item,
85
177
  DropdownMenu as Root
@@ -1,11 +1,53 @@
1
1
  import * as React from "react";
2
- import type { BaseProps } from "./~utils.js";
2
+ import { useCollectionStore, type CollectionItemProps } from "@ariakit/react/collection";
3
+ import { type BaseProps } from "./~utils.js";
3
4
  interface FieldProps extends BaseProps {
4
5
  /**
5
6
  * Allows overriding the default block layout for text controls.
6
7
  */
7
8
  layout?: "inline";
8
9
  }
9
- export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>>;
10
- export declare function useFieldId(): string | undefined;
10
+ /**
11
+ * A container for form controls. It manages ID associations provides a consistent layout and spacing.
12
+ *
13
+ * Example:
14
+ * ```tsx
15
+ * <Field>
16
+ * <Label>Label</Label>
17
+ * <TextBox.Input />
18
+ * </Field>
19
+ * ```
20
+ *
21
+ * Supports a `layout` prop, which can be set to `inline` to align the label and control horizontally.
22
+ *
23
+ * Should contain a `Label` component paired with a form control. Supported form controls include:
24
+ * - `TextBox.Input`
25
+ * - `TextBox.Textarea`
26
+ * - `Checkbox`
27
+ * - `Radio`
28
+ * - `Switch`
29
+ */
30
+ export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
31
+ type CollectionStoreItem = NonNullable<ReturnType<ReturnType<typeof useCollectionStore>["item"]>>;
32
+ interface FieldCollectionStoreItem extends CollectionStoreItem {
33
+ /** The type of field element being tracked */
34
+ elementType: "label" | "control" | "description";
35
+ /** If a control, the type of control. */
36
+ controlType?: "textlike" | "checkable";
37
+ }
38
+ interface FieldCollectionItemControlProps extends Pick<CollectionItemProps, "render" | "id"> {
39
+ type: FieldCollectionStoreItem["controlType"];
40
+ }
41
+ /**
42
+ * An element tracked as a control in the `Field`’s collection.
43
+ */
44
+ export declare function FieldControl(props: FieldCollectionItemControlProps): import("react/jsx-runtime").JSX.Element;
45
+ /**
46
+ * An element tracked as a label in the `Field`’s collection.
47
+ */
48
+ export declare function FieldLabel(props: Pick<CollectionItemProps, "render">): import("react/jsx-runtime").JSX.Element;
49
+ /**
50
+ * An element tracked as a description in the `Field`’s collection.
51
+ */
52
+ export declare function FieldDescription(props: Pick<CollectionItemProps, "render" | "id">): import("react/jsx-runtime").JSX.Element;
11
53
  export {};
@@ -1,27 +1,127 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import * as Ariakit from "@ariakit/react";
4
3
  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
- );
20
- const FieldIdContext = React.createContext(void 0);
21
- function useFieldId() {
22
- return React.useContext(FieldIdContext);
4
+ import { Role } from "@ariakit/react/role";
5
+ import {
6
+ useCollectionStore,
7
+ Collection,
8
+ useCollectionContext,
9
+ CollectionItem
10
+ } from "@ariakit/react/collection";
11
+ import { useStoreState } from "@ariakit/react/store";
12
+ import { forwardRef } from "./~utils.js";
13
+ const Field = forwardRef((props, forwardedRef) => {
14
+ const { layout, ...rest } = props;
15
+ return /* @__PURE__ */ jsx(
16
+ FieldCollection,
17
+ {
18
+ render: /* @__PURE__ */ jsx(
19
+ Role.div,
20
+ {
21
+ ...rest,
22
+ className: cx("\u{1F95D}-field", props.className),
23
+ "data-kiwi-layout": layout,
24
+ ref: forwardedRef
25
+ }
26
+ )
27
+ }
28
+ );
29
+ });
30
+ function FieldCollection(props) {
31
+ const fieldElementCollection = useCollectionStore({
32
+ defaultItems: []
33
+ });
34
+ const renderedItems = useStoreState(fieldElementCollection, "renderedItems");
35
+ const [controlType, controlIndex] = React.useMemo(() => {
36
+ const controlIndex2 = renderedItems.findIndex(
37
+ (item) => item.elementType === "control"
38
+ );
39
+ return [renderedItems[controlIndex2]?.controlType, controlIndex2];
40
+ }, [renderedItems]);
41
+ const labelPlacement = React.useMemo(() => {
42
+ const labelIndex = renderedItems.findIndex(
43
+ (item) => item.elementType === "label"
44
+ );
45
+ if (controlIndex === -1 || labelIndex === -1) return;
46
+ return labelIndex < controlIndex ? "before" : "after";
47
+ }, [renderedItems, controlIndex]);
48
+ return /* @__PURE__ */ jsx(
49
+ Collection,
50
+ {
51
+ ...props,
52
+ store: fieldElementCollection,
53
+ "data-kiwi-label-placement": labelPlacement,
54
+ "data-kiwi-control-type": controlType
55
+ }
56
+ );
57
+ }
58
+ function FieldControl(props) {
59
+ const store = useCollectionContext();
60
+ const generatedId = React.useId();
61
+ const { id = store ? generatedId : void 0, type, ...rest } = props;
62
+ const renderedItems = useStoreState(store, "renderedItems");
63
+ const describedBy = React.useMemo(() => {
64
+ const idRefList = renderedItems?.filter(
65
+ (item) => item.elementType === "description"
66
+ )?.map((item) => item.id).join(" ");
67
+ return idRefList || void 0;
68
+ }, [renderedItems]);
69
+ const getData = React.useCallback(
70
+ (data) => ({
71
+ ...data,
72
+ elementType: "control",
73
+ controlType: type
74
+ }),
75
+ [type]
76
+ );
77
+ return /* @__PURE__ */ jsx(
78
+ CollectionItem,
79
+ {
80
+ id,
81
+ getItem: getData,
82
+ render: /* @__PURE__ */ jsx(Role, { ...rest, "aria-describedby": describedBy })
83
+ }
84
+ );
85
+ }
86
+ function FieldLabel(props) {
87
+ const store = useCollectionContext();
88
+ const renderedItems = useStoreState(store, "renderedItems");
89
+ const fieldId = React.useMemo(
90
+ () => renderedItems?.find(
91
+ (item) => item.elementType === "control"
92
+ )?.id,
93
+ [renderedItems]
94
+ );
95
+ const getData = React.useCallback(
96
+ (data) => ({
97
+ ...data,
98
+ elementType: "label"
99
+ }),
100
+ []
101
+ );
102
+ return /* @__PURE__ */ jsx(
103
+ CollectionItem,
104
+ {
105
+ getItem: getData,
106
+ render: /* @__PURE__ */ jsx(Role.label, { ...props, htmlFor: fieldId })
107
+ }
108
+ );
109
+ }
110
+ function FieldDescription(props) {
111
+ const generatedId = React.useId();
112
+ const { id = generatedId, ...rest } = props;
113
+ const getData = React.useCallback(
114
+ (data) => ({
115
+ ...data,
116
+ elementType: "description"
117
+ }),
118
+ []
119
+ );
120
+ return /* @__PURE__ */ jsx(CollectionItem, { ...rest, id, getItem: getData });
23
121
  }
24
122
  export {
25
123
  Field,
26
- useFieldId
124
+ FieldControl,
125
+ FieldDescription,
126
+ FieldLabel
27
127
  };
@@ -1,17 +1,36 @@
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
- /** URL of the symbol sprite. */
4
+ /**
5
+ * URL of the symbol sprite.
6
+ *
7
+ * Should be a URL to an `.svg` file from `@itwin/itwinui-icons`.
8
+ */
5
9
  href?: string;
6
- /** Size of the icon. Defaults to `regular`. */
10
+ /**
11
+ * Size of the icon. This affects the icon's physical dimensions, as well as the
12
+ * actual SVG contents (different sizes might have different fidelity).
13
+ *
14
+ * Defaults to `"regular"` (16px) and can be optionally set to `"large"` (24px).
15
+ */
7
16
  size?: "regular" | "large";
17
+ /**
18
+ * Alternative text describing the icon.
19
+ *
20
+ * When this prop is passed, the SVG gets rendered as `role="img"` and labelled
21
+ * using the provided text.
22
+ *
23
+ * This prop is not required if the icon is purely decorative. By default, the icon
24
+ * will be hidden from the accessibility tree.
25
+ */
26
+ alt?: string;
8
27
  }
9
28
  /**
10
29
  * Icon component that provides fill and sizing to the SVGs from `@itwin/itwinui-icons`.
11
30
  * It uses an external symbol sprite to render the icon based on the specified `size`.
12
31
  *
13
32
  * ```tsx
14
- * const arrowIcon = new URL("@itwin/itwinui-icons/icons/arrow.svg", import.meta.url).href;
33
+ * const arrowIcon = new URL("@itwin/itwinui-icons/arrow.svg", import.meta.url).href;
15
34
  * <Icon href={arrowIcon} />
16
35
  * ```
17
36
  *
@@ -21,9 +40,15 @@ interface IconProps extends Omit<BaseProps<"svg">, "children"> {
21
40
  * <Icon render={<svg><path d="…" fill="currentColor" /></svg>} />
22
41
  * ```
23
42
  *
24
- * **Note**: This component is meant to be used with decorative icons, so it adds `aria-hidden` by default.
43
+ * By default, this component assumes that the icon is decorative, so it adds `aria-hidden` by default.
44
+ *
45
+ * If the icon is semantically meaningful, the `alt` prop can be used to provide alternative text.
46
+ *
47
+ * ```tsx
48
+ * <Icon href={…} alt="Help" />
49
+ * ```
25
50
  */
26
- export declare const Icon: React.ForwardRefExoticComponent<IconProps & React.RefAttributes<SVGSVGElement>>;
51
+ export declare const Icon: React.ForwardRefExoticComponent<IconProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
27
52
  interface DisclosureArrowProps extends Omit<BaseProps<"svg">, "children"> {
28
53
  /**
29
54
  * Which direction should the arrow point towards?
@@ -31,5 +56,11 @@ interface DisclosureArrowProps extends Omit<BaseProps<"svg">, "children"> {
31
56
  */
32
57
  direction?: "down" | "right";
33
58
  }
34
- export declare const DisclosureArrow: React.ForwardRefExoticComponent<DisclosureArrowProps & React.RefAttributes<SVGSVGElement>>;
59
+ export declare const DisclosureArrow: React.ForwardRefExoticComponent<DisclosureArrowProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
60
+ interface CheckmarkProps extends Omit<BaseProps<"svg">, "children"> {
61
+ }
62
+ export declare const Checkmark: React.ForwardRefExoticComponent<CheckmarkProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
63
+ interface DismissProps extends Omit<BaseProps<"svg">, "children"> {
64
+ }
65
+ export declare const Dismiss: React.ForwardRefExoticComponent<DismissProps & React.RefAttributes<HTMLElement | SVGSVGElement>>;
35
66
  export {};
@@ -1,59 +1,120 @@
1
1
  import { jsx } 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
- const Icon = React.forwardRef(
4
+ import { Role } from "@ariakit/react/role";
5
+ import { forwardRef } from "./~utils.js";
6
+ const Icon = forwardRef((props, forwardedRef) => {
7
+ const { href, size, alt, ...rest } = props;
8
+ const isDecorative = !alt;
9
+ return /* @__PURE__ */ jsx(
10
+ Role.svg,
11
+ {
12
+ "aria-hidden": isDecorative ? "true" : void 0,
13
+ role: isDecorative ? void 0 : "img",
14
+ "aria-label": isDecorative ? void 0 : alt,
15
+ ...rest,
16
+ "data-kiwi-size": size,
17
+ className: cx("\u{1F95D}-icon", props.className),
18
+ ref: forwardedRef,
19
+ children: href ? /* @__PURE__ */ jsx("use", { href: toIconHref(href, size) }) : null
20
+ }
21
+ );
22
+ });
23
+ function toIconHref(href, size) {
24
+ const separator = href.includes("#") ? "--" : "#";
25
+ const suffix = toIconId(size);
26
+ return `${href}${separator}${suffix}`;
27
+ }
28
+ function toIconId(size) {
29
+ if (size === "large") return "icon-large";
30
+ return "icon";
31
+ }
32
+ const DisclosureArrow = forwardRef(
6
33
  (props, forwardedRef) => {
7
- const { href, size = "regular", ...rest } = props;
8
- const iconId = toIconId(size);
34
+ const { direction = "down", ...rest } = props;
35
+ const path = React.useMemo(() => {
36
+ switch (direction) {
37
+ case "down":
38
+ return /* @__PURE__ */ jsx("path", { d: "M8 10 5 7h6l-3 3Z" });
39
+ case "right":
40
+ return /* @__PURE__ */ jsx("path", { d: "M7 11V5l3 3-3 3Z" });
41
+ }
42
+ }, [direction]);
9
43
  return /* @__PURE__ */ jsx(
10
- Ariakit.Role.svg,
44
+ Icon,
11
45
  {
12
- "data-kiwi-size": size,
13
- "aria-hidden": true,
14
46
  ...rest,
15
- className: cx("\u{1F95D}-icon", props.className),
16
- ref: forwardedRef,
17
- children: /* @__PURE__ */ jsx("use", { href: `${props.href}#${iconId}` })
47
+ render: /* @__PURE__ */ jsx(
48
+ Role.svg,
49
+ {
50
+ width: "16",
51
+ height: "16",
52
+ fill: "currentColor",
53
+ viewBox: "0 0 16 16",
54
+ render: props.render,
55
+ children: path
56
+ }
57
+ ),
58
+ className: cx("\u{1F95D}-disclosure-arrow", props.className),
59
+ ref: forwardedRef
60
+ }
61
+ );
62
+ }
63
+ );
64
+ const Checkmark = forwardRef(
65
+ (props, forwardedRef) => {
66
+ return /* @__PURE__ */ jsx(
67
+ Icon,
68
+ {
69
+ ...props,
70
+ render: /* @__PURE__ */ jsx(
71
+ Role.svg,
72
+ {
73
+ width: "16",
74
+ height: "16",
75
+ fill: "currentColor",
76
+ viewBox: "0 0 16 16",
77
+ render: props.render,
78
+ children: /* @__PURE__ */ jsx(
79
+ "path",
80
+ {
81
+ fillRule: "evenodd",
82
+ d: "M13.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3-3a.5.5 0 1 1 .708-.708L6.5 10.793l6.646-6.647a.5.5 0 0 1 .708 0Z",
83
+ clipRule: "evenodd"
84
+ }
85
+ )
86
+ }
87
+ ),
88
+ ref: forwardedRef
89
+ }
90
+ );
91
+ }
92
+ );
93
+ const Dismiss = forwardRef(
94
+ (props, forwardedRef) => {
95
+ return /* @__PURE__ */ jsx(
96
+ Icon,
97
+ {
98
+ ...props,
99
+ render: /* @__PURE__ */ jsx(
100
+ Role.svg,
101
+ {
102
+ width: "16",
103
+ height: "16",
104
+ viewBox: "0 0 16 16",
105
+ fill: "currentColor",
106
+ render: props.render,
107
+ children: /* @__PURE__ */ jsx("path", { d: "M4.853 4.146a.5.5 0 1 0-.707.708L7.293 8l-3.147 3.146a.5.5 0 0 0 .707.708L8 8.707l3.146 3.147a.5.5 0 0 0 .707-.708L8.707 8l3.146-3.146a.5.5 0 1 0-.707-.708L8 7.293 4.853 4.146Z" })
108
+ }
109
+ ),
110
+ ref: forwardedRef
18
111
  }
19
112
  );
20
113
  }
21
114
  );
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
115
  export {
116
+ Checkmark,
57
117
  DisclosureArrow,
118
+ Dismiss,
58
119
  Icon
59
120
  };