@charcoal-ui/react 6.1.0-beta.0 → 6.1.0-beta.2
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/dist/components/Notification/NotificationItem.cjs +30 -0
- package/dist/components/Notification/NotificationItem.cjs.map +1 -0
- package/dist/components/Notification/NotificationItem.d.ts +15 -0
- package/dist/components/Notification/NotificationItem.d.ts.map +1 -0
- package/dist/components/Notification/NotificationItem.js +30 -0
- package/dist/components/Notification/NotificationItem.js.map +1 -0
- package/dist/components/Notification/NotificationRegion.cjs +50 -0
- package/dist/components/Notification/NotificationRegion.cjs.map +1 -0
- package/dist/components/Notification/NotificationRegion.d.ts +14 -0
- package/dist/components/Notification/NotificationRegion.d.ts.map +1 -0
- package/dist/components/Notification/NotificationRegion.js +50 -0
- package/dist/components/Notification/NotificationRegion.js.map +1 -0
- package/dist/components/Notification/Snackbar/index.d.ts +29 -0
- package/dist/components/Notification/Snackbar/index.d.ts.map +1 -0
- package/dist/components/Notification/Snackbar/index2.cjs +79 -0
- package/dist/components/Notification/Snackbar/index2.cjs.map +1 -0
- package/dist/components/Notification/Snackbar/index2.js +78 -0
- package/dist/components/Notification/Snackbar/index2.js.map +1 -0
- package/dist/components/Notification/Toast/index.d.ts +28 -0
- package/dist/components/Notification/Toast/index.d.ts.map +1 -0
- package/dist/components/Notification/Toast/index2.cjs +86 -0
- package/dist/components/Notification/Toast/index2.cjs.map +1 -0
- package/dist/components/Notification/Toast/index2.js +85 -0
- package/dist/components/Notification/Toast/index2.js.map +1 -0
- package/dist/components/Notification/types.d.ts +27 -0
- package/dist/components/Notification/types.d.ts.map +1 -0
- package/dist/components/Notification/useNotificationQueue.cjs +155 -0
- package/dist/components/Notification/useNotificationQueue.cjs.map +1 -0
- package/dist/components/Notification/useNotificationQueue.d.ts +16 -0
- package/dist/components/Notification/useNotificationQueue.d.ts.map +1 -0
- package/dist/components/Notification/useNotificationQueue.js +155 -0
- package/dist/components/Notification/useNotificationQueue.js.map +1 -0
- package/dist/components/Pagination/index2.js +60 -52
- package/dist/components/Pagination/index2.js.map +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.css +822 -757
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/layered.css +822 -757
- package/dist/layered.css.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/css-output.test.ts +39 -6
- package/src/components/Notification/NotificationItem.tsx +51 -0
- package/src/components/Notification/NotificationRegion.tsx +76 -0
- package/src/components/{Snackbar → Notification/Snackbar}/__snapshots__/index.css.snap +1 -42
- package/src/components/{Snackbar → Notification/Snackbar}/index.css +1 -43
- package/src/components/{Snackbar → Notification/Snackbar}/index.story.tsx +70 -34
- package/src/components/{Snackbar → Notification/Snackbar}/index.test.tsx +99 -18
- package/src/components/Notification/Snackbar/index.tsx +136 -0
- package/src/components/Notification/Toast/__snapshots__/index.css.snap +62 -0
- package/src/components/Notification/Toast/index.css +61 -0
- package/src/components/Notification/Toast/index.story.tsx +177 -0
- package/src/components/Notification/Toast/index.test.tsx +263 -0
- package/src/components/Notification/Toast/index.tsx +86 -0
- package/src/components/Notification/__snapshots__/layout.css.snap +47 -0
- package/src/components/Notification/layout.css +46 -0
- package/src/components/Notification/types.ts +28 -0
- package/src/components/Notification/useNotificationQueue.ts +235 -0
- package/src/index.ts +17 -5
- package/dist/components/Snackbar/index.d.ts +0 -52
- package/dist/components/Snackbar/index.d.ts.map +0 -1
- package/dist/components/Snackbar/index2.cjs +0 -268
- package/dist/components/Snackbar/index2.cjs.map +0 -1
- package/dist/components/Snackbar/index2.js +0 -263
- package/dist/components/Snackbar/index2.js.map +0 -1
- 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,29 @@
|
|
|
1
|
+
import '../layout.css';
|
|
2
|
+
import './index.css';
|
|
3
|
+
import { type HTMLAttributes, 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
|
+
action?: ReactNode;
|
|
8
|
+
onClose?: (reason: SnackbarCloseReason) => void;
|
|
9
|
+
};
|
|
10
|
+
type SnackbarBaseProps = {
|
|
11
|
+
message: ReactNode;
|
|
12
|
+
action?: ReactNode;
|
|
13
|
+
dim?: boolean;
|
|
14
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
15
|
+
export type SnackbarProps = Omit<SnackbarBaseProps, 'action'> & {
|
|
16
|
+
/** Snackbar の右側に表示するアクション */
|
|
17
|
+
action: NonNullable<ReactNode>;
|
|
18
|
+
};
|
|
19
|
+
export type UseSnackbarProps = Omit<NotificationProps, 'position'> & {
|
|
20
|
+
position?: Position;
|
|
21
|
+
dim?: boolean;
|
|
22
|
+
};
|
|
23
|
+
declare const Snackbar: import("react").ForwardRefExoticComponent<Omit<SnackbarBaseProps, "action"> & {
|
|
24
|
+
/** Snackbar の右側に表示するアクション */
|
|
25
|
+
action: NonNullable<ReactNode>;
|
|
26
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
27
|
+
export default Snackbar;
|
|
28
|
+
export declare function useSnackbar(props?: UseSnackbarProps): readonly [import("react/jsx-runtime").JSX.Element, (message: ReactNode, options?: ShowSnackbarOptions) => void];
|
|
29
|
+
//# 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;AAEpB,OAAO,EAAc,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAKvE,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,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;CAChD,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,SAAS,CAAA;IAClB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,CAAA;AAEpD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,GAAG;IAC9D,6BAA6B;IAC7B,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG;IACnE,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAOD,QAAA,MAAM,QAAQ;IAdZ,6BAA6B;YACrB,WAAW,CAAC,SAAS,CAAC;kDAiB/B,CAAA;eAEc,QAAQ;AAEvB,wBAAgB,WAAW,CAAC,KAAK,GAAE,gBAAqB,gEAkB/B,SAAS,YAAW,mBAAmB,WAsC/D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_useClassNames = require('../../../_lib/useClassNames.cjs');
|
|
3
|
+
require('../layout.cjs');
|
|
4
|
+
require('./index.cjs');
|
|
5
|
+
const require_NotificationItem = require('../NotificationItem.cjs');
|
|
6
|
+
const require_NotificationRegion = require('../NotificationRegion.cjs');
|
|
7
|
+
const require_useNotificationQueue = require('../useNotificationQueue.cjs');
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
|
|
11
|
+
//#region src/components/Notification/Snackbar/index.tsx
|
|
12
|
+
const Snackbar = (0, react.forwardRef)(function Snackbar(props, ref) {
|
|
13
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarBase, {
|
|
14
|
+
...props,
|
|
15
|
+
ref
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
function useSnackbar(props = {}) {
|
|
19
|
+
"use memo";
|
|
20
|
+
const { position = "bottom", dim = false, duration, order, ...regionProps } = props;
|
|
21
|
+
const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = require_useNotificationQueue.useNotificationQueue("snackbar", {
|
|
22
|
+
duration,
|
|
23
|
+
order,
|
|
24
|
+
timeoutReason: "timeout",
|
|
25
|
+
unmountedReason: "unmounted"
|
|
26
|
+
});
|
|
27
|
+
function show(message, options = {}) {
|
|
28
|
+
enqueue({
|
|
29
|
+
message,
|
|
30
|
+
action: options.action
|
|
31
|
+
}, options.onClose);
|
|
32
|
+
}
|
|
33
|
+
return [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationRegion.NotificationRegion, {
|
|
34
|
+
name: "snackbar",
|
|
35
|
+
state,
|
|
36
|
+
position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
|
|
37
|
+
...regionProps,
|
|
38
|
+
children: state.visibleToasts.map((toast_0) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationItem.NotificationItem, {
|
|
39
|
+
name: "snackbar",
|
|
40
|
+
toast: toast_0,
|
|
41
|
+
state,
|
|
42
|
+
itemRef,
|
|
43
|
+
onHoverStart,
|
|
44
|
+
onHoverEnd,
|
|
45
|
+
"data-dim": dim,
|
|
46
|
+
"data-with-action": toast_0.content.action !== void 0,
|
|
47
|
+
children: toast_0.content.action !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
48
|
+
onClick: () => close(toast_0.key, "action"),
|
|
49
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarAction, { action: toast_0.content.action })
|
|
50
|
+
})
|
|
51
|
+
}, toast_0.key))
|
|
52
|
+
}), show];
|
|
53
|
+
}
|
|
54
|
+
const SnackbarBase = (0, react.forwardRef)(function SnackbarBase({ message, action, dim = false, className, ...rootProps }, ref) {
|
|
55
|
+
const classNames = require_useClassNames.useClassNames("charcoal-notification", "charcoal-snackbar", className);
|
|
56
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
57
|
+
...rootProps,
|
|
58
|
+
ref,
|
|
59
|
+
className: classNames,
|
|
60
|
+
"data-dim": dim,
|
|
61
|
+
"data-with-action": action !== void 0,
|
|
62
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
63
|
+
role: "status",
|
|
64
|
+
className: "charcoal-notification-content",
|
|
65
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
66
|
+
className: "charcoal-notification-label",
|
|
67
|
+
children: message
|
|
68
|
+
})
|
|
69
|
+
}), action !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarAction, { action })]
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
function SnackbarAction({ action }) {
|
|
73
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: action });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.default = Snackbar;
|
|
78
|
+
exports.useSnackbar = useSnackbar;
|
|
79
|
+
//# sourceMappingURL=index2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index2.cjs","names":["toast"],"sources":["../../../../src/components/Notification/Snackbar/index.tsx"],"sourcesContent":["import '../layout.css'\nimport './index.css'\n\nimport { forwardRef, type HTMLAttributes, type ReactNode } from 'react'\nimport { useClassNames } from '../../../_lib/useClassNames'\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 action?: ReactNode\n onClose?: (reason: SnackbarCloseReason) => void\n}\n\ntype SnackbarBaseProps = {\n message: ReactNode\n action?: ReactNode\n dim?: boolean\n} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>\n\nexport type SnackbarProps = Omit<SnackbarBaseProps, 'action'> & {\n /** Snackbar の右側に表示するアクション */\n action: NonNullable<ReactNode>\n}\n\nexport type UseSnackbarProps = Omit<NotificationProps, 'position'> & {\n position?: Position\n dim?: boolean\n}\n\ntype SnackbarContent = {\n message: ReactNode\n action?: ReactNode\n}\n\nconst Snackbar = forwardRef<HTMLDivElement, SnackbarProps>(\n function Snackbar(props, ref) {\n return <SnackbarBase {...props} ref={ref} />\n },\n)\n\nexport default Snackbar\n\nexport function useSnackbar(props: UseSnackbarProps = {}) {\n 'use memo'\n\n const {\n position = 'bottom',\n dim = false,\n duration,\n order,\n ...regionProps\n } = props\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({ message, action: options.action }, options.onClose)\n }\n\n const hasAction = state.visibleToasts.some(\n (toast) => toast.content.action !== undefined,\n )\n const effectivePosition = hasAction ? 'bottom' : position\n const element = (\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 <div onClick={() => close(toast.key, 'action')}>\n <SnackbarAction action={toast.content.action} />\n </div>\n )}\n </NotificationItem>\n ))}\n </NotificationRegion>\n )\n\n return [element, show] as const\n}\n\nconst SnackbarBase = forwardRef<HTMLDivElement, SnackbarBaseProps>(\n function SnackbarBase(\n { message, action, dim = false, className, ...rootProps },\n ref,\n ) {\n const classNames = useClassNames(\n 'charcoal-notification',\n 'charcoal-snackbar',\n className,\n )\n\n return (\n <div\n {...rootProps}\n ref={ref}\n className={classNames}\n data-dim={dim}\n data-with-action={action !== undefined}\n >\n <div role=\"status\" className=\"charcoal-notification-content\">\n <div className=\"charcoal-notification-label\">{message}</div>\n </div>\n {action !== undefined && <SnackbarAction action={action} />}\n </div>\n )\n },\n)\n\nfunction SnackbarAction({ action }: { action: ReactNode }) {\n return <div>{action}</div>\n}\n"],"mappings":";;;;;;;;;;;AAuCA,MAAM,iCACJ,SAAS,SAAS,OAAO,KAAK;CAC5B,OAAO,2CAAC,cAAD;EAAc,GAAI;EAAY;CAAI;AAC3C,CACF;AAIA,SAAgB,YAAY,QAA0B,CAAC,GAAG;CACxD;CAEA,MAAM,EACJ,WAAW,UACX,MAAM,OACN,UACA,OACA,GAAG,gBACD;CACJ,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,QAAQ;GAAE;GAAS,QAAQ,QAAQ;EAAO,GAAG,QAAQ,OAAO;CAC9D;CAmCA,OAAO,CAAC,2CA5BL,+CAAD;EACE,MAAK;EACE;EACP,UARc,MAAM,cAAc,MACnC,UAAU,MAAM,QAAQ,WAAW,MAEZ,IAAY,WAAW;EAM7C,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,OAAD;IAAK,eAAe,MAAMA,QAAM,KAAK,QAAQ;cAC3C,2CAAC,gBAAD,EAAgB,QAAQA,QAAM,QAAQ,OAAO;GAC1C;EAES,GAfXA,QAAM,GAeK,CACnB;CACiB,CAGd,GAAS,IAAI;AACvB;AAEA,MAAM,qCACJ,SAAS,aACP,EAAE,SAAS,QAAQ,MAAM,OAAO,WAAW,GAAG,aAC9C,KACA;CACA,MAAM,aAAa,oCACjB,yBACA,qBACA,SACF;CAEA,OACE,4CAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,YAAU;EACV,oBAAkB,WAAW;YAL/B,CAOE,2CAAC,OAAD;GAAK,MAAK;GAAS,WAAU;aAC3B,2CAAC,OAAD;IAAK,WAAU;cAA+B;GAAa;EACxD,IACJ,WAAW,UAAa,2CAAC,gBAAD,EAAwB,OAAO,EACrD;;AAET,CACF;AAEA,SAAS,eAAe,EAAE,UAAiC;CACzD,OAAO,2CAAC,OAAD,YAAM,OAAY;AAC3B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useClassNames } from "../../../_lib/useClassNames.js";
|
|
3
|
+
/* empty css */
|
|
4
|
+
/* empty css */
|
|
5
|
+
import { NotificationItem } from "../NotificationItem.js";
|
|
6
|
+
import { NotificationRegion } from "../NotificationRegion.js";
|
|
7
|
+
import { useNotificationQueue } from "../useNotificationQueue.js";
|
|
8
|
+
import { forwardRef } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region src/components/Notification/Snackbar/index.tsx
|
|
12
|
+
const Snackbar = forwardRef(function Snackbar(props, ref) {
|
|
13
|
+
return /* @__PURE__ */ jsx(SnackbarBase, {
|
|
14
|
+
...props,
|
|
15
|
+
ref
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
function useSnackbar(props = {}) {
|
|
19
|
+
"use memo";
|
|
20
|
+
const { position = "bottom", dim = false, duration, order, ...regionProps } = props;
|
|
21
|
+
const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = useNotificationQueue("snackbar", {
|
|
22
|
+
duration,
|
|
23
|
+
order,
|
|
24
|
+
timeoutReason: "timeout",
|
|
25
|
+
unmountedReason: "unmounted"
|
|
26
|
+
});
|
|
27
|
+
function show(message, options = {}) {
|
|
28
|
+
enqueue({
|
|
29
|
+
message,
|
|
30
|
+
action: options.action
|
|
31
|
+
}, options.onClose);
|
|
32
|
+
}
|
|
33
|
+
return [/* @__PURE__ */ jsx(NotificationRegion, {
|
|
34
|
+
name: "snackbar",
|
|
35
|
+
state,
|
|
36
|
+
position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
|
|
37
|
+
...regionProps,
|
|
38
|
+
children: state.visibleToasts.map((toast_0) => /* @__PURE__ */ jsx(NotificationItem, {
|
|
39
|
+
name: "snackbar",
|
|
40
|
+
toast: toast_0,
|
|
41
|
+
state,
|
|
42
|
+
itemRef,
|
|
43
|
+
onHoverStart,
|
|
44
|
+
onHoverEnd,
|
|
45
|
+
"data-dim": dim,
|
|
46
|
+
"data-with-action": toast_0.content.action !== void 0,
|
|
47
|
+
children: toast_0.content.action !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
48
|
+
onClick: () => close(toast_0.key, "action"),
|
|
49
|
+
children: /* @__PURE__ */ jsx(SnackbarAction, { action: toast_0.content.action })
|
|
50
|
+
})
|
|
51
|
+
}, toast_0.key))
|
|
52
|
+
}), show];
|
|
53
|
+
}
|
|
54
|
+
const SnackbarBase = forwardRef(function SnackbarBase({ message, action, dim = false, className, ...rootProps }, ref) {
|
|
55
|
+
const classNames = useClassNames("charcoal-notification", "charcoal-snackbar", className);
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
...rootProps,
|
|
58
|
+
ref,
|
|
59
|
+
className: classNames,
|
|
60
|
+
"data-dim": dim,
|
|
61
|
+
"data-with-action": action !== void 0,
|
|
62
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
63
|
+
role: "status",
|
|
64
|
+
className: "charcoal-notification-content",
|
|
65
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
66
|
+
className: "charcoal-notification-label",
|
|
67
|
+
children: message
|
|
68
|
+
})
|
|
69
|
+
}), action !== void 0 && /* @__PURE__ */ jsx(SnackbarAction, { action })]
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
function SnackbarAction({ action }) {
|
|
73
|
+
return /* @__PURE__ */ jsx("div", { children: action });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { Snackbar as default, useSnackbar };
|
|
78
|
+
//# sourceMappingURL=index2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index2.js","names":["toast"],"sources":["../../../../src/components/Notification/Snackbar/index.tsx"],"sourcesContent":["import '../layout.css'\nimport './index.css'\n\nimport { forwardRef, type HTMLAttributes, type ReactNode } from 'react'\nimport { useClassNames } from '../../../_lib/useClassNames'\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 action?: ReactNode\n onClose?: (reason: SnackbarCloseReason) => void\n}\n\ntype SnackbarBaseProps = {\n message: ReactNode\n action?: ReactNode\n dim?: boolean\n} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>\n\nexport type SnackbarProps = Omit<SnackbarBaseProps, 'action'> & {\n /** Snackbar の右側に表示するアクション */\n action: NonNullable<ReactNode>\n}\n\nexport type UseSnackbarProps = Omit<NotificationProps, 'position'> & {\n position?: Position\n dim?: boolean\n}\n\ntype SnackbarContent = {\n message: ReactNode\n action?: ReactNode\n}\n\nconst Snackbar = forwardRef<HTMLDivElement, SnackbarProps>(\n function Snackbar(props, ref) {\n return <SnackbarBase {...props} ref={ref} />\n },\n)\n\nexport default Snackbar\n\nexport function useSnackbar(props: UseSnackbarProps = {}) {\n 'use memo'\n\n const {\n position = 'bottom',\n dim = false,\n duration,\n order,\n ...regionProps\n } = props\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({ message, action: options.action }, options.onClose)\n }\n\n const hasAction = state.visibleToasts.some(\n (toast) => toast.content.action !== undefined,\n )\n const effectivePosition = hasAction ? 'bottom' : position\n const element = (\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 <div onClick={() => close(toast.key, 'action')}>\n <SnackbarAction action={toast.content.action} />\n </div>\n )}\n </NotificationItem>\n ))}\n </NotificationRegion>\n )\n\n return [element, show] as const\n}\n\nconst SnackbarBase = forwardRef<HTMLDivElement, SnackbarBaseProps>(\n function SnackbarBase(\n { message, action, dim = false, className, ...rootProps },\n ref,\n ) {\n const classNames = useClassNames(\n 'charcoal-notification',\n 'charcoal-snackbar',\n className,\n )\n\n return (\n <div\n {...rootProps}\n ref={ref}\n className={classNames}\n data-dim={dim}\n data-with-action={action !== undefined}\n >\n <div role=\"status\" className=\"charcoal-notification-content\">\n <div className=\"charcoal-notification-label\">{message}</div>\n </div>\n {action !== undefined && <SnackbarAction action={action} />}\n </div>\n )\n },\n)\n\nfunction SnackbarAction({ action }: { action: ReactNode }) {\n return <div>{action}</div>\n}\n"],"mappings":";;;;;;;;;;;AAuCA,MAAM,WAAW,WACf,SAAS,SAAS,OAAO,KAAK;CAC5B,OAAO,oBAAC,cAAD;EAAc,GAAI;EAAY;CAAI;AAC3C,CACF;AAIA,SAAgB,YAAY,QAA0B,CAAC,GAAG;CACxD;CAEA,MAAM,EACJ,WAAW,UACX,MAAM,OACN,UACA,OACA,GAAG,gBACD;CACJ,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,QAAQ;GAAE;GAAS,QAAQ,QAAQ;EAAO,GAAG,QAAQ,OAAO;CAC9D;CAmCA,OAAO,CAAC,oBA5BL,oBAAD;EACE,MAAK;EACE;EACP,UARc,MAAM,cAAc,MACnC,UAAU,MAAM,QAAQ,WAAW,MAEZ,IAAY,WAAW;EAM7C,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,OAAD;IAAK,eAAe,MAAMA,QAAM,KAAK,QAAQ;cAC3C,oBAAC,gBAAD,EAAgB,QAAQA,QAAM,QAAQ,OAAO;GAC1C;EAES,GAfXA,QAAM,GAeK,CACnB;CACiB,CAGd,GAAS,IAAI;AACvB;AAEA,MAAM,eAAe,WACnB,SAAS,aACP,EAAE,SAAS,QAAQ,MAAM,OAAO,WAAW,GAAG,aAC9C,KACA;CACA,MAAM,aAAa,cACjB,yBACA,qBACA,SACF;CAEA,OACE,qBAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,YAAU;EACV,oBAAkB,WAAW;YAL/B,CAOE,oBAAC,OAAD;GAAK,MAAK;GAAS,WAAU;aAC3B,oBAAC,OAAD;IAAK,WAAU;cAA+B;GAAa;EACxD,IACJ,WAAW,UAAa,oBAAC,gBAAD,EAAwB,OAAO,EACrD;;AAET,CACF;AAEA,SAAS,eAAe,EAAE,UAAiC;CACzD,OAAO,oBAAC,OAAD,YAAM,OAAY;AAC3B"}
|
|
@@ -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"}
|