@itwin/itwinui-react 5.0.0-alpha.4 → 5.0.0-alpha.6
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/CHANGELOG.md +18 -0
- package/dist/DEV/bricks/Checkbox.js +14 -10
- package/dist/DEV/bricks/Chip.js +2 -2
- package/dist/DEV/bricks/Description.js +13 -11
- package/dist/DEV/bricks/Field.js +101 -55
- package/dist/DEV/bricks/Label.js +10 -7
- package/dist/DEV/bricks/Radio.js +14 -10
- package/dist/DEV/bricks/Select.js +15 -12
- package/dist/DEV/bricks/Switch.js +15 -11
- package/dist/DEV/bricks/Table.js +114 -0
- package/dist/DEV/bricks/TextBox.js +37 -29
- package/dist/DEV/bricks/Tree.js +47 -36
- package/dist/DEV/bricks/styles.css.js +1 -1
- package/dist/DEV/foundations/styles.css.js +1 -1
- package/dist/bricks/Checkbox.js +14 -10
- package/dist/bricks/Chip.d.ts +8 -4
- package/dist/bricks/Chip.js +2 -2
- package/dist/bricks/Description.d.ts +2 -3
- package/dist/bricks/Description.js +13 -11
- package/dist/bricks/Field.d.ts +19 -5
- package/dist/bricks/Field.js +101 -55
- package/dist/bricks/Label.js +10 -7
- package/dist/bricks/Radio.js +14 -10
- package/dist/bricks/Select.js +15 -12
- package/dist/bricks/Switch.js +15 -11
- package/dist/bricks/Table.d.ts +115 -0
- package/dist/bricks/Table.js +108 -0
- package/dist/bricks/TextBox.js +37 -29
- package/dist/bricks/Tree.d.ts +59 -18
- package/dist/bricks/Tree.js +45 -35
- package/dist/bricks/styles.css.js +1 -1
- package/dist/foundations/styles.css.js +1 -1
- package/package.json +2 -2
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
2
|
import { forwardRef } from "./~utils.js";
|
|
4
3
|
import cx from "classnames";
|
|
5
4
|
import { Text } from "./Text.js";
|
|
6
|
-
import {
|
|
5
|
+
import { FieldDescription } from "./Field.js";
|
|
7
6
|
const Description = forwardRef(
|
|
8
7
|
(props, forwardedRef) => {
|
|
9
|
-
const
|
|
10
|
-
const { id = generatedId, tone, ...rest } = props;
|
|
11
|
-
useFieldRegisterDescribedBy(id);
|
|
8
|
+
const { id, tone, ...rest } = props;
|
|
12
9
|
return /* @__PURE__ */ jsx(
|
|
13
|
-
|
|
10
|
+
FieldDescription,
|
|
14
11
|
{
|
|
15
|
-
...rest,
|
|
16
12
|
id,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
)
|
|
21
23
|
}
|
|
22
24
|
);
|
|
23
25
|
}
|
package/dist/bricks/Field.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import * as Ariakit from "@ariakit/react";
|
|
2
3
|
import { type BaseProps } from "./~utils.js";
|
|
3
4
|
interface FieldProps extends BaseProps {
|
|
4
5
|
/**
|
|
@@ -27,13 +28,26 @@ interface FieldProps extends BaseProps {
|
|
|
27
28
|
* - `Switch`
|
|
28
29
|
*/
|
|
29
30
|
export declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
31
|
+
type CollectionStoreItem = NonNullable<ReturnType<ReturnType<typeof Ariakit.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<Ariakit.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;
|
|
30
45
|
/**
|
|
31
|
-
*
|
|
46
|
+
* An element tracked as a label in the `Field`’s collection.
|
|
32
47
|
*/
|
|
33
|
-
export declare function
|
|
48
|
+
export declare function FieldLabel(props: Pick<Ariakit.CollectionItemProps, "render">): import("react/jsx-runtime").JSX.Element;
|
|
34
49
|
/**
|
|
35
|
-
*
|
|
50
|
+
* An element tracked as a description in the `Field`’s collection.
|
|
36
51
|
*/
|
|
37
|
-
export declare function
|
|
38
|
-
export declare function useFieldId(): string | undefined;
|
|
52
|
+
export declare function FieldDescription(props: Pick<Ariakit.CollectionItemProps, "render" | "id">): import("react/jsx-runtime").JSX.Element;
|
|
39
53
|
export {};
|
package/dist/bricks/Field.js
CHANGED
|
@@ -4,74 +4,120 @@ import * as Ariakit from "@ariakit/react";
|
|
|
4
4
|
import cx from "classnames";
|
|
5
5
|
import { forwardRef } from "./~utils.js";
|
|
6
6
|
const Field = forwardRef((props, forwardedRef) => {
|
|
7
|
-
const fieldId = React.useId();
|
|
8
7
|
const { layout, ...rest } = props;
|
|
9
|
-
return /* @__PURE__ */ jsx(
|
|
10
|
-
|
|
8
|
+
return /* @__PURE__ */ jsx(
|
|
9
|
+
FieldCollection,
|
|
11
10
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
render: /* @__PURE__ */ jsx(
|
|
12
|
+
Ariakit.Role.div,
|
|
13
|
+
{
|
|
14
|
+
...rest,
|
|
15
|
+
className: cx("\u{1F95D}-field", props.className),
|
|
16
|
+
"data-kiwi-layout": layout,
|
|
17
|
+
ref: forwardedRef
|
|
18
|
+
}
|
|
19
|
+
)
|
|
16
20
|
}
|
|
17
|
-
)
|
|
21
|
+
);
|
|
18
22
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
function FieldCollection(props) {
|
|
24
|
+
const fieldElementCollection = Ariakit.useCollectionStore({
|
|
25
|
+
defaultItems: []
|
|
26
|
+
});
|
|
27
|
+
const renderedItems = Ariakit.useStoreState(
|
|
28
|
+
fieldElementCollection,
|
|
29
|
+
"renderedItems"
|
|
30
|
+
);
|
|
31
|
+
const [controlType, controlIndex] = React.useMemo(() => {
|
|
32
|
+
const controlIndex2 = renderedItems.findIndex(
|
|
33
|
+
(item) => item.elementType === "control"
|
|
34
|
+
);
|
|
35
|
+
return [renderedItems[controlIndex2]?.controlType, controlIndex2];
|
|
36
|
+
}, [renderedItems]);
|
|
37
|
+
const labelPlacement = React.useMemo(() => {
|
|
38
|
+
const labelIndex = renderedItems.findIndex(
|
|
39
|
+
(item) => item.elementType === "label"
|
|
40
|
+
);
|
|
41
|
+
if (controlIndex === -1 || labelIndex === -1) return;
|
|
42
|
+
return labelIndex < controlIndex ? "before" : "after";
|
|
43
|
+
}, [renderedItems, controlIndex]);
|
|
36
44
|
return /* @__PURE__ */ jsx(
|
|
37
|
-
|
|
45
|
+
Ariakit.Collection,
|
|
38
46
|
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
unregister
|
|
44
|
-
}),
|
|
45
|
-
[describedBy, register, unregister]
|
|
46
|
-
),
|
|
47
|
-
children: props.children
|
|
47
|
+
...props,
|
|
48
|
+
store: fieldElementCollection,
|
|
49
|
+
"data-kiwi-label-placement": labelPlacement,
|
|
50
|
+
"data-kiwi-control-type": controlType
|
|
48
51
|
}
|
|
49
52
|
);
|
|
50
53
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
function FieldControl(props) {
|
|
55
|
+
const store = Ariakit.useCollectionContext();
|
|
56
|
+
const generatedId = React.useId();
|
|
57
|
+
const { id = store ? generatedId : void 0, type, ...rest } = props;
|
|
58
|
+
const renderedItems = Ariakit.useStoreState(store, "renderedItems");
|
|
59
|
+
const describedBy = React.useMemo(() => {
|
|
60
|
+
const idRefList = renderedItems?.filter(
|
|
61
|
+
(item) => item.elementType === "description"
|
|
62
|
+
)?.map((item) => item.id).join(" ");
|
|
63
|
+
return idRefList || void 0;
|
|
64
|
+
}, [renderedItems]);
|
|
65
|
+
const getData = React.useCallback(
|
|
66
|
+
(data) => ({
|
|
67
|
+
...data,
|
|
68
|
+
elementType: "control",
|
|
69
|
+
controlType: type
|
|
70
|
+
}),
|
|
71
|
+
[type]
|
|
72
|
+
);
|
|
73
|
+
return /* @__PURE__ */ jsx(
|
|
74
|
+
Ariakit.CollectionItem,
|
|
75
|
+
{
|
|
76
|
+
id,
|
|
77
|
+
getItem: getData,
|
|
78
|
+
render: /* @__PURE__ */ jsx(Ariakit.Role, { ...rest, "aria-describedby": describedBy })
|
|
79
|
+
}
|
|
56
80
|
);
|
|
57
81
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
function FieldLabel(props) {
|
|
83
|
+
const store = Ariakit.useCollectionContext();
|
|
84
|
+
const renderedItems = Ariakit.useStoreState(store, "renderedItems");
|
|
85
|
+
const fieldId = React.useMemo(
|
|
86
|
+
() => renderedItems?.find(
|
|
87
|
+
(item) => item.elementType === "control"
|
|
88
|
+
)?.id,
|
|
89
|
+
[renderedItems]
|
|
90
|
+
);
|
|
91
|
+
const getData = React.useCallback(
|
|
92
|
+
(data) => ({
|
|
93
|
+
...data,
|
|
94
|
+
elementType: "label"
|
|
95
|
+
}),
|
|
96
|
+
[]
|
|
97
|
+
);
|
|
98
|
+
return /* @__PURE__ */ jsx(
|
|
99
|
+
Ariakit.CollectionItem,
|
|
100
|
+
{
|
|
101
|
+
getItem: getData,
|
|
102
|
+
render: /* @__PURE__ */ jsx(Ariakit.Role.label, { ...props, htmlFor: fieldId })
|
|
103
|
+
}
|
|
104
|
+
);
|
|
67
105
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
function FieldDescription(props) {
|
|
107
|
+
const generatedId = React.useId();
|
|
108
|
+
const { id = generatedId, ...rest } = props;
|
|
109
|
+
const getData = React.useCallback(
|
|
110
|
+
(data) => ({
|
|
111
|
+
...data,
|
|
112
|
+
elementType: "description"
|
|
113
|
+
}),
|
|
114
|
+
[]
|
|
115
|
+
);
|
|
116
|
+
return /* @__PURE__ */ jsx(Ariakit.CollectionItem, { ...rest, id, getItem: getData });
|
|
71
117
|
}
|
|
72
118
|
export {
|
|
73
119
|
Field,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
120
|
+
FieldControl,
|
|
121
|
+
FieldDescription,
|
|
122
|
+
FieldLabel
|
|
77
123
|
};
|
package/dist/bricks/Label.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
3
|
import * as Ariakit from "@ariakit/react";
|
|
4
|
-
import { useFieldId } from "./Field.js";
|
|
5
4
|
import { forwardRef } from "./~utils.js";
|
|
5
|
+
import { FieldLabel } from "./Field.js";
|
|
6
6
|
const Label = forwardRef((props, forwardedRef) => {
|
|
7
|
-
const fieldId = useFieldId();
|
|
8
7
|
return /* @__PURE__ */ jsx(
|
|
9
|
-
|
|
8
|
+
FieldLabel,
|
|
10
9
|
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
render: /* @__PURE__ */ jsx(
|
|
11
|
+
Ariakit.Role.label,
|
|
12
|
+
{
|
|
13
|
+
...props,
|
|
14
|
+
className: cx("\u{1F95D}-label", props.className),
|
|
15
|
+
ref: forwardedRef
|
|
16
|
+
}
|
|
17
|
+
)
|
|
15
18
|
}
|
|
16
19
|
);
|
|
17
20
|
});
|
package/dist/bricks/Radio.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
3
|
import * as Ariakit from "@ariakit/react";
|
|
4
|
-
import {
|
|
4
|
+
import { FieldControl } from "./Field.js";
|
|
5
5
|
import { forwardRef } from "./~utils.js";
|
|
6
6
|
const Radio = forwardRef((props, forwardedRef) => {
|
|
7
|
-
const
|
|
8
|
-
const describedBy = useFieldDescribedBy(props["aria-describedby"]);
|
|
7
|
+
const { id, ...rest } = props;
|
|
9
8
|
return /* @__PURE__ */ jsx(
|
|
10
|
-
|
|
9
|
+
FieldControl,
|
|
11
10
|
{
|
|
12
|
-
|
|
13
|
-
id
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
type: "checkable",
|
|
12
|
+
id,
|
|
13
|
+
render: /* @__PURE__ */ jsx(
|
|
14
|
+
Ariakit.Radio,
|
|
15
|
+
{
|
|
16
|
+
accessibleWhenDisabled: true,
|
|
17
|
+
...rest,
|
|
18
|
+
className: cx("\u{1F95D}-checkbox", "\u{1F95D}-radio", props.className),
|
|
19
|
+
ref: forwardedRef
|
|
20
|
+
}
|
|
21
|
+
)
|
|
18
22
|
}
|
|
19
23
|
);
|
|
20
24
|
});
|
package/dist/bricks/Select.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isBrowser
|
|
8
8
|
} from "./~utils.js";
|
|
9
9
|
import { DisclosureArrow } from "./Icon.js";
|
|
10
|
-
import {
|
|
10
|
+
import { FieldControl } from "./Field.js";
|
|
11
11
|
const supportsHas = isBrowser && CSS?.supports?.("selector(:has(+ *))");
|
|
12
12
|
const HtmlSelectContext = React.createContext(() => {
|
|
13
13
|
});
|
|
@@ -25,10 +25,8 @@ const SelectRoot = forwardRef((props, forwardedRef) => {
|
|
|
25
25
|
});
|
|
26
26
|
const HtmlSelect = forwardRef(
|
|
27
27
|
(props, forwardedRef) => {
|
|
28
|
-
const { variant = "solid", ...rest } = props;
|
|
28
|
+
const { id, variant = "solid", ...rest } = props;
|
|
29
29
|
const setIsHtmlSelect = React.useContext(HtmlSelectContext);
|
|
30
|
-
const fieldId = useFieldId();
|
|
31
|
-
const describedBy = useFieldDescribedBy(props["aria-describedby"]);
|
|
32
30
|
React.useEffect(
|
|
33
31
|
function updateContext() {
|
|
34
32
|
setIsHtmlSelect(true);
|
|
@@ -37,15 +35,20 @@ const HtmlSelect = forwardRef(
|
|
|
37
35
|
);
|
|
38
36
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
39
37
|
/* @__PURE__ */ jsx(
|
|
40
|
-
|
|
38
|
+
FieldControl,
|
|
41
39
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
type: "textlike",
|
|
41
|
+
id,
|
|
42
|
+
render: /* @__PURE__ */ jsx(
|
|
43
|
+
Ariakit.Role.select,
|
|
44
|
+
{
|
|
45
|
+
...rest,
|
|
46
|
+
className: cx("\u{1F95D}-button", "\u{1F95D}-select", props.className),
|
|
47
|
+
"data-kiwi-tone": "neutral",
|
|
48
|
+
"data-kiwi-variant": variant,
|
|
49
|
+
ref: forwardedRef
|
|
50
|
+
}
|
|
51
|
+
)
|
|
49
52
|
}
|
|
50
53
|
),
|
|
51
54
|
/* @__PURE__ */ jsx(DisclosureArrow, { className: "\u{1F95D}-select-arrow" })
|
package/dist/bricks/Switch.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import cx from "classnames";
|
|
3
3
|
import * as Ariakit from "@ariakit/react";
|
|
4
|
-
import {
|
|
4
|
+
import { FieldControl } from "./Field.js";
|
|
5
5
|
import { forwardRef } from "./~utils.js";
|
|
6
6
|
const Switch = forwardRef(
|
|
7
7
|
(props, forwardedRef) => {
|
|
8
|
-
const
|
|
9
|
-
const describedBy = useFieldDescribedBy(props["aria-describedby"]);
|
|
8
|
+
const { id, ...rest } = props;
|
|
10
9
|
return /* @__PURE__ */ jsx(
|
|
11
|
-
|
|
10
|
+
FieldControl,
|
|
12
11
|
{
|
|
13
|
-
|
|
14
|
-
id
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
type: "checkable",
|
|
13
|
+
id,
|
|
14
|
+
render: /* @__PURE__ */ jsx(
|
|
15
|
+
Ariakit.Checkbox,
|
|
16
|
+
{
|
|
17
|
+
accessibleWhenDisabled: true,
|
|
18
|
+
...rest,
|
|
19
|
+
className: cx("\u{1F95D}-switch", props.className),
|
|
20
|
+
role: "switch",
|
|
21
|
+
ref: forwardedRef
|
|
22
|
+
}
|
|
23
|
+
)
|
|
20
24
|
}
|
|
21
25
|
);
|
|
22
26
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type BaseProps } from "./~utils.js";
|
|
3
|
+
interface TableProps extends BaseProps {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A table is a grid of rows and columns that displays data in a structured format.
|
|
7
|
+
*
|
|
8
|
+
* `Table.Root` is the root component for a table.
|
|
9
|
+
* `Table.Header`, `Table.Body`, and `Table.Cell` can be nested inside a `Table.Root` to create a table structure.
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <Table.Root>
|
|
14
|
+
* <Table.Caption>Table Caption</Table.Caption>
|
|
15
|
+
* <Table.Header>
|
|
16
|
+
* <Table.Row>
|
|
17
|
+
* <Table.Cell>Header 1</Table.Cell>
|
|
18
|
+
* <Table.Cell>Header 2</Table.Cell>
|
|
19
|
+
* </Table.Row>
|
|
20
|
+
* </Table.Header>
|
|
21
|
+
*
|
|
22
|
+
* <Table.Body>
|
|
23
|
+
* <Table.Row>
|
|
24
|
+
* <Table.Cell>Cell 1.1</Table.Cell>
|
|
25
|
+
* <Table.Cell>Cell 1.2</Table.Cell>
|
|
26
|
+
* </Table.Row>
|
|
27
|
+
* <Table.Row>
|
|
28
|
+
* <Table.Cell>Cell 2.1</Table.Cell>
|
|
29
|
+
* <Table.Cell>Cell 2.2</Table.Cell>
|
|
30
|
+
* </Table.Row>
|
|
31
|
+
* </Table.Body>
|
|
32
|
+
* </Table.Root>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare const Table: React.ForwardRefExoticComponent<TableProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
36
|
+
interface TableHeaderProps extends BaseProps {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `Table.Header` is a column component of cells that labels the columns of a table.
|
|
40
|
+
* `Table.Row` and `Table.Cell` can be nested inside a `Table.Header` to create a header row.
|
|
41
|
+
*
|
|
42
|
+
* Example:
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <Table.Header>
|
|
45
|
+
* <Table.Row>
|
|
46
|
+
* <Table.Cell>Header 1</Table.Cell>
|
|
47
|
+
* <Table.Cell>Header 2</Table.Cell>
|
|
48
|
+
* </Table.Row>
|
|
49
|
+
* </Table.Header>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare const TableHeader: React.ForwardRefExoticComponent<TableHeaderProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
53
|
+
interface TableBodyProps extends BaseProps {
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* `Table.Body` is a component that contains the rows of table data.
|
|
57
|
+
* Multiple `Table.Row`s and `Table.Cell`s can be nested inside a `Table.Body` to create a table body.
|
|
58
|
+
*
|
|
59
|
+
* This component intentionally does not set `role=rowgroup` because it is not properly supported.
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```tsx
|
|
63
|
+
* <Table.Body>
|
|
64
|
+
* <Table.Row>
|
|
65
|
+
* <Table.Cell>Cell 1.1</Table.Cell>
|
|
66
|
+
* <Table.Cell>Cell 1.2</Table.Cell>
|
|
67
|
+
* </Table.Row>
|
|
68
|
+
* <Table.Row>
|
|
69
|
+
* <Table.Cell>Cell 2.1</Table.Cell>
|
|
70
|
+
* <Table.Cell>Cell 2.2</Table.Cell>
|
|
71
|
+
* </Table.Row>
|
|
72
|
+
* </Table.Body>
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const TableBody: React.ForwardRefExoticComponent<TableBodyProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
76
|
+
interface TableRowProps extends BaseProps {
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `Table.Row` is a component that contains the cells of a table row.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
* ```tsx
|
|
83
|
+
* <Table.Row>
|
|
84
|
+
* <Table.Cell>Cell 1.1</Table.Cell>
|
|
85
|
+
* <Table.Cell>Cell 1.2</Table.Cell>
|
|
86
|
+
* </Table.Row>
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare const TableRow: React.ForwardRefExoticComponent<TableRowProps & React.RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
90
|
+
interface TableCaptionProps extends BaseProps<"caption"> {
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* `Table.Caption` is a component that contains the caption of a table.
|
|
94
|
+
*
|
|
95
|
+
* Example:
|
|
96
|
+
* ```tsx
|
|
97
|
+
* <Table.Root>
|
|
98
|
+
* <Table.Caption>Table Caption</Table.Caption>
|
|
99
|
+
* …
|
|
100
|
+
* </Table.Root>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare const TableCaption: React.ForwardRefExoticComponent<TableCaptionProps & React.RefAttributes<HTMLElement>>;
|
|
104
|
+
interface TableCellProps extends BaseProps<"span"> {
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* `Table.Cell` is a component that contains the data of a table cell.
|
|
108
|
+
*
|
|
109
|
+
* Example:
|
|
110
|
+
* ```tsx
|
|
111
|
+
* <Table.Cell>Cell 1.1</Table.Cell>
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare const TableCell: React.ForwardRefExoticComponent<TableCellProps & React.RefAttributes<HTMLElement | HTMLSpanElement>>;
|
|
115
|
+
export { Table as Root, TableHeader as Header, TableBody as Body, TableRow as Row, TableCaption as Caption, TableCell as Cell, };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as Ariakit from "@ariakit/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import cx from "classnames";
|
|
5
|
+
import { forwardRef } from "./~utils.js";
|
|
6
|
+
import { useMergedRefs } from "./~hooks.js";
|
|
7
|
+
const TableContext = React.createContext({
|
|
8
|
+
setCaptionId: () => {
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const Table = forwardRef((props, forwardedRef) => {
|
|
12
|
+
const [captionId, setCaptionId] = React.useState();
|
|
13
|
+
const tableContext = React.useMemo(() => ({ setCaptionId }), []);
|
|
14
|
+
return /* @__PURE__ */ jsx(TableContext.Provider, { value: tableContext, children: /* @__PURE__ */ jsx(
|
|
15
|
+
Ariakit.Role,
|
|
16
|
+
{
|
|
17
|
+
...props,
|
|
18
|
+
className: cx("\u{1F95D}-table", props.className),
|
|
19
|
+
ref: forwardedRef,
|
|
20
|
+
role: "table",
|
|
21
|
+
"aria-labelledby": captionId,
|
|
22
|
+
children: props.children
|
|
23
|
+
}
|
|
24
|
+
) });
|
|
25
|
+
});
|
|
26
|
+
const TableHeaderContext = React.createContext(false);
|
|
27
|
+
const TableHeader = forwardRef(
|
|
28
|
+
(props, forwardedRef) => {
|
|
29
|
+
return /* @__PURE__ */ jsx(TableHeaderContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
|
|
30
|
+
Ariakit.Role.div,
|
|
31
|
+
{
|
|
32
|
+
...props,
|
|
33
|
+
className: cx("\u{1F95D}-table-header", props.className),
|
|
34
|
+
ref: forwardedRef,
|
|
35
|
+
role: "rowgroup",
|
|
36
|
+
children: props.children
|
|
37
|
+
}
|
|
38
|
+
) });
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
const TableBody = forwardRef((props, forwardedRef) => {
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
Ariakit.Role.div,
|
|
44
|
+
{
|
|
45
|
+
...props,
|
|
46
|
+
className: cx("\u{1F95D}-table-body", props.className),
|
|
47
|
+
ref: forwardedRef,
|
|
48
|
+
children: props.children
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
const TableRow = forwardRef((props, forwardedRef) => {
|
|
53
|
+
const { children, ...rest } = props;
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
Ariakit.Role.div,
|
|
56
|
+
{
|
|
57
|
+
...rest,
|
|
58
|
+
className: cx("\u{1F95D}-table-row", props.className),
|
|
59
|
+
ref: forwardedRef,
|
|
60
|
+
role: "row",
|
|
61
|
+
children
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
const TableCaption = forwardRef(
|
|
66
|
+
(props, forwardedRef) => {
|
|
67
|
+
const fallbackId = React.useId();
|
|
68
|
+
const { id = fallbackId, children, ...rest } = props;
|
|
69
|
+
const { setCaptionId } = React.useContext(TableContext);
|
|
70
|
+
const captionIdRef = React.useCallback(
|
|
71
|
+
(element) => {
|
|
72
|
+
setCaptionId(element ? id : void 0);
|
|
73
|
+
},
|
|
74
|
+
[id, setCaptionId]
|
|
75
|
+
);
|
|
76
|
+
return /* @__PURE__ */ jsx(
|
|
77
|
+
Ariakit.Role,
|
|
78
|
+
{
|
|
79
|
+
...rest,
|
|
80
|
+
id,
|
|
81
|
+
className: cx("\u{1F95D}-table-caption", props.className),
|
|
82
|
+
ref: useMergedRefs(forwardedRef, captionIdRef),
|
|
83
|
+
children
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
const TableCell = forwardRef((props, forwardedRef) => {
|
|
89
|
+
const isWithinTableHeader = React.useContext(TableHeaderContext);
|
|
90
|
+
return /* @__PURE__ */ jsx(
|
|
91
|
+
Ariakit.Role.span,
|
|
92
|
+
{
|
|
93
|
+
...props,
|
|
94
|
+
className: cx("\u{1F95D}-table-cell", props.className),
|
|
95
|
+
ref: forwardedRef,
|
|
96
|
+
role: isWithinTableHeader ? "columnheader" : "cell",
|
|
97
|
+
children: props.children
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
export {
|
|
102
|
+
TableBody as Body,
|
|
103
|
+
TableCaption as Caption,
|
|
104
|
+
TableCell as Cell,
|
|
105
|
+
TableHeader as Header,
|
|
106
|
+
Table as Root,
|
|
107
|
+
TableRow as Row
|
|
108
|
+
};
|