@cerberus-design/react 0.6.1-next-79cd0cd → 0.6.1-next-fb37218
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/build/legacy/_tsup-dts-rollup.d.ts +5 -1
- package/build/legacy/aria-helpers/tabs.aria.js +2 -2
- package/build/legacy/{chunk-YJCWUN33.js → chunk-67S42J4B.js} +5 -16
- package/build/legacy/chunk-67S42J4B.js.map +1 -0
- package/build/{modern/chunk-DQOYTLGB.js → legacy/chunk-7KJIZIAU.js} +9 -5
- package/build/legacy/chunk-7KJIZIAU.js.map +1 -0
- package/build/legacy/chunk-JI4YTPEJ.js +47 -0
- package/build/legacy/chunk-JI4YTPEJ.js.map +1 -0
- package/build/legacy/{chunk-S7HBD2A7.js → chunk-KFUXGX33.js} +2 -2
- package/build/legacy/{chunk-5GSXIYD3.js → chunk-X2JMXTBH.js} +6 -8
- package/build/{modern/chunk-5GSXIYD3.js.map → legacy/chunk-X2JMXTBH.js.map} +1 -1
- package/build/legacy/components/Tab.js +3 -3
- package/build/legacy/components/TabList.js +2 -2
- package/build/legacy/components/TabPanel.js +2 -2
- package/build/legacy/context/tabs.js +1 -1
- package/build/legacy/index.js +5 -5
- package/build/modern/_tsup-dts-rollup.d.ts +5 -1
- package/build/modern/aria-helpers/tabs.aria.js +2 -2
- package/build/modern/{chunk-YJCWUN33.js → chunk-67S42J4B.js} +5 -16
- package/build/modern/chunk-67S42J4B.js.map +1 -0
- package/build/{legacy/chunk-DQOYTLGB.js → modern/chunk-7KJIZIAU.js} +9 -5
- package/build/modern/chunk-7KJIZIAU.js.map +1 -0
- package/build/modern/chunk-HBEEHHON.js +46 -0
- package/build/modern/chunk-HBEEHHON.js.map +1 -0
- package/build/modern/{chunk-S7HBD2A7.js → chunk-KFUXGX33.js} +2 -2
- package/build/modern/{chunk-5GSXIYD3.js → chunk-X2JMXTBH.js} +6 -8
- package/build/{legacy/chunk-5GSXIYD3.js.map → modern/chunk-X2JMXTBH.js.map} +1 -1
- package/build/modern/components/Tab.js +3 -3
- package/build/modern/components/TabList.js +2 -2
- package/build/modern/components/TabPanel.js +2 -2
- package/build/modern/context/tabs.js +1 -1
- package/build/modern/index.js +5 -5
- package/package.json +2 -2
- package/src/components/Tab.tsx +3 -84
- package/src/components/TabList.tsx +2 -4
- package/src/components/TabPanel.tsx +3 -14
- package/src/context/tabs.tsx +15 -5
- package/build/legacy/chunk-DQOYTLGB.js.map +0 -1
- package/build/legacy/chunk-YA2UV2AB.js +0 -126
- package/build/legacy/chunk-YA2UV2AB.js.map +0 -1
- package/build/legacy/chunk-YJCWUN33.js.map +0 -1
- package/build/modern/chunk-DQOYTLGB.js.map +0 -1
- package/build/modern/chunk-SUP7U42W.js +0 -125
- package/build/modern/chunk-SUP7U42W.js.map +0 -1
- package/build/modern/chunk-YJCWUN33.js.map +0 -1
- /package/build/legacy/{chunk-S7HBD2A7.js.map → chunk-KFUXGX33.js.map} +0 -0
- /package/build/modern/{chunk-S7HBD2A7.js.map → chunk-KFUXGX33.js.map} +0 -0
|
@@ -13,6 +13,7 @@ import type { InputHTMLAttributes } from 'react';
|
|
|
13
13
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
14
14
|
import { label } from '@cerberus/styled-system/recipes';
|
|
15
15
|
import { MutableRefObject } from 'react';
|
|
16
|
+
import type { Pretty } from '@cerberus-design/styled-system/types';
|
|
16
17
|
import { PropsWithChildren } from 'react';
|
|
17
18
|
import { radio } from '@cerberus-design/styled-system/recipes';
|
|
18
19
|
import { ReactNode } from 'react';
|
|
@@ -20,6 +21,7 @@ import { RecipeVariantProps } from '@cerberus/styled-system/css';
|
|
|
20
21
|
import type { RecipeVariantProps as RecipeVariantProps_2 } from '@cerberus-design/styled-system/types';
|
|
21
22
|
import type { RecipeVariantProps as RecipeVariantProps_3 } from '@cerberus/styled-system/types';
|
|
22
23
|
import { RefObject } from 'react';
|
|
24
|
+
import { TabsVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
23
25
|
import { tag } from '@cerberus/styled-system/recipes';
|
|
24
26
|
import type { TextareaHTMLAttributes } from 'react';
|
|
25
27
|
import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
@@ -442,6 +444,7 @@ export { TabProps as TabProps_alias_1 }
|
|
|
442
444
|
|
|
443
445
|
/**
|
|
444
446
|
* The Tabs component provides a context to manage tab state.
|
|
447
|
+
* @param id - the id of the tabs component,
|
|
445
448
|
* @param active - the default active tab id,
|
|
446
449
|
* @param cache - whether to cache the active tab state in local storage
|
|
447
450
|
* @example
|
|
@@ -458,7 +461,7 @@ export { TabProps as TabProps_alias_1 }
|
|
|
458
461
|
* </Tabs>
|
|
459
462
|
* ```
|
|
460
463
|
*/
|
|
461
|
-
declare function Tabs(props: PropsWithChildren<TabsProps>): JSX.Element;
|
|
464
|
+
declare function Tabs(props: PropsWithChildren<TabsProps & TabsVariantProps>): JSX.Element;
|
|
462
465
|
export { Tabs }
|
|
463
466
|
export { Tabs as Tabs_alias_1 }
|
|
464
467
|
|
|
@@ -474,6 +477,7 @@ declare interface TabsContextValue {
|
|
|
474
477
|
tabs: MutableRefObject<HTMLButtonElement[]>;
|
|
475
478
|
id: string;
|
|
476
479
|
active: string;
|
|
480
|
+
styles: Pretty<Record<'tabList' | 'tab' | 'tabPanel', string>>;
|
|
477
481
|
onTabUpdate: (active: string) => void;
|
|
478
482
|
}
|
|
479
483
|
export { TabsContextValue }
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
} from "./chunk-4O4QFF4S.js";
|
|
4
4
|
import {
|
|
5
5
|
useTabsContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7KJIZIAU.js";
|
|
7
7
|
|
|
8
8
|
// src/components/TabPanel.tsx
|
|
9
|
-
import {
|
|
9
|
+
import { cx } from "@cerberus/styled-system/css";
|
|
10
10
|
import { useMemo } from "react";
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
12
|
function TabPanel(props) {
|
|
13
13
|
const { tab, ...nativeProps } = props;
|
|
14
|
-
const { active } = useTabsContext();
|
|
14
|
+
const { active, styles } = useTabsContext();
|
|
15
15
|
const isActive = useMemo(() => active === tab, [active, tab]);
|
|
16
16
|
return /* @__PURE__ */ jsx(Show, { when: isActive, children: /* @__PURE__ */ jsx(
|
|
17
17
|
"div",
|
|
@@ -19,18 +19,7 @@ function TabPanel(props) {
|
|
|
19
19
|
...nativeProps,
|
|
20
20
|
...isActive && { tabIndex: 0 },
|
|
21
21
|
"aria-labelledby": tab,
|
|
22
|
-
className: cx(
|
|
23
|
-
nativeProps.className,
|
|
24
|
-
css({
|
|
25
|
-
rounded: "md",
|
|
26
|
-
_focusVisible: {
|
|
27
|
-
boxShadow: "none",
|
|
28
|
-
outline: "3px solid",
|
|
29
|
-
outlineColor: "action.border.focus",
|
|
30
|
-
outlineOffset: "2px"
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
),
|
|
22
|
+
className: cx(nativeProps.className, styles.tabPanel),
|
|
34
23
|
id: `panel:${tab}`,
|
|
35
24
|
role: "tabpanel"
|
|
36
25
|
}
|
|
@@ -40,4 +29,4 @@ function TabPanel(props) {
|
|
|
40
29
|
export {
|
|
41
30
|
TabPanel
|
|
42
31
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-67S42J4B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/TabPanel.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { useMemo, type HTMLAttributes } from 'react'\nimport { useTabsContext } from '../context/tabs'\nimport { Show } from './Show'\n\n/**\n * This module provides a TabPanel component.\n * @module\n */\n\nexport interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {\n tab: string\n}\n\n/**\n * The TabPanel component provides a panel element to be used in a Tabs provider.\n * @param tab - the value of the tab that will be tracked as the active tab and used for aria attributes\n * @example\n * ```tsx\n * <TabPanel tab=\"overview\">\n * Overview content\n * </TabPanel>\n * ```\n */\nexport function TabPanel(props: TabPanelProps) {\n const { tab, ...nativeProps } = props\n const { active, styles } = useTabsContext()\n const isActive = useMemo(() => active === tab, [active, tab])\n\n return (\n <Show when={isActive}>\n <div\n {...nativeProps}\n {...(isActive && { tabIndex: 0 })}\n aria-labelledby={tab}\n className={cx(nativeProps.className, styles.tabPanel)}\n id={`panel:${tab}`}\n role=\"tabpanel\"\n />\n </Show>\n )\n}\n"],"mappings":";;;;;;;;AAEA,SAAS,UAAU;AACnB,SAAS,eAAoC;AA8BvC;AAPC,SAAS,SAAS,OAAsB;AAC7C,QAAM,EAAE,KAAK,GAAG,YAAY,IAAI;AAChC,QAAM,EAAE,QAAQ,OAAO,IAAI,eAAe;AAC1C,QAAM,WAAW,QAAQ,MAAM,WAAW,KAAK,CAAC,QAAQ,GAAG,CAAC;AAE5D,SACE,oBAAC,QAAK,MAAM,UACV;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAI,YAAY,EAAE,UAAU,EAAE;AAAA,MAC/B,mBAAiB;AAAA,MACjB,WAAW,GAAG,YAAY,WAAW,OAAO,QAAQ;AAAA,MACpD,IAAI,SAAS,GAAG;AAAA,MAChB,MAAK;AAAA;AAAA,EACP,GACF;AAEJ;","names":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/context/tabs.tsx
|
|
2
|
+
import {
|
|
3
|
+
tabs
|
|
4
|
+
} from "@cerberus-design/styled-system/recipes";
|
|
2
5
|
import {
|
|
3
6
|
createContext,
|
|
4
7
|
useContext,
|
|
@@ -10,20 +13,21 @@ import {
|
|
|
10
13
|
import { jsx } from "react/jsx-runtime";
|
|
11
14
|
var TabsContext = createContext(null);
|
|
12
15
|
function Tabs(props) {
|
|
13
|
-
const { cache, active, id } = props;
|
|
16
|
+
const { cache, active, id, palette } = props;
|
|
14
17
|
const [activeTab, setActiveTab] = useState(() => cache ? "" : active ?? "");
|
|
15
|
-
const
|
|
18
|
+
const tabsList = useRef([]);
|
|
16
19
|
const uuid = useMemo(() => {
|
|
17
20
|
return id ? `cerberus-tabs-${id}` : "cerberus-tabs";
|
|
18
21
|
}, [id]);
|
|
19
22
|
const value = useMemo(
|
|
20
23
|
() => ({
|
|
21
|
-
tabs,
|
|
24
|
+
tabs: tabsList,
|
|
22
25
|
id: uuid,
|
|
23
26
|
active: activeTab,
|
|
27
|
+
styles: tabs({ palette }),
|
|
24
28
|
onTabUpdate: setActiveTab
|
|
25
29
|
}),
|
|
26
|
-
[activeTab, setActiveTab, uuid,
|
|
30
|
+
[activeTab, setActiveTab, palette, uuid, tabsList]
|
|
27
31
|
);
|
|
28
32
|
useEffect(() => {
|
|
29
33
|
if (cache) {
|
|
@@ -53,4 +57,4 @@ export {
|
|
|
53
57
|
Tabs,
|
|
54
58
|
useTabsContext
|
|
55
59
|
};
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-7KJIZIAU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/tabs.tsx"],"sourcesContent":["'use client'\n\nimport {\n tabs,\n type TabsVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { Pretty } from '@cerberus-design/styled-system/types'\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type MutableRefObject,\n type PropsWithChildren,\n} from 'react'\n\n/**\n * This module provides a Tabs component and a hook to access its context.\n * @module\n */\n\nexport interface TabsContextValue {\n tabs: MutableRefObject<HTMLButtonElement[]>\n id: string\n active: string\n styles: Pretty<Record<'tabList' | 'tab' | 'tabPanel', string>>\n onTabUpdate: (active: string) => void\n}\n\nexport const TabsContext = createContext<TabsContextValue | null>(null)\n\nexport interface TabsProps {\n id?: string\n active?: string\n cache?: boolean\n}\n\n/**\n * The Tabs component provides a context to manage tab state.\n * @param id - the id of the tabs component,\n * @param active - the default active tab id,\n * @param cache - whether to cache the active tab state in local storage\n * @example\n * ```tsx\n * <Tabs cache>\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * <TabPanels>\n * <TabPanel id=\"overview\">Overview content</TabPanel>\n * <TabPanel id=\"guidelines\">Guidelines content</TabPanel>\n * </TabPanels>\n * </Tabs>\n * ```\n */\nexport function Tabs(\n props: PropsWithChildren<TabsProps & TabsVariantProps>,\n): JSX.Element {\n const { cache, active, id, palette } = props\n const [activeTab, setActiveTab] = useState(() => (cache ? '' : active ?? ''))\n const tabsList = useRef<HTMLButtonElement[]>([])\n const uuid = useMemo(() => {\n return id ? `cerberus-tabs-${id}` : 'cerberus-tabs'\n }, [id])\n\n const value = useMemo(\n () => ({\n tabs: tabsList,\n id: uuid,\n active: activeTab,\n styles: tabs({ palette }),\n onTabUpdate: setActiveTab,\n }),\n [activeTab, setActiveTab, palette, uuid, tabsList],\n )\n\n // Get the active tab from local storage\n useEffect(() => {\n if (cache) {\n const cachedTab = window.localStorage.getItem(uuid)\n setActiveTab(\n cache ? cachedTab || (props.active ?? '') : props.active ?? '',\n )\n }\n }, [cache, active, uuid])\n\n // Update the active tab in local storage\n useEffect(() => {\n if (cache && activeTab) {\n window.localStorage.setItem(uuid, activeTab)\n }\n }, [activeTab, cache])\n\n return (\n <TabsContext.Provider value={value}>{props.children}</TabsContext.Provider>\n )\n}\n\nexport function useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext)\n if (!context) {\n throw new Error('useTabsContext must be used within a Tabs Provider.')\n }\n return context\n}\n"],"mappings":";AAEA;AAAA,EACE;AAAA,OAEK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAiFH;AAlEG,IAAM,cAAc,cAAuC,IAAI;AA2B/D,SAAS,KACd,OACa;AACb,QAAM,EAAE,OAAO,QAAQ,IAAI,QAAQ,IAAI;AACvC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,MAAO,QAAQ,KAAK,UAAU,EAAG;AAC5E,QAAM,WAAW,OAA4B,CAAC,CAAC;AAC/C,QAAM,OAAO,QAAQ,MAAM;AACzB,WAAO,KAAK,iBAAiB,EAAE,KAAK;AAAA,EACtC,GAAG,CAAC,EAAE,CAAC;AAEP,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,QAAQ,KAAK,EAAE,QAAQ,CAAC;AAAA,MACxB,aAAa;AAAA,IACf;AAAA,IACA,CAAC,WAAW,cAAc,SAAS,MAAM,QAAQ;AAAA,EACnD;AAGA,YAAU,MAAM;AACd,QAAI,OAAO;AACT,YAAM,YAAY,OAAO,aAAa,QAAQ,IAAI;AAClD;AAAA,QACE,QAAQ,cAAc,MAAM,UAAU,MAAM,MAAM,UAAU;AAAA,MAC9D;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,IAAI,CAAC;AAGxB,YAAU,MAAM;AACd,QAAI,SAAS,WAAW;AACtB,aAAO,aAAa,QAAQ,MAAM,SAAS;AAAA,IAC7C;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAErB,SACE,oBAAC,YAAY,UAAZ,EAAqB,OAAe,gBAAM,UAAS;AAExD;AAEO,SAAS,iBAAmC;AACjD,QAAM,UAAU,WAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTabsKeyboardNavigation
|
|
3
|
+
} from "./chunk-KFUXGX33.js";
|
|
4
|
+
import {
|
|
5
|
+
useTabsContext
|
|
6
|
+
} from "./chunk-7KJIZIAU.js";
|
|
7
|
+
|
|
8
|
+
// src/components/Tab.tsx
|
|
9
|
+
import {
|
|
10
|
+
useMemo,
|
|
11
|
+
useTransition
|
|
12
|
+
} from "react";
|
|
13
|
+
import { cx } from "@cerberus/styled-system/css";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
function Tab(props) {
|
|
16
|
+
const { value, ...nativeProps } = props;
|
|
17
|
+
const { active, onTabUpdate, styles } = useTabsContext();
|
|
18
|
+
const [isPending, startTransition] = useTransition();
|
|
19
|
+
const { ref } = useTabsKeyboardNavigation();
|
|
20
|
+
const isActive = useMemo(() => active === value, [active, value]);
|
|
21
|
+
function handleClick(e) {
|
|
22
|
+
var _a;
|
|
23
|
+
(_a = props.onClick) == null ? void 0 : _a.call(props, e);
|
|
24
|
+
startTransition(() => onTabUpdate(e.currentTarget.value));
|
|
25
|
+
}
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
"button",
|
|
28
|
+
{
|
|
29
|
+
...nativeProps,
|
|
30
|
+
...!isActive && { tabIndex: -1 },
|
|
31
|
+
"aria-controls": `panel:${value}`,
|
|
32
|
+
"aria-busy": isPending,
|
|
33
|
+
"aria-selected": isActive,
|
|
34
|
+
id: value,
|
|
35
|
+
className: cx(nativeProps.className, styles.tab),
|
|
36
|
+
onClick: handleClick,
|
|
37
|
+
role: "tab",
|
|
38
|
+
ref,
|
|
39
|
+
value
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
Tab
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=chunk-JI4YTPEJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/Tab.tsx"],"sourcesContent":["'use client'\n\nimport {\n useMemo,\n useTransition,\n type ButtonHTMLAttributes,\n type MouseEvent,\n} from 'react'\nimport { useTabsContext } from '../context/tabs'\nimport { cx } from '@cerberus/styled-system/css'\nimport { useTabsKeyboardNavigation } from '../aria-helpers/tabs.aria'\n\n/**\n * This module provides a Tab component.\n * @module\n */\nexport interface TabProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n value: string\n}\n\n/**\n * The Tab component provides a tab element to be used in a TabList.\n * @definition [ARIA Target Size](https://www.w3.org/WAI/WCAG21/Understanding/target-size.html#:~:text=Understanding%20SC%202.5.,%3ATarget%20Size%20(Level%20AAA)&text=The%20size%20of%20the%20target,Equivalent)\n * @definition [Tab docs](https://cerberus.digitalu.design/react/tabs)\n * @param value - the id of the tab that will be tracked as the active tab and used for aria attributes\n * @example\n * ```tsx\n * <Tab value=\"overview\">\n * Overview\n * </Tab>\n * ```\n */\nexport function Tab(props: TabProps) {\n const { value, ...nativeProps } = props\n const { active, onTabUpdate, styles } = useTabsContext()\n const [isPending, startTransition] = useTransition()\n const { ref } = useTabsKeyboardNavigation()\n const isActive = useMemo(() => active === value, [active, value])\n\n function handleClick(e: MouseEvent<HTMLButtonElement>) {\n props.onClick?.(e)\n startTransition(() => onTabUpdate(e.currentTarget.value))\n }\n\n return (\n <button\n {...nativeProps}\n {...(!isActive && { tabIndex: -1 })}\n aria-controls={`panel:${value}`}\n aria-busy={isPending}\n aria-selected={isActive}\n id={value}\n className={cx(nativeProps.className, styles.tab)}\n onClick={handleClick}\n role=\"tab\"\n ref={ref}\n value={value}\n />\n )\n}\n"],"mappings":";;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,UAAU;AAoCf;AAbG,SAAS,IAAI,OAAiB;AACnC,QAAM,EAAE,OAAO,GAAG,YAAY,IAAI;AAClC,QAAM,EAAE,QAAQ,aAAa,OAAO,IAAI,eAAe;AACvD,QAAM,CAAC,WAAW,eAAe,IAAI,cAAc;AACnD,QAAM,EAAE,IAAI,IAAI,0BAA0B;AAC1C,QAAM,WAAW,QAAQ,MAAM,WAAW,OAAO,CAAC,QAAQ,KAAK,CAAC;AAEhE,WAAS,YAAY,GAAkC;AAvCzD;AAwCI,gBAAM,YAAN,+BAAgB;AAChB,oBAAgB,MAAM,YAAY,EAAE,cAAc,KAAK,CAAC;AAAA,EAC1D;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAI,CAAC,YAAY,EAAE,UAAU,GAAG;AAAA,MACjC,iBAAe,SAAS,KAAK;AAAA,MAC7B,aAAW;AAAA,MACX,iBAAe;AAAA,MACf,IAAI;AAAA,MACJ,WAAW,GAAG,YAAY,WAAW,OAAO,GAAG;AAAA,MAC/C,SAAS;AAAA,MACT,MAAK;AAAA,MACL;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useTabsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7KJIZIAU.js";
|
|
4
4
|
|
|
5
5
|
// src/aria-helpers/tabs.aria.ts
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
@@ -61,4 +61,4 @@ function useTabsKeyboardNavigation() {
|
|
|
61
61
|
export {
|
|
62
62
|
useTabsKeyboardNavigation
|
|
63
63
|
};
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-KFUXGX33.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useTabsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7KJIZIAU.js";
|
|
4
4
|
|
|
5
5
|
// src/components/TabList.tsx
|
|
6
6
|
import { cx } from "@cerberus/styled-system/css";
|
|
@@ -8,7 +8,7 @@ import { hstack } from "@cerberus/styled-system/patterns";
|
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
function TabList(props) {
|
|
10
10
|
const { description, ...nativeProps } = props;
|
|
11
|
-
const { id } = useTabsContext();
|
|
11
|
+
const { id, styles } = useTabsContext();
|
|
12
12
|
return /* @__PURE__ */ jsx(
|
|
13
13
|
"div",
|
|
14
14
|
{
|
|
@@ -17,11 +17,9 @@ function TabList(props) {
|
|
|
17
17
|
className: cx(
|
|
18
18
|
nativeProps.className,
|
|
19
19
|
hstack({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
w: "full"
|
|
24
|
-
})
|
|
20
|
+
gap: "0"
|
|
21
|
+
}),
|
|
22
|
+
styles.tabList
|
|
25
23
|
),
|
|
26
24
|
id: id ?? nativeProps.id
|
|
27
25
|
}
|
|
@@ -31,4 +29,4 @@ function TabList(props) {
|
|
|
31
29
|
export {
|
|
32
30
|
TabList
|
|
33
31
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-X2JMXTBH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/TabList.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { hstack } from '@cerberus/styled-system/patterns'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\nimport { useTabsContext } from '../context/tabs'\n\n/**\n * This module provides a TabList component.\n * @module\n */\n\nexport interface TabListProps extends HTMLAttributes<HTMLDivElement> {\n description: string\n}\n\n/**\n * The TabList component provides a container for tab elements.\n * @param description - a description of what the tab list contains\n * @example\n * ```tsx\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * ```\n */\nexport function TabList(props: PropsWithChildren<TabListProps>) {\n const { description, ...nativeProps } = props\n const { id } = useTabsContext()\n\n return (\n <div\n {...nativeProps}\n aria-describedby={description}\n className={cx(\n nativeProps.className,\n hstack({\n
|
|
1
|
+
{"version":3,"sources":["../../src/components/TabList.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { hstack } from '@cerberus/styled-system/patterns'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\nimport { useTabsContext } from '../context/tabs'\n\n/**\n * This module provides a TabList component.\n * @module\n */\n\nexport interface TabListProps extends HTMLAttributes<HTMLDivElement> {\n description: string\n}\n\n/**\n * The TabList component provides a container for tab elements.\n * @param description - a description of what the tab list contains\n * @example\n * ```tsx\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * ```\n */\nexport function TabList(props: PropsWithChildren<TabListProps>) {\n const { description, ...nativeProps } = props\n const { id, styles } = useTabsContext()\n\n return (\n <div\n {...nativeProps}\n aria-describedby={description}\n className={cx(\n nativeProps.className,\n hstack({\n gap: '0',\n }),\n styles.tabList,\n )}\n id={id ?? nativeProps.id}\n />\n )\n}\n"],"mappings":";;;;;AAEA,SAAS,UAAU;AACnB,SAAS,cAAc;AA6BnB;AALG,SAAS,QAAQ,OAAwC;AAC9D,QAAM,EAAE,aAAa,GAAG,YAAY,IAAI;AACxC,QAAM,EAAE,IAAI,OAAO,IAAI,eAAe;AAEtC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,oBAAkB;AAAA,MAClB,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,OAAO;AAAA,UACL,KAAK;AAAA,QACP,CAAC;AAAA,QACD,OAAO;AAAA,MACT;AAAA,MACA,IAAI,MAAM,YAAY;AAAA;AAAA,EACxB;AAEJ;","names":[]}
|
package/build/legacy/index.js
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-WE3JNSNO.js";
|
|
4
4
|
import {
|
|
5
5
|
Tab
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JI4YTPEJ.js";
|
|
7
7
|
import {
|
|
8
8
|
TabList
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-X2JMXTBH.js";
|
|
10
10
|
import {
|
|
11
11
|
TabPanel
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-67S42J4B.js";
|
|
13
13
|
import {
|
|
14
14
|
Tag
|
|
15
15
|
} from "./chunk-5XNLWIZO.js";
|
|
@@ -61,12 +61,12 @@ import {
|
|
|
61
61
|
} from "./chunk-JF76VIL3.js";
|
|
62
62
|
import {
|
|
63
63
|
useTabsKeyboardNavigation
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-KFUXGX33.js";
|
|
65
65
|
import {
|
|
66
66
|
Tabs,
|
|
67
67
|
TabsContext,
|
|
68
68
|
useTabsContext
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-7KJIZIAU.js";
|
|
70
70
|
import {
|
|
71
71
|
$cerberusIcons,
|
|
72
72
|
defineIcons
|
|
@@ -13,6 +13,7 @@ import type { InputHTMLAttributes } from 'react';
|
|
|
13
13
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
14
14
|
import { label } from '@cerberus/styled-system/recipes';
|
|
15
15
|
import { MutableRefObject } from 'react';
|
|
16
|
+
import type { Pretty } from '@cerberus-design/styled-system/types';
|
|
16
17
|
import { PropsWithChildren } from 'react';
|
|
17
18
|
import { radio } from '@cerberus-design/styled-system/recipes';
|
|
18
19
|
import { ReactNode } from 'react';
|
|
@@ -20,6 +21,7 @@ import { RecipeVariantProps } from '@cerberus/styled-system/css';
|
|
|
20
21
|
import type { RecipeVariantProps as RecipeVariantProps_2 } from '@cerberus-design/styled-system/types';
|
|
21
22
|
import type { RecipeVariantProps as RecipeVariantProps_3 } from '@cerberus/styled-system/types';
|
|
22
23
|
import { RefObject } from 'react';
|
|
24
|
+
import { TabsVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
23
25
|
import { tag } from '@cerberus/styled-system/recipes';
|
|
24
26
|
import type { TextareaHTMLAttributes } from 'react';
|
|
25
27
|
import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
@@ -442,6 +444,7 @@ export { TabProps as TabProps_alias_1 }
|
|
|
442
444
|
|
|
443
445
|
/**
|
|
444
446
|
* The Tabs component provides a context to manage tab state.
|
|
447
|
+
* @param id - the id of the tabs component,
|
|
445
448
|
* @param active - the default active tab id,
|
|
446
449
|
* @param cache - whether to cache the active tab state in local storage
|
|
447
450
|
* @example
|
|
@@ -458,7 +461,7 @@ export { TabProps as TabProps_alias_1 }
|
|
|
458
461
|
* </Tabs>
|
|
459
462
|
* ```
|
|
460
463
|
*/
|
|
461
|
-
declare function Tabs(props: PropsWithChildren<TabsProps>): JSX.Element;
|
|
464
|
+
declare function Tabs(props: PropsWithChildren<TabsProps & TabsVariantProps>): JSX.Element;
|
|
462
465
|
export { Tabs }
|
|
463
466
|
export { Tabs as Tabs_alias_1 }
|
|
464
467
|
|
|
@@ -474,6 +477,7 @@ declare interface TabsContextValue {
|
|
|
474
477
|
tabs: MutableRefObject<HTMLButtonElement[]>;
|
|
475
478
|
id: string;
|
|
476
479
|
active: string;
|
|
480
|
+
styles: Pretty<Record<'tabList' | 'tab' | 'tabPanel', string>>;
|
|
477
481
|
onTabUpdate: (active: string) => void;
|
|
478
482
|
}
|
|
479
483
|
export { TabsContextValue }
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
} from "./chunk-4O4QFF4S.js";
|
|
4
4
|
import {
|
|
5
5
|
useTabsContext
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7KJIZIAU.js";
|
|
7
7
|
|
|
8
8
|
// src/components/TabPanel.tsx
|
|
9
|
-
import {
|
|
9
|
+
import { cx } from "@cerberus/styled-system/css";
|
|
10
10
|
import { useMemo } from "react";
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
12
|
function TabPanel(props) {
|
|
13
13
|
const { tab, ...nativeProps } = props;
|
|
14
|
-
const { active } = useTabsContext();
|
|
14
|
+
const { active, styles } = useTabsContext();
|
|
15
15
|
const isActive = useMemo(() => active === tab, [active, tab]);
|
|
16
16
|
return /* @__PURE__ */ jsx(Show, { when: isActive, children: /* @__PURE__ */ jsx(
|
|
17
17
|
"div",
|
|
@@ -19,18 +19,7 @@ function TabPanel(props) {
|
|
|
19
19
|
...nativeProps,
|
|
20
20
|
...isActive && { tabIndex: 0 },
|
|
21
21
|
"aria-labelledby": tab,
|
|
22
|
-
className: cx(
|
|
23
|
-
nativeProps.className,
|
|
24
|
-
css({
|
|
25
|
-
rounded: "md",
|
|
26
|
-
_focusVisible: {
|
|
27
|
-
boxShadow: "none",
|
|
28
|
-
outline: "3px solid",
|
|
29
|
-
outlineColor: "action.border.focus",
|
|
30
|
-
outlineOffset: "2px"
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
),
|
|
22
|
+
className: cx(nativeProps.className, styles.tabPanel),
|
|
34
23
|
id: `panel:${tab}`,
|
|
35
24
|
role: "tabpanel"
|
|
36
25
|
}
|
|
@@ -40,4 +29,4 @@ function TabPanel(props) {
|
|
|
40
29
|
export {
|
|
41
30
|
TabPanel
|
|
42
31
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-67S42J4B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/TabPanel.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { useMemo, type HTMLAttributes } from 'react'\nimport { useTabsContext } from '../context/tabs'\nimport { Show } from './Show'\n\n/**\n * This module provides a TabPanel component.\n * @module\n */\n\nexport interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {\n tab: string\n}\n\n/**\n * The TabPanel component provides a panel element to be used in a Tabs provider.\n * @param tab - the value of the tab that will be tracked as the active tab and used for aria attributes\n * @example\n * ```tsx\n * <TabPanel tab=\"overview\">\n * Overview content\n * </TabPanel>\n * ```\n */\nexport function TabPanel(props: TabPanelProps) {\n const { tab, ...nativeProps } = props\n const { active, styles } = useTabsContext()\n const isActive = useMemo(() => active === tab, [active, tab])\n\n return (\n <Show when={isActive}>\n <div\n {...nativeProps}\n {...(isActive && { tabIndex: 0 })}\n aria-labelledby={tab}\n className={cx(nativeProps.className, styles.tabPanel)}\n id={`panel:${tab}`}\n role=\"tabpanel\"\n />\n </Show>\n )\n}\n"],"mappings":";;;;;;;;AAEA,SAAS,UAAU;AACnB,SAAS,eAAoC;AA8BvC;AAPC,SAAS,SAAS,OAAsB;AAC7C,QAAM,EAAE,KAAK,GAAG,YAAY,IAAI;AAChC,QAAM,EAAE,QAAQ,OAAO,IAAI,eAAe;AAC1C,QAAM,WAAW,QAAQ,MAAM,WAAW,KAAK,CAAC,QAAQ,GAAG,CAAC;AAE5D,SACE,oBAAC,QAAK,MAAM,UACV;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAI,YAAY,EAAE,UAAU,EAAE;AAAA,MAC/B,mBAAiB;AAAA,MACjB,WAAW,GAAG,YAAY,WAAW,OAAO,QAAQ;AAAA,MACpD,IAAI,SAAS,GAAG;AAAA,MAChB,MAAK;AAAA;AAAA,EACP,GACF;AAEJ;","names":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/context/tabs.tsx
|
|
2
|
+
import {
|
|
3
|
+
tabs
|
|
4
|
+
} from "@cerberus-design/styled-system/recipes";
|
|
2
5
|
import {
|
|
3
6
|
createContext,
|
|
4
7
|
useContext,
|
|
@@ -10,20 +13,21 @@ import {
|
|
|
10
13
|
import { jsx } from "react/jsx-runtime";
|
|
11
14
|
var TabsContext = createContext(null);
|
|
12
15
|
function Tabs(props) {
|
|
13
|
-
const { cache, active, id } = props;
|
|
16
|
+
const { cache, active, id, palette } = props;
|
|
14
17
|
const [activeTab, setActiveTab] = useState(() => cache ? "" : active ?? "");
|
|
15
|
-
const
|
|
18
|
+
const tabsList = useRef([]);
|
|
16
19
|
const uuid = useMemo(() => {
|
|
17
20
|
return id ? `cerberus-tabs-${id}` : "cerberus-tabs";
|
|
18
21
|
}, [id]);
|
|
19
22
|
const value = useMemo(
|
|
20
23
|
() => ({
|
|
21
|
-
tabs,
|
|
24
|
+
tabs: tabsList,
|
|
22
25
|
id: uuid,
|
|
23
26
|
active: activeTab,
|
|
27
|
+
styles: tabs({ palette }),
|
|
24
28
|
onTabUpdate: setActiveTab
|
|
25
29
|
}),
|
|
26
|
-
[activeTab, setActiveTab, uuid,
|
|
30
|
+
[activeTab, setActiveTab, palette, uuid, tabsList]
|
|
27
31
|
);
|
|
28
32
|
useEffect(() => {
|
|
29
33
|
if (cache) {
|
|
@@ -53,4 +57,4 @@ export {
|
|
|
53
57
|
Tabs,
|
|
54
58
|
useTabsContext
|
|
55
59
|
};
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-7KJIZIAU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/tabs.tsx"],"sourcesContent":["'use client'\n\nimport {\n tabs,\n type TabsVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { Pretty } from '@cerberus-design/styled-system/types'\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type MutableRefObject,\n type PropsWithChildren,\n} from 'react'\n\n/**\n * This module provides a Tabs component and a hook to access its context.\n * @module\n */\n\nexport interface TabsContextValue {\n tabs: MutableRefObject<HTMLButtonElement[]>\n id: string\n active: string\n styles: Pretty<Record<'tabList' | 'tab' | 'tabPanel', string>>\n onTabUpdate: (active: string) => void\n}\n\nexport const TabsContext = createContext<TabsContextValue | null>(null)\n\nexport interface TabsProps {\n id?: string\n active?: string\n cache?: boolean\n}\n\n/**\n * The Tabs component provides a context to manage tab state.\n * @param id - the id of the tabs component,\n * @param active - the default active tab id,\n * @param cache - whether to cache the active tab state in local storage\n * @example\n * ```tsx\n * <Tabs cache>\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * <TabPanels>\n * <TabPanel id=\"overview\">Overview content</TabPanel>\n * <TabPanel id=\"guidelines\">Guidelines content</TabPanel>\n * </TabPanels>\n * </Tabs>\n * ```\n */\nexport function Tabs(\n props: PropsWithChildren<TabsProps & TabsVariantProps>,\n): JSX.Element {\n const { cache, active, id, palette } = props\n const [activeTab, setActiveTab] = useState(() => (cache ? '' : active ?? ''))\n const tabsList = useRef<HTMLButtonElement[]>([])\n const uuid = useMemo(() => {\n return id ? `cerberus-tabs-${id}` : 'cerberus-tabs'\n }, [id])\n\n const value = useMemo(\n () => ({\n tabs: tabsList,\n id: uuid,\n active: activeTab,\n styles: tabs({ palette }),\n onTabUpdate: setActiveTab,\n }),\n [activeTab, setActiveTab, palette, uuid, tabsList],\n )\n\n // Get the active tab from local storage\n useEffect(() => {\n if (cache) {\n const cachedTab = window.localStorage.getItem(uuid)\n setActiveTab(\n cache ? cachedTab || (props.active ?? '') : props.active ?? '',\n )\n }\n }, [cache, active, uuid])\n\n // Update the active tab in local storage\n useEffect(() => {\n if (cache && activeTab) {\n window.localStorage.setItem(uuid, activeTab)\n }\n }, [activeTab, cache])\n\n return (\n <TabsContext.Provider value={value}>{props.children}</TabsContext.Provider>\n )\n}\n\nexport function useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext)\n if (!context) {\n throw new Error('useTabsContext must be used within a Tabs Provider.')\n }\n return context\n}\n"],"mappings":";AAEA;AAAA,EACE;AAAA,OAEK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAiFH;AAlEG,IAAM,cAAc,cAAuC,IAAI;AA2B/D,SAAS,KACd,OACa;AACb,QAAM,EAAE,OAAO,QAAQ,IAAI,QAAQ,IAAI;AACvC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,MAAO,QAAQ,KAAK,UAAU,EAAG;AAC5E,QAAM,WAAW,OAA4B,CAAC,CAAC;AAC/C,QAAM,OAAO,QAAQ,MAAM;AACzB,WAAO,KAAK,iBAAiB,EAAE,KAAK;AAAA,EACtC,GAAG,CAAC,EAAE,CAAC;AAEP,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,QAAQ,KAAK,EAAE,QAAQ,CAAC;AAAA,MACxB,aAAa;AAAA,IACf;AAAA,IACA,CAAC,WAAW,cAAc,SAAS,MAAM,QAAQ;AAAA,EACnD;AAGA,YAAU,MAAM;AACd,QAAI,OAAO;AACT,YAAM,YAAY,OAAO,aAAa,QAAQ,IAAI;AAClD;AAAA,QACE,QAAQ,cAAc,MAAM,UAAU,MAAM,MAAM,UAAU;AAAA,MAC9D;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,QAAQ,IAAI,CAAC;AAGxB,YAAU,MAAM;AACd,QAAI,SAAS,WAAW;AACtB,aAAO,aAAa,QAAQ,MAAM,SAAS;AAAA,IAC7C;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAErB,SACE,oBAAC,YAAY,UAAZ,EAAqB,OAAe,gBAAM,UAAS;AAExD;AAEO,SAAS,iBAAmC;AACjD,QAAM,UAAU,WAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTabsKeyboardNavigation
|
|
3
|
+
} from "./chunk-KFUXGX33.js";
|
|
4
|
+
import {
|
|
5
|
+
useTabsContext
|
|
6
|
+
} from "./chunk-7KJIZIAU.js";
|
|
7
|
+
|
|
8
|
+
// src/components/Tab.tsx
|
|
9
|
+
import {
|
|
10
|
+
useMemo,
|
|
11
|
+
useTransition
|
|
12
|
+
} from "react";
|
|
13
|
+
import { cx } from "@cerberus/styled-system/css";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
function Tab(props) {
|
|
16
|
+
const { value, ...nativeProps } = props;
|
|
17
|
+
const { active, onTabUpdate, styles } = useTabsContext();
|
|
18
|
+
const [isPending, startTransition] = useTransition();
|
|
19
|
+
const { ref } = useTabsKeyboardNavigation();
|
|
20
|
+
const isActive = useMemo(() => active === value, [active, value]);
|
|
21
|
+
function handleClick(e) {
|
|
22
|
+
props.onClick?.(e);
|
|
23
|
+
startTransition(() => onTabUpdate(e.currentTarget.value));
|
|
24
|
+
}
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
"button",
|
|
27
|
+
{
|
|
28
|
+
...nativeProps,
|
|
29
|
+
...!isActive && { tabIndex: -1 },
|
|
30
|
+
"aria-controls": `panel:${value}`,
|
|
31
|
+
"aria-busy": isPending,
|
|
32
|
+
"aria-selected": isActive,
|
|
33
|
+
id: value,
|
|
34
|
+
className: cx(nativeProps.className, styles.tab),
|
|
35
|
+
onClick: handleClick,
|
|
36
|
+
role: "tab",
|
|
37
|
+
ref,
|
|
38
|
+
value
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
Tab
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=chunk-HBEEHHON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/Tab.tsx"],"sourcesContent":["'use client'\n\nimport {\n useMemo,\n useTransition,\n type ButtonHTMLAttributes,\n type MouseEvent,\n} from 'react'\nimport { useTabsContext } from '../context/tabs'\nimport { cx } from '@cerberus/styled-system/css'\nimport { useTabsKeyboardNavigation } from '../aria-helpers/tabs.aria'\n\n/**\n * This module provides a Tab component.\n * @module\n */\nexport interface TabProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n value: string\n}\n\n/**\n * The Tab component provides a tab element to be used in a TabList.\n * @definition [ARIA Target Size](https://www.w3.org/WAI/WCAG21/Understanding/target-size.html#:~:text=Understanding%20SC%202.5.,%3ATarget%20Size%20(Level%20AAA)&text=The%20size%20of%20the%20target,Equivalent)\n * @definition [Tab docs](https://cerberus.digitalu.design/react/tabs)\n * @param value - the id of the tab that will be tracked as the active tab and used for aria attributes\n * @example\n * ```tsx\n * <Tab value=\"overview\">\n * Overview\n * </Tab>\n * ```\n */\nexport function Tab(props: TabProps) {\n const { value, ...nativeProps } = props\n const { active, onTabUpdate, styles } = useTabsContext()\n const [isPending, startTransition] = useTransition()\n const { ref } = useTabsKeyboardNavigation()\n const isActive = useMemo(() => active === value, [active, value])\n\n function handleClick(e: MouseEvent<HTMLButtonElement>) {\n props.onClick?.(e)\n startTransition(() => onTabUpdate(e.currentTarget.value))\n }\n\n return (\n <button\n {...nativeProps}\n {...(!isActive && { tabIndex: -1 })}\n aria-controls={`panel:${value}`}\n aria-busy={isPending}\n aria-selected={isActive}\n id={value}\n className={cx(nativeProps.className, styles.tab)}\n onClick={handleClick}\n role=\"tab\"\n ref={ref}\n value={value}\n />\n )\n}\n"],"mappings":";;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,UAAU;AAoCf;AAbG,SAAS,IAAI,OAAiB;AACnC,QAAM,EAAE,OAAO,GAAG,YAAY,IAAI;AAClC,QAAM,EAAE,QAAQ,aAAa,OAAO,IAAI,eAAe;AACvD,QAAM,CAAC,WAAW,eAAe,IAAI,cAAc;AACnD,QAAM,EAAE,IAAI,IAAI,0BAA0B;AAC1C,QAAM,WAAW,QAAQ,MAAM,WAAW,OAAO,CAAC,QAAQ,KAAK,CAAC;AAEhE,WAAS,YAAY,GAAkC;AACrD,UAAM,UAAU,CAAC;AACjB,oBAAgB,MAAM,YAAY,EAAE,cAAc,KAAK,CAAC;AAAA,EAC1D;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAI,CAAC,YAAY,EAAE,UAAU,GAAG;AAAA,MACjC,iBAAe,SAAS,KAAK;AAAA,MAC7B,aAAW;AAAA,MACX,iBAAe;AAAA,MACf,IAAI;AAAA,MACJ,WAAW,GAAG,YAAY,WAAW,OAAO,GAAG;AAAA,MAC/C,SAAS;AAAA,MACT,MAAK;AAAA,MACL;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useTabsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7KJIZIAU.js";
|
|
4
4
|
|
|
5
5
|
// src/aria-helpers/tabs.aria.ts
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
@@ -61,4 +61,4 @@ function useTabsKeyboardNavigation() {
|
|
|
61
61
|
export {
|
|
62
62
|
useTabsKeyboardNavigation
|
|
63
63
|
};
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-KFUXGX33.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useTabsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7KJIZIAU.js";
|
|
4
4
|
|
|
5
5
|
// src/components/TabList.tsx
|
|
6
6
|
import { cx } from "@cerberus/styled-system/css";
|
|
@@ -8,7 +8,7 @@ import { hstack } from "@cerberus/styled-system/patterns";
|
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
function TabList(props) {
|
|
10
10
|
const { description, ...nativeProps } = props;
|
|
11
|
-
const { id } = useTabsContext();
|
|
11
|
+
const { id, styles } = useTabsContext();
|
|
12
12
|
return /* @__PURE__ */ jsx(
|
|
13
13
|
"div",
|
|
14
14
|
{
|
|
@@ -17,11 +17,9 @@ function TabList(props) {
|
|
|
17
17
|
className: cx(
|
|
18
18
|
nativeProps.className,
|
|
19
19
|
hstack({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
w: "full"
|
|
24
|
-
})
|
|
20
|
+
gap: "0"
|
|
21
|
+
}),
|
|
22
|
+
styles.tabList
|
|
25
23
|
),
|
|
26
24
|
id: id ?? nativeProps.id
|
|
27
25
|
}
|
|
@@ -31,4 +29,4 @@ function TabList(props) {
|
|
|
31
29
|
export {
|
|
32
30
|
TabList
|
|
33
31
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-X2JMXTBH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/TabList.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { hstack } from '@cerberus/styled-system/patterns'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\nimport { useTabsContext } from '../context/tabs'\n\n/**\n * This module provides a TabList component.\n * @module\n */\n\nexport interface TabListProps extends HTMLAttributes<HTMLDivElement> {\n description: string\n}\n\n/**\n * The TabList component provides a container for tab elements.\n * @param description - a description of what the tab list contains\n * @example\n * ```tsx\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * ```\n */\nexport function TabList(props: PropsWithChildren<TabListProps>) {\n const { description, ...nativeProps } = props\n const { id } = useTabsContext()\n\n return (\n <div\n {...nativeProps}\n aria-describedby={description}\n className={cx(\n nativeProps.className,\n hstack({\n
|
|
1
|
+
{"version":3,"sources":["../../src/components/TabList.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus/styled-system/css'\nimport { hstack } from '@cerberus/styled-system/patterns'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\nimport { useTabsContext } from '../context/tabs'\n\n/**\n * This module provides a TabList component.\n * @module\n */\n\nexport interface TabListProps extends HTMLAttributes<HTMLDivElement> {\n description: string\n}\n\n/**\n * The TabList component provides a container for tab elements.\n * @param description - a description of what the tab list contains\n * @example\n * ```tsx\n * <TabList description=\"Button details\">\n * <Tab id=\"overview\">Overview</Tab>\n * <Tab id=\"guidelines\">Guidelines</Tab>\n * </TabList>\n * ```\n */\nexport function TabList(props: PropsWithChildren<TabListProps>) {\n const { description, ...nativeProps } = props\n const { id, styles } = useTabsContext()\n\n return (\n <div\n {...nativeProps}\n aria-describedby={description}\n className={cx(\n nativeProps.className,\n hstack({\n gap: '0',\n }),\n styles.tabList,\n )}\n id={id ?? nativeProps.id}\n />\n )\n}\n"],"mappings":";;;;;AAEA,SAAS,UAAU;AACnB,SAAS,cAAc;AA6BnB;AALG,SAAS,QAAQ,OAAwC;AAC9D,QAAM,EAAE,aAAa,GAAG,YAAY,IAAI;AACxC,QAAM,EAAE,IAAI,OAAO,IAAI,eAAe;AAEtC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,oBAAkB;AAAA,MAClB,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,OAAO;AAAA,UACL,KAAK;AAAA,QACP,CAAC;AAAA,QACD,OAAO;AAAA,MACT;AAAA,MACA,IAAI,MAAM,YAAY;AAAA;AAAA,EACxB;AAEJ;","names":[]}
|