@charcoal-ui/react 6.1.0-beta.0 → 6.1.0-beta.1

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.
Files changed (65) hide show
  1. package/dist/components/Notification/NotificationItem.cjs +30 -0
  2. package/dist/components/Notification/NotificationItem.cjs.map +1 -0
  3. package/dist/components/Notification/NotificationItem.d.ts +15 -0
  4. package/dist/components/Notification/NotificationItem.d.ts.map +1 -0
  5. package/dist/components/Notification/NotificationItem.js +30 -0
  6. package/dist/components/Notification/NotificationItem.js.map +1 -0
  7. package/dist/components/Notification/NotificationRegion.cjs +50 -0
  8. package/dist/components/Notification/NotificationRegion.cjs.map +1 -0
  9. package/dist/components/Notification/NotificationRegion.d.ts +14 -0
  10. package/dist/components/Notification/NotificationRegion.d.ts.map +1 -0
  11. package/dist/components/Notification/NotificationRegion.js +50 -0
  12. package/dist/components/Notification/NotificationRegion.js.map +1 -0
  13. package/dist/components/Notification/Snackbar/index.d.ts +45 -0
  14. package/dist/components/Notification/Snackbar/index.d.ts.map +1 -0
  15. package/dist/components/Notification/Snackbar/index2.cjs +99 -0
  16. package/dist/components/Notification/Snackbar/index2.cjs.map +1 -0
  17. package/dist/components/Notification/Snackbar/index2.js +94 -0
  18. package/dist/components/Notification/Snackbar/index2.js.map +1 -0
  19. package/dist/components/Notification/Toast/index.d.ts +28 -0
  20. package/dist/components/Notification/Toast/index.d.ts.map +1 -0
  21. package/dist/components/Notification/Toast/index2.cjs +86 -0
  22. package/dist/components/Notification/Toast/index2.cjs.map +1 -0
  23. package/dist/components/Notification/Toast/index2.js +81 -0
  24. package/dist/components/Notification/Toast/index2.js.map +1 -0
  25. package/dist/components/Notification/types.d.ts +27 -0
  26. package/dist/components/Notification/types.d.ts.map +1 -0
  27. package/dist/components/Notification/useNotificationQueue.cjs +155 -0
  28. package/dist/components/Notification/useNotificationQueue.cjs.map +1 -0
  29. package/dist/components/Notification/useNotificationQueue.d.ts +16 -0
  30. package/dist/components/Notification/useNotificationQueue.d.ts.map +1 -0
  31. package/dist/components/Notification/useNotificationQueue.js +155 -0
  32. package/dist/components/Notification/useNotificationQueue.js.map +1 -0
  33. package/dist/index.cjs +4 -1
  34. package/dist/index.css +1315 -1250
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +3 -2
  38. package/dist/layered.css +1315 -1250
  39. package/dist/layered.css.map +1 -1
  40. package/package.json +5 -5
  41. package/src/__tests__/css-output.test.ts +39 -6
  42. package/src/components/Notification/NotificationItem.tsx +51 -0
  43. package/src/components/Notification/NotificationRegion.tsx +76 -0
  44. package/src/components/{Snackbar → Notification/Snackbar}/__snapshots__/index.css.snap +1 -42
  45. package/src/components/{Snackbar → Notification/Snackbar}/index.css +1 -43
  46. package/src/components/{Snackbar → Notification/Snackbar}/index.story.tsx +52 -23
  47. package/src/components/{Snackbar → Notification/Snackbar}/index.test.tsx +61 -11
  48. package/src/components/Notification/Snackbar/index.tsx +131 -0
  49. package/src/components/Notification/Toast/__snapshots__/index.css.snap +62 -0
  50. package/src/components/Notification/Toast/index.css +61 -0
  51. package/src/components/Notification/Toast/index.story.tsx +174 -0
  52. package/src/components/Notification/Toast/index.test.tsx +263 -0
  53. package/src/components/Notification/Toast/index.tsx +86 -0
  54. package/src/components/Notification/__snapshots__/layout.css.snap +47 -0
  55. package/src/components/Notification/layout.css +46 -0
  56. package/src/components/Notification/types.ts +28 -0
  57. package/src/components/Notification/useNotificationQueue.ts +235 -0
  58. package/src/index.ts +14 -2
  59. package/dist/components/Snackbar/index.d.ts +0 -52
  60. package/dist/components/Snackbar/index.d.ts.map +0 -1
  61. package/dist/components/Snackbar/index2.cjs +0 -268
  62. package/dist/components/Snackbar/index2.cjs.map +0 -1
  63. package/dist/components/Snackbar/index2.js +0 -263
  64. package/dist/components/Snackbar/index2.js.map +0 -1
  65. package/src/components/Snackbar/index.tsx +0 -455
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ let react_jsx_runtime = require("react/jsx-runtime");
3
+ let react_aria_useToast = require("react-aria/useToast");
4
+
5
+ //#region src/components/Notification/NotificationItem.tsx
6
+ function NotificationItem({ name, toast, state, itemRef, onHoverStart, onHoverEnd, children, ...rootProps }) {
7
+ const { toastProps, contentProps, titleProps } = (0, react_aria_useToast.useToast)({ toast }, state, itemRef);
8
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
9
+ ...toastProps,
10
+ ...rootProps,
11
+ ref: itemRef,
12
+ className: `charcoal-notification charcoal-${name}`,
13
+ onPointerEnter: onHoverStart,
14
+ onPointerLeave: onHoverEnd,
15
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
16
+ ...contentProps,
17
+ role: "status",
18
+ className: "charcoal-notification-content",
19
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20
+ ...titleProps,
21
+ className: "charcoal-notification-label",
22
+ children: toast.content.message
23
+ })
24
+ }), children]
25
+ });
26
+ }
27
+
28
+ //#endregion
29
+ exports.NotificationItem = NotificationItem;
30
+ //# sourceMappingURL=NotificationItem.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationItem.cjs","names":[],"sources":["../../../src/components/Notification/NotificationItem.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode, RefObject } from 'react'\nimport { useToast } from 'react-aria/useToast'\nimport type { QueuedToast, ToastState } from 'react-stately/useToastState'\nimport type { NotificationName } from './types'\n\nexport function NotificationItem<TContent extends { message: ReactNode }>({\n name,\n toast,\n state,\n itemRef,\n onHoverStart,\n onHoverEnd,\n children,\n ...rootProps\n}: {\n name: NotificationName\n toast: QueuedToast<TContent>\n state: ToastState<TContent>\n itemRef: RefObject<HTMLDivElement>\n onHoverStart: () => void\n onHoverEnd: () => void\n children?: ReactNode\n} & Omit<HTMLAttributes<HTMLDivElement>, 'itemRef'>) {\n const { toastProps, contentProps, titleProps } = useToast(\n { toast },\n state,\n itemRef,\n )\n\n return (\n <div\n {...toastProps}\n {...rootProps}\n ref={itemRef}\n className={`charcoal-notification charcoal-${name}`}\n onPointerEnter={onHoverStart}\n onPointerLeave={onHoverEnd}\n >\n <div\n {...contentProps}\n role=\"status\"\n className=\"charcoal-notification-content\"\n >\n <div {...titleProps} className=\"charcoal-notification-label\">\n {toast.content.message}\n </div>\n </div>\n {children}\n </div>\n )\n}\n"],"mappings":";;;;;AAKA,SAAgB,iBAA0D,EACxE,MACA,OACA,OACA,SACA,cACA,YACA,UACA,GAAG,aASgD;CACnD,MAAM,EAAE,YAAY,cAAc,iDAChC,EAAE,MAAM,GACR,OACA,OACF;CAEA,OACE,4CAAC,OAAD;EACE,GAAI;EACJ,GAAI;EACJ,KAAK;EACL,WAAW,kCAAkC;EAC7C,gBAAgB;EAChB,gBAAgB;YANlB,CAQE,2CAAC,OAAD;GACE,GAAI;GACJ,MAAK;GACL,WAAU;aAEV,2CAAC,OAAD;IAAK,GAAI;IAAY,WAAU;cAC5B,MAAM,QAAQ;GACZ;EACF,IACJ,QACE;;AAET"}
@@ -0,0 +1,15 @@
1
+ import type { HTMLAttributes, ReactNode, RefObject } from 'react';
2
+ import type { QueuedToast, ToastState } from 'react-stately/useToastState';
3
+ import type { NotificationName } from './types';
4
+ export declare function NotificationItem<TContent extends {
5
+ message: ReactNode;
6
+ }>({ name, toast, state, itemRef, onHoverStart, onHoverEnd, children, ...rootProps }: {
7
+ name: NotificationName;
8
+ toast: QueuedToast<TContent>;
9
+ state: ToastState<TContent>;
10
+ itemRef: RefObject<HTMLDivElement>;
11
+ onHoverStart: () => void;
12
+ onHoverEnd: () => void;
13
+ children?: ReactNode;
14
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'itemRef'>): import("react/jsx-runtime").JSX.Element;
15
+ //# sourceMappingURL=NotificationItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationItem.d.ts","sourceRoot":"","sources":["../../../src/components/Notification/NotificationItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,wBAAgB,gBAAgB,CAAC,QAAQ,SAAS;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,EAAE,EACxE,IAAI,EACJ,KAAK,EACL,KAAK,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,GAAG,SAAS,EACb,EAAE;IACD,IAAI,EAAE,gBAAgB,CAAA;IACtB,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC5B,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC3B,OAAO,EAAE,SAAS,CAAC,cAAc,CAAC,CAAA;IAClC,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB,UAAU,EAAE,MAAM,IAAI,CAAA;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC,2CA4BlD"}
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useToast } from "react-aria/useToast";
4
+
5
+ //#region src/components/Notification/NotificationItem.tsx
6
+ function NotificationItem({ name, toast, state, itemRef, onHoverStart, onHoverEnd, children, ...rootProps }) {
7
+ const { toastProps, contentProps, titleProps } = useToast({ toast }, state, itemRef);
8
+ return /* @__PURE__ */ jsxs("div", {
9
+ ...toastProps,
10
+ ...rootProps,
11
+ ref: itemRef,
12
+ className: `charcoal-notification charcoal-${name}`,
13
+ onPointerEnter: onHoverStart,
14
+ onPointerLeave: onHoverEnd,
15
+ children: [/* @__PURE__ */ jsx("div", {
16
+ ...contentProps,
17
+ role: "status",
18
+ className: "charcoal-notification-content",
19
+ children: /* @__PURE__ */ jsx("div", {
20
+ ...titleProps,
21
+ className: "charcoal-notification-label",
22
+ children: toast.content.message
23
+ })
24
+ }), children]
25
+ });
26
+ }
27
+
28
+ //#endregion
29
+ export { NotificationItem };
30
+ //# sourceMappingURL=NotificationItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationItem.js","names":[],"sources":["../../../src/components/Notification/NotificationItem.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode, RefObject } from 'react'\nimport { useToast } from 'react-aria/useToast'\nimport type { QueuedToast, ToastState } from 'react-stately/useToastState'\nimport type { NotificationName } from './types'\n\nexport function NotificationItem<TContent extends { message: ReactNode }>({\n name,\n toast,\n state,\n itemRef,\n onHoverStart,\n onHoverEnd,\n children,\n ...rootProps\n}: {\n name: NotificationName\n toast: QueuedToast<TContent>\n state: ToastState<TContent>\n itemRef: RefObject<HTMLDivElement>\n onHoverStart: () => void\n onHoverEnd: () => void\n children?: ReactNode\n} & Omit<HTMLAttributes<HTMLDivElement>, 'itemRef'>) {\n const { toastProps, contentProps, titleProps } = useToast(\n { toast },\n state,\n itemRef,\n )\n\n return (\n <div\n {...toastProps}\n {...rootProps}\n ref={itemRef}\n className={`charcoal-notification charcoal-${name}`}\n onPointerEnter={onHoverStart}\n onPointerLeave={onHoverEnd}\n >\n <div\n {...contentProps}\n role=\"status\"\n className=\"charcoal-notification-content\"\n >\n <div {...titleProps} className=\"charcoal-notification-label\">\n {toast.content.message}\n </div>\n </div>\n {children}\n </div>\n )\n}\n"],"mappings":";;;;;AAKA,SAAgB,iBAA0D,EACxE,MACA,OACA,OACA,SACA,cACA,YACA,UACA,GAAG,aASgD;CACnD,MAAM,EAAE,YAAY,cAAc,eAAe,SAC/C,EAAE,MAAM,GACR,OACA,OACF;CAEA,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,GAAI;EACJ,KAAK;EACL,WAAW,kCAAkC;EAC7C,gBAAgB;EAChB,gBAAgB;YANlB,CAQE,oBAAC,OAAD;GACE,GAAI;GACJ,MAAK;GACL,WAAU;aAEV,oBAAC,OAAD;IAAK,GAAI;IAAY,WAAU;cAC5B,MAAM,QAAQ;GACZ;EACF,IACJ,QACE;;AAET"}
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ const require_useClassNames = require('../../_lib/useClassNames.cjs');
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+ let react_aria_Overlay = require("react-aria/Overlay");
6
+ let react_aria_useToast = require("react-aria/useToast");
7
+
8
+ //#region src/components/Notification/NotificationRegion.tsx
9
+ const DEFAULT_OFFSET = 16;
10
+ const DEFAULT_Z_INDEX = 20;
11
+ function NotificationRegion({ name, state, position, offset = DEFAULT_OFFSET, zIndex = DEFAULT_Z_INDEX, portalContainer, className, children }) {
12
+ const regionRef = (0, react.useRef)(null);
13
+ const pausedByFocusRef = (0, react.useRef)(false);
14
+ const { regionProps } = (0, react_aria_useToast.useToastRegion)({}, {
15
+ ...state,
16
+ pauseAll() {
17
+ if (regionRef.current?.contains(document.activeElement)) {
18
+ pausedByFocusRef.current = true;
19
+ state.pauseAll();
20
+ }
21
+ },
22
+ resumeAll() {
23
+ if (pausedByFocusRef.current) {
24
+ pausedByFocusRef.current = false;
25
+ state.resumeAll();
26
+ }
27
+ }
28
+ }, regionRef);
29
+ const classNames = require_useClassNames.useClassNames("charcoal-notification-region", `charcoal-${name}-region`, className);
30
+ if (state.visibleToasts.length === 0) return null;
31
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_Overlay.Overlay, {
32
+ disableFocusManagement: true,
33
+ portalContainer,
34
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
35
+ ...regionProps,
36
+ ref: regionRef,
37
+ className: classNames,
38
+ "data-position": position,
39
+ style: {
40
+ zIndex,
41
+ [`--charcoal-${name}-offset`]: `${offset}px`
42
+ },
43
+ children
44
+ })
45
+ });
46
+ }
47
+
48
+ //#endregion
49
+ exports.NotificationRegion = NotificationRegion;
50
+ //# sourceMappingURL=NotificationRegion.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationRegion.cjs","names":[],"sources":["../../../src/components/Notification/NotificationRegion.tsx"],"sourcesContent":["import { useRef, type CSSProperties, type ReactNode } from 'react'\nimport { Overlay } from 'react-aria/Overlay'\nimport { useToastRegion } from 'react-aria/useToast'\nimport type { ToastState } from 'react-stately/useToastState'\nimport { useClassNames } from '../../_lib/useClassNames'\nimport type { NotificationName, Position } from './types'\n\nconst DEFAULT_OFFSET = 16\nconst DEFAULT_Z_INDEX = 20\n\nexport function NotificationRegion<TContent>({\n name,\n state,\n position,\n offset = DEFAULT_OFFSET,\n zIndex = DEFAULT_Z_INDEX,\n portalContainer,\n className,\n children,\n}: {\n name: NotificationName\n state: ToastState<TContent>\n position: Position\n offset?: number\n zIndex?: number\n portalContainer?: HTMLElement\n className?: string\n children: ReactNode\n}) {\n const regionRef = useRef<HTMLDivElement>(null)\n const pausedByFocusRef = useRef(false)\n const timerState: ToastState<TContent> = {\n ...state,\n pauseAll() {\n if (regionRef.current?.contains(document.activeElement)) {\n pausedByFocusRef.current = true\n state.pauseAll()\n }\n },\n resumeAll() {\n if (pausedByFocusRef.current) {\n pausedByFocusRef.current = false\n state.resumeAll()\n }\n },\n }\n const { regionProps } = useToastRegion({}, timerState, regionRef)\n const classNames = useClassNames(\n 'charcoal-notification-region',\n `charcoal-${name}-region`,\n className,\n )\n\n if (state.visibleToasts.length === 0) {\n return null\n }\n\n return (\n <Overlay disableFocusManagement portalContainer={portalContainer}>\n <div\n {...regionProps}\n ref={regionRef}\n className={classNames}\n data-position={position}\n style={\n {\n zIndex,\n [`--charcoal-${name}-offset`]: `${offset}px`,\n } as CSSProperties\n }\n >\n {children}\n </div>\n </Overlay>\n )\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAExB,SAAgB,mBAA6B,EAC3C,MACA,OACA,UACA,SAAS,gBACT,SAAS,iBACT,iBACA,WACA,YAUC;CACD,MAAM,8BAAmC,IAAI;CAC7C,MAAM,qCAA0B,KAAK;CAgBrC,MAAM,EAAE,wDAA+B,CAAC,GAAG;EAdzC,GAAG;EACH,WAAW;GACT,IAAI,UAAU,SAAS,SAAS,SAAS,aAAa,GAAG;IACvD,iBAAiB,UAAU;IAC3B,MAAM,SAAS;GACjB;EACF;EACA,YAAY;GACV,IAAI,iBAAiB,SAAS;IAC5B,iBAAiB,UAAU;IAC3B,MAAM,UAAU;GAClB;EACF;CAEyC,GAAY,SAAS;CAChE,MAAM,aAAa,oCACjB,gCACA,YAAY,KAAI,UAChB,SACF;CAEA,IAAI,MAAM,cAAc,WAAW,GACjC,OAAO;CAGT,OACE,2CAAC,4BAAD;EAAS;EAAwC;YAC/C,2CAAC,OAAD;GACE,GAAI;GACJ,KAAK;GACL,WAAW;GACX,iBAAe;GACf,OACE;IACE;KACC,cAAc,KAAI,WAAY,GAAG,OAAM;GAC1C;GAGD;EACE;CACE;AAEb"}
@@ -0,0 +1,14 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { ToastState } from 'react-stately/useToastState';
3
+ import type { NotificationName, Position } from './types';
4
+ export declare function NotificationRegion<TContent>({ name, state, position, offset, zIndex, portalContainer, className, children, }: {
5
+ name: NotificationName;
6
+ state: ToastState<TContent>;
7
+ position: Position;
8
+ offset?: number;
9
+ zIndex?: number;
10
+ portalContainer?: HTMLElement;
11
+ className?: string;
12
+ children: ReactNode;
13
+ }): import("react/jsx-runtime").JSX.Element | null;
14
+ //# sourceMappingURL=NotificationRegion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationRegion.d.ts","sourceRoot":"","sources":["../../../src/components/Notification/NotificationRegion.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGlE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKzD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,EAC3C,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,MAAuB,EACvB,MAAwB,EACxB,eAAe,EACf,SAAS,EACT,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,gBAAgB,CAAA;IACtB,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC3B,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACpB,kDA+CA"}
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { useClassNames } from "../../_lib/useClassNames.js";
3
+ import { useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { Overlay } from "react-aria/Overlay";
6
+ import { useToastRegion } from "react-aria/useToast";
7
+
8
+ //#region src/components/Notification/NotificationRegion.tsx
9
+ const DEFAULT_OFFSET = 16;
10
+ const DEFAULT_Z_INDEX = 20;
11
+ function NotificationRegion({ name, state, position, offset = DEFAULT_OFFSET, zIndex = DEFAULT_Z_INDEX, portalContainer, className, children }) {
12
+ const regionRef = useRef(null);
13
+ const pausedByFocusRef = useRef(false);
14
+ const { regionProps } = useToastRegion({}, {
15
+ ...state,
16
+ pauseAll() {
17
+ if (regionRef.current?.contains(document.activeElement)) {
18
+ pausedByFocusRef.current = true;
19
+ state.pauseAll();
20
+ }
21
+ },
22
+ resumeAll() {
23
+ if (pausedByFocusRef.current) {
24
+ pausedByFocusRef.current = false;
25
+ state.resumeAll();
26
+ }
27
+ }
28
+ }, regionRef);
29
+ const classNames = useClassNames("charcoal-notification-region", `charcoal-${name}-region`, className);
30
+ if (state.visibleToasts.length === 0) return null;
31
+ return /* @__PURE__ */ jsx(Overlay, {
32
+ disableFocusManagement: true,
33
+ portalContainer,
34
+ children: /* @__PURE__ */ jsx("div", {
35
+ ...regionProps,
36
+ ref: regionRef,
37
+ className: classNames,
38
+ "data-position": position,
39
+ style: {
40
+ zIndex,
41
+ [`--charcoal-${name}-offset`]: `${offset}px`
42
+ },
43
+ children
44
+ })
45
+ });
46
+ }
47
+
48
+ //#endregion
49
+ export { NotificationRegion };
50
+ //# sourceMappingURL=NotificationRegion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationRegion.js","names":[],"sources":["../../../src/components/Notification/NotificationRegion.tsx"],"sourcesContent":["import { useRef, type CSSProperties, type ReactNode } from 'react'\nimport { Overlay } from 'react-aria/Overlay'\nimport { useToastRegion } from 'react-aria/useToast'\nimport type { ToastState } from 'react-stately/useToastState'\nimport { useClassNames } from '../../_lib/useClassNames'\nimport type { NotificationName, Position } from './types'\n\nconst DEFAULT_OFFSET = 16\nconst DEFAULT_Z_INDEX = 20\n\nexport function NotificationRegion<TContent>({\n name,\n state,\n position,\n offset = DEFAULT_OFFSET,\n zIndex = DEFAULT_Z_INDEX,\n portalContainer,\n className,\n children,\n}: {\n name: NotificationName\n state: ToastState<TContent>\n position: Position\n offset?: number\n zIndex?: number\n portalContainer?: HTMLElement\n className?: string\n children: ReactNode\n}) {\n const regionRef = useRef<HTMLDivElement>(null)\n const pausedByFocusRef = useRef(false)\n const timerState: ToastState<TContent> = {\n ...state,\n pauseAll() {\n if (regionRef.current?.contains(document.activeElement)) {\n pausedByFocusRef.current = true\n state.pauseAll()\n }\n },\n resumeAll() {\n if (pausedByFocusRef.current) {\n pausedByFocusRef.current = false\n state.resumeAll()\n }\n },\n }\n const { regionProps } = useToastRegion({}, timerState, regionRef)\n const classNames = useClassNames(\n 'charcoal-notification-region',\n `charcoal-${name}-region`,\n className,\n )\n\n if (state.visibleToasts.length === 0) {\n return null\n }\n\n return (\n <Overlay disableFocusManagement portalContainer={portalContainer}>\n <div\n {...regionProps}\n ref={regionRef}\n className={classNames}\n data-position={position}\n style={\n {\n zIndex,\n [`--charcoal-${name}-offset`]: `${offset}px`,\n } as CSSProperties\n }\n >\n {children}\n </div>\n </Overlay>\n )\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAExB,SAAgB,mBAA6B,EAC3C,MACA,OACA,UACA,SAAS,gBACT,SAAS,iBACT,iBACA,WACA,YAUC;CACD,MAAM,YAAY,OAAuB,IAAI;CAC7C,MAAM,mBAAmB,OAAO,KAAK;CAgBrC,MAAM,EAAE,gBAAgB,eAAe,CAAC,GAAG;EAdzC,GAAG;EACH,WAAW;GACT,IAAI,UAAU,SAAS,SAAS,SAAS,aAAa,GAAG;IACvD,iBAAiB,UAAU;IAC3B,MAAM,SAAS;GACjB;EACF;EACA,YAAY;GACV,IAAI,iBAAiB,SAAS;IAC5B,iBAAiB,UAAU;IAC3B,MAAM,UAAU;GAClB;EACF;CAEyC,GAAY,SAAS;CAChE,MAAM,aAAa,cACjB,gCACA,YAAY,KAAI,UAChB,SACF;CAEA,IAAI,MAAM,cAAc,WAAW,GACjC,OAAO;CAGT,OACE,oBAAC,SAAD;EAAS;EAAwC;YAC/C,oBAAC,OAAD;GACE,GAAI;GACJ,KAAK;GACL,WAAW;GACX,iBAAe;GACf,OACE;IACE;KACC,cAAc,KAAI,WAAY,GAAG,OAAM;GAC1C;GAGD;EACE;CACE;AAEb"}
@@ -0,0 +1,45 @@
1
+ import '../layout.css';
2
+ import './index.css';
3
+ import type { ReactNode } from 'react';
4
+ import type { NotificationProps, Position } from '../types';
5
+ export type SnackbarCloseReason = 'timeout' | 'replaced' | 'action' | 'close' | 'unmounted';
6
+ export type ShowSnackbarOptions = {
7
+ /**
8
+ * Snackbar の右側に表示するアクション
9
+ */
10
+ action?: ReactNode;
11
+ /**
12
+ * Snackbar が閉じるときに呼び出される
13
+ */
14
+ onClose?: (reason: SnackbarCloseReason) => void;
15
+ };
16
+ export type SnackbarHandler = {
17
+ show: (message: ReactNode, options?: ShowSnackbarOptions) => void;
18
+ };
19
+ export type SnackbarProps = Omit<NotificationProps, 'position'> & {
20
+ /**
21
+ * Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される
22
+ * @default 'bottom'
23
+ */
24
+ position?: Position;
25
+ /**
26
+ * 暗い背景色
27
+ * @default false
28
+ */
29
+ dim?: boolean;
30
+ };
31
+ declare const Snackbar: import("react").ForwardRefExoticComponent<Omit<NotificationProps, "position"> & {
32
+ /**
33
+ * Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される
34
+ * @default 'bottom'
35
+ */
36
+ position?: Position;
37
+ /**
38
+ * 暗い背景色
39
+ * @default false
40
+ */
41
+ dim?: boolean;
42
+ } & import("react").RefAttributes<SnackbarHandler>>;
43
+ export default Snackbar;
44
+ export declare function useSnackbar(props?: SnackbarProps): readonly [import("react/jsx-runtime").JSX.Element, (message: ReactNode, options?: ShowSnackbarOptions) => void];
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Notification/Snackbar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE3D,MAAM,MAAM,mBAAmB,GAC7B,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,CAAA;AAE3D,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;CAChD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAA;CAClE,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG;IAChE;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAOD,QAAA,MAAM,QAAQ;IAjBZ;;;OAGG;eACQ,QAAQ;IACnB;;;OAGG;UACG,OAAO;mDAqEb,CAAA;eAEa,QAAQ;AAEvB,wBAAgB,WAAW,CAAC,KAAK,GAAE,aAAkB,gEAK5B,SAAS,YAAY,mBAAmB,WAIhE"}
@@ -0,0 +1,99 @@
1
+ "use client";
2
+ require('../layout.cjs');
3
+ require('./index.cjs');
4
+ const require_NotificationItem = require('../NotificationItem.cjs');
5
+ const require_NotificationRegion = require('../NotificationRegion.cjs');
6
+ const require_useNotificationQueue = require('../useNotificationQueue.cjs');
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ let react_compiler_runtime = require("react-compiler-runtime");
10
+
11
+ //#region src/components/Notification/Snackbar/index.tsx
12
+ const Snackbar = (0, react.forwardRef)(function Snackbar({ position = "bottom", dim = false, duration, order, ...regionProps }, ref) {
13
+ "use memo";
14
+ const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = require_useNotificationQueue.useNotificationQueue("snackbar", {
15
+ duration,
16
+ order,
17
+ timeoutReason: "timeout",
18
+ unmountedReason: "unmounted"
19
+ });
20
+ function show(message, options = {}) {
21
+ enqueue({
22
+ message,
23
+ action: options.action
24
+ }, options.onClose);
25
+ }
26
+ (0, react.useImperativeHandle)(ref, () => ({ show }));
27
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationRegion.NotificationRegion, {
28
+ name: "snackbar",
29
+ state,
30
+ position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
31
+ ...regionProps,
32
+ children: state.visibleToasts.map((toast_0) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationItem.NotificationItem, {
33
+ name: "snackbar",
34
+ toast: toast_0,
35
+ state,
36
+ itemRef,
37
+ onHoverStart,
38
+ onHoverEnd,
39
+ "data-dim": dim,
40
+ "data-with-action": toast_0.content.action !== void 0,
41
+ children: toast_0.content.action !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarAction, {
42
+ action: toast_0.content.action,
43
+ onClick: () => close(toast_0.key, "action")
44
+ })
45
+ }, toast_0.key))
46
+ });
47
+ });
48
+ function useSnackbar(t0) {
49
+ "use memo";
50
+ const $ = (0, react_compiler_runtime.c)(8);
51
+ if ($[0] !== "1dc1eb8429c7be1137abcfa05286c14e7ca96230a56b18d315897aa3a5101e4e") {
52
+ for (let $i = 0; $i < 8; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
53
+ $[0] = "1dc1eb8429c7be1137abcfa05286c14e7ca96230a56b18d315897aa3a5101e4e";
54
+ }
55
+ let t1;
56
+ if ($[1] !== t0) {
57
+ t1 = t0 === void 0 ? {} : t0;
58
+ $[1] = t0;
59
+ $[2] = t1;
60
+ } else t1 = $[2];
61
+ const props = t1;
62
+ const snackbarHandlerRef = (0, react.useRef)(null);
63
+ let t2;
64
+ if ($[3] !== props) {
65
+ t2 = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Snackbar, {
66
+ ref: snackbarHandlerRef,
67
+ ...props
68
+ });
69
+ $[3] = props;
70
+ $[4] = t2;
71
+ } else t2 = $[4];
72
+ const element = t2;
73
+ let t3;
74
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
75
+ t3 = function show(message, options) {
76
+ snackbarHandlerRef.current?.show(message, options);
77
+ };
78
+ $[5] = t3;
79
+ } else t3 = $[5];
80
+ const show = t3;
81
+ let t4;
82
+ if ($[6] !== element) {
83
+ t4 = [element, show];
84
+ $[6] = element;
85
+ $[7] = t4;
86
+ } else t4 = $[7];
87
+ return t4;
88
+ }
89
+ function SnackbarAction({ action, onClick }) {
90
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
91
+ onClick,
92
+ children: action
93
+ });
94
+ }
95
+
96
+ //#endregion
97
+ exports.default = Snackbar;
98
+ exports.useSnackbar = useSnackbar;
99
+ //# sourceMappingURL=index2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index2.cjs","names":["toast","snackbarHandlerRef"],"sources":["../../../../src/components/Notification/Snackbar/index.tsx"],"sourcesContent":["import '../layout.css'\nimport './index.css'\n\nimport { forwardRef, useImperativeHandle, useRef } from 'react'\nimport type { ReactNode } from 'react'\nimport { NotificationItem } from '../NotificationItem'\nimport { NotificationRegion } from '../NotificationRegion'\nimport { useNotificationQueue } from '../useNotificationQueue'\nimport type { NotificationProps, Position } from '../types'\n\nexport type SnackbarCloseReason =\n 'timeout' | 'replaced' | 'action' | 'close' | 'unmounted'\n\nexport type ShowSnackbarOptions = {\n /**\n * Snackbar の右側に表示するアクション\n */\n action?: ReactNode\n /**\n * Snackbar が閉じるときに呼び出される\n */\n onClose?: (reason: SnackbarCloseReason) => void\n}\n\nexport type SnackbarHandler = {\n show: (message: ReactNode, options?: ShowSnackbarOptions) => void\n}\n\nexport type SnackbarProps = Omit<NotificationProps, 'position'> & {\n /**\n * Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される\n * @default 'bottom'\n */\n position?: Position\n /**\n * 暗い背景色\n * @default false\n */\n dim?: boolean\n}\n\ntype SnackbarContent = {\n message: ReactNode\n action?: ReactNode\n}\n\nconst Snackbar = forwardRef<SnackbarHandler, SnackbarProps>(function Snackbar(\n { position = 'bottom', dim = false, duration, order, ...regionProps },\n ref,\n) {\n 'use memo'\n\n const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } =\n useNotificationQueue<SnackbarContent, SnackbarCloseReason>('snackbar', {\n duration,\n order,\n timeoutReason: 'timeout',\n unmountedReason: 'unmounted',\n })\n\n function show(message: ReactNode, options: ShowSnackbarOptions = {}) {\n enqueue(\n {\n message,\n action: options.action,\n },\n options.onClose,\n )\n }\n\n useImperativeHandle(ref, () => ({ show }))\n\n // アクション付きの Snackbar は常に下部に表示される\n const hasAction = state.visibleToasts.some(\n (toast) => toast.content.action !== undefined,\n )\n const effectivePosition = hasAction ? 'bottom' : position\n\n return (\n <NotificationRegion\n name=\"snackbar\"\n state={state}\n position={effectivePosition}\n {...regionProps}\n >\n {state.visibleToasts.map((toast) => (\n <NotificationItem\n key={toast.key}\n name=\"snackbar\"\n toast={toast}\n state={state}\n itemRef={itemRef}\n onHoverStart={onHoverStart}\n onHoverEnd={onHoverEnd}\n data-dim={dim}\n data-with-action={toast.content.action !== undefined}\n >\n {toast.content.action !== undefined && (\n <SnackbarAction\n action={toast.content.action}\n onClick={() => close(toast.key, 'action')}\n />\n )}\n </NotificationItem>\n ))}\n </NotificationRegion>\n )\n})\n\nexport default Snackbar\n\nexport function useSnackbar(props: SnackbarProps = {}) {\n 'use memo'\n\n const snackbarHandlerRef = useRef<SnackbarHandler>(null)\n const element = <Snackbar ref={snackbarHandlerRef} {...props} />\n function show(message: ReactNode, options?: ShowSnackbarOptions) {\n snackbarHandlerRef.current?.show(message, options)\n }\n return [element, show] as const\n}\n\nfunction SnackbarAction({\n action,\n onClick,\n}: {\n action: ReactNode\n onClick: () => void\n}) {\n return <div onClick={onClick}>{action}</div>\n}\n"],"mappings":";;;;;;;;;;;AA8CA,MAAM,iCAAsD,SAAS,SACnE,EAAE,WAAW,UAAU,MAAM,OAAO,UAAU,OAAO,GAAG,eACxD,KACA;CACA;CAEA,MAAM,EAAE,OAAO,SAAS,SAAS,OAAO,cAAc,eACpD,kDAA2D,YAAY;EACrE;EACA;EACA,eAAe;EACf,iBAAiB;CACnB,CAAC;CAEH,SAAS,KAAK,SAAoB,UAA+B,CAAC,GAAG;EACnE,QACE;GACE;GACA,QAAQ,QAAQ;EAClB,GACA,QAAQ,OACV;CACF;CAEA,+BAAoB,YAAY,EAAE,KAAK,EAAE;CAQzC,OACE,2CAAC,+CAAD;EACE,MAAK;EACE;EACP,UATc,MAAM,cAAc,MACnC,UAAU,MAAM,QAAQ,WAAW,MAEZ,IAAY,WAAW;EAO7C,GAAI;YAEH,MAAM,cAAc,KAAKA,YACxB,2CAAC,2CAAD;GAEE,MAAK;GACL,OAAOA;GACA;GACE;GACK;GACF;GACZ,YAAU;GACV,oBAAkBA,QAAM,QAAQ,WAAW;aAE1CA,QAAM,QAAQ,WAAW,UACxB,2CAAC,gBAAD;IACE,QAAQA,QAAM,QAAQ;IACtB,eAAe,MAAMA,QAAM,KAAK,QAAQ;GAAE;EAG9B,GAhBXA,QAAM,GAgBK,CACnB;CACiB;AAExB,CAAC;AAID,SAAO,YAAA,IAAA;CAAA;CAAA,MAAA,kCAAA,CAAA;CAAA,IAAA,EAAA,OAAA,oEAAA;EAAA,KAAA,IAAA,KAAA,GAAA,KAAA,GAAA,MAAA,GAAA,EAAA,MAAA,OAAA,IAAA,2BAAA;EAAA,EAAA,KAAA;CAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,IAAA;EAAqB,KAAA,OAAA,SAAA,CAAwB,IAAxB;EAAyB,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAzB,MAAA,QAAA;CAG1B,MAAA,uCAAmD,IAAI;CAAC,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA;EACxC,KAAA,2CAAC,UAAD;GAAeC,KAAA;GAAkB,GAAM;EAAK;EAAI,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAhE,MAAA,UAAgB;CAAgD,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA,IAAA,2BAAA,GAAA;EAChE,KAAA,SAAA,KAAA,SAAA,SAAA;GACE,mBAAkB,SAAc,KAAC,SAAS,OAAO;EAAC;EACnD,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAFD,MAAA,OAAA;CAEC,IAAA;CAAA,IAAA,EAAA,OAAA,SAAA;EACM,KAAA,CAAC,SAAS,IAAI;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAAf;AAAwB;AAGjC,SAAS,eAAe,EACtB,QACA,WAIC;CACD,OAAO,2CAAC,OAAD;EAAc;YAAU;CAAY;AAC7C"}
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ /* empty css */
3
+ /* empty css */
4
+ import { NotificationItem } from "../NotificationItem.js";
5
+ import { NotificationRegion } from "../NotificationRegion.js";
6
+ import { useNotificationQueue } from "../useNotificationQueue.js";
7
+ import { forwardRef, useImperativeHandle, useRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import { c } from "react-compiler-runtime";
10
+
11
+ //#region src/components/Notification/Snackbar/index.tsx
12
+ const Snackbar = forwardRef(function Snackbar({ position = "bottom", dim = false, duration, order, ...regionProps }, ref) {
13
+ "use memo";
14
+ const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = useNotificationQueue("snackbar", {
15
+ duration,
16
+ order,
17
+ timeoutReason: "timeout",
18
+ unmountedReason: "unmounted"
19
+ });
20
+ function show(message, options = {}) {
21
+ enqueue({
22
+ message,
23
+ action: options.action
24
+ }, options.onClose);
25
+ }
26
+ useImperativeHandle(ref, () => ({ show }));
27
+ return /* @__PURE__ */ jsx(NotificationRegion, {
28
+ name: "snackbar",
29
+ state,
30
+ position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
31
+ ...regionProps,
32
+ children: state.visibleToasts.map((toast_0) => /* @__PURE__ */ jsx(NotificationItem, {
33
+ name: "snackbar",
34
+ toast: toast_0,
35
+ state,
36
+ itemRef,
37
+ onHoverStart,
38
+ onHoverEnd,
39
+ "data-dim": dim,
40
+ "data-with-action": toast_0.content.action !== void 0,
41
+ children: toast_0.content.action !== void 0 && /* @__PURE__ */ jsx(SnackbarAction, {
42
+ action: toast_0.content.action,
43
+ onClick: () => close(toast_0.key, "action")
44
+ })
45
+ }, toast_0.key))
46
+ });
47
+ });
48
+ function useSnackbar(t0) {
49
+ "use memo";
50
+ const $ = c(7);
51
+ let t1;
52
+ if ($[0] !== t0) {
53
+ t1 = t0 === void 0 ? {} : t0;
54
+ $[0] = t0;
55
+ $[1] = t1;
56
+ } else t1 = $[1];
57
+ const props = t1;
58
+ const snackbarHandlerRef = useRef(null);
59
+ let t2;
60
+ if ($[2] !== props) {
61
+ t2 = /* @__PURE__ */ jsx(Snackbar, {
62
+ ref: snackbarHandlerRef,
63
+ ...props
64
+ });
65
+ $[2] = props;
66
+ $[3] = t2;
67
+ } else t2 = $[3];
68
+ const element = t2;
69
+ let t3;
70
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
71
+ t3 = function show(message, options) {
72
+ snackbarHandlerRef.current?.show(message, options);
73
+ };
74
+ $[4] = t3;
75
+ } else t3 = $[4];
76
+ const show = t3;
77
+ let t4;
78
+ if ($[5] !== element) {
79
+ t4 = [element, show];
80
+ $[5] = element;
81
+ $[6] = t4;
82
+ } else t4 = $[6];
83
+ return t4;
84
+ }
85
+ function SnackbarAction({ action, onClick }) {
86
+ return /* @__PURE__ */ jsx("div", {
87
+ onClick,
88
+ children: action
89
+ });
90
+ }
91
+
92
+ //#endregion
93
+ export { Snackbar as default, useSnackbar };
94
+ //# sourceMappingURL=index2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index2.js","names":["toast","snackbarHandlerRef"],"sources":["../../../../src/components/Notification/Snackbar/index.tsx"],"sourcesContent":["import '../layout.css'\nimport './index.css'\n\nimport { forwardRef, useImperativeHandle, useRef } from 'react'\nimport type { ReactNode } from 'react'\nimport { NotificationItem } from '../NotificationItem'\nimport { NotificationRegion } from '../NotificationRegion'\nimport { useNotificationQueue } from '../useNotificationQueue'\nimport type { NotificationProps, Position } from '../types'\n\nexport type SnackbarCloseReason =\n 'timeout' | 'replaced' | 'action' | 'close' | 'unmounted'\n\nexport type ShowSnackbarOptions = {\n /**\n * Snackbar の右側に表示するアクション\n */\n action?: ReactNode\n /**\n * Snackbar が閉じるときに呼び出される\n */\n onClose?: (reason: SnackbarCloseReason) => void\n}\n\nexport type SnackbarHandler = {\n show: (message: ReactNode, options?: ShowSnackbarOptions) => void\n}\n\nexport type SnackbarProps = Omit<NotificationProps, 'position'> & {\n /**\n * Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される\n * @default 'bottom'\n */\n position?: Position\n /**\n * 暗い背景色\n * @default false\n */\n dim?: boolean\n}\n\ntype SnackbarContent = {\n message: ReactNode\n action?: ReactNode\n}\n\nconst Snackbar = forwardRef<SnackbarHandler, SnackbarProps>(function Snackbar(\n { position = 'bottom', dim = false, duration, order, ...regionProps },\n ref,\n) {\n 'use memo'\n\n const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } =\n useNotificationQueue<SnackbarContent, SnackbarCloseReason>('snackbar', {\n duration,\n order,\n timeoutReason: 'timeout',\n unmountedReason: 'unmounted',\n })\n\n function show(message: ReactNode, options: ShowSnackbarOptions = {}) {\n enqueue(\n {\n message,\n action: options.action,\n },\n options.onClose,\n )\n }\n\n useImperativeHandle(ref, () => ({ show }))\n\n // アクション付きの Snackbar は常に下部に表示される\n const hasAction = state.visibleToasts.some(\n (toast) => toast.content.action !== undefined,\n )\n const effectivePosition = hasAction ? 'bottom' : position\n\n return (\n <NotificationRegion\n name=\"snackbar\"\n state={state}\n position={effectivePosition}\n {...regionProps}\n >\n {state.visibleToasts.map((toast) => (\n <NotificationItem\n key={toast.key}\n name=\"snackbar\"\n toast={toast}\n state={state}\n itemRef={itemRef}\n onHoverStart={onHoverStart}\n onHoverEnd={onHoverEnd}\n data-dim={dim}\n data-with-action={toast.content.action !== undefined}\n >\n {toast.content.action !== undefined && (\n <SnackbarAction\n action={toast.content.action}\n onClick={() => close(toast.key, 'action')}\n />\n )}\n </NotificationItem>\n ))}\n </NotificationRegion>\n )\n})\n\nexport default Snackbar\n\nexport function useSnackbar(props: SnackbarProps = {}) {\n 'use memo'\n\n const snackbarHandlerRef = useRef<SnackbarHandler>(null)\n const element = <Snackbar ref={snackbarHandlerRef} {...props} />\n function show(message: ReactNode, options?: ShowSnackbarOptions) {\n snackbarHandlerRef.current?.show(message, options)\n }\n return [element, show] as const\n}\n\nfunction SnackbarAction({\n action,\n onClick,\n}: {\n action: ReactNode\n onClick: () => void\n}) {\n return <div onClick={onClick}>{action}</div>\n}\n"],"mappings":";;;;;;;;;;;AA8CA,MAAM,WAAW,WAA2C,SAAS,SACnE,EAAE,WAAW,UAAU,MAAM,OAAO,UAAU,OAAO,GAAG,eACxD,KACA;CACA;CAEA,MAAM,EAAE,OAAO,SAAS,SAAS,OAAO,cAAc,eACpD,qBAA2D,YAAY;EACrE;EACA;EACA,eAAe;EACf,iBAAiB;CACnB,CAAC;CAEH,SAAS,KAAK,SAAoB,UAA+B,CAAC,GAAG;EACnE,QACE;GACE;GACA,QAAQ,QAAQ;EAClB,GACA,QAAQ,OACV;CACF;CAEA,oBAAoB,YAAY,EAAE,KAAK,EAAE;CAQzC,OACE,oBAAC,oBAAD;EACE,MAAK;EACE;EACP,UATc,MAAM,cAAc,MACnC,UAAU,MAAM,QAAQ,WAAW,MAEZ,IAAY,WAAW;EAO7C,GAAI;YAEH,MAAM,cAAc,KAAKA,YACxB,oBAAC,kBAAD;GAEE,MAAK;GACL,OAAOA;GACA;GACE;GACK;GACF;GACZ,YAAU;GACV,oBAAkBA,QAAM,QAAQ,WAAW;aAE1CA,QAAM,QAAQ,WAAW,UACxB,oBAAC,gBAAD;IACE,QAAQA,QAAM,QAAQ;IACtB,eAAe,MAAMA,QAAM,KAAK,QAAQ;GAAE;EAG9B,GAhBXA,QAAM,GAgBK,CACnB;CACiB;AAExB,CAAC;AAID,SAAO,YAAA,IAAA;CAAA;CAAA,MAAA,IAAA,EAAA,CAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,IAAA;EAAqB,KAAA,OAAA,SAAA,CAAwB,IAAxB;EAAyB,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAzB,MAAA,QAAA;CAG1B,MAAA,qBAA2B,OAAwB,IAAI;CAAC,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA;EACxC,KAAA,oBAAC,UAAD;GAAeC,KAAA;GAAkB,GAAM;EAAK;EAAI,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAhE,MAAA,UAAgB;CAAgD,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA,IAAA,2BAAA,GAAA;EAChE,KAAA,SAAA,KAAA,SAAA,SAAA;GACE,mBAAkB,SAAc,KAAC,SAAS,OAAO;EAAC;EACnD,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAFD,MAAA,OAAA;CAEC,IAAA;CAAA,IAAA,EAAA,OAAA,SAAA;EACM,KAAA,CAAC,SAAS,IAAI;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAAf;AAAwB;AAGjC,SAAS,eAAe,EACtB,QACA,WAIC;CACD,OAAO,oBAAC,OAAD;EAAc;YAAU;CAAY;AAC7C"}
@@ -0,0 +1,28 @@
1
+ import '../layout.css';
2
+ import './index.css';
3
+ import type { ReactNode } from 'react';
4
+ import type { NotificationProps, Position } from '../types';
5
+ export type ToastType = 'success' | 'error';
6
+ export type ShowToastOptions = {
7
+ type: ToastType;
8
+ };
9
+ export type ToastHandler = {
10
+ show: (message: ReactNode, options: ShowToastOptions) => void;
11
+ };
12
+ export type ToastProps = Omit<NotificationProps, 'position'> & {
13
+ /**
14
+ * Toast の表示位置
15
+ * @default 'top'
16
+ */
17
+ position?: Position;
18
+ };
19
+ declare const Toast: import("react").ForwardRefExoticComponent<Omit<NotificationProps, "position"> & {
20
+ /**
21
+ * Toast の表示位置
22
+ * @default 'top'
23
+ */
24
+ position?: Position;
25
+ } & import("react").RefAttributes<ToastHandler>>;
26
+ export default Toast;
27
+ export declare function useToast(props?: ToastProps): readonly [import("react/jsx-runtime").JSX.Element, (message: ReactNode, options: ShowToastOptions) => void];
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Notification/Toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AACtB,OAAO,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE3D,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AAE3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC9D,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG;IAC7D;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAOD,QAAA,MAAM,KAAK;IAZT;;;OAGG;eACQ,QAAQ;gDA+CnB,CAAA;eAEa,KAAK;AAEpB,wBAAgB,QAAQ,CAAC,KAAK,GAAE,UAAe,gEAKtB,SAAS,WAAW,gBAAgB,WAI5D"}
@@ -0,0 +1,86 @@
1
+ "use client";
2
+ require('../layout.cjs');
3
+ const require_NotificationItem = require('../NotificationItem.cjs');
4
+ const require_NotificationRegion = require('../NotificationRegion.cjs');
5
+ const require_useNotificationQueue = require('../useNotificationQueue.cjs');
6
+ require('./index.cjs');
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ let react_compiler_runtime = require("react-compiler-runtime");
10
+
11
+ //#region src/components/Notification/Toast/index.tsx
12
+ const Toast = (0, react.forwardRef)(function Toast({ position = "top", duration, order, ...regionProps }, ref) {
13
+ "use memo";
14
+ const { state, itemRef, enqueue, onHoverStart, onHoverEnd } = require_useNotificationQueue.useNotificationQueue("toast", {
15
+ duration,
16
+ order
17
+ });
18
+ function show(message, options) {
19
+ enqueue({
20
+ message,
21
+ type: options.type
22
+ });
23
+ }
24
+ (0, react.useImperativeHandle)(ref, () => ({ show }));
25
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationRegion.NotificationRegion, {
26
+ name: "toast",
27
+ state,
28
+ position,
29
+ ...regionProps,
30
+ children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationItem.NotificationItem, {
31
+ name: "toast",
32
+ toast,
33
+ state,
34
+ itemRef,
35
+ onHoverStart,
36
+ onHoverEnd,
37
+ "data-type": toast.content.type
38
+ }, toast.key))
39
+ });
40
+ });
41
+ function useToast(t0) {
42
+ "use memo";
43
+ const $ = (0, react_compiler_runtime.c)(8);
44
+ if ($[0] !== "aad1570b2784f7343f322f27996bd84f97380bf45debf5009829c7eb5dc91e8e") {
45
+ for (let $i = 0; $i < 8; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
46
+ $[0] = "aad1570b2784f7343f322f27996bd84f97380bf45debf5009829c7eb5dc91e8e";
47
+ }
48
+ let t1;
49
+ if ($[1] !== t0) {
50
+ t1 = t0 === void 0 ? {} : t0;
51
+ $[1] = t0;
52
+ $[2] = t1;
53
+ } else t1 = $[2];
54
+ const props = t1;
55
+ const toastHandlerRef = (0, react.useRef)(null);
56
+ let t2;
57
+ if ($[3] !== props) {
58
+ t2 = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Toast, {
59
+ ref: toastHandlerRef,
60
+ ...props
61
+ });
62
+ $[3] = props;
63
+ $[4] = t2;
64
+ } else t2 = $[4];
65
+ const element = t2;
66
+ let t3;
67
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
68
+ t3 = function show(message, options) {
69
+ toastHandlerRef.current?.show(message, options);
70
+ };
71
+ $[5] = t3;
72
+ } else t3 = $[5];
73
+ const show = t3;
74
+ let t4;
75
+ if ($[6] !== element) {
76
+ t4 = [element, show];
77
+ $[6] = element;
78
+ $[7] = t4;
79
+ } else t4 = $[7];
80
+ return t4;
81
+ }
82
+
83
+ //#endregion
84
+ exports.default = Toast;
85
+ exports.useToast = useToast;
86
+ //# sourceMappingURL=index2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index2.cjs","names":["toastHandlerRef"],"sources":["../../../../src/components/Notification/Toast/index.tsx"],"sourcesContent":["import '../layout.css'\nimport './index.css'\n\nimport { forwardRef, useImperativeHandle, useRef } from 'react'\nimport type { ReactNode } from 'react'\nimport { NotificationItem } from '../NotificationItem'\nimport { NotificationRegion } from '../NotificationRegion'\nimport { useNotificationQueue } from '../useNotificationQueue'\nimport type { NotificationProps, Position } from '../types'\n\nexport type ToastType = 'success' | 'error'\n\nexport type ShowToastOptions = {\n type: ToastType\n}\n\nexport type ToastHandler = {\n show: (message: ReactNode, options: ShowToastOptions) => void\n}\n\nexport type ToastProps = Omit<NotificationProps, 'position'> & {\n /**\n * Toast の表示位置\n * @default 'top'\n */\n position?: Position\n}\n\ntype ToastContent = {\n message: ReactNode\n type: ToastType\n}\n\nconst Toast = forwardRef<ToastHandler, ToastProps>(function Toast(\n { position = 'top', duration, order, ...regionProps },\n ref,\n) {\n 'use memo'\n\n const { state, itemRef, enqueue, onHoverStart, onHoverEnd } =\n useNotificationQueue<ToastContent>('toast', { duration, order })\n\n function show(message: ReactNode, options: ShowToastOptions) {\n enqueue({\n message,\n type: options.type,\n })\n }\n\n useImperativeHandle(ref, () => ({ show }))\n\n return (\n <NotificationRegion\n name=\"toast\"\n state={state}\n position={position}\n {...regionProps}\n >\n {state.visibleToasts.map((toast) => (\n <NotificationItem\n key={toast.key}\n name=\"toast\"\n toast={toast}\n state={state}\n itemRef={itemRef}\n onHoverStart={onHoverStart}\n onHoverEnd={onHoverEnd}\n data-type={toast.content.type}\n />\n ))}\n </NotificationRegion>\n )\n})\n\nexport default Toast\n\nexport function useToast(props: ToastProps = {}) {\n 'use memo'\n\n const toastHandlerRef = useRef<ToastHandler>(null)\n const element = <Toast ref={toastHandlerRef} {...props} />\n function show(message: ReactNode, options: ShowToastOptions) {\n toastHandlerRef.current?.show(message, options)\n }\n return [element, show] as const\n}\n"],"mappings":";;;;;;;;;;;AAiCA,MAAM,8BAA6C,SAAS,MAC1D,EAAE,WAAW,OAAO,UAAU,OAAO,GAAG,eACxC,KACA;CACA;CAEA,MAAM,EAAE,OAAO,SAAS,SAAS,cAAc,eAC7C,kDAAmC,SAAS;EAAE;EAAU;CAAM,CAAC;CAEjE,SAAS,KAAK,SAAoB,SAA2B;EAC3D,QAAQ;GACN;GACA,MAAM,QAAQ;EAChB,CAAC;CACH;CAEA,+BAAoB,YAAY,EAAE,KAAK,EAAE;CAEzC,OACE,2CAAC,+CAAD;EACE,MAAK;EACE;EACG;EACV,GAAI;YAEH,MAAM,cAAc,KAAK,UACxB,2CAAC,2CAAD;GAEE,MAAK;GACE;GACA;GACE;GACK;GACF;GACZ,aAAW,MAAM,QAAQ;EAAK,GAPzB,MAAM,GAOmB,CAEjC;CACiB;AAExB,CAAC;AAID,SAAO,SAAA,IAAA;CAAA;CAAA,MAAA,kCAAA,CAAA;CAAA,IAAA,EAAA,OAAA,oEAAA;EAAA,KAAA,IAAA,KAAA,GAAA,KAAA,GAAA,MAAA,GAAA,EAAA,MAAA,OAAA,IAAA,2BAAA;EAAA,EAAA,KAAA;CAAA;CAAA,IAAA;CAAA,IAAA,EAAA,OAAA,IAAA;EAAkB,KAAA,OAAA,SAAA,CAAqB,IAArB;EAAsB,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAtB,MAAA,QAAA;CAGvB,MAAA,oCAA6C,IAAI;CAAC,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA;EAClC,KAAA,2CAAC,OAAD;GAAYA,KAAA;GAAe,GAAM;EAAK;EAAI,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAA1D,MAAA,UAAgB;CAA0C,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA,IAAA,2BAAA,GAAA;EAC1D,KAAA,SAAA,KAAA,SAAA,SAAA;GACE,gBAAe,SAAc,KAAC,SAAS,OAAO;EAAC;EAChD,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAFD,MAAA,OAAA;CAEC,IAAA;CAAA,IAAA,EAAA,OAAA,SAAA;EACM,KAAA,CAAC,SAAS,IAAI;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAAf;AAAwB"}