@itwin/itwinui-react 5.0.0-alpha.1 → 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.
- package/LICENSE.md +1 -1
- package/README.md +6 -6
- package/dist/DEV/bricks/Anchor.js +5 -10
- package/dist/DEV/bricks/Avatar.js +24 -0
- package/dist/DEV/bricks/Badge.js +22 -0
- package/dist/DEV/bricks/Button.js +11 -4
- package/dist/DEV/bricks/Checkbox.js +17 -9
- package/dist/DEV/bricks/Chip.js +42 -0
- package/dist/DEV/bricks/Description.js +29 -0
- package/dist/DEV/bricks/Divider.js +3 -2
- package/dist/DEV/bricks/DropdownMenu.js +109 -30
- package/dist/DEV/bricks/Field.js +115 -14
- package/dist/DEV/bricks/Icon.js +70 -8
- package/dist/DEV/bricks/IconButton.js +14 -3
- package/dist/DEV/bricks/Kbd.internal.js +19 -0
- package/dist/DEV/bricks/Kbd.js +23 -6
- package/dist/DEV/bricks/Label.js +11 -8
- package/dist/DEV/bricks/ProgressBar.js +25 -0
- package/dist/DEV/bricks/Radio.js +17 -9
- package/dist/DEV/bricks/Root.js +35 -4
- package/dist/DEV/bricks/Select.js +17 -11
- package/dist/DEV/bricks/Skeleton.js +24 -0
- package/dist/DEV/bricks/Spinner.js +40 -0
- package/dist/DEV/bricks/Switch.js +18 -10
- package/dist/DEV/bricks/Table.js +114 -0
- package/dist/DEV/bricks/Tabs.js +6 -6
- package/dist/DEV/bricks/Text.js +2 -2
- package/dist/DEV/bricks/TextBox.js +54 -16
- package/dist/DEV/bricks/Tooltip.js +17 -25
- package/dist/DEV/bricks/Tree.js +15 -107
- package/dist/DEV/bricks/TreeItem.js +224 -0
- package/dist/DEV/bricks/VisuallyHidden.js +2 -2
- package/dist/DEV/bricks/index.js +16 -0
- package/dist/DEV/bricks/styles.css.js +2 -2
- package/dist/DEV/bricks/~hooks.js +55 -3
- package/dist/DEV/bricks/~utils.GhostAligner.js +13 -0
- package/dist/DEV/bricks/{ListItem.js → ~utils.ListItem.js} +19 -3
- package/dist/DEV/foundations/styles.css.js +2 -2
- package/dist/bricks/Anchor.js +5 -10
- package/dist/bricks/Avatar.d.ts +47 -0
- package/dist/bricks/Avatar.js +23 -0
- package/dist/bricks/Badge.d.ts +28 -0
- package/dist/bricks/Badge.js +21 -0
- package/dist/bricks/Button.js +11 -4
- package/dist/bricks/Checkbox.d.ts +2 -2
- package/dist/bricks/Checkbox.js +17 -9
- package/dist/bricks/Chip.d.ts +31 -0
- package/dist/bricks/Chip.js +41 -0
- package/dist/bricks/Description.d.ts +19 -0
- package/dist/bricks/Description.js +29 -0
- package/dist/bricks/Divider.d.ts +2 -2
- package/dist/bricks/Divider.js +3 -2
- package/dist/bricks/DropdownMenu.d.ts +41 -14
- package/dist/bricks/DropdownMenu.js +106 -30
- package/dist/bricks/Field.d.ts +23 -1
- package/dist/bricks/Field.js +115 -14
- package/dist/bricks/Icon.d.ts +34 -3
- package/dist/bricks/Icon.js +68 -8
- package/dist/bricks/IconButton.d.ts +20 -4
- package/dist/bricks/IconButton.js +14 -3
- package/dist/bricks/Kbd.d.ts +15 -0
- package/dist/bricks/Kbd.internal.d.ts +17 -0
- package/dist/bricks/Kbd.internal.js +19 -0
- package/dist/bricks/Kbd.js +16 -6
- package/dist/bricks/Label.js +11 -8
- package/dist/bricks/ProgressBar.d.ts +31 -0
- package/dist/bricks/ProgressBar.js +24 -0
- package/dist/bricks/Radio.d.ts +2 -2
- package/dist/bricks/Radio.js +17 -9
- package/dist/bricks/Root.js +35 -4
- package/dist/bricks/Select.d.ts +9 -3
- package/dist/bricks/Select.js +17 -11
- package/dist/bricks/Skeleton.d.ts +25 -0
- package/dist/bricks/Skeleton.js +23 -0
- package/dist/bricks/Spinner.d.ts +31 -0
- package/dist/bricks/Spinner.js +39 -0
- package/dist/bricks/Switch.d.ts +2 -2
- package/dist/bricks/Switch.js +18 -10
- package/dist/bricks/Table.d.ts +115 -0
- package/dist/bricks/Table.js +108 -0
- package/dist/bricks/Tabs.d.ts +4 -4
- package/dist/bricks/Tabs.js +6 -6
- package/dist/bricks/Text.d.ts +1 -1
- package/dist/bricks/Text.js +2 -2
- package/dist/bricks/TextBox.d.ts +23 -2
- package/dist/bricks/TextBox.js +53 -16
- package/dist/bricks/Tooltip.d.ts +2 -2
- package/dist/bricks/Tooltip.js +17 -25
- package/dist/bricks/Tree.d.ts +19 -20
- package/dist/bricks/Tree.js +14 -102
- package/dist/bricks/TreeItem.d.ts +123 -0
- package/dist/bricks/TreeItem.js +219 -0
- package/dist/bricks/VisuallyHidden.js +2 -2
- package/dist/bricks/index.d.ts +8 -0
- package/dist/bricks/index.js +16 -0
- package/dist/bricks/styles.css.js +2 -2
- package/dist/bricks/~hooks.d.ts +55 -0
- package/dist/bricks/~hooks.js +55 -3
- package/dist/bricks/~utils.GhostAligner.d.ts +22 -0
- package/dist/bricks/~utils.GhostAligner.js +13 -0
- package/dist/bricks/~utils.ListItem.d.ts +14 -0
- package/dist/bricks/{ListItem.js → ~utils.ListItem.js} +18 -3
- package/dist/bricks/~utils.d.ts +6 -3
- package/dist/foundations/styles.css.js +2 -2
- package/package.json +14 -13
- package/CHANGELOG.md +0 -14
- package/dist/DEV/bricks/Textarea.js +0 -30
- package/dist/bricks/ListItem.d.ts +0 -10
- package/dist/bricks/Textarea.d.ts +0 -24
- package/dist/bricks/Textarea.js +0 -29
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright ©
|
|
3
|
+
Copyright © 2025 Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @itwin/itwinui-react
|
|
2
2
|
|
|
3
|
-
A React component library for the
|
|
3
|
+
A React component library for the next evolution of the iTwinUI design system.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
To use components from the
|
|
7
|
+
To use components from the iTwinUI design system in your app, you’ll need to wrap your app’s UI with iTwinUI's `<Root>` component, and specify the required `colorScheme` and `density` props:
|
|
8
8
|
|
|
9
9
|
```jsx
|
|
10
10
|
import { Root } from "@itwin/itwinui-react/bricks";
|
|
@@ -12,18 +12,18 @@ import { Root } from "@itwin/itwinui-react/bricks";
|
|
|
12
12
|
export function App() {
|
|
13
13
|
return (
|
|
14
14
|
<Root colorScheme="dark" density="dense">
|
|
15
|
-
{/* Use
|
|
15
|
+
{/* Use design system components here */}
|
|
16
16
|
</Root>
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
This will ensure
|
|
21
|
+
This will ensure iTwinUI's styles are loaded to either the document or the encompassing shadow root.
|
|
22
22
|
|
|
23
23
|
Once that’s in place you can import and use components from `@itwin/itwinui-react/bricks`.
|
|
24
24
|
|
|
25
25
|
## Contributing
|
|
26
26
|
|
|
27
|
-
Are you interested in helping
|
|
27
|
+
Are you interested in helping iTwinUI grow and expand? You can submit feature requests or bugs by creating [issues](https://github.com/iTwin/design-system/issues).
|
|
28
28
|
|
|
29
|
-
If you're interested in contributing code, please read [`CONTRIBUTING.md`](https://github.com/iTwin/
|
|
29
|
+
If you're interested in contributing code, please read [`CONTRIBUTING.md`](https://github.com/iTwin/design-system/blob/main/CONTRIBUTING.md) for more information.
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
|
-
import
|
|
3
|
+
import { Role } from "@ariakit/react/role";
|
|
4
|
+
import { Focusable } from "@ariakit/react/focusable";
|
|
4
5
|
import { forwardRef } from "./~utils.js";
|
|
5
6
|
const Anchor = forwardRef((props, forwardedRef) => {
|
|
6
7
|
const { tone = "neutral", ...rest } = props;
|
|
7
8
|
return /* @__PURE__ */ jsx(
|
|
8
|
-
|
|
9
|
+
Role.a,
|
|
9
10
|
{
|
|
10
|
-
"data-kiwi-tone": tone,
|
|
11
11
|
...rest,
|
|
12
|
+
"data-kiwi-tone": tone,
|
|
12
13
|
className: cx("\u{1F95D}-anchor", props.className),
|
|
13
|
-
render: /* @__PURE__ */ jsx(
|
|
14
|
-
Ariakit.Focusable,
|
|
15
|
-
{
|
|
16
|
-
accessibleWhenDisabled: true,
|
|
17
|
-
render: props.render || /* @__PURE__ */ jsx("a", {})
|
|
18
|
-
}
|
|
19
|
-
),
|
|
14
|
+
render: /* @__PURE__ */ jsx(Focusable, { accessibleWhenDisabled: true, render: props.render || /* @__PURE__ */ jsx("a", {}) }),
|
|
20
15
|
ref: forwardedRef
|
|
21
16
|
}
|
|
22
17
|
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import { Role } from "@ariakit/react/role";
|
|
4
|
+
import { forwardRef } from "./~utils.js";
|
|
5
|
+
const Avatar = forwardRef((props, forwardedRef) => {
|
|
6
|
+
const { size = "medium", initials, alt, image, children, ...rest } = props;
|
|
7
|
+
const isDecorative = !alt;
|
|
8
|
+
return /* @__PURE__ */ jsx(
|
|
9
|
+
Role.span,
|
|
10
|
+
{
|
|
11
|
+
role: isDecorative ? void 0 : "img",
|
|
12
|
+
"aria-label": isDecorative ? void 0 : alt,
|
|
13
|
+
...rest,
|
|
14
|
+
"data-kiwi-size": size,
|
|
15
|
+
className: cx("\u{1F95D}-avatar", props.className),
|
|
16
|
+
ref: forwardedRef,
|
|
17
|
+
children: image ?? /* @__PURE__ */ jsx("abbr", { className: "\u{1F95D}-avatar-initials", "aria-hidden": "true", children: initials?.substring(0, 1) })
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
DEV: Avatar.displayName = "Avatar";
|
|
22
|
+
export {
|
|
23
|
+
Avatar
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import { Role } from "@ariakit/react/role";
|
|
4
|
+
import { forwardRef } from "./~utils.js";
|
|
5
|
+
const Badge = forwardRef((props, forwardedRef) => {
|
|
6
|
+
const { tone = "neutral", variant = "solid", label, ...rest } = props;
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
|
+
Role.span,
|
|
9
|
+
{
|
|
10
|
+
...rest,
|
|
11
|
+
"data-kiwi-tone": tone,
|
|
12
|
+
"data-kiwi-variant": variant,
|
|
13
|
+
className: cx("\u{1F95D}-badge", props.className),
|
|
14
|
+
ref: forwardedRef,
|
|
15
|
+
children: label
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
DEV: Badge.displayName = "Badge";
|
|
20
|
+
export {
|
|
21
|
+
Badge
|
|
22
|
+
};
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
|
-
import
|
|
3
|
+
import { Button as AkButton } from "@ariakit/react/button";
|
|
4
4
|
import { forwardRef } from "./~utils.js";
|
|
5
|
+
import { useGhostAlignment } from "./~utils.GhostAligner.js";
|
|
5
6
|
const Button = forwardRef(
|
|
6
7
|
(props, forwardedRef) => {
|
|
7
8
|
const { variant = "solid", tone = "neutral", ...rest } = props;
|
|
9
|
+
const ghostAlignment = useGhostAlignment();
|
|
8
10
|
return /* @__PURE__ */ jsx(
|
|
9
|
-
|
|
11
|
+
AkButton,
|
|
10
12
|
{
|
|
11
13
|
accessibleWhenDisabled: true,
|
|
14
|
+
...rest,
|
|
12
15
|
"data-kiwi-variant": variant,
|
|
13
16
|
"data-kiwi-tone": tone,
|
|
14
|
-
|
|
15
|
-
className: cx(
|
|
17
|
+
"data-kiwi-ghost-align": variant === "ghost" ? ghostAlignment : void 0,
|
|
18
|
+
className: cx(
|
|
19
|
+
"\u{1F95D}-button",
|
|
20
|
+
{ "\u{1F95D}-ghost-aligner": variant === "ghost" },
|
|
21
|
+
props.className
|
|
22
|
+
),
|
|
16
23
|
ref: forwardedRef
|
|
17
24
|
}
|
|
18
25
|
);
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
Checkbox as AkCheckbox
|
|
5
|
+
} from "@ariakit/react/checkbox";
|
|
6
|
+
import { FieldControl } from "./Field.js";
|
|
5
7
|
import { forwardRef } from "./~utils.js";
|
|
6
8
|
const Checkbox = forwardRef(
|
|
7
9
|
(props, forwardedRef) => {
|
|
8
|
-
const
|
|
10
|
+
const { id, ...rest } = props;
|
|
9
11
|
return /* @__PURE__ */ jsx(
|
|
10
|
-
|
|
12
|
+
FieldControl,
|
|
11
13
|
{
|
|
12
|
-
|
|
13
|
-
id
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
type: "checkable",
|
|
15
|
+
id,
|
|
16
|
+
render: /* @__PURE__ */ jsx(
|
|
17
|
+
AkCheckbox,
|
|
18
|
+
{
|
|
19
|
+
accessibleWhenDisabled: true,
|
|
20
|
+
...rest,
|
|
21
|
+
className: cx("\u{1F95D}-checkbox", props.className),
|
|
22
|
+
ref: forwardedRef
|
|
23
|
+
}
|
|
24
|
+
)
|
|
17
25
|
}
|
|
18
26
|
);
|
|
19
27
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Role } from "@ariakit/react/role";
|
|
5
|
+
import { forwardRef } from "./~utils.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { Dismiss } from "./Icon.js";
|
|
8
|
+
const Chip = forwardRef((props, forwardedRef) => {
|
|
9
|
+
const { variant = "solid", onDismiss, label, ...rest } = props;
|
|
10
|
+
const baseId = React.useId();
|
|
11
|
+
const labelId = `${baseId}-label`;
|
|
12
|
+
const dismissIconId = `${baseId}-dismiss`;
|
|
13
|
+
return /* @__PURE__ */ jsxs(
|
|
14
|
+
Role.div,
|
|
15
|
+
{
|
|
16
|
+
"data-kiwi-variant": variant,
|
|
17
|
+
...rest,
|
|
18
|
+
className: cx("\u{1F95D}-chip", props.className),
|
|
19
|
+
ref: forwardedRef,
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx("span", { id: labelId, children: label }),
|
|
22
|
+
onDismiss && /* @__PURE__ */ jsx(
|
|
23
|
+
IconButton,
|
|
24
|
+
{
|
|
25
|
+
id: dismissIconId,
|
|
26
|
+
className: "\u{1F95D}-chip-dismiss-button",
|
|
27
|
+
variant: "ghost",
|
|
28
|
+
"aria-labelledby": `${dismissIconId} ${labelId}`,
|
|
29
|
+
label: "Dismiss",
|
|
30
|
+
labelVariant: "visually-hidden",
|
|
31
|
+
icon: /* @__PURE__ */ jsx(Dismiss, {}),
|
|
32
|
+
onClick: onDismiss
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
DEV: Chip.displayName = "Chip";
|
|
40
|
+
export {
|
|
41
|
+
Chip
|
|
42
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "./~utils.js";
|
|
3
|
+
import cx from "classnames";
|
|
4
|
+
import { Text } from "./Text.js";
|
|
5
|
+
import { FieldDescription } from "./Field.js";
|
|
6
|
+
const Description = forwardRef(
|
|
7
|
+
(props, forwardedRef) => {
|
|
8
|
+
const { id, tone, ...rest } = props;
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
FieldDescription,
|
|
11
|
+
{
|
|
12
|
+
id,
|
|
13
|
+
render: /* @__PURE__ */ jsx(
|
|
14
|
+
Text,
|
|
15
|
+
{
|
|
16
|
+
...rest,
|
|
17
|
+
variant: "caption-md",
|
|
18
|
+
"data-kiwi-tone": tone ?? "neutral",
|
|
19
|
+
className: cx("\u{1F95D}-description", props.className),
|
|
20
|
+
ref: forwardedRef
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
export {
|
|
28
|
+
Description
|
|
29
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
|
-
import
|
|
3
|
+
import { Role } from "@ariakit/react/role";
|
|
4
|
+
import { Separator } from "@ariakit/react/separator";
|
|
4
5
|
import { forwardRef } from "./~utils.js";
|
|
5
6
|
const Divider = forwardRef((props, forwardedRef) => {
|
|
6
7
|
const { presentational, ...rest } = props;
|
|
7
|
-
const Comp = presentational ?
|
|
8
|
+
const Comp = presentational ? Role : Separator;
|
|
8
9
|
return /* @__PURE__ */ jsx(
|
|
9
10
|
Comp,
|
|
10
11
|
{
|
|
@@ -1,12 +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
|
|
5
|
-
import * as ListItem from "./ListItem.js";
|
|
4
|
+
import * as ListItem from "./~utils.ListItem.js";
|
|
6
5
|
import { Button } from "./Button.js";
|
|
7
6
|
import { Kbd } from "./Kbd.js";
|
|
8
|
-
import { DisclosureArrow } from "./Icon.js";
|
|
9
|
-
import {
|
|
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";
|
|
10
22
|
function DropdownMenu(props) {
|
|
11
23
|
const {
|
|
12
24
|
children,
|
|
@@ -15,21 +27,9 @@ function DropdownMenu(props) {
|
|
|
15
27
|
setOpen: setOpenProp,
|
|
16
28
|
defaultOpen: defaultOpenProp
|
|
17
29
|
} = props;
|
|
18
|
-
const store = Ariakit.useMenuStore();
|
|
19
|
-
const open = Ariakit.useStoreState(store, (state) => state.open);
|
|
20
|
-
const popover = Ariakit.useStoreState(store, (state) => state.popoverElement);
|
|
21
|
-
React.useEffect(
|
|
22
|
-
function syncPopoverWithOpenState() {
|
|
23
|
-
if (popover?.isConnected) {
|
|
24
|
-
popover?.togglePopover?.(open);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
[open, popover]
|
|
28
|
-
);
|
|
29
30
|
return /* @__PURE__ */ jsx(
|
|
30
|
-
|
|
31
|
+
MenuProvider,
|
|
31
32
|
{
|
|
32
|
-
store,
|
|
33
33
|
placement,
|
|
34
34
|
defaultOpen: defaultOpenProp,
|
|
35
35
|
open: openProp,
|
|
@@ -41,14 +41,16 @@ function DropdownMenu(props) {
|
|
|
41
41
|
DEV: DropdownMenu.displayName = "DropdownMenu.Root";
|
|
42
42
|
const DropdownMenuContent = forwardRef(
|
|
43
43
|
(props, forwardedRef) => {
|
|
44
|
+
const popover = usePopoverApi(useMenuContext());
|
|
44
45
|
return /* @__PURE__ */ jsx(
|
|
45
|
-
|
|
46
|
+
Menu,
|
|
46
47
|
{
|
|
47
|
-
portal:
|
|
48
|
+
portal: popover.portal,
|
|
48
49
|
unmountOnHide: true,
|
|
49
50
|
...props,
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
gutter: 4,
|
|
52
|
+
style: { ...popover.style, ...props.style },
|
|
53
|
+
wrapperProps: popover.wrapperProps,
|
|
52
54
|
className: cx("\u{1F95D}-dropdown-menu", props.className),
|
|
53
55
|
ref: forwardedRef
|
|
54
56
|
}
|
|
@@ -59,8 +61,9 @@ DEV: DropdownMenuContent.displayName = "DropdownMenu.Content";
|
|
|
59
61
|
const DropdownMenuButton = forwardRef(
|
|
60
62
|
(props, forwardedRef) => {
|
|
61
63
|
const { accessibleWhenDisabled = true, children, ...rest } = props;
|
|
64
|
+
const open = useStoreState(useMenuContext(), (state) => state?.open);
|
|
62
65
|
return /* @__PURE__ */ jsx(
|
|
63
|
-
|
|
66
|
+
MenuButton,
|
|
64
67
|
{
|
|
65
68
|
accessibleWhenDisabled: true,
|
|
66
69
|
render: /* @__PURE__ */ jsxs(Button, { accessibleWhenDisabled, children: [
|
|
@@ -69,6 +72,7 @@ const DropdownMenuButton = forwardRef(
|
|
|
69
72
|
] }),
|
|
70
73
|
...rest,
|
|
71
74
|
className: cx("\u{1F95D}-dropdown-menu-button", props.className),
|
|
75
|
+
"data-has-popover-open": open || void 0,
|
|
72
76
|
ref: forwardedRef
|
|
73
77
|
}
|
|
74
78
|
);
|
|
@@ -77,29 +81,104 @@ const DropdownMenuButton = forwardRef(
|
|
|
77
81
|
DEV: DropdownMenuButton.displayName = "DropdownMenu.Button";
|
|
78
82
|
const DropdownMenuItem = forwardRef(
|
|
79
83
|
(props, forwardedRef) => {
|
|
80
|
-
const { shortcuts, ...rest } = props;
|
|
81
|
-
const shortcutKeys = React.useMemo(() => {
|
|
82
|
-
return typeof shortcuts === "string" ? shortcuts.split("+").map((key) => key.trim()) : [];
|
|
83
|
-
}, [shortcuts]);
|
|
84
|
-
const hasShortcuts = shortcutKeys.length > 0;
|
|
84
|
+
const { label, shortcuts, icon, ...rest } = props;
|
|
85
85
|
return /* @__PURE__ */ jsxs(
|
|
86
|
-
|
|
86
|
+
MenuItem,
|
|
87
87
|
{
|
|
88
88
|
accessibleWhenDisabled: true,
|
|
89
89
|
...rest,
|
|
90
90
|
render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
|
|
91
|
+
className: cx("\u{1F95D}-dropdown-menu-item", props.className),
|
|
91
92
|
ref: forwardedRef,
|
|
92
93
|
children: [
|
|
93
|
-
/* @__PURE__ */ jsx(
|
|
94
|
-
|
|
94
|
+
icon ? /* @__PURE__ */ jsx(DropdownMenuIcon, { icon }) : null,
|
|
95
|
+
/* @__PURE__ */ jsx(ListItem.Content, { children: label }),
|
|
96
|
+
shortcuts ? /* @__PURE__ */ jsx(DropdownMenuItemShortcuts, { shortcuts }) : null
|
|
95
97
|
]
|
|
96
98
|
}
|
|
97
99
|
);
|
|
98
100
|
}
|
|
99
101
|
);
|
|
100
102
|
DEV: DropdownMenuItem.displayName = "DropdownMenu.Item";
|
|
103
|
+
const DropdownMenuItemShortcuts = forwardRef((props, forwardedRef) => {
|
|
104
|
+
const { shortcuts, ...rest } = props;
|
|
105
|
+
const shortcutKeys = React.useMemo(() => {
|
|
106
|
+
return shortcuts.split("+").map((key) => ({
|
|
107
|
+
key: key.trim(),
|
|
108
|
+
isSymbol: key in predefinedSymbols
|
|
109
|
+
}));
|
|
110
|
+
}, [shortcuts]);
|
|
111
|
+
return /* @__PURE__ */ jsx(
|
|
112
|
+
ListItem.Decoration,
|
|
113
|
+
{
|
|
114
|
+
...rest,
|
|
115
|
+
className: cx("\u{1F95D}-dropdown-menu-item-shortcuts", props.className),
|
|
116
|
+
ref: forwardedRef,
|
|
117
|
+
children: shortcutKeys.map(({ key, isSymbol }, index) => {
|
|
118
|
+
if (isSymbol) {
|
|
119
|
+
return /* @__PURE__ */ jsx(
|
|
120
|
+
Kbd,
|
|
121
|
+
{
|
|
122
|
+
variant: "ghost",
|
|
123
|
+
symbol: key
|
|
124
|
+
},
|
|
125
|
+
`${key + index}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return /* @__PURE__ */ jsx(Kbd, { variant: "ghost", children: key }, `${key + index}`);
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
DEV: DropdownMenuItemShortcuts.displayName = "DropdownMenuItemShortcuts";
|
|
134
|
+
const DropdownMenuIcon = forwardRef(
|
|
135
|
+
(props, forwardedRef) => {
|
|
136
|
+
const { icon, ...rest } = props;
|
|
137
|
+
return /* @__PURE__ */ jsx(
|
|
138
|
+
ListItem.Decoration,
|
|
139
|
+
{
|
|
140
|
+
render: /* @__PURE__ */ jsx(
|
|
141
|
+
Icon,
|
|
142
|
+
{
|
|
143
|
+
href: typeof icon === "string" ? icon : void 0,
|
|
144
|
+
render: React.isValidElement(icon) ? icon : void 0
|
|
145
|
+
}
|
|
146
|
+
),
|
|
147
|
+
...rest,
|
|
148
|
+
ref: forwardedRef
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
DEV: DropdownMenuIcon.displayName = "DropdownMenuIcon";
|
|
154
|
+
const DropdownMenuCheckboxItem = forwardRef((props, forwardedRef) => {
|
|
155
|
+
const { label, icon, ...rest } = props;
|
|
156
|
+
return /* @__PURE__ */ jsxs(
|
|
157
|
+
MenuItemCheckbox,
|
|
158
|
+
{
|
|
159
|
+
accessibleWhenDisabled: true,
|
|
160
|
+
value: props.defaultChecked ? "on" : void 0,
|
|
161
|
+
...rest,
|
|
162
|
+
render: /* @__PURE__ */ jsx(ListItem.Root, { render: props.render }),
|
|
163
|
+
className: cx("\u{1F95D}-dropdown-menu-item", props.className),
|
|
164
|
+
ref: forwardedRef,
|
|
165
|
+
children: [
|
|
166
|
+
icon ? /* @__PURE__ */ jsx(DropdownMenuIcon, { icon }) : null,
|
|
167
|
+
/* @__PURE__ */ jsx(ListItem.Content, { children: label }),
|
|
168
|
+
/* @__PURE__ */ jsx(
|
|
169
|
+
ListItem.Decoration,
|
|
170
|
+
{
|
|
171
|
+
render: /* @__PURE__ */ jsx(Checkmark, { className: "\u{1F95D}-dropdown-menu-checkmark" })
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
DEV: DropdownMenuCheckboxItem.displayName = "DropdownMenu.CheckboxItem";
|
|
101
179
|
export {
|
|
102
180
|
DropdownMenuButton as Button,
|
|
181
|
+
DropdownMenuCheckboxItem as CheckboxItem,
|
|
103
182
|
DropdownMenuContent as Content,
|
|
104
183
|
DropdownMenuItem as Item,
|
|
105
184
|
DropdownMenu as Root
|
package/dist/DEV/bricks/Field.js
CHANGED
|
@@ -1,27 +1,128 @@
|
|
|
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";
|
|
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";
|
|
5
12
|
import { forwardRef } from "./~utils.js";
|
|
6
13
|
const Field = forwardRef((props, forwardedRef) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Ariakit.Role,
|
|
14
|
+
const { layout, ...rest } = props;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
FieldCollection,
|
|
11
17
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
)
|
|
16
27
|
}
|
|
17
|
-
)
|
|
28
|
+
);
|
|
18
29
|
});
|
|
19
30
|
DEV: Field.displayName = "Field";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
function FieldCollection(props) {
|
|
32
|
+
const fieldElementCollection = useCollectionStore({
|
|
33
|
+
defaultItems: []
|
|
34
|
+
});
|
|
35
|
+
const renderedItems = useStoreState(fieldElementCollection, "renderedItems");
|
|
36
|
+
const [controlType, controlIndex] = React.useMemo(() => {
|
|
37
|
+
const controlIndex2 = renderedItems.findIndex(
|
|
38
|
+
(item) => item.elementType === "control"
|
|
39
|
+
);
|
|
40
|
+
return [renderedItems[controlIndex2]?.controlType, controlIndex2];
|
|
41
|
+
}, [renderedItems]);
|
|
42
|
+
const labelPlacement = React.useMemo(() => {
|
|
43
|
+
const labelIndex = renderedItems.findIndex(
|
|
44
|
+
(item) => item.elementType === "label"
|
|
45
|
+
);
|
|
46
|
+
if (controlIndex === -1 || labelIndex === -1) return;
|
|
47
|
+
return labelIndex < controlIndex ? "before" : "after";
|
|
48
|
+
}, [renderedItems, controlIndex]);
|
|
49
|
+
return /* @__PURE__ */ jsx(
|
|
50
|
+
Collection,
|
|
51
|
+
{
|
|
52
|
+
...props,
|
|
53
|
+
store: fieldElementCollection,
|
|
54
|
+
"data-kiwi-label-placement": labelPlacement,
|
|
55
|
+
"data-kiwi-control-type": controlType
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function FieldControl(props) {
|
|
60
|
+
const store = useCollectionContext();
|
|
61
|
+
const generatedId = React.useId();
|
|
62
|
+
const { id = store ? generatedId : void 0, type, ...rest } = props;
|
|
63
|
+
const renderedItems = useStoreState(store, "renderedItems");
|
|
64
|
+
const describedBy = React.useMemo(() => {
|
|
65
|
+
const idRefList = renderedItems?.filter(
|
|
66
|
+
(item) => item.elementType === "description"
|
|
67
|
+
)?.map((item) => item.id).join(" ");
|
|
68
|
+
return idRefList || void 0;
|
|
69
|
+
}, [renderedItems]);
|
|
70
|
+
const getData = React.useCallback(
|
|
71
|
+
(data) => ({
|
|
72
|
+
...data,
|
|
73
|
+
elementType: "control",
|
|
74
|
+
controlType: type
|
|
75
|
+
}),
|
|
76
|
+
[type]
|
|
77
|
+
);
|
|
78
|
+
return /* @__PURE__ */ jsx(
|
|
79
|
+
CollectionItem,
|
|
80
|
+
{
|
|
81
|
+
id,
|
|
82
|
+
getItem: getData,
|
|
83
|
+
render: /* @__PURE__ */ jsx(Role, { ...rest, "aria-describedby": describedBy })
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function FieldLabel(props) {
|
|
88
|
+
const store = useCollectionContext();
|
|
89
|
+
const renderedItems = useStoreState(store, "renderedItems");
|
|
90
|
+
const fieldId = React.useMemo(
|
|
91
|
+
() => renderedItems?.find(
|
|
92
|
+
(item) => item.elementType === "control"
|
|
93
|
+
)?.id,
|
|
94
|
+
[renderedItems]
|
|
95
|
+
);
|
|
96
|
+
const getData = React.useCallback(
|
|
97
|
+
(data) => ({
|
|
98
|
+
...data,
|
|
99
|
+
elementType: "label"
|
|
100
|
+
}),
|
|
101
|
+
[]
|
|
102
|
+
);
|
|
103
|
+
return /* @__PURE__ */ jsx(
|
|
104
|
+
CollectionItem,
|
|
105
|
+
{
|
|
106
|
+
getItem: getData,
|
|
107
|
+
render: /* @__PURE__ */ jsx(Role.label, { ...props, htmlFor: fieldId })
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
function FieldDescription(props) {
|
|
112
|
+
const generatedId = React.useId();
|
|
113
|
+
const { id = generatedId, ...rest } = props;
|
|
114
|
+
const getData = React.useCallback(
|
|
115
|
+
(data) => ({
|
|
116
|
+
...data,
|
|
117
|
+
elementType: "description"
|
|
118
|
+
}),
|
|
119
|
+
[]
|
|
120
|
+
);
|
|
121
|
+
return /* @__PURE__ */ jsx(CollectionItem, { ...rest, id, getItem: getData });
|
|
23
122
|
}
|
|
24
123
|
export {
|
|
25
124
|
Field,
|
|
26
|
-
|
|
125
|
+
FieldControl,
|
|
126
|
+
FieldDescription,
|
|
127
|
+
FieldLabel
|
|
27
128
|
};
|