@primer/react 38.43.0-rc.fd837f586 → 38.44.0-rc.0a55e3e04

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.
@@ -1,159 +1,235 @@
1
1
  import { c } from "../utils/react-compiler-runtime.js";
2
2
  import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
3
+ import { useControllableState } from "../hooks/useControllableState.js";
4
+ import { Button } from "../internal/components/ButtonReset.js";
3
5
  import { TableGroupContext } from "./TableGroupContext.js";
4
6
  import Table_module_css_default from "./Table.module.css.js";
5
7
  import { TableRow } from "./Table.js";
6
- import { useId } from "react";
8
+ import { useId, useRef } from "react";
7
9
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
10
  import { clsx } from "clsx";
11
+ import { ChevronRightIcon } from "@primer/octicons-react";
9
12
  //#region src/DataTable/TableGroup.tsx
10
13
  function TableGroup(t0) {
11
- const $ = c(38);
12
- const { className, id, label, rowCount, colSpan, children, "aria-label": ariaLabel } = t0;
14
+ const $ = c(60);
15
+ const { className, id, label, rowCount, colSpan, children, "aria-label": ariaLabel, collapsible: t1, expanded: controlledExpanded, defaultExpanded: t2, onExpandedChange } = t0;
16
+ const collapsible = t1 === void 0 ? false : t1;
17
+ const defaultExpanded = t2 === void 0 ? true : t2;
13
18
  const headerId = useId();
14
- let t1;
15
- if ($[0] !== headerId) {
16
- t1 = { headerId };
17
- $[0] = headerId;
18
- $[1] = t1;
19
- } else t1 = $[1];
20
- const contextValue = t1;
21
- let t2;
22
- if ($[2] !== className) {
23
- t2 = clsx("TableGroupHeaderBody", Table_module_css_default.TableGroupHeaderBody, className);
24
- $[2] = className;
25
- $[3] = t2;
26
- } else t2 = $[3];
19
+ const bodyId = useId();
20
+ const headerRef = useRef(null);
27
21
  let t3;
28
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
29
- t3 = clsx("TableGroupHeaderCell", Table_module_css_default.TableGroupHeaderCell);
30
- $[4] = t3;
31
- } else t3 = $[4];
22
+ if ($[0] !== onExpandedChange) {
23
+ t3 = (value) => onExpandedChange === null || onExpandedChange === void 0 ? void 0 : onExpandedChange({ expanded: value });
24
+ $[0] = onExpandedChange;
25
+ $[1] = t3;
26
+ } else t3 = $[1];
32
27
  let t4;
33
- let t5;
34
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
35
- t4 = clsx("TableGroupHeaderContent", Table_module_css_default.TableGroupHeaderContent);
36
- t5 = clsx("TableGroupHeaderLabel", Table_module_css_default.TableGroupHeaderLabel);
28
+ if ($[2] !== controlledExpanded || $[3] !== defaultExpanded || $[4] !== t3) {
29
+ t4 = {
30
+ name: "Table.Group expanded",
31
+ value: controlledExpanded,
32
+ defaultValue: defaultExpanded,
33
+ onChange: t3
34
+ };
35
+ $[2] = controlledExpanded;
36
+ $[3] = defaultExpanded;
37
+ $[4] = t3;
37
38
  $[5] = t4;
38
- $[6] = t5;
39
- } else {
40
- t4 = $[5];
41
- t5 = $[6];
42
- }
39
+ } else t4 = $[5];
40
+ const [expanded, setExpanded] = useControllableState(t4);
41
+ const isExpanded = !collapsible || expanded;
42
+ let t5;
43
+ if ($[6] !== headerId) {
44
+ t5 = { headerId };
45
+ $[6] = headerId;
46
+ $[7] = t5;
47
+ } else t5 = $[7];
48
+ const contextValue = t5;
43
49
  let t6;
44
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
45
- t6 = /* @__PURE__ */ jsx(VisuallyHidden, { children: "," });
46
- $[7] = t6;
47
- } else t6 = $[7];
50
+ if ($[8] !== isExpanded) {
51
+ t6 = (body) => {
52
+ if (!isExpanded && body !== null && body !== void 0 && body.contains(body.ownerDocument.activeElement)) {
53
+ var _headerRef$current;
54
+ (_headerRef$current = headerRef.current) === null || _headerRef$current === void 0 || (_headerRef$current = _headerRef$current.querySelector("button")) === null || _headerRef$current === void 0 || _headerRef$current.focus();
55
+ }
56
+ };
57
+ $[8] = isExpanded;
58
+ $[9] = t6;
59
+ } else t6 = $[9];
60
+ const bodyRef = t6;
48
61
  let t7;
49
- if ($[8] !== label) {
50
- t7 = /* @__PURE__ */ jsxs("span", {
51
- className: t5,
52
- children: [label, t6]
53
- });
54
- $[8] = label;
55
- $[9] = t7;
56
- } else t7 = $[9];
62
+ if ($[10] !== className) {
63
+ t7 = clsx("TableGroupHeaderBody", Table_module_css_default.TableGroupHeaderBody, className);
64
+ $[10] = className;
65
+ $[11] = t7;
66
+ } else t7 = $[11];
57
67
  let t8;
58
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
59
- t8 = clsx("TableGroupHeaderCount", Table_module_css_default.TableGroupHeaderCount);
60
- $[10] = t8;
61
- } else t8 = $[10];
62
- const t9 = rowCount === 1 ? " row" : " rows";
68
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
69
+ t8 = clsx("TableGroupHeaderCell", Table_module_css_default.TableGroupHeaderCell);
70
+ $[12] = t8;
71
+ } else t8 = $[12];
72
+ const t9 = collapsible ? ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : label : ariaLabel;
63
73
  let t10;
64
- if ($[11] !== t9) {
65
- t10 = /* @__PURE__ */ jsx(VisuallyHidden, { children: t9 });
66
- $[11] = t9;
67
- $[12] = t10;
68
- } else t10 = $[12];
74
+ if ($[13] !== ariaLabel || $[14] !== bodyId || $[15] !== collapsible || $[16] !== expanded || $[17] !== isExpanded || $[18] !== label || $[19] !== rowCount || $[20] !== setExpanded) {
75
+ t10 = collapsible ? /* @__PURE__ */ jsx(Button, {
76
+ className: Table_module_css_default.TableGroupToggle,
77
+ "data-component": "Table.Group.Toggle",
78
+ "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : label,
79
+ "aria-description": `${rowCount} ${rowCount === 1 ? "row" : "rows"}`,
80
+ "aria-expanded": isExpanded,
81
+ "aria-controls": bodyId,
82
+ onClick: () => {
83
+ setExpanded(!expanded);
84
+ },
85
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, { "aria-hidden": "true" })
86
+ }) : null;
87
+ $[13] = ariaLabel;
88
+ $[14] = bodyId;
89
+ $[15] = collapsible;
90
+ $[16] = expanded;
91
+ $[17] = isExpanded;
92
+ $[18] = label;
93
+ $[19] = rowCount;
94
+ $[20] = setExpanded;
95
+ $[21] = t10;
96
+ } else t10 = $[21];
69
97
  let t11;
70
- if ($[13] !== rowCount || $[14] !== t10) {
71
- t11 = /* @__PURE__ */ jsxs("span", {
72
- className: t8,
73
- children: [rowCount, t10]
98
+ if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
99
+ t11 = clsx("TableGroupHeaderContent", Table_module_css_default.TableGroupHeaderContent);
100
+ $[22] = t11;
101
+ } else t11 = $[22];
102
+ const t12 = collapsible || void 0;
103
+ let t13;
104
+ if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
105
+ t13 = clsx("TableGroupHeaderLabel", Table_module_css_default.TableGroupHeaderLabel);
106
+ $[23] = t13;
107
+ } else t13 = $[23];
108
+ let t14;
109
+ if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
110
+ t14 = /* @__PURE__ */ jsx(VisuallyHidden, { children: "," });
111
+ $[24] = t14;
112
+ } else t14 = $[24];
113
+ let t15;
114
+ if ($[25] !== label) {
115
+ t15 = /* @__PURE__ */ jsxs("span", {
116
+ className: t13,
117
+ children: [label, t14]
74
118
  });
75
- $[13] = rowCount;
76
- $[14] = t10;
77
- $[15] = t11;
78
- } else t11 = $[15];
79
- let t12;
80
- if ($[16] !== t11 || $[17] !== t7) {
81
- t12 = /* @__PURE__ */ jsxs("span", {
82
- className: t4,
83
- children: [t7, t11]
119
+ $[25] = label;
120
+ $[26] = t15;
121
+ } else t15 = $[26];
122
+ let t16;
123
+ if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
124
+ t16 = clsx("TableGroupHeaderCount", Table_module_css_default.TableGroupHeaderCount);
125
+ $[27] = t16;
126
+ } else t16 = $[27];
127
+ const t17 = rowCount === 1 ? " row" : " rows";
128
+ let t18;
129
+ if ($[28] !== t17) {
130
+ t18 = /* @__PURE__ */ jsx(VisuallyHidden, { children: t17 });
131
+ $[28] = t17;
132
+ $[29] = t18;
133
+ } else t18 = $[29];
134
+ let t19;
135
+ if ($[30] !== rowCount || $[31] !== t18) {
136
+ t19 = /* @__PURE__ */ jsxs("span", {
137
+ className: t16,
138
+ children: [rowCount, t18]
84
139
  });
85
- $[16] = t11;
86
- $[17] = t7;
87
- $[18] = t12;
88
- } else t12 = $[18];
89
- let t13;
90
- if ($[19] !== ariaLabel || $[20] !== colSpan || $[21] !== headerId || $[22] !== t12) {
91
- t13 = /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx("th", {
140
+ $[30] = rowCount;
141
+ $[31] = t18;
142
+ $[32] = t19;
143
+ } else t19 = $[32];
144
+ let t20;
145
+ if ($[33] !== t12 || $[34] !== t15 || $[35] !== t19) {
146
+ t20 = /* @__PURE__ */ jsxs("span", {
147
+ className: t11,
148
+ "aria-hidden": t12,
149
+ children: [t15, t19]
150
+ });
151
+ $[33] = t12;
152
+ $[34] = t15;
153
+ $[35] = t19;
154
+ $[36] = t20;
155
+ } else t20 = $[36];
156
+ let t21;
157
+ if ($[37] !== colSpan || $[38] !== headerId || $[39] !== t10 || $[40] !== t20 || $[41] !== t9) {
158
+ t21 = /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsxs("th", {
92
159
  id: headerId,
93
- className: t3,
160
+ ref: headerRef,
161
+ className: t8,
94
162
  scope: "colgroup",
95
163
  colSpan,
96
164
  role: "columnheader",
97
- "aria-label": ariaLabel,
165
+ "aria-label": t9,
98
166
  "data-component": "Table.Group.Header",
99
- children: t12
167
+ children: [t10, t20]
100
168
  }) });
101
- $[19] = ariaLabel;
102
- $[20] = colSpan;
103
- $[21] = headerId;
104
- $[22] = t12;
105
- $[23] = t13;
106
- } else t13 = $[23];
107
- let t14;
108
- if ($[24] !== id || $[25] !== t13 || $[26] !== t2) {
109
- t14 = /* @__PURE__ */ jsx("tbody", {
110
- className: t2,
169
+ $[37] = colSpan;
170
+ $[38] = headerId;
171
+ $[39] = t10;
172
+ $[40] = t20;
173
+ $[41] = t9;
174
+ $[42] = t21;
175
+ } else t21 = $[42];
176
+ let t22;
177
+ if ($[43] !== id || $[44] !== t21 || $[45] !== t7) {
178
+ t22 = /* @__PURE__ */ jsx("tbody", {
179
+ className: t7,
111
180
  role: "rowgroup",
112
181
  "data-component": "Table.Group",
113
182
  "data-group-id": id,
114
- children: t13
183
+ children: t21
115
184
  });
116
- $[24] = id;
117
- $[25] = t13;
118
- $[26] = t2;
119
- $[27] = t14;
120
- } else t14 = $[27];
121
- let t15;
122
- if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
123
- t15 = clsx("TableBody", Table_module_css_default.TableBody);
124
- $[28] = t15;
125
- } else t15 = $[28];
126
- let t16;
127
- if ($[29] !== children || $[30] !== contextValue) {
128
- t16 = /* @__PURE__ */ jsx(TableGroupContext.Provider, {
185
+ $[43] = id;
186
+ $[44] = t21;
187
+ $[45] = t7;
188
+ $[46] = t22;
189
+ } else t22 = $[46];
190
+ const t23 = !isExpanded;
191
+ let t24;
192
+ if ($[47] === Symbol.for("react.memo_cache_sentinel")) {
193
+ t24 = clsx("TableBody", Table_module_css_default.TableBody);
194
+ $[47] = t24;
195
+ } else t24 = $[47];
196
+ let t25;
197
+ if ($[48] !== children || $[49] !== contextValue) {
198
+ t25 = /* @__PURE__ */ jsx(TableGroupContext.Provider, {
129
199
  value: contextValue,
130
200
  children
131
201
  });
132
- $[29] = children;
133
- $[30] = contextValue;
134
- $[31] = t16;
135
- } else t16 = $[31];
136
- let t17;
137
- if ($[32] !== id || $[33] !== t16) {
138
- t17 = /* @__PURE__ */ jsx("tbody", {
139
- className: t15,
202
+ $[48] = children;
203
+ $[49] = contextValue;
204
+ $[50] = t25;
205
+ } else t25 = $[50];
206
+ let t26;
207
+ if ($[51] !== bodyId || $[52] !== bodyRef || $[53] !== id || $[54] !== t23 || $[55] !== t25) {
208
+ t26 = /* @__PURE__ */ jsx("tbody", {
209
+ id: bodyId,
210
+ ref: bodyRef,
211
+ hidden: t23,
212
+ className: t24,
140
213
  role: "rowgroup",
141
214
  "data-component": "Table.Group.Body",
142
215
  "data-group-id": id,
143
- children: t16
216
+ children: t25
144
217
  });
145
- $[32] = id;
146
- $[33] = t16;
147
- $[34] = t17;
148
- } else t17 = $[34];
149
- let t18;
150
- if ($[35] !== t14 || $[36] !== t17) {
151
- t18 = /* @__PURE__ */ jsxs(Fragment$1, { children: [t14, t17] });
152
- $[35] = t14;
153
- $[36] = t17;
154
- $[37] = t18;
155
- } else t18 = $[37];
156
- return t18;
218
+ $[51] = bodyId;
219
+ $[52] = bodyRef;
220
+ $[53] = id;
221
+ $[54] = t23;
222
+ $[55] = t25;
223
+ $[56] = t26;
224
+ } else t26 = $[56];
225
+ let t27;
226
+ if ($[57] !== t22 || $[58] !== t26) {
227
+ t27 = /* @__PURE__ */ jsxs(Fragment$1, { children: [t22, t26] });
228
+ $[57] = t22;
229
+ $[58] = t26;
230
+ $[59] = t27;
231
+ } else t27 = $[59];
232
+ return t27;
157
233
  }
158
234
  //#endregion
159
235
  export { TableGroup };