@a11y-core/react 0.1.0-alpha.0
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/README.md +252 -0
- package/dist/chunk-3WBTHTVK.js +41 -0
- package/dist/chunk-3WBTHTVK.js.map +1 -0
- package/dist/chunk-47MFBHV6.js +85 -0
- package/dist/chunk-47MFBHV6.js.map +1 -0
- package/dist/chunk-7A3IDIUB.cjs +89 -0
- package/dist/chunk-7A3IDIUB.cjs.map +1 -0
- package/dist/chunk-AZFZWGI6.cjs +383 -0
- package/dist/chunk-AZFZWGI6.cjs.map +1 -0
- package/dist/chunk-CTW5D77X.cjs +220 -0
- package/dist/chunk-CTW5D77X.cjs.map +1 -0
- package/dist/chunk-EY73HQNR.js +380 -0
- package/dist/chunk-EY73HQNR.js.map +1 -0
- package/dist/chunk-FJABCNFE.js +215 -0
- package/dist/chunk-FJABCNFE.js.map +1 -0
- package/dist/chunk-FTZ5KCOO.js +326 -0
- package/dist/chunk-FTZ5KCOO.js.map +1 -0
- package/dist/chunk-GS3H4T2O.cjs +106 -0
- package/dist/chunk-GS3H4T2O.cjs.map +1 -0
- package/dist/chunk-N6L4GLFC.cjs +45 -0
- package/dist/chunk-N6L4GLFC.cjs.map +1 -0
- package/dist/chunk-N774QCHE.js +234 -0
- package/dist/chunk-N774QCHE.js.map +1 -0
- package/dist/chunk-OSHIYZCZ.cjs +386 -0
- package/dist/chunk-OSHIYZCZ.cjs.map +1 -0
- package/dist/chunk-SRJSGDIA.js +373 -0
- package/dist/chunk-SRJSGDIA.js.map +1 -0
- package/dist/chunk-THB5U7YC.cjs +338 -0
- package/dist/chunk-THB5U7YC.cjs.map +1 -0
- package/dist/chunk-U6DUSMEA.js +99 -0
- package/dist/chunk-U6DUSMEA.js.map +1 -0
- package/dist/chunk-WDCYEMBO.cjs +245 -0
- package/dist/chunk-WDCYEMBO.cjs.map +1 -0
- package/dist/components/combobox/index.cjs +31 -0
- package/dist/components/combobox/index.cjs.map +1 -0
- package/dist/components/combobox/index.d.cts +55 -0
- package/dist/components/combobox/index.d.ts +55 -0
- package/dist/components/combobox/index.js +6 -0
- package/dist/components/combobox/index.js.map +1 -0
- package/dist/components/dialog/index.cjs +46 -0
- package/dist/components/dialog/index.cjs.map +1 -0
- package/dist/components/dialog/index.d.cts +84 -0
- package/dist/components/dialog/index.d.ts +84 -0
- package/dist/components/dialog/index.js +5 -0
- package/dist/components/dialog/index.js.map +1 -0
- package/dist/components/menu/index.cjs +46 -0
- package/dist/components/menu/index.cjs.map +1 -0
- package/dist/components/menu/index.d.cts +80 -0
- package/dist/components/menu/index.d.ts +80 -0
- package/dist/components/menu/index.js +5 -0
- package/dist/components/menu/index.js.map +1 -0
- package/dist/components/tabs/index.cjs +35 -0
- package/dist/components/tabs/index.cjs.map +1 -0
- package/dist/components/tabs/index.d.cts +65 -0
- package/dist/components/tabs/index.d.ts +65 -0
- package/dist/components/tabs/index.js +6 -0
- package/dist/components/tabs/index.js.map +1 -0
- package/dist/components/toast/index.cjs +24 -0
- package/dist/components/toast/index.cjs.map +1 -0
- package/dist/components/toast/index.d.cts +49 -0
- package/dist/components/toast/index.d.ts +49 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/index.js.map +1 -0
- package/dist/index.cjs +698 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +402 -0
- package/dist/index.d.ts +402 -0
- package/dist/index.js +426 -0
- package/dist/index.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { useAnnouncer } from './chunk-47MFBHV6.js';
|
|
2
|
+
import { useKeyboard } from './chunk-U6DUSMEA.js';
|
|
3
|
+
import { useId } from './chunk-3WBTHTVK.js';
|
|
4
|
+
import React, { createContext, forwardRef, useState, useRef, useCallback, useContext } from 'react';
|
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var TabsContext = createContext(null);
|
|
8
|
+
function useTabsContext() {
|
|
9
|
+
const context = useContext(TabsContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Tabs compound components must be used within a Tabs component"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
var TabsProvider = TabsContext.Provider;
|
|
18
|
+
var Tabs = forwardRef(function Tabs2({
|
|
19
|
+
defaultValue = "",
|
|
20
|
+
value: controlledValue,
|
|
21
|
+
onValueChange,
|
|
22
|
+
orientation = "horizontal",
|
|
23
|
+
activationMode = "automatic",
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
26
|
+
}, ref) {
|
|
27
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
28
|
+
const selectedValue = controlledValue ?? uncontrolledValue;
|
|
29
|
+
const tabsRef = useRef([]);
|
|
30
|
+
const baseId = useId("tabs");
|
|
31
|
+
const setSelectedValue = useCallback(
|
|
32
|
+
(value) => {
|
|
33
|
+
if (controlledValue === void 0) {
|
|
34
|
+
setUncontrolledValue(value);
|
|
35
|
+
}
|
|
36
|
+
onValueChange?.(value);
|
|
37
|
+
},
|
|
38
|
+
[controlledValue, onValueChange]
|
|
39
|
+
);
|
|
40
|
+
const registerTab = useCallback((value) => {
|
|
41
|
+
if (!tabsRef.current.includes(value)) {
|
|
42
|
+
tabsRef.current.push(value);
|
|
43
|
+
}
|
|
44
|
+
}, []);
|
|
45
|
+
const unregisterTab = useCallback((value) => {
|
|
46
|
+
const index = tabsRef.current.indexOf(value);
|
|
47
|
+
if (index > -1) {
|
|
48
|
+
tabsRef.current.splice(index, 1);
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
const getTabValues = useCallback(() => [...tabsRef.current], []);
|
|
52
|
+
const contextValue = {
|
|
53
|
+
selectedValue,
|
|
54
|
+
setSelectedValue,
|
|
55
|
+
baseId,
|
|
56
|
+
orientation,
|
|
57
|
+
activationMode,
|
|
58
|
+
registerTab,
|
|
59
|
+
unregisterTab,
|
|
60
|
+
getTabValues
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsx(TabsProvider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
ref,
|
|
66
|
+
"data-orientation": orientation,
|
|
67
|
+
"data-a11y-core-tabs": true,
|
|
68
|
+
...props,
|
|
69
|
+
children
|
|
70
|
+
}
|
|
71
|
+
) });
|
|
72
|
+
});
|
|
73
|
+
var TabList = forwardRef(
|
|
74
|
+
function TabList2({ children, "aria-label": ariaLabel, onKeyDown, ...props }, ref) {
|
|
75
|
+
const {
|
|
76
|
+
orientation,
|
|
77
|
+
selectedValue,
|
|
78
|
+
setSelectedValue,
|
|
79
|
+
getTabValues,
|
|
80
|
+
activationMode
|
|
81
|
+
} = useTabsContext();
|
|
82
|
+
const navigateToTab = useCallback(
|
|
83
|
+
(direction) => {
|
|
84
|
+
const values = getTabValues();
|
|
85
|
+
if (values.length === 0) return;
|
|
86
|
+
const currentIndex = values.indexOf(selectedValue);
|
|
87
|
+
let newIndex;
|
|
88
|
+
switch (direction) {
|
|
89
|
+
case "next":
|
|
90
|
+
newIndex = (currentIndex + 1) % values.length;
|
|
91
|
+
break;
|
|
92
|
+
case "previous":
|
|
93
|
+
newIndex = (currentIndex - 1 + values.length) % values.length;
|
|
94
|
+
break;
|
|
95
|
+
case "first":
|
|
96
|
+
newIndex = 0;
|
|
97
|
+
break;
|
|
98
|
+
case "last":
|
|
99
|
+
newIndex = values.length - 1;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const newValue = values[newIndex];
|
|
103
|
+
if (newValue) {
|
|
104
|
+
const tabElement = document.querySelector(
|
|
105
|
+
`[data-a11y-core-tab][data-value="${newValue}"]`
|
|
106
|
+
);
|
|
107
|
+
tabElement?.focus();
|
|
108
|
+
if (activationMode === "automatic") {
|
|
109
|
+
setSelectedValue(newValue);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
[getTabValues, selectedValue, setSelectedValue, activationMode]
|
|
114
|
+
);
|
|
115
|
+
const keyboardProps = useKeyboard(
|
|
116
|
+
{
|
|
117
|
+
ArrowRight: () => {
|
|
118
|
+
if (orientation === "horizontal") navigateToTab("next");
|
|
119
|
+
},
|
|
120
|
+
ArrowLeft: () => {
|
|
121
|
+
if (orientation === "horizontal") navigateToTab("previous");
|
|
122
|
+
},
|
|
123
|
+
ArrowDown: () => {
|
|
124
|
+
if (orientation === "vertical") navigateToTab("next");
|
|
125
|
+
},
|
|
126
|
+
ArrowUp: () => {
|
|
127
|
+
if (orientation === "vertical") navigateToTab("previous");
|
|
128
|
+
},
|
|
129
|
+
Home: () => navigateToTab("first"),
|
|
130
|
+
End: () => navigateToTab("last")
|
|
131
|
+
},
|
|
132
|
+
{ preventDefault: true }
|
|
133
|
+
);
|
|
134
|
+
const handleKeyDown = (event) => {
|
|
135
|
+
onKeyDown?.(event);
|
|
136
|
+
if (!event.defaultPrevented) {
|
|
137
|
+
keyboardProps.onKeyDown(event);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
ref,
|
|
144
|
+
role: "tablist",
|
|
145
|
+
"aria-label": ariaLabel,
|
|
146
|
+
"aria-orientation": orientation,
|
|
147
|
+
onKeyDown: handleKeyDown,
|
|
148
|
+
"data-a11y-core-tablist": true,
|
|
149
|
+
...props,
|
|
150
|
+
children
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
var Tab = forwardRef(function Tab2({ value, disabled = false, children, onClick, ...props }, ref) {
|
|
156
|
+
const {
|
|
157
|
+
selectedValue,
|
|
158
|
+
setSelectedValue,
|
|
159
|
+
baseId,
|
|
160
|
+
registerTab,
|
|
161
|
+
unregisterTab
|
|
162
|
+
} = useTabsContext();
|
|
163
|
+
const { announce } = useAnnouncer();
|
|
164
|
+
React.useEffect(() => {
|
|
165
|
+
registerTab(value);
|
|
166
|
+
return () => unregisterTab(value);
|
|
167
|
+
}, [value, registerTab, unregisterTab]);
|
|
168
|
+
const isSelected = selectedValue === value;
|
|
169
|
+
const tabId = `${baseId}-tab-${value}`;
|
|
170
|
+
const panelId = `${baseId}-panel-${value}`;
|
|
171
|
+
const handleClick = (event) => {
|
|
172
|
+
onClick?.(event);
|
|
173
|
+
if (!event.defaultPrevented && !disabled) {
|
|
174
|
+
setSelectedValue(value);
|
|
175
|
+
announce(`${value} tab selected`);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
return /* @__PURE__ */ jsx(
|
|
179
|
+
"button",
|
|
180
|
+
{
|
|
181
|
+
ref,
|
|
182
|
+
type: "button",
|
|
183
|
+
role: "tab",
|
|
184
|
+
id: tabId,
|
|
185
|
+
"aria-selected": isSelected,
|
|
186
|
+
"aria-controls": panelId,
|
|
187
|
+
"aria-disabled": disabled,
|
|
188
|
+
tabIndex: isSelected ? 0 : -1,
|
|
189
|
+
onClick: handleClick,
|
|
190
|
+
disabled,
|
|
191
|
+
"data-selected": isSelected,
|
|
192
|
+
"data-disabled": disabled,
|
|
193
|
+
"data-value": value,
|
|
194
|
+
"data-a11y-core-tab": true,
|
|
195
|
+
...props,
|
|
196
|
+
children
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
var TabPanel = forwardRef(
|
|
201
|
+
function TabPanel2({ value, forceMount = false, children, ...props }, ref) {
|
|
202
|
+
const { selectedValue, baseId } = useTabsContext();
|
|
203
|
+
const isSelected = selectedValue === value;
|
|
204
|
+
const tabId = `${baseId}-tab-${value}`;
|
|
205
|
+
const panelId = `${baseId}-panel-${value}`;
|
|
206
|
+
if (!isSelected && !forceMount) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return /* @__PURE__ */ jsx(
|
|
210
|
+
"div",
|
|
211
|
+
{
|
|
212
|
+
ref,
|
|
213
|
+
role: "tabpanel",
|
|
214
|
+
id: panelId,
|
|
215
|
+
"aria-labelledby": tabId,
|
|
216
|
+
tabIndex: 0,
|
|
217
|
+
hidden: !isSelected,
|
|
218
|
+
"data-selected": isSelected,
|
|
219
|
+
"data-a11y-core-tabpanel": true,
|
|
220
|
+
...props,
|
|
221
|
+
children
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
var TabsCompound = Object.assign(Tabs, {
|
|
227
|
+
List: TabList,
|
|
228
|
+
Tab,
|
|
229
|
+
Panel: TabPanel
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
export { Tab, TabList, TabPanel, Tabs, TabsCompound, useTabsContext };
|
|
233
|
+
//# sourceMappingURL=chunk-N774QCHE.js.map
|
|
234
|
+
//# sourceMappingURL=chunk-N774QCHE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/tabs/tabs-context.ts","../src/components/tabs/tabs.tsx"],"names":["Tabs","TabList","Tab","TabPanel"],"mappings":";;;;;;AAqBA,IAAM,WAAA,GAAc,cAAuC,IAAI,CAAA;AAExD,SAAS,cAAA,GAAmC;AACjD,EAAA,MAAM,OAAA,GAAU,WAAW,WAAW,CAAA;AACtC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAEO,IAAM,eAAe,WAAA,CAAY,QAAA;ACTjC,IAAM,IAAA,GAAO,UAAA,CAAsC,SAASA,KAAAA,CACjE;AAAA,EACE,YAAA,GAAe,EAAA;AAAA,EACf,KAAA,EAAO,eAAA;AAAA,EACP,aAAA;AAAA,EACA,WAAA,GAAc,YAAA;AAAA,EACd,cAAA,GAAiB,WAAA;AAAA,EACjB,QAAA;AAAA,EACA,GAAG;AACL,CAAA,EACA,GAAA,EACA;AACA,EAAA,MAAM,CAAC,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ACA,IAAA,EAAK,UAAA;AAAA,QACL,EAAA,EAAI,OAAA;AAAA,QACJ,iBAAA,EAAiB,KAAA;AAAA,QACjB,QAAA,EAAU,CAAA;AAAA,QACV,QAAQ,CAAC,UAAA;AAAA,QACT,eAAA,EAAe,UAAA;AAAA,QACf,yBAAA,EAAuB,IAAA;AAAA,QACtB,GAAG,KAAA;AAAA,QAEH;AAAA;AAAA,KACH;AAAA,EAEJ;AACF;AAEO,IAAM,YAAA,GAAe,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM;AAAA,EAC9C,IAAA,EAAM,OAAA;AAAA,EACN,GAAA;AAAA,EACA,KAAA,EAAO;AACT,CAAC","file":"chunk-N774QCHE.js","sourcesContent":["import { createContext, useContext } from 'react';\n\nexport interface TabsContextValue {\n /** Currently selected tab value */\n selectedValue: string;\n /** Change selected tab */\n setSelectedValue: (value: string) => void;\n /** Base ID for ARIA relationships */\n baseId: string;\n /** Orientation of tabs */\n orientation: 'horizontal' | 'vertical';\n /** Whether tabs are activated on focus or on click */\n activationMode: 'automatic' | 'manual';\n /** Register a tab */\n registerTab: (value: string) => void;\n /** Unregister a tab */\n unregisterTab: (value: string) => void;\n /** Get all tab values */\n getTabValues: () => string[];\n}\n\nconst TabsContext = createContext<TabsContextValue | null>(null);\n\nexport function useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext);\n if (!context) {\n throw new Error(\n 'Tabs compound components must be used within a Tabs component'\n );\n }\n return context;\n}\n\nexport const TabsProvider = TabsContext.Provider;\n","import React, { forwardRef, useCallback, useRef, useState } from 'react';\nimport { useId } from '../../hooks/use-id';\nimport { useKeyboard } from '../../hooks/use-keyboard';\nimport { useAnnouncer } from '../../hooks/use-announcer';\nimport {\n TabsProvider,\n useTabsContext,\n type TabsContextValue,\n} from './tabs-context';\n\nexport interface TabsProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Default selected tab value */\n defaultValue?: string;\n /** Controlled selected value */\n value?: string;\n /** Called when selection changes */\n onValueChange?: (value: string) => void;\n /** Orientation of tabs */\n orientation?: 'horizontal' | 'vertical';\n /** Activation mode */\n activationMode?: 'automatic' | 'manual';\n children: React.ReactNode;\n}\n\nexport const Tabs = forwardRef<HTMLDivElement, TabsProps>(function Tabs(\n {\n defaultValue = '',\n value: controlledValue,\n onValueChange,\n orientation = 'horizontal',\n activationMode = 'automatic',\n children,\n ...props\n },\n ref\n) {\n const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);\n const selectedValue = controlledValue ?? uncontrolledValue;\n const tabsRef = useRef<string[]>([]);\n const baseId = useId('tabs');\n\n const setSelectedValue = useCallback(\n (value: string) => {\n if (controlledValue === undefined) {\n setUncontrolledValue(value);\n }\n onValueChange?.(value);\n },\n [controlledValue, onValueChange]\n );\n\n const registerTab = useCallback((value: string) => {\n if (!tabsRef.current.includes(value)) {\n tabsRef.current.push(value);\n }\n }, []);\n\n const unregisterTab = useCallback((value: string) => {\n const index = tabsRef.current.indexOf(value);\n if (index > -1) {\n tabsRef.current.splice(index, 1);\n }\n }, []);\n\n const getTabValues = useCallback(() => [...tabsRef.current], []);\n\n const contextValue: TabsContextValue = {\n selectedValue,\n setSelectedValue,\n baseId,\n orientation,\n activationMode,\n registerTab,\n unregisterTab,\n getTabValues,\n };\n\n return (\n <TabsProvider value={contextValue}>\n <div\n ref={ref}\n data-orientation={orientation}\n data-a11y-core-tabs\n {...props}\n >\n {children}\n </div>\n </TabsProvider>\n );\n});\n\nexport interface TabListProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Accessible label for the tab list */\n 'aria-label'?: string;\n children: React.ReactNode;\n}\n\nexport const TabList = forwardRef<HTMLDivElement, TabListProps>(\n function TabList(\n { children, 'aria-label': ariaLabel, onKeyDown, ...props },\n ref\n ) {\n const {\n orientation,\n selectedValue,\n setSelectedValue,\n getTabValues,\n activationMode,\n } = useTabsContext();\n\n const navigateToTab = useCallback(\n (direction: 'next' | 'previous' | 'first' | 'last') => {\n const values = getTabValues();\n if (values.length === 0) return;\n\n const currentIndex = values.indexOf(selectedValue);\n let newIndex: number;\n\n switch (direction) {\n case 'next':\n newIndex = (currentIndex + 1) % values.length;\n break;\n case 'previous':\n newIndex = (currentIndex - 1 + values.length) % values.length;\n break;\n case 'first':\n newIndex = 0;\n break;\n case 'last':\n newIndex = values.length - 1;\n break;\n }\n\n const newValue = values[newIndex];\n if (newValue) {\n const tabElement = document.querySelector(\n `[data-a11y-core-tab][data-value=\"${newValue}\"]`\n ) as HTMLElement;\n tabElement?.focus();\n\n if (activationMode === 'automatic') {\n setSelectedValue(newValue);\n }\n }\n },\n [getTabValues, selectedValue, setSelectedValue, activationMode]\n );\n\n const keyboardProps = useKeyboard(\n {\n ArrowRight: () => {\n if (orientation === 'horizontal') navigateToTab('next');\n },\n ArrowLeft: () => {\n if (orientation === 'horizontal') navigateToTab('previous');\n },\n ArrowDown: () => {\n if (orientation === 'vertical') navigateToTab('next');\n },\n ArrowUp: () => {\n if (orientation === 'vertical') navigateToTab('previous');\n },\n Home: () => navigateToTab('first'),\n End: () => navigateToTab('last'),\n },\n { preventDefault: true }\n );\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) {\n keyboardProps.onKeyDown(event);\n }\n };\n\n return (\n <div\n ref={ref}\n role=\"tablist\"\n aria-label={ariaLabel}\n aria-orientation={orientation}\n onKeyDown={handleKeyDown}\n data-a11y-core-tablist\n {...props}\n >\n {children}\n </div>\n );\n }\n);\n\nexport interface TabProps extends Omit<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n 'value'\n> {\n /** Value identifying this tab */\n value: string;\n /** Whether the tab is disabled */\n disabled?: boolean;\n children: React.ReactNode;\n}\n\nexport const Tab = forwardRef<HTMLButtonElement, TabProps>(function Tab(\n { value, disabled = false, children, onClick, ...props },\n ref\n) {\n const {\n selectedValue,\n setSelectedValue,\n baseId,\n registerTab,\n unregisterTab,\n } = useTabsContext();\n const { announce } = useAnnouncer();\n\n React.useEffect(() => {\n registerTab(value);\n return () => unregisterTab(value);\n }, [value, registerTab, unregisterTab]);\n\n const isSelected = selectedValue === value;\n const tabId = `${baseId}-tab-${value}`;\n const panelId = `${baseId}-panel-${value}`;\n\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (!event.defaultPrevented && !disabled) {\n setSelectedValue(value);\n announce(`${value} tab selected`);\n }\n };\n\n return (\n <button\n ref={ref}\n type=\"button\"\n role=\"tab\"\n id={tabId}\n aria-selected={isSelected}\n aria-controls={panelId}\n aria-disabled={disabled}\n tabIndex={isSelected ? 0 : -1}\n onClick={handleClick}\n disabled={disabled}\n data-selected={isSelected}\n data-disabled={disabled}\n data-value={value}\n data-a11y-core-tab\n {...props}\n >\n {children}\n </button>\n );\n});\n\nexport interface TabPanelProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Value identifying this panel (must match a Tab value) */\n value: string;\n /** Whether to keep panel mounted when not selected */\n forceMount?: boolean;\n children: React.ReactNode;\n}\n\nexport const TabPanel = forwardRef<HTMLDivElement, TabPanelProps>(\n function TabPanel({ value, forceMount = false, children, ...props }, ref) {\n const { selectedValue, baseId } = useTabsContext();\n\n const isSelected = selectedValue === value;\n const tabId = `${baseId}-tab-${value}`;\n const panelId = `${baseId}-panel-${value}`;\n\n if (!isSelected && !forceMount) {\n return null;\n }\n\n return (\n <div\n ref={ref}\n role=\"tabpanel\"\n id={panelId}\n aria-labelledby={tabId}\n tabIndex={0}\n hidden={!isSelected}\n data-selected={isSelected}\n data-a11y-core-tabpanel\n {...props}\n >\n {children}\n </div>\n );\n }\n);\n\nexport const TabsCompound = Object.assign(Tabs, {\n List: TabList,\n Tab: Tab,\n Panel: TabPanel,\n});\n"]}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk7A3IDIUB_cjs = require('./chunk-7A3IDIUB.cjs');
|
|
4
|
+
var chunkGS3H4T2O_cjs = require('./chunk-GS3H4T2O.cjs');
|
|
5
|
+
var chunkN6L4GLFC_cjs = require('./chunk-N6L4GLFC.cjs');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var core = require('@a11y-core/core');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
var warnings = core.createComponentWarnings("Combobox");
|
|
11
|
+
var ComboboxContext = react.createContext(null);
|
|
12
|
+
function useComboboxContext() {
|
|
13
|
+
const context = react.useContext(ComboboxContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"Combobox compound components must be used within a Combobox component"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
function Combobox({
|
|
22
|
+
options,
|
|
23
|
+
value: controlledValue,
|
|
24
|
+
onValueChange,
|
|
25
|
+
onInputChange,
|
|
26
|
+
defaultInputValue = "",
|
|
27
|
+
disabled = false,
|
|
28
|
+
filterFn,
|
|
29
|
+
"aria-label": ariaLabel,
|
|
30
|
+
"aria-labelledby": ariaLabelledBy,
|
|
31
|
+
children
|
|
32
|
+
}) {
|
|
33
|
+
const [inputValue, setInputValueState] = react.useState(defaultInputValue);
|
|
34
|
+
const [selectedValue, setSelectedValueState] = react.useState(
|
|
35
|
+
controlledValue ?? null
|
|
36
|
+
);
|
|
37
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
38
|
+
const [highlightedIndex, setHighlightedIndex] = react.useState(-1);
|
|
39
|
+
const inputId = chunkN6L4GLFC_cjs.useId("combobox-input");
|
|
40
|
+
const listboxId = chunkN6L4GLFC_cjs.useId("combobox-listbox");
|
|
41
|
+
const baseOptionId = chunkN6L4GLFC_cjs.useId("combobox-option");
|
|
42
|
+
react.useEffect(() => {
|
|
43
|
+
if (controlledValue !== void 0) {
|
|
44
|
+
setSelectedValueState(controlledValue);
|
|
45
|
+
const option = options.find((o) => o.value === controlledValue);
|
|
46
|
+
if (option) {
|
|
47
|
+
setInputValueState(option.label);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, [controlledValue, options]);
|
|
51
|
+
const setInputValue = react.useCallback(
|
|
52
|
+
(value) => {
|
|
53
|
+
setInputValueState(value);
|
|
54
|
+
onInputChange?.(value);
|
|
55
|
+
},
|
|
56
|
+
[onInputChange]
|
|
57
|
+
);
|
|
58
|
+
const setSelectedValue = react.useCallback(
|
|
59
|
+
(value) => {
|
|
60
|
+
if (controlledValue === void 0) {
|
|
61
|
+
setSelectedValueState(value);
|
|
62
|
+
}
|
|
63
|
+
onValueChange?.(value);
|
|
64
|
+
},
|
|
65
|
+
[controlledValue, onValueChange]
|
|
66
|
+
);
|
|
67
|
+
const filteredOptions = react.useMemo(() => {
|
|
68
|
+
if (!inputValue) return options;
|
|
69
|
+
const defaultFilter = (opt, input) => opt.label.toLowerCase().includes(input.toLowerCase());
|
|
70
|
+
const filter = filterFn ?? defaultFilter;
|
|
71
|
+
return options.filter((opt) => filter(opt, inputValue));
|
|
72
|
+
}, [options, inputValue, filterFn]);
|
|
73
|
+
const getOptionId = react.useCallback(
|
|
74
|
+
(index) => `${baseOptionId}-${index}`,
|
|
75
|
+
[baseOptionId]
|
|
76
|
+
);
|
|
77
|
+
const onSelect = react.useCallback(
|
|
78
|
+
(option) => {
|
|
79
|
+
setSelectedValue(option.value);
|
|
80
|
+
setInputValue(option.label);
|
|
81
|
+
setIsOpen(false);
|
|
82
|
+
setHighlightedIndex(-1);
|
|
83
|
+
},
|
|
84
|
+
[setSelectedValue, setInputValue]
|
|
85
|
+
);
|
|
86
|
+
react.useEffect(() => {
|
|
87
|
+
if (!ariaLabel && !ariaLabelledBy) {
|
|
88
|
+
warnings.warning(
|
|
89
|
+
"Combobox has no accessible label.",
|
|
90
|
+
"Add aria-label or aria-labelledby prop."
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}, [ariaLabel, ariaLabelledBy]);
|
|
94
|
+
const contextValue = {
|
|
95
|
+
inputValue,
|
|
96
|
+
setInputValue,
|
|
97
|
+
selectedValue,
|
|
98
|
+
setSelectedValue,
|
|
99
|
+
isOpen,
|
|
100
|
+
setIsOpen,
|
|
101
|
+
highlightedIndex,
|
|
102
|
+
setHighlightedIndex,
|
|
103
|
+
options,
|
|
104
|
+
filteredOptions,
|
|
105
|
+
inputId,
|
|
106
|
+
listboxId,
|
|
107
|
+
getOptionId,
|
|
108
|
+
onSelect
|
|
109
|
+
};
|
|
110
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComboboxContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx("div", { "data-a11y-core-combobox": true, "data-disabled": disabled, children }) });
|
|
111
|
+
}
|
|
112
|
+
var ComboboxInput = react.forwardRef(
|
|
113
|
+
function ComboboxInput2({ clearable = false, onKeyDown, onFocus, onBlur, ...props }, ref) {
|
|
114
|
+
const {
|
|
115
|
+
inputValue,
|
|
116
|
+
setInputValue,
|
|
117
|
+
setSelectedValue,
|
|
118
|
+
isOpen,
|
|
119
|
+
setIsOpen,
|
|
120
|
+
highlightedIndex,
|
|
121
|
+
setHighlightedIndex,
|
|
122
|
+
filteredOptions,
|
|
123
|
+
inputId,
|
|
124
|
+
listboxId,
|
|
125
|
+
getOptionId,
|
|
126
|
+
onSelect
|
|
127
|
+
} = useComboboxContext();
|
|
128
|
+
const { announce } = chunk7A3IDIUB_cjs.useAnnouncer();
|
|
129
|
+
const keyboardProps = chunkGS3H4T2O_cjs.useKeyboard(
|
|
130
|
+
{
|
|
131
|
+
ArrowDown: () => {
|
|
132
|
+
if (!isOpen) {
|
|
133
|
+
setIsOpen(true);
|
|
134
|
+
setHighlightedIndex(0);
|
|
135
|
+
} else {
|
|
136
|
+
const nextIndex = (highlightedIndex + 1) % filteredOptions.length;
|
|
137
|
+
setHighlightedIndex(nextIndex);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
ArrowUp: () => {
|
|
141
|
+
if (!isOpen) {
|
|
142
|
+
setIsOpen(true);
|
|
143
|
+
setHighlightedIndex(filteredOptions.length - 1);
|
|
144
|
+
} else {
|
|
145
|
+
const prevIndex = (highlightedIndex - 1 + filteredOptions.length) % filteredOptions.length;
|
|
146
|
+
setHighlightedIndex(prevIndex);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
Enter: () => {
|
|
150
|
+
if (isOpen && highlightedIndex >= 0) {
|
|
151
|
+
const option = filteredOptions[highlightedIndex];
|
|
152
|
+
if (option && !option.disabled) {
|
|
153
|
+
onSelect(option);
|
|
154
|
+
announce(`${option.label} selected`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
Escape: () => {
|
|
159
|
+
if (isOpen) {
|
|
160
|
+
setIsOpen(false);
|
|
161
|
+
setHighlightedIndex(-1);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
Tab: () => {
|
|
165
|
+
if (isOpen) {
|
|
166
|
+
setIsOpen(false);
|
|
167
|
+
setHighlightedIndex(-1);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
},
|
|
171
|
+
Home: () => {
|
|
172
|
+
if (isOpen) {
|
|
173
|
+
setHighlightedIndex(0);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
End: () => {
|
|
177
|
+
if (isOpen) {
|
|
178
|
+
setHighlightedIndex(filteredOptions.length - 1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{ preventDefault: true, stopPropagation: false }
|
|
183
|
+
);
|
|
184
|
+
const handleKeyDown = (event) => {
|
|
185
|
+
onKeyDown?.(event);
|
|
186
|
+
if (!event.defaultPrevented) {
|
|
187
|
+
keyboardProps.onKeyDown(event);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const handleChange = (event) => {
|
|
191
|
+
const value = event.target.value;
|
|
192
|
+
setInputValue(value);
|
|
193
|
+
setIsOpen(true);
|
|
194
|
+
setHighlightedIndex(0);
|
|
195
|
+
if (value === "") {
|
|
196
|
+
setSelectedValue(null);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const handleFocus = (event) => {
|
|
200
|
+
onFocus?.(event);
|
|
201
|
+
setIsOpen(true);
|
|
202
|
+
};
|
|
203
|
+
const handleBlur = (event) => {
|
|
204
|
+
onBlur?.(event);
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
setIsOpen(false);
|
|
207
|
+
}, 150);
|
|
208
|
+
};
|
|
209
|
+
const handleClear = () => {
|
|
210
|
+
setInputValue("");
|
|
211
|
+
setSelectedValue(null);
|
|
212
|
+
setIsOpen(false);
|
|
213
|
+
};
|
|
214
|
+
const activeDescendant = isOpen && highlightedIndex >= 0 ? getOptionId(highlightedIndex) : void 0;
|
|
215
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-a11y-core-combobox-input-wrapper": true, children: [
|
|
216
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
217
|
+
"input",
|
|
218
|
+
{
|
|
219
|
+
ref,
|
|
220
|
+
id: inputId,
|
|
221
|
+
type: "text",
|
|
222
|
+
role: "combobox",
|
|
223
|
+
value: inputValue,
|
|
224
|
+
onChange: handleChange,
|
|
225
|
+
onKeyDown: handleKeyDown,
|
|
226
|
+
onFocus: handleFocus,
|
|
227
|
+
onBlur: handleBlur,
|
|
228
|
+
"aria-expanded": isOpen,
|
|
229
|
+
"aria-controls": listboxId,
|
|
230
|
+
"aria-activedescendant": activeDescendant,
|
|
231
|
+
"aria-autocomplete": "list",
|
|
232
|
+
"aria-haspopup": "listbox",
|
|
233
|
+
autoComplete: "off",
|
|
234
|
+
"data-a11y-core-combobox-input": true,
|
|
235
|
+
...props
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
clearable && inputValue && /* @__PURE__ */ jsxRuntime.jsx(
|
|
239
|
+
"button",
|
|
240
|
+
{
|
|
241
|
+
type: "button",
|
|
242
|
+
onClick: handleClear,
|
|
243
|
+
"aria-label": "Clear selection",
|
|
244
|
+
tabIndex: -1,
|
|
245
|
+
"data-a11y-core-combobox-clear": true,
|
|
246
|
+
children: "\xD7"
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
] });
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
var ComboboxListbox = react.forwardRef(function ComboboxListbox2({ emptyMessage = "No results found", children, style, ...props }, forwardedRef) {
|
|
253
|
+
const { isOpen, filteredOptions, listboxId, inputId } = useComboboxContext();
|
|
254
|
+
const { announce } = chunk7A3IDIUB_cjs.useAnnouncer();
|
|
255
|
+
const internalRef = react.useRef(null);
|
|
256
|
+
const [position, setPosition] = react.useState("bottom");
|
|
257
|
+
react.useEffect(() => {
|
|
258
|
+
if (isOpen) {
|
|
259
|
+
const count = filteredOptions.length;
|
|
260
|
+
announce(
|
|
261
|
+
count === 0 ? "No results" : `${count} result${count === 1 ? "" : "s"} available`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}, [isOpen, filteredOptions.length, announce]);
|
|
265
|
+
react.useLayoutEffect(() => {
|
|
266
|
+
if (isOpen && internalRef.current) {
|
|
267
|
+
const listbox = internalRef.current;
|
|
268
|
+
const rect = listbox.getBoundingClientRect();
|
|
269
|
+
const viewportHeight = window.innerHeight;
|
|
270
|
+
const spaceBelow = viewportHeight - rect.top;
|
|
271
|
+
const spaceAbove = rect.top;
|
|
272
|
+
const listboxHeight = Math.min(rect.height, 200);
|
|
273
|
+
if (spaceBelow < listboxHeight + 50 && spaceAbove > spaceBelow) {
|
|
274
|
+
setPosition("top");
|
|
275
|
+
} else {
|
|
276
|
+
setPosition("bottom");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}, [isOpen]);
|
|
280
|
+
const setRefs = react.useCallback(
|
|
281
|
+
(node) => {
|
|
282
|
+
internalRef.current = node;
|
|
283
|
+
if (typeof forwardedRef === "function") {
|
|
284
|
+
forwardedRef(node);
|
|
285
|
+
} else if (forwardedRef) {
|
|
286
|
+
forwardedRef.current = node;
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
[forwardedRef]
|
|
290
|
+
);
|
|
291
|
+
if (!isOpen) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
const positionStyle = position === "top" ? { bottom: "100%", top: "auto", marginBottom: "4px", marginTop: 0 } : {};
|
|
295
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
296
|
+
"ul",
|
|
297
|
+
{
|
|
298
|
+
ref: setRefs,
|
|
299
|
+
id: listboxId,
|
|
300
|
+
role: "listbox",
|
|
301
|
+
"aria-labelledby": inputId,
|
|
302
|
+
style: { ...style, ...positionStyle },
|
|
303
|
+
"data-a11y-core-combobox-listbox": true,
|
|
304
|
+
"data-position": position,
|
|
305
|
+
...props,
|
|
306
|
+
children: filteredOptions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("li", { role: "presentation", "data-a11y-core-combobox-empty": true, children: emptyMessage }) : children ?? filteredOptions.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(ComboboxOption, { option, index }, option.value))
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
});
|
|
310
|
+
var ComboboxOption = react.forwardRef(
|
|
311
|
+
function ComboboxOption2({ option, index, onClick, onMouseEnter, ...props }, forwardedRef) {
|
|
312
|
+
const {
|
|
313
|
+
selectedValue,
|
|
314
|
+
highlightedIndex,
|
|
315
|
+
setHighlightedIndex,
|
|
316
|
+
getOptionId,
|
|
317
|
+
onSelect
|
|
318
|
+
} = useComboboxContext();
|
|
319
|
+
const internalRef = react.useRef(null);
|
|
320
|
+
const isSelected = selectedValue === option.value;
|
|
321
|
+
const isHighlighted = highlightedIndex === index;
|
|
322
|
+
const optionId = getOptionId(index);
|
|
323
|
+
react.useEffect(() => {
|
|
324
|
+
if (isHighlighted && internalRef.current) {
|
|
325
|
+
internalRef.current.scrollIntoView({
|
|
326
|
+
block: "nearest",
|
|
327
|
+
behavior: "smooth"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}, [isHighlighted]);
|
|
331
|
+
const handleClick = (event) => {
|
|
332
|
+
onClick?.(event);
|
|
333
|
+
if (!event.defaultPrevented && !option.disabled) {
|
|
334
|
+
onSelect(option);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const handleMouseEnter = (event) => {
|
|
338
|
+
onMouseEnter?.(event);
|
|
339
|
+
if (!option.disabled) {
|
|
340
|
+
setHighlightedIndex(index);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const setRefs = react.useCallback(
|
|
344
|
+
(node) => {
|
|
345
|
+
internalRef.current = node;
|
|
346
|
+
if (typeof forwardedRef === "function") {
|
|
347
|
+
forwardedRef(node);
|
|
348
|
+
} else if (forwardedRef) {
|
|
349
|
+
forwardedRef.current = node;
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
[forwardedRef]
|
|
353
|
+
);
|
|
354
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
355
|
+
"li",
|
|
356
|
+
{
|
|
357
|
+
ref: setRefs,
|
|
358
|
+
id: optionId,
|
|
359
|
+
role: "option",
|
|
360
|
+
"aria-selected": isSelected,
|
|
361
|
+
"aria-disabled": option.disabled,
|
|
362
|
+
"data-highlighted": isHighlighted,
|
|
363
|
+
"data-selected": isSelected,
|
|
364
|
+
"data-disabled": option.disabled,
|
|
365
|
+
onClick: handleClick,
|
|
366
|
+
onMouseEnter: handleMouseEnter,
|
|
367
|
+
"data-a11y-core-combobox-option": true,
|
|
368
|
+
...props,
|
|
369
|
+
children: option.label
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
var ComboboxCompound = Object.assign(Combobox, {
|
|
375
|
+
Input: ComboboxInput,
|
|
376
|
+
Listbox: ComboboxListbox,
|
|
377
|
+
Option: ComboboxOption
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
exports.Combobox = Combobox;
|
|
381
|
+
exports.ComboboxCompound = ComboboxCompound;
|
|
382
|
+
exports.ComboboxInput = ComboboxInput;
|
|
383
|
+
exports.ComboboxListbox = ComboboxListbox;
|
|
384
|
+
exports.ComboboxOption = ComboboxOption;
|
|
385
|
+
//# sourceMappingURL=chunk-OSHIYZCZ.cjs.map
|
|
386
|
+
//# sourceMappingURL=chunk-OSHIYZCZ.cjs.map
|