@cerberus-design/react 0.13.1-next-d1e87c5 → 0.13.1-next-394d7c4
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.cts +19 -0
- package/build/legacy/context/notification-center.cjs.map +1 -1
- package/build/legacy/hooks/useRootColors.cjs +49 -0
- package/build/legacy/hooks/useRootColors.cjs.map +1 -0
- package/build/legacy/index.cjs +22 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +19 -0
- package/build/modern/{chunk-KUT2YEEQ.js → chunk-B3LRHIEG.js} +6 -6
- package/build/modern/chunk-B3LRHIEG.js.map +1 -0
- package/build/modern/{chunk-4D6VIGNQ.js → chunk-FHS7VVGN.js} +6 -6
- package/build/modern/chunk-RO4AJOVX.js +24 -0
- package/build/modern/chunk-RO4AJOVX.js.map +1 -0
- package/build/modern/{chunk-MMHCX2RG.js → chunk-S6JWPDB4.js} +6 -6
- package/build/modern/{chunk-MXMVC3ZQ.js → chunk-SRPSJGNI.js} +9 -9
- package/build/modern/context/confirm-modal.js +3 -3
- package/build/modern/context/cta-modal.js +4 -4
- package/build/modern/context/notification-center.js +3 -3
- package/build/modern/context/prompt-modal.js +3 -3
- package/build/modern/hooks/useRootColors.js +8 -0
- package/build/modern/hooks/useRootColors.js.map +1 -0
- package/build/modern/index.js +37 -33
- package/build/modern/index.js.map +1 -1
- package/package.json +3 -3
- package/src/context/notification-center.tsx +1 -0
- package/src/hooks/useRootColors.ts +49 -0
- package/src/index.ts +1 -0
- package/build/modern/chunk-KUT2YEEQ.js.map +0 -1
- /package/build/modern/{chunk-4D6VIGNQ.js.map → chunk-FHS7VVGN.js.map} +0 -0
- /package/build/modern/{chunk-MMHCX2RG.js.map → chunk-S6JWPDB4.js.map} +0 -0
- /package/build/modern/{chunk-MXMVC3ZQ.js.map → chunk-SRPSJGNI.js.map} +0 -0
|
@@ -2097,6 +2097,14 @@ export { RadioRecipe as RadioRecipe_alias_1 }
|
|
|
2097
2097
|
|
|
2098
2098
|
export { rectIntersection }
|
|
2099
2099
|
|
|
2100
|
+
/**
|
|
2101
|
+
* This module provides a hook to get Cerberus colors from the document root.
|
|
2102
|
+
* @module useRootColors
|
|
2103
|
+
*/
|
|
2104
|
+
declare type RootColorsResult = Record<string, string>;
|
|
2105
|
+
export { RootColorsResult }
|
|
2106
|
+
export { RootColorsResult as RootColorsResult_alias_1 }
|
|
2107
|
+
|
|
2100
2108
|
export { ScreenReaderInstructions }
|
|
2101
2109
|
|
|
2102
2110
|
/**
|
|
@@ -3010,6 +3018,17 @@ declare function usePromptModal(): PromptModalValue;
|
|
|
3010
3018
|
export { usePromptModal }
|
|
3011
3019
|
export { usePromptModal as usePromptModal_alias_1 }
|
|
3012
3020
|
|
|
3021
|
+
/**
|
|
3022
|
+
* This hook returns a record of Cerberus colors from the document root.
|
|
3023
|
+
* This is useful when you are working with a component that uses the `<canvas>`
|
|
3024
|
+
* element.
|
|
3025
|
+
* @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).
|
|
3026
|
+
* @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
3027
|
+
*/
|
|
3028
|
+
declare function useRootColors(colors?: string[]): RootColorsResult;
|
|
3029
|
+
export { useRootColors }
|
|
3030
|
+
export { useRootColors as useRootColors_alias_1 }
|
|
3031
|
+
|
|
3013
3032
|
export { useSensor }
|
|
3014
3033
|
|
|
3015
3034
|
export { useSensors }
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NotificationHeading
|
|
3
|
+
} from "./chunk-SXIXDXG3.js";
|
|
1
4
|
import {
|
|
2
5
|
Portal
|
|
3
6
|
} from "./chunk-K2PSHGS7.js";
|
|
@@ -8,14 +11,11 @@ import {
|
|
|
8
11
|
NotificationDescription
|
|
9
12
|
} from "./chunk-XEW6TJJ4.js";
|
|
10
13
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
Button
|
|
15
|
+
} from "./chunk-EXGKZGML.js";
|
|
13
16
|
import {
|
|
14
17
|
Show
|
|
15
18
|
} from "./chunk-BUVVRQLZ.js";
|
|
16
|
-
import {
|
|
17
|
-
Button
|
|
18
|
-
} from "./chunk-EXGKZGML.js";
|
|
19
19
|
|
|
20
20
|
// src/context/notification-center.tsx
|
|
21
21
|
import {
|
|
@@ -159,4 +159,4 @@ export {
|
|
|
159
159
|
NotificationCenter,
|
|
160
160
|
useNotificationCenter
|
|
161
161
|
};
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
162
|
+
//# sourceMappingURL=chunk-B3LRHIEG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/notification-center.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n type ReactNode,\n} from 'react'\nimport { Show } from '../components/Show'\nimport { NotificationHeading } from '../components/NotificationHeading'\nimport { NotificationDescription } from '../components/NotificationDescription'\nimport { Notification } from '../components/Notification'\nimport { animateIn, vstack } from '@cerberus/styled-system/patterns'\nimport { Portal, type PortalProps } from '../components/Portal'\nimport { notification } from '@cerberus/styled-system/recipes'\nimport { Button } from '../components/Button'\nimport { cx } from '@cerberus/styled-system/css'\n\n/**\n * This module provides a context and hook for notifications.\n * @module\n */\n\nexport interface NotifyOptions {\n /**\n * The palette of the notification.\n * @default 'info'\n */\n palette: 'info' | 'success' | 'warning' | 'danger'\n /**\n * The heading of the notification.\n */\n heading: string\n /**\n * The unique id of the notification.\n */\n id?: string\n /**\n * The description of the notification.\n */\n description?: ReactNode\n /**\n * The action to take when the notification is closed\n */\n onClose?: () => void\n}\n\nexport interface NotificationsValue {\n notify: (options: NotifyOptions) => void\n}\n\nconst NotificationsContext = createContext<NotificationsValue | null>(null)\n\nexport interface NotificationsProviderProps extends PortalProps {}\n\n/**\n * Provides a notification center to the app.\n * @see https://cerberus.digitalu.design/react/notification\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <Notifications>\n * <SomeFeatureSection />\n * </Notifications>\n *\n * // Use the hook to show a notification.\n * const notify = useNotifications()\n *\n * const handleClick = useCallback(() => {\n * notify({\n * palette: 'info',\n * heading: 'New feature!',\n * description: 'We have added a new feature to the app.',\n * })\n * }, [notify])\n * ```\n */\nexport function NotificationCenter(\n props: PropsWithChildren<NotificationsProviderProps>,\n) {\n const [activeNotifications, setActiveNotifications] = useState<\n NotifyOptions[]\n >([])\n const styles = notification()\n\n const handleNotify = useCallback((options: NotifyOptions) => {\n setActiveNotifications((prev) => {\n const id = `${options.palette}:${prev.length + 1}`\n return [...prev, { ...options, id }]\n })\n }, [])\n\n const handleClose = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n setActiveNotifications((prev) => {\n const item = prev.find((option) => option.id === target.value)\n if (item?.onClose) item.onClose()\n return prev.filter((option) => option.id !== target.value)\n })\n }, [])\n\n const handleCloseAll = useCallback(() => {\n setActiveNotifications((prev) => {\n prev.forEach((item) => {\n if (item.onClose) item.onClose()\n })\n return []\n })\n }, [])\n\n const value = useMemo(\n () => ({\n notify: handleNotify,\n }),\n [handleNotify],\n )\n\n // For some reason, the vstack pattern alignItems is not registering here.\n // So we are forcing it with the style prop.\n\n return (\n <NotificationsContext.Provider value={value}>\n {props.children}\n\n <Show when={activeNotifications.length > 0}>\n <Portal container={props.container}>\n <div className={styles.center}>\n <Show when={activeNotifications.length >= 4}>\n <Button\n className={cx(styles.closeAll, animateIn())}\n onClick={handleCloseAll}\n palette=\"action\"\n shape=\"rounded\"\n size=\"sm\"\n usage=\"ghost\"\n >\n Close all\n </Button>\n </Show>\n\n <div\n className={vstack({\n alignItems: 'flex-end',\n gap: '4',\n })}\n style={{\n alignItems: 'flex-end',\n }}\n >\n {activeNotifications.map((option) => (\n <MatchNotification\n key={option.id}\n {...option}\n onClose={handleClose}\n />\n ))}\n </div>\n </div>\n </Portal>\n </Show>\n </NotificationsContext.Provider>\n )\n}\n\ninterface MatchNotificationProps extends Omit<NotifyOptions, 'onClose'> {\n onClose: (e: MouseEvent<HTMLButtonElement>) => void\n key: string | undefined\n}\n\nfunction MatchNotification(props: MatchNotificationProps) {\n const { palette, id, onClose, heading, description } = props\n\n switch (palette) {\n case 'success':\n return (\n <Notification\n id={id!}\n key={id}\n onClose={onClose}\n open\n palette=\"success\"\n >\n <NotificationHeading palette=\"success\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"success\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'warning':\n return (\n <Notification\n id={id!}\n key={id}\n onClose={onClose}\n open\n palette=\"warning\"\n >\n <NotificationHeading palette=\"warning\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"warning\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'danger':\n return (\n <Notification id={id!} key={id} onClose={onClose} open palette=\"danger\">\n <NotificationHeading palette=\"danger\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"danger\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'info':\n default:\n return (\n <Notification id={id!} key={id} onClose={onClose} open palette=\"info\">\n <NotificationHeading palette=\"info\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"info\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n }\n}\n\n/**\n * The hook to use the NotificationCenter.\n * @returns The notify method to trigger a notification.\n * @example\n * ```tsx\n * const {notify} = useNotificationCenter()\n * notify({\n * palette: 'info',\n * heading: 'New feature',\n * description: 'We have added a new feature to the app.',\n * })\n * ```\n */\nexport function useNotificationCenter(): NotificationsValue {\n const context = useContext(NotificationsContext)\n if (!context) {\n throw new Error(\n 'useNotificationCenter must be used within a NotificationsProvider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;A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qBAAC,gBAAa,IAAkB,SAAkB,MAAI,MAAC,SAAQ,UAC7D;AAAA,4BAAC,uBAAoB,SAAQ,UAAU,mBAAQ;AAAA,QAC/C,oBAAC,2BAAwB,SAAQ,UAC9B,uBACH;AAAA,WAJ0B,EAK5B;AAAA,IAGJ,KAAK;AAAA,IACL;AACE,aACE,qBAAC,gBAAa,IAAkB,SAAkB,MAAI,MAAC,SAAQ,QAC7D;AAAA,4BAAC,uBAAoB,SAAQ,QAAQ,mBAAQ;AAAA,QAC7C,oBAAC,2BAAwB,SAAQ,QAC9B,uBACH;AAAA,WAJ0B,EAK5B;AAAA,EAEN;AACF;AAeO,SAAS,wBAA4C;AAC1D,QAAM,UAAU,WAAW,oBAAoB;AAC/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
3
|
} from "./chunk-K2PSHGS7.js";
|
|
4
|
+
import {
|
|
5
|
+
ModalDescription
|
|
6
|
+
} from "./chunk-Q7BRMIBR.js";
|
|
4
7
|
import {
|
|
5
8
|
ModalHeader
|
|
6
9
|
} from "./chunk-XY6WL55R.js";
|
|
@@ -11,8 +14,8 @@ import {
|
|
|
11
14
|
Modal
|
|
12
15
|
} from "./chunk-BE4EOU2P.js";
|
|
13
16
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
Button
|
|
18
|
+
} from "./chunk-EXGKZGML.js";
|
|
16
19
|
import {
|
|
17
20
|
useModal
|
|
18
21
|
} from "./chunk-KGQG5JGW.js";
|
|
@@ -22,9 +25,6 @@ import {
|
|
|
22
25
|
import {
|
|
23
26
|
Show
|
|
24
27
|
} from "./chunk-BUVVRQLZ.js";
|
|
25
|
-
import {
|
|
26
|
-
Button
|
|
27
|
-
} from "./chunk-EXGKZGML.js";
|
|
28
28
|
import {
|
|
29
29
|
trapFocus
|
|
30
30
|
} from "./chunk-JIZQFTW6.js";
|
|
@@ -170,4 +170,4 @@ export {
|
|
|
170
170
|
ConfirmModal,
|
|
171
171
|
useConfirmModal
|
|
172
172
|
};
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
173
|
+
//# sourceMappingURL=chunk-FHS7VVGN.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/hooks/useRootColors.ts
|
|
2
|
+
import { useEffect, useReducer } from "react";
|
|
3
|
+
function useRootColors(colors = []) {
|
|
4
|
+
const [state, dispatch] = useReducer(rootColorsReducer, {});
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (Object.keys(state).length === colors.length) return;
|
|
7
|
+
const rootStyles = getComputedStyle(document.body);
|
|
8
|
+
const rootColors = colors.reduce((acc, color) => {
|
|
9
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
10
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
13
|
+
dispatch(rootColors);
|
|
14
|
+
}, [colors]);
|
|
15
|
+
return state;
|
|
16
|
+
}
|
|
17
|
+
function rootColorsReducer(state, action) {
|
|
18
|
+
return { ...state, ...action };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
useRootColors
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-RO4AJOVX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useRootColors.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useReducer } from 'react'\n\n/**\n * This module provides a hook to get Cerberus colors from the document root.\n * @module useRootColors\n */\n\nexport type RootColorsResult = Record<string, string>\n\n/**\n * This hook returns a record of Cerberus colors from the document root.\n * This is useful when you are working with a component that uses the `<canvas>`\n * element.\n * @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).\n * @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.\n */\nexport function useRootColors(colors: string[] = []): RootColorsResult {\n const [state, dispatch] = useReducer(rootColorsReducer, {})\n\n useEffect(() => {\n if (Object.keys(state).length === colors.length) return\n\n const rootStyles = getComputedStyle(document.body)\n const rootColors = colors.reduce((acc, color) => {\n const formattedColor = color\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .toLowerCase()\n .replaceAll('.', '-')\n acc[color as keyof typeof acc] = rootStyles\n .getPropertyValue(`--cerberus-colors-${formattedColor}`)\n .trim()\n return acc\n }, {} as RootColorsResult)\n\n dispatch(rootColors)\n }, [colors])\n\n // reducer is already memoized\n return state\n}\n\nfunction rootColorsReducer(\n state: Record<string, string>,\n action: Record<string, string>,\n): Record<string, string> {\n return { ...state, ...action }\n}\n"],"mappings":";AAEA,SAAS,WAAW,kBAAkB;AAgB/B,SAAS,cAAc,SAAmB,CAAC,GAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,mBAAmB,CAAC,CAAC;AAE1D,YAAU,MAAM;AACd,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,OAAO,OAAQ;AAEjD,UAAM,aAAa,iBAAiB,SAAS,IAAI;AACjD,UAAM,aAAa,OAAO,OAAO,CAAC,KAAK,UAAU;AAC/C,YAAM,iBAAiB,MACpB,QAAQ,mBAAmB,OAAO,EAClC,YAAY,EACZ,WAAW,KAAK,GAAG;AACtB,UAAI,KAAyB,IAAI,WAC9B,iBAAiB,qBAAqB,cAAc,EAAE,EACtD,KAAK;AACR,aAAO;AAAA,IACT,GAAG,CAAC,CAAqB;AAEzB,aAAS,UAAU;AAAA,EACrB,GAAG,CAAC,MAAM,CAAC;AAGX,SAAO;AACT;AAEA,SAAS,kBACP,OACA,QACwB;AACxB,SAAO,EAAE,GAAG,OAAO,GAAG,OAAO;AAC/B;","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
3
|
} from "./chunk-K2PSHGS7.js";
|
|
4
|
+
import {
|
|
5
|
+
ModalDescription
|
|
6
|
+
} from "./chunk-Q7BRMIBR.js";
|
|
4
7
|
import {
|
|
5
8
|
ModalHeader
|
|
6
9
|
} from "./chunk-XY6WL55R.js";
|
|
@@ -17,8 +20,8 @@ import {
|
|
|
17
20
|
Modal
|
|
18
21
|
} from "./chunk-BE4EOU2P.js";
|
|
19
22
|
import {
|
|
20
|
-
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
Button
|
|
24
|
+
} from "./chunk-EXGKZGML.js";
|
|
22
25
|
import {
|
|
23
26
|
Field
|
|
24
27
|
} from "./chunk-UZDVOIW5.js";
|
|
@@ -31,9 +34,6 @@ import {
|
|
|
31
34
|
import {
|
|
32
35
|
Show
|
|
33
36
|
} from "./chunk-BUVVRQLZ.js";
|
|
34
|
-
import {
|
|
35
|
-
Button
|
|
36
|
-
} from "./chunk-EXGKZGML.js";
|
|
37
37
|
import {
|
|
38
38
|
trapFocus
|
|
39
39
|
} from "./chunk-JIZQFTW6.js";
|
|
@@ -240,4 +240,4 @@ export {
|
|
|
240
240
|
PromptModal,
|
|
241
241
|
usePromptModal
|
|
242
242
|
};
|
|
243
|
-
//# sourceMappingURL=chunk-
|
|
243
|
+
//# sourceMappingURL=chunk-S6JWPDB4.js.map
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
3
|
} from "./chunk-K2PSHGS7.js";
|
|
4
|
+
import {
|
|
5
|
+
ModalDescription
|
|
6
|
+
} from "./chunk-Q7BRMIBR.js";
|
|
4
7
|
import {
|
|
5
8
|
ModalHeader
|
|
6
9
|
} from "./chunk-XY6WL55R.js";
|
|
7
10
|
import {
|
|
8
11
|
ModalHeading
|
|
9
12
|
} from "./chunk-2UXE5PDG.js";
|
|
13
|
+
import {
|
|
14
|
+
IconButton
|
|
15
|
+
} from "./chunk-APD6IX5R.js";
|
|
10
16
|
import {
|
|
11
17
|
Modal
|
|
12
18
|
} from "./chunk-BE4EOU2P.js";
|
|
13
19
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import {
|
|
17
|
-
IconButton
|
|
18
|
-
} from "./chunk-APD6IX5R.js";
|
|
20
|
+
Button
|
|
21
|
+
} from "./chunk-EXGKZGML.js";
|
|
19
22
|
import {
|
|
20
23
|
useModal
|
|
21
24
|
} from "./chunk-KGQG5JGW.js";
|
|
@@ -25,9 +28,6 @@ import {
|
|
|
25
28
|
import {
|
|
26
29
|
Show
|
|
27
30
|
} from "./chunk-BUVVRQLZ.js";
|
|
28
|
-
import {
|
|
29
|
-
Button
|
|
30
|
-
} from "./chunk-EXGKZGML.js";
|
|
31
31
|
import {
|
|
32
32
|
trapFocus
|
|
33
33
|
} from "./chunk-JIZQFTW6.js";
|
|
@@ -152,4 +152,4 @@ export {
|
|
|
152
152
|
CTAModal,
|
|
153
153
|
useCTAModal
|
|
154
154
|
};
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-SRPSJGNI.js.map
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import {
|
|
3
3
|
ConfirmModal,
|
|
4
4
|
useConfirmModal
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-FHS7VVGN.js";
|
|
6
6
|
import "../chunk-K2PSHGS7.js";
|
|
7
|
+
import "../chunk-Q7BRMIBR.js";
|
|
7
8
|
import "../chunk-XY6WL55R.js";
|
|
8
9
|
import "../chunk-2UXE5PDG.js";
|
|
9
10
|
import "../chunk-BE4EOU2P.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-EXGKZGML.js";
|
|
11
12
|
import "../chunk-KGQG5JGW.js";
|
|
12
13
|
import "../chunk-SPZYPRZ6.js";
|
|
13
14
|
import "../chunk-BUVVRQLZ.js";
|
|
14
|
-
import "../chunk-EXGKZGML.js";
|
|
15
15
|
import "../chunk-JIZQFTW6.js";
|
|
16
16
|
import "../chunk-VERRHMW4.js";
|
|
17
17
|
import "../chunk-F27AAKQ3.js";
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import {
|
|
3
3
|
CTAModal,
|
|
4
4
|
useCTAModal
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-SRPSJGNI.js";
|
|
6
6
|
import "../chunk-K2PSHGS7.js";
|
|
7
|
+
import "../chunk-Q7BRMIBR.js";
|
|
7
8
|
import "../chunk-XY6WL55R.js";
|
|
8
9
|
import "../chunk-2UXE5PDG.js";
|
|
9
|
-
import "../chunk-BE4EOU2P.js";
|
|
10
|
-
import "../chunk-Q7BRMIBR.js";
|
|
11
10
|
import "../chunk-APD6IX5R.js";
|
|
11
|
+
import "../chunk-BE4EOU2P.js";
|
|
12
|
+
import "../chunk-EXGKZGML.js";
|
|
12
13
|
import "../chunk-KGQG5JGW.js";
|
|
13
14
|
import "../chunk-SPZYPRZ6.js";
|
|
14
15
|
import "../chunk-BUVVRQLZ.js";
|
|
15
|
-
import "../chunk-EXGKZGML.js";
|
|
16
16
|
import "../chunk-JIZQFTW6.js";
|
|
17
17
|
import "../chunk-VERRHMW4.js";
|
|
18
18
|
import "../chunk-F27AAKQ3.js";
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
NotificationCenter,
|
|
4
4
|
useNotificationCenter
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-B3LRHIEG.js";
|
|
6
|
+
import "../chunk-SXIXDXG3.js";
|
|
6
7
|
import "../chunk-K2PSHGS7.js";
|
|
7
8
|
import "../chunk-7SGPJM66.js";
|
|
8
9
|
import "../chunk-XEW6TJJ4.js";
|
|
9
|
-
import "../chunk-SXIXDXG3.js";
|
|
10
|
-
import "../chunk-BUVVRQLZ.js";
|
|
11
10
|
import "../chunk-EXGKZGML.js";
|
|
11
|
+
import "../chunk-BUVVRQLZ.js";
|
|
12
12
|
import "../chunk-JIZQFTW6.js";
|
|
13
13
|
import "../chunk-VERRHMW4.js";
|
|
14
14
|
import "../chunk-F27AAKQ3.js";
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
PromptModal,
|
|
4
4
|
usePromptModal
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-S6JWPDB4.js";
|
|
6
6
|
import "../chunk-K2PSHGS7.js";
|
|
7
|
+
import "../chunk-Q7BRMIBR.js";
|
|
7
8
|
import "../chunk-XY6WL55R.js";
|
|
8
9
|
import "../chunk-2UXE5PDG.js";
|
|
9
10
|
import "../chunk-NKM6PISB.js";
|
|
10
11
|
import "../chunk-NMF2HYWO.js";
|
|
11
12
|
import "../chunk-BE4EOU2P.js";
|
|
12
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-EXGKZGML.js";
|
|
13
14
|
import "../chunk-UZDVOIW5.js";
|
|
14
15
|
import "../chunk-KGQG5JGW.js";
|
|
15
16
|
import "../chunk-SPZYPRZ6.js";
|
|
16
17
|
import "../chunk-BUVVRQLZ.js";
|
|
17
|
-
import "../chunk-EXGKZGML.js";
|
|
18
18
|
import "../chunk-JIZQFTW6.js";
|
|
19
19
|
import "../chunk-VERRHMW4.js";
|
|
20
20
|
import "../chunk-F27AAKQ3.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/build/modern/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NotificationCenter,
|
|
3
|
+
useNotificationCenter
|
|
4
|
+
} from "./chunk-B3LRHIEG.js";
|
|
1
5
|
import {
|
|
2
6
|
PromptModal,
|
|
3
7
|
usePromptModal
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-S6JWPDB4.js";
|
|
5
9
|
import {
|
|
6
10
|
ThemeProvider,
|
|
7
11
|
useThemeContext
|
|
8
12
|
} from "./chunk-EB37HRCN.js";
|
|
13
|
+
import {
|
|
14
|
+
Thead
|
|
15
|
+
} from "./chunk-Y6QQCRQV.js";
|
|
9
16
|
import {
|
|
10
17
|
Toggle
|
|
11
18
|
} from "./chunk-NMNONSHU.js";
|
|
@@ -15,15 +22,14 @@ import {
|
|
|
15
22
|
import {
|
|
16
23
|
ConfirmModal,
|
|
17
24
|
useConfirmModal
|
|
18
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-FHS7VVGN.js";
|
|
19
26
|
import {
|
|
20
27
|
CTAModal,
|
|
21
28
|
useCTAModal
|
|
22
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-SRPSJGNI.js";
|
|
23
30
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from "./chunk-KUT2YEEQ.js";
|
|
31
|
+
TabList
|
|
32
|
+
} from "./chunk-UKPF7JOB.js";
|
|
27
33
|
import {
|
|
28
34
|
TabPanel
|
|
29
35
|
} from "./chunk-AYIRV5CL.js";
|
|
@@ -47,8 +53,8 @@ import {
|
|
|
47
53
|
Th
|
|
48
54
|
} from "./chunk-SGKHA4EB.js";
|
|
49
55
|
import {
|
|
50
|
-
|
|
51
|
-
} from "./chunk-
|
|
56
|
+
NotificationHeading
|
|
57
|
+
} from "./chunk-SXIXDXG3.js";
|
|
52
58
|
import {
|
|
53
59
|
Portal
|
|
54
60
|
} from "./chunk-K2PSHGS7.js";
|
|
@@ -66,8 +72,8 @@ import {
|
|
|
66
72
|
Tab
|
|
67
73
|
} from "./chunk-SLF6SIPB.js";
|
|
68
74
|
import {
|
|
69
|
-
|
|
70
|
-
} from "./chunk-
|
|
75
|
+
ModalDescription
|
|
76
|
+
} from "./chunk-Q7BRMIBR.js";
|
|
71
77
|
import {
|
|
72
78
|
ModalHeader
|
|
73
79
|
} from "./chunk-XY6WL55R.js";
|
|
@@ -95,11 +101,18 @@ import {
|
|
|
95
101
|
NotificationDescription
|
|
96
102
|
} from "./chunk-XEW6TJJ4.js";
|
|
97
103
|
import {
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
FileStatus,
|
|
105
|
+
processStatus
|
|
106
|
+
} from "./chunk-7MM5KYEX.js";
|
|
107
|
+
import {
|
|
108
|
+
ProgressBar
|
|
109
|
+
} from "./chunk-KCANMM64.js";
|
|
100
110
|
import {
|
|
101
111
|
FileUploader
|
|
102
112
|
} from "./chunk-W4DXACNV.js";
|
|
113
|
+
import {
|
|
114
|
+
IconButton
|
|
115
|
+
} from "./chunk-APD6IX5R.js";
|
|
103
116
|
import {
|
|
104
117
|
Input
|
|
105
118
|
} from "./chunk-NKM6PISB.js";
|
|
@@ -122,8 +135,8 @@ import {
|
|
|
122
135
|
Modal
|
|
123
136
|
} from "./chunk-BE4EOU2P.js";
|
|
124
137
|
import {
|
|
125
|
-
|
|
126
|
-
} from "./chunk-
|
|
138
|
+
Button
|
|
139
|
+
} from "./chunk-EXGKZGML.js";
|
|
127
140
|
import {
|
|
128
141
|
Checkbox
|
|
129
142
|
} from "./chunk-NB6DV4VA.js";
|
|
@@ -140,32 +153,25 @@ import {
|
|
|
140
153
|
FeatureFlags,
|
|
141
154
|
useFeatureFlags
|
|
142
155
|
} from "./chunk-CJFW36DZ.js";
|
|
143
|
-
import {
|
|
144
|
-
Fieldset
|
|
145
|
-
} from "./chunk-3ZDFQO25.js";
|
|
146
|
-
import {
|
|
147
|
-
FieldsetLabel
|
|
148
|
-
} from "./chunk-PZAZKQMO.js";
|
|
149
|
-
import {
|
|
150
|
-
FileStatus,
|
|
151
|
-
processStatus
|
|
152
|
-
} from "./chunk-7MM5KYEX.js";
|
|
153
|
-
import {
|
|
154
|
-
ProgressBar
|
|
155
|
-
} from "./chunk-KCANMM64.js";
|
|
156
|
-
import {
|
|
157
|
-
IconButton
|
|
158
|
-
} from "./chunk-APD6IX5R.js";
|
|
159
156
|
import {
|
|
160
157
|
FieldMessage
|
|
161
158
|
} from "./chunk-JWIJHSI6.js";
|
|
159
|
+
import {
|
|
160
|
+
Fieldset
|
|
161
|
+
} from "./chunk-3ZDFQO25.js";
|
|
162
162
|
import {
|
|
163
163
|
Field,
|
|
164
164
|
useFieldContext
|
|
165
165
|
} from "./chunk-UZDVOIW5.js";
|
|
166
|
+
import {
|
|
167
|
+
FieldsetLabel
|
|
168
|
+
} from "./chunk-PZAZKQMO.js";
|
|
166
169
|
import {
|
|
167
170
|
useModal
|
|
168
171
|
} from "./chunk-KGQG5JGW.js";
|
|
172
|
+
import {
|
|
173
|
+
useRootColors
|
|
174
|
+
} from "./chunk-RO4AJOVX.js";
|
|
169
175
|
import {
|
|
170
176
|
MODE_KEY,
|
|
171
177
|
THEME_KEY,
|
|
@@ -188,9 +194,6 @@ import {
|
|
|
188
194
|
import {
|
|
189
195
|
Show
|
|
190
196
|
} from "./chunk-BUVVRQLZ.js";
|
|
191
|
-
import {
|
|
192
|
-
Button
|
|
193
|
-
} from "./chunk-EXGKZGML.js";
|
|
194
197
|
import "./chunk-55J6XMHW.js";
|
|
195
198
|
import {
|
|
196
199
|
createNavTriggerProps
|
|
@@ -309,6 +312,7 @@ export {
|
|
|
309
312
|
useNavMenuContext,
|
|
310
313
|
useNotificationCenter,
|
|
311
314
|
usePromptModal,
|
|
315
|
+
useRootColors,
|
|
312
316
|
useTabsContext,
|
|
313
317
|
useTabsKeyboardNavigation,
|
|
314
318
|
useTheme,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/**\n * This module is the entry point for the Cerberus React package.\n * @module\n */\n\n// components\n\nexport * from './components/Admonition'\nexport * from './components/Avatar'\nexport * from './components/Button'\nexport * from './components/Checkbox'\nexport * from './components/CircularProgress'\nexport * from './components/Droppable'\nexport * from './components/FieldMessage'\nexport * from './components/FeatureFlag'\nexport * from './components/Fieldset'\nexport * from './components/FieldsetLabel'\nexport * from './components/FileStatus'\nexport * from './components/FileUploader'\nexport * from './components/IconButton'\nexport * from './components/Input'\nexport * from './components/Label'\nexport * from './components/Legend'\nexport * from './components/Menu'\nexport * from './components/Modal'\nexport * from './components/ModalHeader'\nexport * from './components/ModalHeading'\nexport * from './components/ModalDescription'\nexport * from './components/NavMenuTrigger'\nexport * from './components/NavMenuList'\nexport * from './components/NavMenuLink'\nexport * from './components/Notification'\nexport * from './components/NotificationHeading'\nexport * from './components/NotificationDescription'\nexport * from './components/Portal'\nexport * from './components/ProgressBar'\nexport * from './components/Radio'\nexport * from './components/Select'\nexport * from './components/Spinner'\nexport * from './components/Tab'\nexport * from './components/TabList'\nexport * from './components/TabPanel'\nexport * from './components/Table'\nexport * from './components/Thead'\nexport * from './components/Th'\nexport * from './components/Td'\nexport * from './components/Tbody'\nexport * from './components/Tag'\nexport * from './components/Textarea'\nexport * from './components/Toggle'\nexport * from './components/Tooltip'\nexport * from './components/Show'\n\n// context\n\nexport * from './context/confirm-modal'\nexport * from './context/cta-modal'\nexport * from './context/feature-flags'\nexport * from './context/field'\nexport * from './context/navMenu'\nexport * from './context/notification-center'\nexport * from './context/prompt-modal'\nexport * from './context/tabs'\nexport * from './context/theme'\n\n// hooks\n\nexport * from './hooks/useDate'\nexport * from './hooks/useModal'\nexport * from './hooks/useTheme'\nexport * from './hooks/useToggle'\n\n// aria-helpers\n\nexport * from './aria-helpers/nav-menu.aria'\nexport * from './aria-helpers/tabs.aria'\nexport * from './aria-helpers/trap-focus.aria'\n\n// utils\n\nexport * from './config/defineIcons'\nexport * from './utils/index'\n\n// shared types\n\nexport * from './types'\n\n// 3rd party\n\nexport * from '@dnd-kit/core'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/**\n * This module is the entry point for the Cerberus React package.\n * @module\n */\n\n// components\n\nexport * from './components/Admonition'\nexport * from './components/Avatar'\nexport * from './components/Button'\nexport * from './components/Checkbox'\nexport * from './components/CircularProgress'\nexport * from './components/Droppable'\nexport * from './components/FieldMessage'\nexport * from './components/FeatureFlag'\nexport * from './components/Fieldset'\nexport * from './components/FieldsetLabel'\nexport * from './components/FileStatus'\nexport * from './components/FileUploader'\nexport * from './components/IconButton'\nexport * from './components/Input'\nexport * from './components/Label'\nexport * from './components/Legend'\nexport * from './components/Menu'\nexport * from './components/Modal'\nexport * from './components/ModalHeader'\nexport * from './components/ModalHeading'\nexport * from './components/ModalDescription'\nexport * from './components/NavMenuTrigger'\nexport * from './components/NavMenuList'\nexport * from './components/NavMenuLink'\nexport * from './components/Notification'\nexport * from './components/NotificationHeading'\nexport * from './components/NotificationDescription'\nexport * from './components/Portal'\nexport * from './components/ProgressBar'\nexport * from './components/Radio'\nexport * from './components/Select'\nexport * from './components/Spinner'\nexport * from './components/Tab'\nexport * from './components/TabList'\nexport * from './components/TabPanel'\nexport * from './components/Table'\nexport * from './components/Thead'\nexport * from './components/Th'\nexport * from './components/Td'\nexport * from './components/Tbody'\nexport * from './components/Tag'\nexport * from './components/Textarea'\nexport * from './components/Toggle'\nexport * from './components/Tooltip'\nexport * from './components/Show'\n\n// context\n\nexport * from './context/confirm-modal'\nexport * from './context/cta-modal'\nexport * from './context/feature-flags'\nexport * from './context/field'\nexport * from './context/navMenu'\nexport * from './context/notification-center'\nexport * from './context/prompt-modal'\nexport * from './context/tabs'\nexport * from './context/theme'\n\n// hooks\n\nexport * from './hooks/useDate'\nexport * from './hooks/useModal'\nexport * from './hooks/useTheme'\nexport * from './hooks/useToggle'\nexport * from './hooks/useRootColors'\n\n// aria-helpers\n\nexport * from './aria-helpers/nav-menu.aria'\nexport * from './aria-helpers/tabs.aria'\nexport * from './aria-helpers/trap-focus.aria'\n\n// utils\n\nexport * from './config/defineIcons'\nexport * from './utils/index'\n\n// shared types\n\nexport * from './types'\n\n// 3rd party\n\nexport * from '@dnd-kit/core'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerberus-design/react",
|
|
3
|
-
"version": "0.13.1-next-
|
|
3
|
+
"version": "0.13.1-next-394d7c4",
|
|
4
4
|
"description": "The Cerberus Design React component library.",
|
|
5
5
|
"browserslist": "> 0.25%, not dead",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"react": "^18",
|
|
27
27
|
"react-dom": "^18",
|
|
28
28
|
"tsup": "^8.1.0",
|
|
29
|
-
"@cerberus-design/
|
|
30
|
-
"@cerberus-design/
|
|
29
|
+
"@cerberus-design/styled-system": "0.13.1-next-394d7c4",
|
|
30
|
+
"@cerberus-design/configs": "0.0.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useReducer } from 'react'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This module provides a hook to get Cerberus colors from the document root.
|
|
7
|
+
* @module useRootColors
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type RootColorsResult = Record<string, string>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This hook returns a record of Cerberus colors from the document root.
|
|
14
|
+
* This is useful when you are working with a component that uses the `<canvas>`
|
|
15
|
+
* element.
|
|
16
|
+
* @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).
|
|
17
|
+
* @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
18
|
+
*/
|
|
19
|
+
export function useRootColors(colors: string[] = []): RootColorsResult {
|
|
20
|
+
const [state, dispatch] = useReducer(rootColorsReducer, {})
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (Object.keys(state).length === colors.length) return
|
|
24
|
+
|
|
25
|
+
const rootStyles = getComputedStyle(document.body)
|
|
26
|
+
const rootColors = colors.reduce((acc, color) => {
|
|
27
|
+
const formattedColor = color
|
|
28
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replaceAll('.', '-')
|
|
31
|
+
acc[color as keyof typeof acc] = rootStyles
|
|
32
|
+
.getPropertyValue(`--cerberus-colors-${formattedColor}`)
|
|
33
|
+
.trim()
|
|
34
|
+
return acc
|
|
35
|
+
}, {} as RootColorsResult)
|
|
36
|
+
|
|
37
|
+
dispatch(rootColors)
|
|
38
|
+
}, [colors])
|
|
39
|
+
|
|
40
|
+
// reducer is already memoized
|
|
41
|
+
return state
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function rootColorsReducer(
|
|
45
|
+
state: Record<string, string>,
|
|
46
|
+
action: Record<string, string>,
|
|
47
|
+
): Record<string, string> {
|
|
48
|
+
return { ...state, ...action }
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/notification-center.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n type ReactNode,\n} from 'react'\nimport { Show } from '../components/Show'\nimport { NotificationHeading } from '../components/NotificationHeading'\nimport { NotificationDescription } from '../components/NotificationDescription'\nimport { Notification } from '../components/Notification'\nimport { animateIn, vstack } from '@cerberus/styled-system/patterns'\nimport { Portal, type PortalProps } from '../components/Portal'\nimport { notification } from '@cerberus/styled-system/recipes'\nimport { Button } from '../components/Button'\nimport { cx } from '@cerberus/styled-system/css'\n\n/**\n * This module provides a context and hook for notifications.\n * @module\n */\n\nexport interface NotifyOptions {\n /**\n * The palette of the notification.\n * @default 'info'\n */\n palette: 'info' | 'success' | 'warning' | 'danger'\n /**\n * The heading of the notification.\n */\n heading: string\n /**\n * The unique id of the notification.\n */\n id?: string\n /**\n * The description of the notification.\n */\n description?: ReactNode\n /**\n * The action to take when the notification is closed\n */\n onClose?: () => void\n}\n\nexport interface NotificationsValue {\n notify: (options: NotifyOptions) => void\n}\n\nconst NotificationsContext = createContext<NotificationsValue | null>(null)\n\nexport interface NotificationsProviderProps extends PortalProps {}\n\n/**\n * Provides a notification center to the app.\n * @see https://cerberus.digitalu.design/react/notification\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <Notifications>\n * <SomeFeatureSection />\n * </Notifications>\n *\n * // Use the hook to show a notification.\n * const notify = useNotifications()\n *\n * const handleClick = useCallback(() => {\n * notify({\n * palette: 'info',\n * heading: 'New feature!',\n * description: 'We have added a new feature to the app.',\n * })\n * }, [notify])\n * ```\n */\nexport function NotificationCenter(\n props: PropsWithChildren<NotificationsProviderProps>,\n) {\n const [activeNotifications, setActiveNotifications] = useState<\n NotifyOptions[]\n >([])\n const styles = notification()\n\n const handleNotify = useCallback((options: NotifyOptions) => {\n setActiveNotifications((prev) => {\n const id = `${options.palette}:${prev.length + 1}`\n return [...prev, { ...options, id }]\n })\n }, [])\n\n const handleClose = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n setActiveNotifications((prev) => {\n const item = prev.find((option) => option.id === target.value)\n if (item?.onClose) item.onClose()\n return prev.filter((option) => option.id !== target.value)\n })\n }, [])\n\n const handleCloseAll = useCallback(() => {\n setActiveNotifications((prev) => {\n prev.forEach((item) => {\n if (item.onClose) item.onClose()\n })\n return []\n })\n }, [])\n\n const value = useMemo(\n () => ({\n notify: handleNotify,\n }),\n [handleNotify],\n )\n\n // For some reason, the vstack pattern alignItems is not registering here.\n // So we are forcing it with the style prop.\n\n return (\n <NotificationsContext.Provider value={value}>\n {props.children}\n\n <Show when={activeNotifications.length > 0}>\n <Portal container={props.container}>\n <div className={styles.center}>\n <Show when={activeNotifications.length >= 4}>\n <Button\n className={cx(styles.closeAll, animateIn())}\n onClick={handleCloseAll}\n palette=\"action\"\n shape=\"rounded\"\n size=\"sm\"\n usage=\"ghost\"\n >\n Close all\n </Button>\n </Show>\n <div\n className={vstack({\n alignItems: 'flex-end',\n gap: '4',\n })}\n style={{\n alignItems: 'flex-end',\n }}\n >\n {activeNotifications.map((option) => (\n <MatchNotification\n key={option.id}\n {...option}\n onClose={handleClose}\n />\n ))}\n </div>\n </div>\n </Portal>\n </Show>\n </NotificationsContext.Provider>\n )\n}\n\ninterface MatchNotificationProps extends Omit<NotifyOptions, 'onClose'> {\n onClose: (e: MouseEvent<HTMLButtonElement>) => void\n key: string | undefined\n}\n\nfunction MatchNotification(props: MatchNotificationProps) {\n const { palette, id, onClose, heading, description } = props\n\n switch (palette) {\n case 'success':\n return (\n <Notification\n id={id!}\n key={id}\n onClose={onClose}\n open\n palette=\"success\"\n >\n <NotificationHeading palette=\"success\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"success\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'warning':\n return (\n <Notification\n id={id!}\n key={id}\n onClose={onClose}\n open\n palette=\"warning\"\n >\n <NotificationHeading palette=\"warning\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"warning\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'danger':\n return (\n <Notification id={id!} key={id} onClose={onClose} open palette=\"danger\">\n <NotificationHeading palette=\"danger\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"danger\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'info':\n default:\n return (\n <Notification id={id!} key={id} onClose={onClose} open palette=\"info\">\n <NotificationHeading palette=\"info\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"info\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n }\n}\n\n/**\n * The hook to use the NotificationCenter.\n * @returns The notify method to trigger a notification.\n * @example\n * ```tsx\n * const {notify} = useNotificationCenter()\n * notify({\n * palette: 'info',\n * heading: 'New feature',\n * description: 'We have added a new feature to the app.',\n * })\n * ```\n */\nexport function useNotificationCenter(): NotificationsValue {\n const context = useContext(NotificationsContext)\n if (!context) {\n throw new Error(\n 'useNotificationCenter must be used within a NotificationsProvider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAKP,SAAS,WAAW,cAAc;AAElC,SAAS,oBAAoB;AAE7B,SAAS,UAAU;AA8GT,SAEI,KAFJ;AA3EV,IAAM,uBAAuB,cAAyC,IAAI;AA0BnE,SAAS,mBACd,OACA;AACA,QAAM,CAAC,qBAAqB,sBAAsB,IAAI,SAEpD,CAAC,CAAC;AACJ,QAAM,SAAS,aAAa;AAE5B,QAAM,eAAe,YAAY,CAAC,YAA2B;AAC3D,2BAAuB,CAAC,SAAS;AAC/B,YAAM,KAAK,GAAG,QAAQ,OAAO,IAAI,KAAK,SAAS,CAAC;AAChD,aAAO,CAAC,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,CAAC;AAAA,IACrC,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc,YAAY,CAAC,MAAqC;AACpE,UAAM,SAAS,EAAE;AACjB,2BAAuB,CAAC,SAAS;AAC/B,YAAM,OAAO,KAAK,KAAK,CAAC,WAAW,OAAO,OAAO,OAAO,KAAK;AAC7D,UAAI,MAAM,QAAS,MAAK,QAAQ;AAChC,aAAO,KAAK,OAAO,CAAC,WAAW,OAAO,OAAO,OAAO,KAAK;AAAA,IAC3D,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,iBAAiB,YAAY,MAAM;AACvC,2BAAuB,CAAC,SAAS;AAC/B,WAAK,QAAQ,CAAC,SAAS;AACrB,YAAI,KAAK,QAAS,MAAK,QAAQ;AAAA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