@charcoal-ui/react 6.1.0-beta.1 → 6.1.0-beta.3
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/Snackbar/index.d.ts +15 -31
- package/dist/components/Notification/Snackbar/index.d.ts.map +1 -1
- package/dist/components/Notification/Snackbar/index2.cjs +33 -53
- package/dist/components/Notification/Snackbar/index2.cjs.map +1 -1
- package/dist/components/Notification/Snackbar/index2.js +35 -51
- package/dist/components/Notification/Snackbar/index2.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +487 -487
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/layered.css +487 -487
- package/dist/layered.css.map +1 -1
- package/package.json +5 -5
- package/src/components/Notification/Snackbar/index.story.tsx +28 -21
- package/src/components/Notification/Snackbar/index.test.tsx +38 -7
- package/src/components/Notification/Snackbar/index.tsx +63 -58
- package/src/components/Notification/Toast/index.story.tsx +9 -6
- package/src/index.ts +3 -3
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
import '../layout.css';
|
|
2
2
|
import './index.css';
|
|
3
|
-
import type
|
|
3
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
4
4
|
import type { NotificationProps, Position } from '../types';
|
|
5
5
|
export type SnackbarCloseReason = 'timeout' | 'replaced' | 'action' | 'close' | 'unmounted';
|
|
6
6
|
export type ShowSnackbarOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* Snackbar の右側に表示するアクション
|
|
9
|
-
*/
|
|
10
7
|
action?: ReactNode;
|
|
11
|
-
/**
|
|
12
|
-
* Snackbar が閉じるときに呼び出される
|
|
13
|
-
*/
|
|
14
8
|
onClose?: (reason: SnackbarCloseReason) => void;
|
|
15
9
|
};
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
*/
|
|
10
|
+
type SnackbarBaseProps = {
|
|
11
|
+
message: ReactNode;
|
|
12
|
+
action?: ReactNode;
|
|
29
13
|
dim?: boolean;
|
|
14
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
15
|
+
export type SnackbarProps = Omit<SnackbarBaseProps, 'action'> & {
|
|
16
|
+
/** Snackbar の右側に表示するアクション */
|
|
17
|
+
action: NonNullable<ReactNode>;
|
|
30
18
|
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される
|
|
34
|
-
* @default 'bottom'
|
|
35
|
-
*/
|
|
19
|
+
export type UseSnackbarProps = Omit<NotificationProps, 'position'> & {
|
|
36
20
|
position?: Position;
|
|
37
|
-
/**
|
|
38
|
-
* 暗い背景色
|
|
39
|
-
* @default false
|
|
40
|
-
*/
|
|
41
21
|
dim?: boolean;
|
|
42
|
-
}
|
|
22
|
+
};
|
|
23
|
+
declare const Snackbar: import("react").ForwardRefExoticComponent<Omit<SnackbarBaseProps, "action"> & {
|
|
24
|
+
/** Snackbar の右側に表示するアクション */
|
|
25
|
+
action: NonNullable<ReactNode>;
|
|
26
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
43
27
|
export default Snackbar;
|
|
44
|
-
export declare function useSnackbar(props?:
|
|
28
|
+
export declare function useSnackbar(props?: UseSnackbarProps): readonly [import("react/jsx-runtime").JSX.Element, (message: ReactNode, options?: ShowSnackbarOptions) => void];
|
|
45
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Notification/Snackbar/index.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AW,CAAC,KAAK,GAAE,gBAAqB,gEAkB/B,SAAS,YAAW,mBAAmB,WAsC/D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
const require_useClassNames = require('../../../_lib/useClassNames.cjs');
|
|
2
3
|
require('../layout.cjs');
|
|
3
4
|
require('./index.cjs');
|
|
4
5
|
const require_NotificationItem = require('../NotificationItem.cjs');
|
|
@@ -6,11 +7,17 @@ const require_NotificationRegion = require('../NotificationRegion.cjs');
|
|
|
6
7
|
const require_useNotificationQueue = require('../useNotificationQueue.cjs');
|
|
7
8
|
let react = require("react");
|
|
8
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
-
let react_compiler_runtime = require("react-compiler-runtime");
|
|
10
10
|
|
|
11
11
|
//#region src/components/Notification/Snackbar/index.tsx
|
|
12
|
-
const Snackbar = (0, react.forwardRef)(function Snackbar(
|
|
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 = {}) {
|
|
13
19
|
"use memo";
|
|
20
|
+
const { position = "bottom", dim = false, duration, order, ...regionProps } = props;
|
|
14
21
|
const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = require_useNotificationQueue.useNotificationQueue("snackbar", {
|
|
15
22
|
duration,
|
|
16
23
|
order,
|
|
@@ -23,8 +30,7 @@ const Snackbar = (0, react.forwardRef)(function Snackbar({ position = "bottom",
|
|
|
23
30
|
action: options.action
|
|
24
31
|
}, options.onClose);
|
|
25
32
|
}
|
|
26
|
-
(0,
|
|
27
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationRegion.NotificationRegion, {
|
|
33
|
+
return [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NotificationRegion.NotificationRegion, {
|
|
28
34
|
name: "snackbar",
|
|
29
35
|
state,
|
|
30
36
|
position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
|
|
@@ -38,59 +44,33 @@ const Snackbar = (0, react.forwardRef)(function Snackbar({ position = "bottom",
|
|
|
38
44
|
onHoverEnd,
|
|
39
45
|
"data-dim": dim,
|
|
40
46
|
"data-with-action": toast_0.content.action !== void 0,
|
|
41
|
-
children: toast_0.content.action !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
42
|
-
|
|
43
|
-
|
|
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 })
|
|
44
50
|
})
|
|
45
51
|
}, 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;
|
|
52
|
+
}), show];
|
|
88
53
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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 })]
|
|
93
70
|
});
|
|
71
|
+
});
|
|
72
|
+
function SnackbarAction({ action }) {
|
|
73
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: action });
|
|
94
74
|
}
|
|
95
75
|
|
|
96
76
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.cjs","names":["toast"
|
|
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,SAA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css */
|
|
3
4
|
/* empty css */
|
|
4
5
|
import { NotificationItem } from "../NotificationItem.js";
|
|
5
6
|
import { NotificationRegion } from "../NotificationRegion.js";
|
|
6
7
|
import { useNotificationQueue } from "../useNotificationQueue.js";
|
|
7
|
-
import { forwardRef
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
import { c } from "react-compiler-runtime";
|
|
8
|
+
import { forwardRef } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
|
|
11
11
|
//#region src/components/Notification/Snackbar/index.tsx
|
|
12
|
-
const Snackbar = forwardRef(function Snackbar(
|
|
12
|
+
const Snackbar = forwardRef(function Snackbar(props, ref) {
|
|
13
|
+
return /* @__PURE__ */ jsx(SnackbarBase, {
|
|
14
|
+
...props,
|
|
15
|
+
ref
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
function useSnackbar(props = {}) {
|
|
13
19
|
"use memo";
|
|
20
|
+
const { position = "bottom", dim = false, duration, order, ...regionProps } = props;
|
|
14
21
|
const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } = useNotificationQueue("snackbar", {
|
|
15
22
|
duration,
|
|
16
23
|
order,
|
|
@@ -23,8 +30,7 @@ const Snackbar = forwardRef(function Snackbar({ position = "bottom", dim = false
|
|
|
23
30
|
action: options.action
|
|
24
31
|
}, options.onClose);
|
|
25
32
|
}
|
|
26
|
-
|
|
27
|
-
return /* @__PURE__ */ jsx(NotificationRegion, {
|
|
33
|
+
return [/* @__PURE__ */ jsx(NotificationRegion, {
|
|
28
34
|
name: "snackbar",
|
|
29
35
|
state,
|
|
30
36
|
position: state.visibleToasts.some((toast) => toast.content.action !== void 0) ? "bottom" : position,
|
|
@@ -38,55 +44,33 @@ const Snackbar = forwardRef(function Snackbar({ position = "bottom", dim = false
|
|
|
38
44
|
onHoverEnd,
|
|
39
45
|
"data-dim": dim,
|
|
40
46
|
"data-with-action": toast_0.content.action !== void 0,
|
|
41
|
-
children: toast_0.content.action !== void 0 && /* @__PURE__ */ jsx(
|
|
42
|
-
|
|
43
|
-
|
|
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 })
|
|
44
50
|
})
|
|
45
51
|
}, 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;
|
|
52
|
+
}), show];
|
|
84
53
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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 })]
|
|
89
70
|
});
|
|
71
|
+
});
|
|
72
|
+
function SnackbarAction({ action }) {
|
|
73
|
+
return /* @__PURE__ */ jsx("div", { children: action });
|
|
90
74
|
}
|
|
91
75
|
|
|
92
76
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.js","names":["toast"
|
|
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"}
|
package/dist/index.cjs
CHANGED
|
@@ -71,12 +71,12 @@ exports.TagItem = require_index$18.default;
|
|
|
71
71
|
exports.TextArea = require_index$9.default;
|
|
72
72
|
exports.TextEllipsis = require_index$20.default;
|
|
73
73
|
exports.TextField = require_index$8.default;
|
|
74
|
+
exports.UnstableSnackbar = require_index$23.default;
|
|
74
75
|
exports.getThemeSync = require_themeHelper.getThemeSync;
|
|
75
76
|
exports.makeSetThemeScriptCode = require_SetThemeScript.makeSetThemeScriptCode;
|
|
76
77
|
exports.prefersColorScheme = require_themeHelper.prefersColorScheme;
|
|
77
78
|
exports.themeSelector = require_themeHelper.themeSelector;
|
|
78
79
|
exports.themeSetter = require_themeHelper.themeSetter;
|
|
79
|
-
exports.unstable_Snackbar = require_index$23.default;
|
|
80
80
|
exports.unstable_Toast = require_index$24.default;
|
|
81
81
|
exports.unstable_useSnackbar = require_index$23.useSnackbar;
|
|
82
82
|
exports.unstable_useToast = require_index$24.useToast;
|