@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.
@@ -1,45 +1,29 @@
1
1
  import '../layout.css';
2
2
  import './index.css';
3
- import type { ReactNode } from 'react';
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
- 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
- */
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
- declare const Snackbar: import("react").ForwardRefExoticComponent<Omit<NotificationProps, "position"> & {
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
- } & import("react").RefAttributes<SnackbarHandler>>;
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?: SnackbarProps): readonly [import("react/jsx-runtime").JSX.Element, (message: ReactNode, options?: ShowSnackbarOptions) => void];
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.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,M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AAM,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"}
@@ -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({ position = "bottom", dim = false, duration, order, ...regionProps }, ref) {
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, react.useImperativeHandle)(ref, () => ({ show }));
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)(SnackbarAction, {
42
- action: toast_0.content.action,
43
- onClick: () => close(toast_0.key, "action")
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 SnackbarAction({ action, onClick }) {
90
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
91
- onClick,
92
- children: action
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","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"}
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"}
@@ -1,16 +1,23 @@
1
1
  "use client";
2
+ import { useClassNames } from "../../../_lib/useClassNames.js";
2
3
  /* empty 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, useImperativeHandle, useRef } from "react";
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({ position = "bottom", dim = false, duration, order, ...regionProps }, ref) {
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
- useImperativeHandle(ref, () => ({ show }));
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(SnackbarAction, {
42
- action: toast_0.content.action,
43
- onClick: () => close(toast_0.key, "action")
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 SnackbarAction({ action, onClick }) {
86
- return /* @__PURE__ */ jsx("div", {
87
- onClick,
88
- children: action
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","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":";;;;;;;;;;;AA8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AgD,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"}
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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Aa,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;