@primer/react 38.29.0-rc.d7f442775 → 38.29.0-rc.ee664b93c
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 +2 -0
- package/dist/ActionList/ActionList-65f7daac.css +2 -0
- package/dist/ActionList/ActionList-65f7daac.css.map +1 -0
- package/dist/ActionList/ActionList.module.css.js +2 -2
- package/dist/ActionList/List.d.ts.map +1 -1
- package/dist/ActionList/List.js +21 -16
- package/dist/AnchoredOverlay/AnchoredOverlay.js +2 -2
- package/dist/ConfirmationDialog/ConfirmationDialog.d.ts +0 -9
- package/dist/ConfirmationDialog/ConfirmationDialog.d.ts.map +1 -1
- package/dist/ConfirmationDialog/ConfirmationDialog.js +1 -42
- package/dist/ConfirmationDialog/useConfirm.d.ts +12 -0
- package/dist/ConfirmationDialog/useConfirm.d.ts.map +1 -0
- package/dist/ConfirmationDialog/useConfirm.js +44 -0
- package/dist/FeatureFlags/DefaultFeatureFlags.d.ts.map +1 -1
- package/dist/FeatureFlags/DefaultFeatureFlags.js +1 -0
- package/dist/KeybindingHint/KeybindingHint.d.ts +0 -14
- package/dist/KeybindingHint/KeybindingHint.d.ts.map +1 -1
- package/dist/KeybindingHint/KeybindingHint.js +1 -16
- package/dist/KeybindingHint/components/Chord.d.ts +0 -2
- package/dist/KeybindingHint/components/Chord.d.ts.map +1 -1
- package/dist/KeybindingHint/components/Chord.js +0 -1
- package/dist/KeybindingHint/components/Sequence.d.ts +0 -2
- package/dist/KeybindingHint/components/Sequence.d.ts.map +1 -1
- package/dist/KeybindingHint/index.d.ts +2 -1
- package/dist/KeybindingHint/index.d.ts.map +1 -1
- package/dist/KeybindingHint/utils.d.ts +15 -0
- package/dist/KeybindingHint/utils.d.ts.map +1 -0
- package/dist/KeybindingHint/utils.js +17 -0
- package/dist/Overlay/Overlay.d.ts +1 -2
- package/dist/Overlay/Overlay.d.ts.map +1 -1
- package/dist/ThemeContext.d.ts +15 -0
- package/dist/ThemeContext.d.ts.map +1 -0
- package/dist/ThemeContext.js +9 -0
- package/dist/ThemeProvider.d.ts +1 -14
- package/dist/ThemeProvider.d.ts.map +1 -1
- package/dist/ThemeProvider.js +3 -18
- package/dist/Timeline/Timeline.d.ts +1 -2
- package/dist/Timeline/Timeline.d.ts.map +1 -1
- package/dist/Token/IssueLabelToken.d.ts.map +1 -1
- package/dist/Token/IssueLabelToken.js +2 -2
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +2 -2
- package/dist/Token/TokenBase.d.ts +1 -3
- package/dist/Token/TokenBase.d.ts.map +1 -1
- package/dist/Token/TokenBase.js +1 -1
- package/dist/Token/_RemoveTokenButton.js +1 -4
- package/dist/TooltipV2/Tooltip.js +2 -1
- package/dist/TreeView/TreeView.js +1 -1
- package/dist/UnderlineNav/UnderlineNav.d.ts +0 -2
- package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
- package/dist/UnderlineNav/UnderlineNav.js +1 -1
- package/dist/experimental/SelectPanel2/SelectPanel.d.ts.map +1 -1
- package/dist/experimental/SelectPanel2/SelectPanel.js +1 -1
- package/dist/experimental/SelectPanel2/index.d.ts +2 -1
- package/dist/experimental/SelectPanel2/index.d.ts.map +1 -1
- package/dist/experimental/Tabs/Tabs.d.ts +3 -111
- package/dist/experimental/Tabs/Tabs.d.ts.map +1 -1
- package/dist/experimental/Tabs/Tabs.js +3 -237
- package/dist/experimental/Tabs/TabsContext.d.ts +3 -0
- package/dist/experimental/Tabs/TabsContext.d.ts.map +1 -0
- package/dist/experimental/Tabs/TabsContext.js +5 -0
- package/dist/experimental/Tabs/index.d.ts +5 -2
- package/dist/experimental/Tabs/index.d.ts.map +1 -1
- package/dist/experimental/Tabs/types.d.ts +107 -0
- package/dist/experimental/Tabs/types.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTab.d.ts +7 -0
- package/dist/experimental/Tabs/useTab.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTab.js +97 -0
- package/dist/experimental/Tabs/useTabList.d.ts +3 -0
- package/dist/experimental/Tabs/useTabList.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabList.js +100 -0
- package/dist/experimental/Tabs/useTabPanel.d.ts +4 -0
- package/dist/experimental/Tabs/useTabPanel.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabPanel.js +37 -0
- package/dist/experimental/Tabs/useTabs.d.ts +3 -0
- package/dist/experimental/Tabs/useTabs.d.ts.map +1 -0
- package/dist/experimental/Tabs/useTabs.js +12 -0
- package/dist/experimental/index.js +6 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/useTheme.d.ts +15 -0
- package/dist/useTheme.d.ts.map +1 -0
- package/dist/useTheme.js +16 -0
- package/dist/utils/story-helpers.d.ts +70 -0
- package/dist/utils/story-helpers.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/ActionList/ActionList-1940009e.css +0 -2
- package/dist/ActionList/ActionList-1940009e.css.map +0 -1
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { c } from 'react-compiler-runtime';
|
|
2
|
-
import React, { useId
|
|
2
|
+
import React, { useId } from 'react';
|
|
3
3
|
import useIsomorphicLayoutEffect from '../../utils/useIsomorphicLayoutEffect.js';
|
|
4
4
|
import { useControllableState } from '../../hooks/useControllableState.js';
|
|
5
|
+
import { TabsContext } from './TabsContext.js';
|
|
5
6
|
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
import { useProvidedRefOrCreate } from '../../hooks/useProvidedRefOrCreate.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* The Tabs component provides the base structure for a tabbed interface, without providing any formal requirement on DOM structure or styling.
|
|
10
|
-
* It manages the state of the selected tab, handles tab ordering/selection and provides context to its child components to ensure an accessible experience.
|
|
11
|
-
*
|
|
12
|
-
* This is intended to be used in conjunction with the `useTab`, `useTabList`, and `useTabPanel` hooks to build a fully accessible tabs component.
|
|
13
|
-
* The `Tab`, `TabList`, and `TabPanel` components are provided for convenience to showcase the API & implementation.
|
|
14
|
-
*/
|
|
15
8
|
function Tabs(props) {
|
|
16
9
|
var _props$defaultValue;
|
|
17
10
|
const $ = c(13);
|
|
@@ -86,232 +79,5 @@ function Tabs(props) {
|
|
|
86
79
|
}
|
|
87
80
|
return t5;
|
|
88
81
|
}
|
|
89
|
-
function useTabList(props) {
|
|
90
|
-
const $ = c(9);
|
|
91
|
-
const {
|
|
92
|
-
"aria-label": ariaLabel,
|
|
93
|
-
"aria-labelledby": ariaLabelledby,
|
|
94
|
-
"aria-orientation": ariaOrientation
|
|
95
|
-
} = props;
|
|
96
|
-
const ref = useProvidedRefOrCreate(props.ref);
|
|
97
|
-
let t0;
|
|
98
|
-
if ($[0] !== ariaOrientation || $[1] !== ref) {
|
|
99
|
-
t0 = event => {
|
|
100
|
-
const {
|
|
101
|
-
current: tablist
|
|
102
|
-
} = ref;
|
|
103
|
-
if (tablist === null) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const tabs = getFocusableTabs(tablist);
|
|
107
|
-
const isVertical = ariaOrientation === "vertical";
|
|
108
|
-
const nextKey = isVertical ? "ArrowDown" : "ArrowRight";
|
|
109
|
-
const prevKey = isVertical ? "ArrowUp" : "ArrowLeft";
|
|
110
|
-
if (event.key === nextKey || event.key === prevKey || event.key === "Home" || event.key === "End") {
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
event.stopPropagation();
|
|
113
|
-
}
|
|
114
|
-
if (event.key === nextKey) {
|
|
115
|
-
const selectedTabIndex = tabs.findIndex(_temp);
|
|
116
|
-
if (selectedTabIndex === -1) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const nextTabIndex = (selectedTabIndex + 1) % tabs.length;
|
|
120
|
-
tabs[nextTabIndex].focus();
|
|
121
|
-
} else {
|
|
122
|
-
if (event.key === prevKey) {
|
|
123
|
-
const selectedTabIndex_0 = tabs.findIndex(_temp2);
|
|
124
|
-
if (selectedTabIndex_0 === -1) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const nextTabIndex_0 = (tabs.length + selectedTabIndex_0 - 1) % tabs.length;
|
|
128
|
-
tabs[nextTabIndex_0].focus();
|
|
129
|
-
} else {
|
|
130
|
-
if (event.key === "Home") {
|
|
131
|
-
if (tabs[0]) {
|
|
132
|
-
tabs[0].focus();
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
if (event.key === "End") {
|
|
136
|
-
if (tabs.length > 0) {
|
|
137
|
-
tabs[tabs.length - 1].focus();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
$[0] = ariaOrientation;
|
|
145
|
-
$[1] = ref;
|
|
146
|
-
$[2] = t0;
|
|
147
|
-
} else {
|
|
148
|
-
t0 = $[2];
|
|
149
|
-
}
|
|
150
|
-
const onKeyDown = t0;
|
|
151
|
-
const t1 = ariaOrientation !== null && ariaOrientation !== void 0 ? ariaOrientation : "horizontal";
|
|
152
|
-
let t2;
|
|
153
|
-
if ($[3] !== ariaLabel || $[4] !== ariaLabelledby || $[5] !== onKeyDown || $[6] !== ref || $[7] !== t1) {
|
|
154
|
-
t2 = {
|
|
155
|
-
tabListProps: {
|
|
156
|
-
ref,
|
|
157
|
-
"aria-label": ariaLabel,
|
|
158
|
-
"aria-labelledby": ariaLabelledby,
|
|
159
|
-
"aria-orientation": t1,
|
|
160
|
-
role: "tablist",
|
|
161
|
-
onKeyDown
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
$[3] = ariaLabel;
|
|
165
|
-
$[4] = ariaLabelledby;
|
|
166
|
-
$[5] = onKeyDown;
|
|
167
|
-
$[6] = ref;
|
|
168
|
-
$[7] = t1;
|
|
169
|
-
$[8] = t2;
|
|
170
|
-
} else {
|
|
171
|
-
t2 = $[8];
|
|
172
|
-
}
|
|
173
|
-
return t2;
|
|
174
|
-
}
|
|
175
|
-
function _temp2(tab_0) {
|
|
176
|
-
return tab_0.getAttribute("aria-selected") === "true";
|
|
177
|
-
}
|
|
178
|
-
function _temp(tab) {
|
|
179
|
-
return tab.getAttribute("aria-selected") === "true";
|
|
180
|
-
}
|
|
181
|
-
function getFocusableTabs(tablist) {
|
|
182
|
-
return Array.from(tablist.querySelectorAll('[role="tab"]:not([aria-disabled])'));
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* A custom hook that provides the props needed for a tab component.
|
|
186
|
-
* The props returned should be spread onto the component (typically a button) with the `role=tab`, under a `tablist`.
|
|
187
|
-
*/
|
|
188
|
-
function useTab(props) {
|
|
189
|
-
const $ = c(21);
|
|
190
|
-
const {
|
|
191
|
-
disabled,
|
|
192
|
-
value
|
|
193
|
-
} = props;
|
|
194
|
-
const tabs = useTabs();
|
|
195
|
-
const selected = tabs.selectedValue === value;
|
|
196
|
-
const id = `${tabs.groupId}-tab-${value}`;
|
|
197
|
-
const panelId = `${tabs.groupId}-panel-${value}`;
|
|
198
|
-
let t0;
|
|
199
|
-
if ($[0] !== tabs || $[1] !== value) {
|
|
200
|
-
t0 = function onKeyDown(event) {
|
|
201
|
-
if (event.key === " " || event.key === "Enter") {
|
|
202
|
-
tabs.selectTab(value);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
$[0] = tabs;
|
|
206
|
-
$[1] = value;
|
|
207
|
-
$[2] = t0;
|
|
208
|
-
} else {
|
|
209
|
-
t0 = $[2];
|
|
210
|
-
}
|
|
211
|
-
const onKeyDown = t0;
|
|
212
|
-
let t1;
|
|
213
|
-
if ($[3] !== disabled || $[4] !== tabs || $[5] !== value) {
|
|
214
|
-
t1 = function onMouseDown(event_0) {
|
|
215
|
-
if (!disabled && event_0.button === 0 && event_0.ctrlKey === false) {
|
|
216
|
-
tabs.selectTab(value);
|
|
217
|
-
} else {
|
|
218
|
-
event_0.preventDefault();
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
$[3] = disabled;
|
|
222
|
-
$[4] = tabs;
|
|
223
|
-
$[5] = value;
|
|
224
|
-
$[6] = t1;
|
|
225
|
-
} else {
|
|
226
|
-
t1 = $[6];
|
|
227
|
-
}
|
|
228
|
-
const onMouseDown = t1;
|
|
229
|
-
let t2;
|
|
230
|
-
if ($[7] !== disabled || $[8] !== selected || $[9] !== tabs || $[10] !== value) {
|
|
231
|
-
t2 = function onFocus() {
|
|
232
|
-
if (!selected && !disabled) {
|
|
233
|
-
tabs.selectTab(value);
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
$[7] = disabled;
|
|
237
|
-
$[8] = selected;
|
|
238
|
-
$[9] = tabs;
|
|
239
|
-
$[10] = value;
|
|
240
|
-
$[11] = t2;
|
|
241
|
-
} else {
|
|
242
|
-
t2 = $[11];
|
|
243
|
-
}
|
|
244
|
-
const onFocus = t2;
|
|
245
|
-
const t3 = disabled ? true : undefined;
|
|
246
|
-
const t4 = selected ? 0 : -1;
|
|
247
|
-
let t5;
|
|
248
|
-
if ($[12] !== id || $[13] !== onFocus || $[14] !== onKeyDown || $[15] !== onMouseDown || $[16] !== panelId || $[17] !== selected || $[18] !== t3 || $[19] !== t4) {
|
|
249
|
-
t5 = {
|
|
250
|
-
tabProps: {
|
|
251
|
-
"aria-disabled": t3,
|
|
252
|
-
"aria-controls": panelId,
|
|
253
|
-
"aria-selected": selected,
|
|
254
|
-
onKeyDown,
|
|
255
|
-
onMouseDown,
|
|
256
|
-
onFocus,
|
|
257
|
-
id,
|
|
258
|
-
role: "tab",
|
|
259
|
-
tabIndex: t4
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
$[12] = id;
|
|
263
|
-
$[13] = onFocus;
|
|
264
|
-
$[14] = onKeyDown;
|
|
265
|
-
$[15] = onMouseDown;
|
|
266
|
-
$[16] = panelId;
|
|
267
|
-
$[17] = selected;
|
|
268
|
-
$[18] = t3;
|
|
269
|
-
$[19] = t4;
|
|
270
|
-
$[20] = t5;
|
|
271
|
-
} else {
|
|
272
|
-
t5 = $[20];
|
|
273
|
-
}
|
|
274
|
-
return t5;
|
|
275
|
-
}
|
|
276
|
-
/** Utility hook for tab panels */
|
|
277
|
-
function useTabPanel(props) {
|
|
278
|
-
const $ = c(5);
|
|
279
|
-
const {
|
|
280
|
-
value
|
|
281
|
-
} = props;
|
|
282
|
-
const tabs = useTabs();
|
|
283
|
-
const id = `${tabs.groupId}-panel-${value}`;
|
|
284
|
-
const tabId = `${tabs.groupId}-tab-${value}`;
|
|
285
|
-
const t0 = tabs.selectedValue === value ? "" : undefined;
|
|
286
|
-
const t1 = tabs.selectedValue !== value;
|
|
287
|
-
let t2;
|
|
288
|
-
if ($[0] !== id || $[1] !== t0 || $[2] !== t1 || $[3] !== tabId) {
|
|
289
|
-
t2 = {
|
|
290
|
-
tabPanelProps: {
|
|
291
|
-
"aria-labelledby": tabId,
|
|
292
|
-
"data-selected": t0,
|
|
293
|
-
id,
|
|
294
|
-
hidden: t1,
|
|
295
|
-
role: "tabpanel"
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
$[0] = id;
|
|
299
|
-
$[1] = t0;
|
|
300
|
-
$[2] = t1;
|
|
301
|
-
$[3] = tabId;
|
|
302
|
-
$[4] = t2;
|
|
303
|
-
} else {
|
|
304
|
-
t2 = $[4];
|
|
305
|
-
}
|
|
306
|
-
return t2;
|
|
307
|
-
}
|
|
308
|
-
const TabsContext = /*#__PURE__*/createContext(null);
|
|
309
|
-
function useTabs() {
|
|
310
|
-
const context = useContext(TabsContext);
|
|
311
|
-
if (context) {
|
|
312
|
-
return context;
|
|
313
|
-
}
|
|
314
|
-
throw new Error("Component must be used within a <Tabs> component");
|
|
315
|
-
}
|
|
316
82
|
|
|
317
|
-
export { Tabs
|
|
83
|
+
export { Tabs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabsContext.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/TabsContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,WAAW,kDAA+C,CAAA"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export { Tabs
|
|
2
|
-
export
|
|
1
|
+
export { Tabs } from './Tabs';
|
|
2
|
+
export { useTab } from './useTab';
|
|
3
|
+
export { useTabList } from './useTabList';
|
|
4
|
+
export { useTabPanel } from './useTabPanel';
|
|
5
|
+
export type { TabsProps, TabListProps, TabProps, TabPanelProps } from './types';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AACzC,YAAY,EAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { AriaAttributes, PropsWithChildren } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Props to be used when the Tabs component's state is controlled by the parent
|
|
5
|
+
*/
|
|
6
|
+
type ControlledTabsProps = {
|
|
7
|
+
/**
|
|
8
|
+
* Specify the selected tab
|
|
9
|
+
*/
|
|
10
|
+
value: string;
|
|
11
|
+
/**
|
|
12
|
+
* `defaultValue` can only be used in the uncontrolled variant of the component
|
|
13
|
+
* If you need to use `defaultValue`, please switch to the uncontrolled variant by removing the `value` prop.
|
|
14
|
+
*/
|
|
15
|
+
defaultValue?: never;
|
|
16
|
+
/**
|
|
17
|
+
* Provide an optional callback that is called when the selected tab changes
|
|
18
|
+
*/
|
|
19
|
+
onValueChange: ({ value }: {
|
|
20
|
+
value: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Props to be used when the Tabs component is managing its own state
|
|
25
|
+
*/
|
|
26
|
+
type UncontrolledTabsProps = {
|
|
27
|
+
/**
|
|
28
|
+
* Specify the default selected tab
|
|
29
|
+
*/
|
|
30
|
+
defaultValue: string;
|
|
31
|
+
/**
|
|
32
|
+
* `value` can only be used in the controlled variant of the component
|
|
33
|
+
* If you need to use `value`, please switch to the controlled variant by removing the `defaultValue` prop.
|
|
34
|
+
*/
|
|
35
|
+
value?: never;
|
|
36
|
+
/**
|
|
37
|
+
* Provide an optional callback that is called when the selected tab changes
|
|
38
|
+
*/
|
|
39
|
+
onValueChange?: ({ value }: {
|
|
40
|
+
value: string;
|
|
41
|
+
}) => void;
|
|
42
|
+
};
|
|
43
|
+
export type TabsProps = PropsWithChildren<ControlledTabsProps | UncontrolledTabsProps>;
|
|
44
|
+
type Label = {
|
|
45
|
+
'aria-label': string;
|
|
46
|
+
};
|
|
47
|
+
type LabelledBy = {
|
|
48
|
+
'aria-labelledby': string;
|
|
49
|
+
};
|
|
50
|
+
type Labelled = Label | LabelledBy;
|
|
51
|
+
export type TabListProps = Labelled & React.HTMLAttributes<HTMLElement>;
|
|
52
|
+
export type TabProps = React.ComponentPropsWithoutRef<'button'> & {
|
|
53
|
+
/**
|
|
54
|
+
* Specify whether the tab is disabled
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Provide a value that uniquely identifies the tab. This should mirror the
|
|
59
|
+
* value provided to the corresponding TabPanel
|
|
60
|
+
*/
|
|
61
|
+
value: string;
|
|
62
|
+
};
|
|
63
|
+
export type TabPanelProps = {
|
|
64
|
+
/**
|
|
65
|
+
* Provide a value that uniquely identifies the tab panel. This should mirror
|
|
66
|
+
* the value set for the corresponding tab
|
|
67
|
+
*/
|
|
68
|
+
value: string;
|
|
69
|
+
};
|
|
70
|
+
export type TabsContextValue = {
|
|
71
|
+
groupId: string;
|
|
72
|
+
selectedValue: string;
|
|
73
|
+
selectTab(value: string): void;
|
|
74
|
+
};
|
|
75
|
+
export type TabListHookProps<T extends HTMLElement> = TabListProps & {
|
|
76
|
+
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */
|
|
77
|
+
ref?: React.RefObject<T>;
|
|
78
|
+
};
|
|
79
|
+
export type TabListHookResult<T extends HTMLElement> = {
|
|
80
|
+
/** Props to be spread onto the tablist element */
|
|
81
|
+
tabListProps: {
|
|
82
|
+
onKeyDown: React.KeyboardEventHandler<T>;
|
|
83
|
+
'aria-orientation': AriaAttributes['aria-orientation'];
|
|
84
|
+
'aria-label': AriaAttributes['aria-label'];
|
|
85
|
+
'aria-labelledby': AriaAttributes['aria-labelledby'];
|
|
86
|
+
ref: React.RefObject<T | null>;
|
|
87
|
+
role: 'tablist';
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export type TabHookResult<T extends HTMLElement> = {
|
|
91
|
+
/** Props to be spread onto the tab component */
|
|
92
|
+
tabProps: Pick<React.HTMLProps<T>, 'aria-controls' | 'aria-disabled' | 'aria-selected' | 'id' | 'tabIndex' | 'onKeyDown' | 'onMouseDown' | 'onFocus'> & {
|
|
93
|
+
role: 'tab';
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export type TabPanelHookResult<T extends HTMLElement> = {
|
|
97
|
+
/** Props to be spread onto the tabpanel component */
|
|
98
|
+
tabPanelProps: Pick<React.HTMLProps<T>, 'aria-labelledby' | 'id' | 'hidden'> & {
|
|
99
|
+
/**
|
|
100
|
+
* An identifier to aid in styling when this panel is selected & active
|
|
101
|
+
*/
|
|
102
|
+
'data-selected': string | undefined;
|
|
103
|
+
role: 'tabpanel';
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TabHookResult, TabProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A custom hook that provides the props needed for a tab component.
|
|
4
|
+
* The props returned should be spread onto the component (typically a button) with the `role=tab`, under a `tablist`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useTab<T extends HTMLElement>(props: Pick<TabProps, 'disabled' | 'value'>): TabHookResult<T>;
|
|
7
|
+
//# sourceMappingURL=useTab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTab.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/useTab.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAA;AAGpD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAwC3G"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
2
|
+
import { useTabs } from './useTabs.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A custom hook that provides the props needed for a tab component.
|
|
6
|
+
* The props returned should be spread onto the component (typically a button) with the `role=tab`, under a `tablist`.
|
|
7
|
+
*/
|
|
8
|
+
function useTab(props) {
|
|
9
|
+
const $ = c(21);
|
|
10
|
+
const {
|
|
11
|
+
disabled,
|
|
12
|
+
value
|
|
13
|
+
} = props;
|
|
14
|
+
const tabs = useTabs();
|
|
15
|
+
const selected = tabs.selectedValue === value;
|
|
16
|
+
const id = `${tabs.groupId}-tab-${value}`;
|
|
17
|
+
const panelId = `${tabs.groupId}-panel-${value}`;
|
|
18
|
+
let t0;
|
|
19
|
+
if ($[0] !== tabs || $[1] !== value) {
|
|
20
|
+
t0 = function onKeyDown(event) {
|
|
21
|
+
if (event.key === " " || event.key === "Enter") {
|
|
22
|
+
tabs.selectTab(value);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
$[0] = tabs;
|
|
26
|
+
$[1] = value;
|
|
27
|
+
$[2] = t0;
|
|
28
|
+
} else {
|
|
29
|
+
t0 = $[2];
|
|
30
|
+
}
|
|
31
|
+
const onKeyDown = t0;
|
|
32
|
+
let t1;
|
|
33
|
+
if ($[3] !== disabled || $[4] !== tabs || $[5] !== value) {
|
|
34
|
+
t1 = function onMouseDown(event_0) {
|
|
35
|
+
if (!disabled && event_0.button === 0 && event_0.ctrlKey === false) {
|
|
36
|
+
tabs.selectTab(value);
|
|
37
|
+
} else {
|
|
38
|
+
event_0.preventDefault();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
$[3] = disabled;
|
|
42
|
+
$[4] = tabs;
|
|
43
|
+
$[5] = value;
|
|
44
|
+
$[6] = t1;
|
|
45
|
+
} else {
|
|
46
|
+
t1 = $[6];
|
|
47
|
+
}
|
|
48
|
+
const onMouseDown = t1;
|
|
49
|
+
let t2;
|
|
50
|
+
if ($[7] !== disabled || $[8] !== selected || $[9] !== tabs || $[10] !== value) {
|
|
51
|
+
t2 = function onFocus() {
|
|
52
|
+
if (!selected && !disabled) {
|
|
53
|
+
tabs.selectTab(value);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
$[7] = disabled;
|
|
57
|
+
$[8] = selected;
|
|
58
|
+
$[9] = tabs;
|
|
59
|
+
$[10] = value;
|
|
60
|
+
$[11] = t2;
|
|
61
|
+
} else {
|
|
62
|
+
t2 = $[11];
|
|
63
|
+
}
|
|
64
|
+
const onFocus = t2;
|
|
65
|
+
const t3 = disabled ? true : undefined;
|
|
66
|
+
const t4 = selected ? 0 : -1;
|
|
67
|
+
let t5;
|
|
68
|
+
if ($[12] !== id || $[13] !== onFocus || $[14] !== onKeyDown || $[15] !== onMouseDown || $[16] !== panelId || $[17] !== selected || $[18] !== t3 || $[19] !== t4) {
|
|
69
|
+
t5 = {
|
|
70
|
+
tabProps: {
|
|
71
|
+
"aria-disabled": t3,
|
|
72
|
+
"aria-controls": panelId,
|
|
73
|
+
"aria-selected": selected,
|
|
74
|
+
onKeyDown,
|
|
75
|
+
onMouseDown,
|
|
76
|
+
onFocus,
|
|
77
|
+
id,
|
|
78
|
+
role: "tab",
|
|
79
|
+
tabIndex: t4
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
$[12] = id;
|
|
83
|
+
$[13] = onFocus;
|
|
84
|
+
$[14] = onKeyDown;
|
|
85
|
+
$[15] = onMouseDown;
|
|
86
|
+
$[16] = panelId;
|
|
87
|
+
$[17] = selected;
|
|
88
|
+
$[18] = t3;
|
|
89
|
+
$[19] = t4;
|
|
90
|
+
$[20] = t5;
|
|
91
|
+
} else {
|
|
92
|
+
t5 = $[20];
|
|
93
|
+
}
|
|
94
|
+
return t5;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { useTab };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTabList.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/useTabList.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAA;AAEhE,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CA+DlG"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
2
|
+
import { useProvidedRefOrCreate } from '../../hooks/useProvidedRefOrCreate.js';
|
|
3
|
+
|
|
4
|
+
function useTabList(props) {
|
|
5
|
+
const $ = c(9);
|
|
6
|
+
const {
|
|
7
|
+
"aria-label": ariaLabel,
|
|
8
|
+
"aria-labelledby": ariaLabelledby,
|
|
9
|
+
"aria-orientation": ariaOrientation
|
|
10
|
+
} = props;
|
|
11
|
+
const ref = useProvidedRefOrCreate(props.ref);
|
|
12
|
+
let t0;
|
|
13
|
+
if ($[0] !== ariaOrientation || $[1] !== ref) {
|
|
14
|
+
t0 = event => {
|
|
15
|
+
const {
|
|
16
|
+
current: tablist
|
|
17
|
+
} = ref;
|
|
18
|
+
if (tablist === null) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const tabs = getFocusableTabs(tablist);
|
|
22
|
+
const isVertical = ariaOrientation === "vertical";
|
|
23
|
+
const nextKey = isVertical ? "ArrowDown" : "ArrowRight";
|
|
24
|
+
const prevKey = isVertical ? "ArrowUp" : "ArrowLeft";
|
|
25
|
+
if (event.key === nextKey || event.key === prevKey || event.key === "Home" || event.key === "End") {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
}
|
|
29
|
+
if (event.key === nextKey) {
|
|
30
|
+
const selectedTabIndex = tabs.findIndex(_temp);
|
|
31
|
+
if (selectedTabIndex === -1) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const nextTabIndex = (selectedTabIndex + 1) % tabs.length;
|
|
35
|
+
tabs[nextTabIndex].focus();
|
|
36
|
+
} else {
|
|
37
|
+
if (event.key === prevKey) {
|
|
38
|
+
const selectedTabIndex_0 = tabs.findIndex(_temp2);
|
|
39
|
+
if (selectedTabIndex_0 === -1) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const nextTabIndex_0 = (tabs.length + selectedTabIndex_0 - 1) % tabs.length;
|
|
43
|
+
tabs[nextTabIndex_0].focus();
|
|
44
|
+
} else {
|
|
45
|
+
if (event.key === "Home") {
|
|
46
|
+
if (tabs[0]) {
|
|
47
|
+
tabs[0].focus();
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (event.key === "End") {
|
|
51
|
+
if (tabs.length > 0) {
|
|
52
|
+
tabs[tabs.length - 1].focus();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
$[0] = ariaOrientation;
|
|
60
|
+
$[1] = ref;
|
|
61
|
+
$[2] = t0;
|
|
62
|
+
} else {
|
|
63
|
+
t0 = $[2];
|
|
64
|
+
}
|
|
65
|
+
const onKeyDown = t0;
|
|
66
|
+
const t1 = ariaOrientation !== null && ariaOrientation !== void 0 ? ariaOrientation : "horizontal";
|
|
67
|
+
let t2;
|
|
68
|
+
if ($[3] !== ariaLabel || $[4] !== ariaLabelledby || $[5] !== onKeyDown || $[6] !== ref || $[7] !== t1) {
|
|
69
|
+
t2 = {
|
|
70
|
+
tabListProps: {
|
|
71
|
+
ref,
|
|
72
|
+
"aria-label": ariaLabel,
|
|
73
|
+
"aria-labelledby": ariaLabelledby,
|
|
74
|
+
"aria-orientation": t1,
|
|
75
|
+
role: "tablist",
|
|
76
|
+
onKeyDown
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
$[3] = ariaLabel;
|
|
80
|
+
$[4] = ariaLabelledby;
|
|
81
|
+
$[5] = onKeyDown;
|
|
82
|
+
$[6] = ref;
|
|
83
|
+
$[7] = t1;
|
|
84
|
+
$[8] = t2;
|
|
85
|
+
} else {
|
|
86
|
+
t2 = $[8];
|
|
87
|
+
}
|
|
88
|
+
return t2;
|
|
89
|
+
}
|
|
90
|
+
function _temp2(tab_0) {
|
|
91
|
+
return tab_0.getAttribute("aria-selected") === "true";
|
|
92
|
+
}
|
|
93
|
+
function _temp(tab) {
|
|
94
|
+
return tab.getAttribute("aria-selected") === "true";
|
|
95
|
+
}
|
|
96
|
+
function getFocusableTabs(tablist) {
|
|
97
|
+
return Array.from(tablist.querySelectorAll('[role="tab"]:not([aria-disabled])'));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { useTabList };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTabPanel.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/useTabPanel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA;AAG9D,kCAAkC;AAClC,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAe9F"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
2
|
+
import { useTabs } from './useTabs.js';
|
|
3
|
+
|
|
4
|
+
/** Utility hook for tab panels */
|
|
5
|
+
function useTabPanel(props) {
|
|
6
|
+
const $ = c(5);
|
|
7
|
+
const {
|
|
8
|
+
value
|
|
9
|
+
} = props;
|
|
10
|
+
const tabs = useTabs();
|
|
11
|
+
const id = `${tabs.groupId}-panel-${value}`;
|
|
12
|
+
const tabId = `${tabs.groupId}-tab-${value}`;
|
|
13
|
+
const t0 = tabs.selectedValue === value ? "" : undefined;
|
|
14
|
+
const t1 = tabs.selectedValue !== value;
|
|
15
|
+
let t2;
|
|
16
|
+
if ($[0] !== id || $[1] !== t0 || $[2] !== t1 || $[3] !== tabId) {
|
|
17
|
+
t2 = {
|
|
18
|
+
tabPanelProps: {
|
|
19
|
+
"aria-labelledby": tabId,
|
|
20
|
+
"data-selected": t0,
|
|
21
|
+
id,
|
|
22
|
+
hidden: t1,
|
|
23
|
+
role: "tabpanel"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
$[0] = id;
|
|
27
|
+
$[1] = t0;
|
|
28
|
+
$[2] = t1;
|
|
29
|
+
$[3] = tabId;
|
|
30
|
+
$[4] = t2;
|
|
31
|
+
} else {
|
|
32
|
+
t2 = $[4];
|
|
33
|
+
}
|
|
34
|
+
return t2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { useTabPanel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTabs.d.ts","sourceRoot":"","sources":["../../../src/experimental/Tabs/useTabs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAA;AAE7C,wBAAgB,OAAO,IAAI,gBAAgB,CAM1C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { TabsContext } from './TabsContext.js';
|
|
3
|
+
|
|
4
|
+
function useTabs() {
|
|
5
|
+
const context = useContext(TabsContext);
|
|
6
|
+
if (context) {
|
|
7
|
+
return context;
|
|
8
|
+
}
|
|
9
|
+
throw new Error("Component must be used within a <Tabs> component");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useTabs };
|