@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,46 @@
|
|
|
1
|
+
.charcoal-notification-region {
|
|
2
|
+
position: fixed;
|
|
3
|
+
left: 0;
|
|
4
|
+
right: 0;
|
|
5
|
+
display: grid;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.charcoal-notification {
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
border-radius: var(--charcoal-radius-oval);
|
|
14
|
+
width: fit-content;
|
|
15
|
+
max-width: calc(100vw - var(--charcoal-space-46));
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
gap: var(--charcoal-space-20);
|
|
20
|
+
pointer-events: auto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.charcoal-notification-content {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
min-width: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.charcoal-notification-label {
|
|
30
|
+
min-width: 0;
|
|
31
|
+
overflow: hidden;
|
|
32
|
+
overflow-wrap: break-word;
|
|
33
|
+
display: -webkit-box;
|
|
34
|
+
-webkit-box-orient: vertical;
|
|
35
|
+
-webkit-line-clamp: 2;
|
|
36
|
+
font-size: var(--charcoal-text-font-size-caption-m);
|
|
37
|
+
font-weight: var(--charcoal-text-font-weight-bold);
|
|
38
|
+
line-height: var(--charcoal-text-line-height-caption-m);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media (prefers-reduced-motion: reduce) {
|
|
42
|
+
.charcoal-notification,
|
|
43
|
+
.charcoal-notification[data-exiting='true'] {
|
|
44
|
+
animation: none;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type NotificationName = 'snackbar' | 'toast'
|
|
2
|
+
export type Position = 'top' | 'bottom'
|
|
3
|
+
export type NotificationOrder = 'queue' | 'replace'
|
|
4
|
+
|
|
5
|
+
export type UseNotificationOptions = {
|
|
6
|
+
position?: Position
|
|
7
|
+
/**
|
|
8
|
+
* 画面端からの距離(ピクセル)
|
|
9
|
+
* @default 16
|
|
10
|
+
*/
|
|
11
|
+
offset?: number
|
|
12
|
+
/**
|
|
13
|
+
* 通知を表示する時間(ミリ秒)。負の値は 0、数値でない値は 5000 として扱う
|
|
14
|
+
* @default 5000
|
|
15
|
+
*/
|
|
16
|
+
duration?: number
|
|
17
|
+
/**
|
|
18
|
+
* 表示中の通知がある場合の次の通知の表示方法
|
|
19
|
+
* @default 'queue'
|
|
20
|
+
*/
|
|
21
|
+
order?: NotificationOrder
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type NotificationProps = UseNotificationOptions & {
|
|
25
|
+
zIndex?: number
|
|
26
|
+
portalContainer?: HTMLElement
|
|
27
|
+
className?: string
|
|
28
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import { useToastState } from 'react-stately/useToastState'
|
|
3
|
+
import type { NotificationName, NotificationOrder } from './types'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_DURATION_MS = 5000
|
|
6
|
+
const ANIMATION_DURATION_MS = 300
|
|
7
|
+
|
|
8
|
+
type QueueItem<TContent, TCloseReason> = {
|
|
9
|
+
content: TContent
|
|
10
|
+
onClose?: (reason: TCloseReason) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useNotificationQueue<
|
|
14
|
+
TContent,
|
|
15
|
+
TCloseReason extends string = never,
|
|
16
|
+
>(
|
|
17
|
+
name: NotificationName,
|
|
18
|
+
{
|
|
19
|
+
duration: durationOption,
|
|
20
|
+
order = 'queue',
|
|
21
|
+
timeoutReason,
|
|
22
|
+
unmountedReason,
|
|
23
|
+
}: {
|
|
24
|
+
duration?: number
|
|
25
|
+
order?: NotificationOrder
|
|
26
|
+
timeoutReason?: TCloseReason
|
|
27
|
+
unmountedReason?: TCloseReason
|
|
28
|
+
} = {},
|
|
29
|
+
) {
|
|
30
|
+
const itemRef = useRef<HTMLDivElement>(null)
|
|
31
|
+
const queueRef = useRef<
|
|
32
|
+
Array<QueueItem<TContent, TCloseReason> & { duration: number }>
|
|
33
|
+
>([])
|
|
34
|
+
const isShowingRef = useRef(false)
|
|
35
|
+
const activeRef = useRef<{
|
|
36
|
+
key: string
|
|
37
|
+
onClose?: (reason: TCloseReason) => void
|
|
38
|
+
reason?: TCloseReason
|
|
39
|
+
notified: boolean
|
|
40
|
+
}>()
|
|
41
|
+
const replaceRef = useRef(false)
|
|
42
|
+
const hoverRef = useRef({
|
|
43
|
+
active: false,
|
|
44
|
+
pending: undefined as (() => void) | undefined,
|
|
45
|
+
})
|
|
46
|
+
// wrapUpdate を固定したまま、後から定義する playNext の最新版を呼ぶ
|
|
47
|
+
const playNextRef = useRef<(() => void) | undefined>(undefined)
|
|
48
|
+
|
|
49
|
+
// wrapUpdate の参照が変わると useToastState が ToastQueue を作り直すため useCallback で固定する
|
|
50
|
+
const wrapUpdate = useCallback(
|
|
51
|
+
function wrapUpdate(
|
|
52
|
+
update: () => void,
|
|
53
|
+
action: 'add' | 'remove' | 'clear',
|
|
54
|
+
) {
|
|
55
|
+
if (action !== 'remove') {
|
|
56
|
+
update()
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function notifyActive() {
|
|
61
|
+
const active = activeRef.current
|
|
62
|
+
if (active === undefined || active.notified) return
|
|
63
|
+
active.notified = true
|
|
64
|
+
const reason = active.reason ?? timeoutReason
|
|
65
|
+
if (reason !== undefined) {
|
|
66
|
+
active.onClose?.(reason)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function finish() {
|
|
71
|
+
activeRef.current = undefined
|
|
72
|
+
update()
|
|
73
|
+
playNextRef.current?.()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
notifyActive()
|
|
77
|
+
|
|
78
|
+
if (hoverRef.current.active) {
|
|
79
|
+
hoverRef.current.pending = () => wrapUpdate(update, 'remove')
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (itemRef.current === null) {
|
|
84
|
+
finish()
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (replaceRef.current) {
|
|
89
|
+
replaceRef.current = false
|
|
90
|
+
finish()
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
const item: HTMLDivElement = itemRef.current
|
|
94
|
+
|
|
95
|
+
// allow-discreteが Newly Available で使えないので、要素の削除をアニメーション完了まで待つ
|
|
96
|
+
item.dataset.exiting = 'true'
|
|
97
|
+
let completed = false
|
|
98
|
+
let fallbackTimer = 0 // complete 内で clearTimeout(setTimeout(...)) すると新規タイマーを即キャンセルしてしまう
|
|
99
|
+
function handleAnimationEnd(event: AnimationEvent) {
|
|
100
|
+
if (
|
|
101
|
+
event.target === item &&
|
|
102
|
+
event.animationName === `charcoal-${name}-exit`
|
|
103
|
+
) {
|
|
104
|
+
complete()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function complete() {
|
|
108
|
+
if (completed) return
|
|
109
|
+
completed = true
|
|
110
|
+
item.removeEventListener('animationend', handleAnimationEnd)
|
|
111
|
+
window.clearTimeout(fallbackTimer)
|
|
112
|
+
finish()
|
|
113
|
+
}
|
|
114
|
+
item.addEventListener('animationend', handleAnimationEnd)
|
|
115
|
+
fallbackTimer = window.setTimeout(complete, ANIMATION_DURATION_MS + 100)
|
|
116
|
+
if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches) {
|
|
117
|
+
complete()
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
[name, timeoutReason],
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const state = useToastState<TContent>({
|
|
124
|
+
maxVisibleToasts: 1,
|
|
125
|
+
wrapUpdate,
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
return () => {
|
|
130
|
+
const active = activeRef.current
|
|
131
|
+
if (active !== undefined && !active.notified) {
|
|
132
|
+
if (unmountedReason !== undefined) {
|
|
133
|
+
active.onClose?.(unmountedReason)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
activeRef.current = undefined
|
|
137
|
+
queueRef.current = []
|
|
138
|
+
isShowingRef.current = false
|
|
139
|
+
}
|
|
140
|
+
}, [unmountedReason])
|
|
141
|
+
|
|
142
|
+
function playNext() {
|
|
143
|
+
const next = queueRef.current.shift()
|
|
144
|
+
if (next === undefined) {
|
|
145
|
+
isShowingRef.current = false
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { duration, onClose, content } = next
|
|
150
|
+
isShowingRef.current = true
|
|
151
|
+
const enterMs = window.matchMedia?.('(prefers-reduced-motion: reduce)')
|
|
152
|
+
.matches
|
|
153
|
+
? 0
|
|
154
|
+
: ANIMATION_DURATION_MS
|
|
155
|
+
const key = state.add(content, {
|
|
156
|
+
// react-stately は 0 を「タイマーなし」と扱うため、最小の正数を渡す
|
|
157
|
+
timeout: Math.max(1, duration + enterMs),
|
|
158
|
+
})
|
|
159
|
+
activeRef.current = { key, onClose, notified: false }
|
|
160
|
+
}
|
|
161
|
+
playNextRef.current = playNext
|
|
162
|
+
|
|
163
|
+
function enqueue(
|
|
164
|
+
content: TContent,
|
|
165
|
+
onClose?: (reason: TCloseReason) => void,
|
|
166
|
+
) {
|
|
167
|
+
const duration =
|
|
168
|
+
typeof durationOption === 'number' && Number.isFinite(durationOption)
|
|
169
|
+
? Math.max(0, durationOption)
|
|
170
|
+
: DEFAULT_DURATION_MS
|
|
171
|
+
|
|
172
|
+
queueRef.current.push({
|
|
173
|
+
content,
|
|
174
|
+
onClose,
|
|
175
|
+
duration,
|
|
176
|
+
})
|
|
177
|
+
if (!isShowingRef.current) {
|
|
178
|
+
playNext()
|
|
179
|
+
} else if (order === 'replace') {
|
|
180
|
+
const active = activeRef.current
|
|
181
|
+
if (active === undefined) return
|
|
182
|
+
|
|
183
|
+
active.reason = 'replaced' as TCloseReason
|
|
184
|
+
replaceRef.current = true
|
|
185
|
+
hoverRef.current.active = false
|
|
186
|
+
const pending = hoverRef.current.pending
|
|
187
|
+
hoverRef.current.pending = undefined
|
|
188
|
+
if (pending !== undefined) {
|
|
189
|
+
pending()
|
|
190
|
+
} else {
|
|
191
|
+
state.close(active.key)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function close(key: string, reason: TCloseReason) {
|
|
197
|
+
const active = activeRef.current
|
|
198
|
+
if (active?.key !== key) return
|
|
199
|
+
active.reason = reason
|
|
200
|
+
hoverRef.current.active = false
|
|
201
|
+
const pending = hoverRef.current.pending
|
|
202
|
+
hoverRef.current.pending = undefined
|
|
203
|
+
if (pending !== undefined) {
|
|
204
|
+
pending()
|
|
205
|
+
} else {
|
|
206
|
+
state.close(key)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function onHoverStart() {
|
|
211
|
+
hoverRef.current.active = true
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function onHoverEnd() {
|
|
215
|
+
hoverRef.current.active = false
|
|
216
|
+
const pending = hoverRef.current.pending
|
|
217
|
+
hoverRef.current.pending = undefined
|
|
218
|
+
pending?.()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function clearHover() {
|
|
222
|
+
hoverRef.current.active = false
|
|
223
|
+
hoverRef.current.pending = undefined
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
state,
|
|
228
|
+
itemRef,
|
|
229
|
+
enqueue,
|
|
230
|
+
close,
|
|
231
|
+
onHoverStart,
|
|
232
|
+
onHoverEnd,
|
|
233
|
+
clearHover,
|
|
234
|
+
}
|
|
235
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -107,10 +107,22 @@ export {
|
|
|
107
107
|
type ScrollStepContext,
|
|
108
108
|
} from './components/Carousel'
|
|
109
109
|
export {
|
|
110
|
-
default as
|
|
110
|
+
default as UnstableSnackbar,
|
|
111
111
|
useSnackbar as unstable_useSnackbar,
|
|
112
|
-
type SnackbarProps as
|
|
113
|
-
type
|
|
114
|
-
type
|
|
115
|
-
|
|
112
|
+
type SnackbarProps as UnstableSnackbarProps,
|
|
113
|
+
type UseSnackbarProps as unstable_UseSnackbarProps,
|
|
114
|
+
type SnackbarCloseReason as unstable_SnackbarCloseReason,
|
|
115
|
+
type ShowSnackbarOptions as unstable_ShowSnackbarOptions,
|
|
116
|
+
} from './components/Notification/Snackbar'
|
|
117
|
+
export {
|
|
118
|
+
default as unstable_Toast,
|
|
119
|
+
useToast as unstable_useToast,
|
|
120
|
+
type ToastProps as unstable_ToastProps,
|
|
121
|
+
type ToastHandler as unstable_ToastHandler,
|
|
122
|
+
type ShowToastOptions as unstable_ShowToastOptions,
|
|
123
|
+
} from './components/Notification/Toast'
|
|
124
|
+
export {
|
|
125
|
+
type NotificationOrder as unstable_NotificationOrder,
|
|
126
|
+
type UseNotificationOptions as unstable_UseNotificationOptions,
|
|
127
|
+
} from './components/Notification/types'
|
|
116
128
|
import './components/FocusRing/index.css'
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import './index.css';
|
|
2
|
-
import type { ElementType, ReactNode } from 'react';
|
|
3
|
-
import { type ButtonProps } from '../Button';
|
|
4
|
-
type SnackbarPosition = 'top' | 'bottom';
|
|
5
|
-
type SnackbarButtonOption<T extends ElementType = 'button'> = Omit<ButtonProps<T>, 'component' | 'className' | 'size'> & {
|
|
6
|
-
/**
|
|
7
|
-
* ボタンのルート要素として使用するコンポーネント。ページ遷移を伴う場合は `Link` を指定する
|
|
8
|
-
* @default 'button'
|
|
9
|
-
* @example 'Link'
|
|
10
|
-
*/
|
|
11
|
-
component?: T;
|
|
12
|
-
} & ('button' extends T ? unknown : {
|
|
13
|
-
component: T;
|
|
14
|
-
});
|
|
15
|
-
export type SnackbarShowOptions<T extends ElementType = 'button'> = {
|
|
16
|
-
/**
|
|
17
|
-
* Snackbar を表示する時間(ミリ秒)。負の値は 0、数値でない値は 5000 として扱う
|
|
18
|
-
* @default 5000
|
|
19
|
-
*/
|
|
20
|
-
duration?: number;
|
|
21
|
-
/**
|
|
22
|
-
* Snackbar の右側に表示するボタン
|
|
23
|
-
*/
|
|
24
|
-
button?: SnackbarButtonOption<T>;
|
|
25
|
-
};
|
|
26
|
-
export type SnackbarHandler = {
|
|
27
|
-
show: <T extends ElementType = 'button'>(message: ReactNode, options?: SnackbarShowOptions<T>) => void;
|
|
28
|
-
};
|
|
29
|
-
export type SnackbarProps = {
|
|
30
|
-
/**
|
|
31
|
-
* Snackbar の表示位置。ボタン付きの場合は `bottom` に固定される
|
|
32
|
-
* @default 'bottom'
|
|
33
|
-
*/
|
|
34
|
-
position?: SnackbarPosition;
|
|
35
|
-
/**
|
|
36
|
-
* 画面端からの距離(ピクセル)
|
|
37
|
-
* @default 16
|
|
38
|
-
*/
|
|
39
|
-
offset?: number;
|
|
40
|
-
/**
|
|
41
|
-
* 暗い背景色
|
|
42
|
-
* @default false
|
|
43
|
-
*/
|
|
44
|
-
dim?: boolean;
|
|
45
|
-
zIndex?: number;
|
|
46
|
-
portalContainer?: HTMLElement;
|
|
47
|
-
className?: string;
|
|
48
|
-
};
|
|
49
|
-
declare const Snackbar: import("react").ForwardRefExoticComponent<SnackbarProps & import("react").RefAttributes<SnackbarHandler>>;
|
|
50
|
-
export default Snackbar;
|
|
51
|
-
export declare function useSnackbar(props?: SnackbarProps): readonly [import("react/jsx-runtime").JSX.Element, <T extends ElementType = "button">(message: ReactNode, options?: SnackbarShowOptions<T>) => void];
|
|
52
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Snackbar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AASpB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAa,MAAM,OAAO,CAAA;AAS9D,OAAe,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAOpD,KAAK,gBAAgB,GAAG,KAAK,GAAG,QAAQ,CAAA;AAExC,KAAK,oBAAoB,CAAC,CAAC,SAAS,WAAW,GAAG,QAAQ,IAAI,IAAI,CAChE,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,GAAG,WAAW,GAAG,MAAM,CACnC,GAAG;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,CAAA;CACd,GAAG,CAAC,QAAQ,SAAS,CAAC,GAAG,OAAO,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA;AAErD,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,WAAW,GAAG,QAAQ,IAAI;IAClE;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,CAAC,CAAC,SAAS,WAAW,GAAG,QAAQ,EACrC,OAAO,EAAE,SAAS,EAClB,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAC7B,IAAI,CAAA;CACV,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAeD,QAAA,MAAM,QAAQ,2GA6JZ,CAAA;eAEa,QAAQ;AAEvB,wBAAgB,WAAW,CAAC,KAAK,GAAE,aAAkB,uDAgBrC,CAAC,SAAS,WAAW,sBACxB,SAAS,YACR,mBAAmB,CAAC,CAAC,CAAC,WAKnC"}
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
const require_useClassNames = require('../../_lib/useClassNames.cjs');
|
|
3
|
-
const require_index = require('../Button/index2.cjs');
|
|
4
|
-
require('./index.cjs');
|
|
5
|
-
let react = require("react");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let react_aria_Overlay = require("react-aria/Overlay");
|
|
8
|
-
let react_compiler_runtime = require("react-compiler-runtime");
|
|
9
|
-
let react_aria_useToast = require("react-aria/useToast");
|
|
10
|
-
let react_stately_useToastState = require("react-stately/useToastState");
|
|
11
|
-
|
|
12
|
-
//#region src/components/Snackbar/index.tsx
|
|
13
|
-
const DEFAULT_DURATION_MS = 5e3;
|
|
14
|
-
const DEFAULT_Z_INDEX = 20;
|
|
15
|
-
const ENTER_ANIMATION_DURATION_MS = 300;
|
|
16
|
-
const Snackbar = (0, react.forwardRef)(function Snackbar({ position = "bottom", offset = 16, dim = false, zIndex = DEFAULT_Z_INDEX, portalContainer, className }, ref) {
|
|
17
|
-
"use memo";
|
|
18
|
-
const snackbarRef = (0, react.useRef)(null);
|
|
19
|
-
const queueRef = (0, react.useRef)([]);
|
|
20
|
-
const isShowingRef = (0, react.useRef)(false);
|
|
21
|
-
const hoverRef = (0, react.useRef)({
|
|
22
|
-
active: false,
|
|
23
|
-
pending: void 0
|
|
24
|
-
});
|
|
25
|
-
const playNextRef = (0, react.useRef)(void 0);
|
|
26
|
-
const state = (0, react_stately_useToastState.useToastState)({
|
|
27
|
-
maxVisibleToasts: 1,
|
|
28
|
-
wrapUpdate: (0, react.useCallback)(function wrapToastUpdate(update, action) {
|
|
29
|
-
if (action !== "remove") {
|
|
30
|
-
update();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
function finish() {
|
|
34
|
-
update();
|
|
35
|
-
playNextRef.current?.();
|
|
36
|
-
}
|
|
37
|
-
if (hoverRef.current.active) {
|
|
38
|
-
hoverRef.current.pending = () => wrapToastUpdate(update, "remove");
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (snackbarRef.current === null) {
|
|
42
|
-
finish();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const snackbar = snackbarRef.current;
|
|
46
|
-
snackbar.dataset.exiting = "true";
|
|
47
|
-
let completed = false;
|
|
48
|
-
let fallbackTimer = 0;
|
|
49
|
-
function handleAnimationEnd(event) {
|
|
50
|
-
if (event.target === snackbar && event.animationName === "charcoal-snackbar-exit") complete();
|
|
51
|
-
}
|
|
52
|
-
function complete() {
|
|
53
|
-
if (completed) return;
|
|
54
|
-
completed = true;
|
|
55
|
-
snackbar.removeEventListener("animationend", handleAnimationEnd);
|
|
56
|
-
window.clearTimeout(fallbackTimer);
|
|
57
|
-
finish();
|
|
58
|
-
}
|
|
59
|
-
snackbar.addEventListener("animationend", handleAnimationEnd);
|
|
60
|
-
fallbackTimer = window.setTimeout(complete, 400);
|
|
61
|
-
if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) complete();
|
|
62
|
-
}, [])
|
|
63
|
-
});
|
|
64
|
-
(0, react.useEffect)(() => {
|
|
65
|
-
return () => {
|
|
66
|
-
queueRef.current = [];
|
|
67
|
-
isShowingRef.current = false;
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
function playNext() {
|
|
71
|
-
const next = queueRef.current.shift();
|
|
72
|
-
if (next === void 0) {
|
|
73
|
-
isShowingRef.current = false;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const { duration, ...content } = next;
|
|
77
|
-
isShowingRef.current = true;
|
|
78
|
-
const enterMs = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? 0 : ENTER_ANIMATION_DURATION_MS;
|
|
79
|
-
state.add(content, { timeout: Math.max(1, duration + enterMs) });
|
|
80
|
-
}
|
|
81
|
-
playNextRef.current = playNext;
|
|
82
|
-
function show(message, options = {}) {
|
|
83
|
-
const { duration: durationOption = DEFAULT_DURATION_MS, button } = options;
|
|
84
|
-
const duration_0 = typeof durationOption === "number" && Number.isFinite(durationOption) ? Math.max(0, durationOption) : DEFAULT_DURATION_MS;
|
|
85
|
-
queueRef.current.push({
|
|
86
|
-
message,
|
|
87
|
-
button,
|
|
88
|
-
duration: duration_0
|
|
89
|
-
});
|
|
90
|
-
if (!isShowingRef.current) playNext();
|
|
91
|
-
}
|
|
92
|
-
(0, react.useImperativeHandle)(ref, () => ({ show }));
|
|
93
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarRegion, {
|
|
94
|
-
state,
|
|
95
|
-
position,
|
|
96
|
-
offset,
|
|
97
|
-
dim,
|
|
98
|
-
zIndex,
|
|
99
|
-
portalContainer,
|
|
100
|
-
className,
|
|
101
|
-
snackbarRef,
|
|
102
|
-
onHoverStart: () => {
|
|
103
|
-
hoverRef.current.active = true;
|
|
104
|
-
},
|
|
105
|
-
onHoverEnd: () => {
|
|
106
|
-
hoverRef.current.active = false;
|
|
107
|
-
const pending = hoverRef.current.pending;
|
|
108
|
-
hoverRef.current.pending = void 0;
|
|
109
|
-
pending?.();
|
|
110
|
-
},
|
|
111
|
-
onActionClose: () => {
|
|
112
|
-
hoverRef.current.active = false;
|
|
113
|
-
hoverRef.current.pending = void 0;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
function useSnackbar(t0) {
|
|
118
|
-
"use memo";
|
|
119
|
-
const $ = (0, react_compiler_runtime.c)(13);
|
|
120
|
-
if ($[0] !== "48b810b1254edf94a70dbb5631d15f47f0d432d4831df67ae86f2f07a6c66338") {
|
|
121
|
-
for (let $i = 0; $i < 13; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
122
|
-
$[0] = "48b810b1254edf94a70dbb5631d15f47f0d432d4831df67ae86f2f07a6c66338";
|
|
123
|
-
}
|
|
124
|
-
let t1;
|
|
125
|
-
if ($[1] !== t0) {
|
|
126
|
-
t1 = t0 === void 0 ? {} : t0;
|
|
127
|
-
$[1] = t0;
|
|
128
|
-
$[2] = t1;
|
|
129
|
-
} else t1 = $[2];
|
|
130
|
-
const { position, offset, dim, zIndex, portalContainer, className } = t1;
|
|
131
|
-
const snackbarHandlerRef = (0, react.useRef)(null);
|
|
132
|
-
let t2;
|
|
133
|
-
if ($[3] !== className || $[4] !== dim || $[5] !== offset || $[6] !== portalContainer || $[7] !== position || $[8] !== zIndex) {
|
|
134
|
-
t2 = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Snackbar, {
|
|
135
|
-
ref: snackbarHandlerRef,
|
|
136
|
-
position,
|
|
137
|
-
offset,
|
|
138
|
-
dim,
|
|
139
|
-
zIndex,
|
|
140
|
-
portalContainer,
|
|
141
|
-
className
|
|
142
|
-
});
|
|
143
|
-
$[3] = className;
|
|
144
|
-
$[4] = dim;
|
|
145
|
-
$[5] = offset;
|
|
146
|
-
$[6] = portalContainer;
|
|
147
|
-
$[7] = position;
|
|
148
|
-
$[8] = zIndex;
|
|
149
|
-
$[9] = t2;
|
|
150
|
-
} else t2 = $[9];
|
|
151
|
-
const element = t2;
|
|
152
|
-
let t3;
|
|
153
|
-
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
|
|
154
|
-
t3 = function show(message, options) {
|
|
155
|
-
snackbarHandlerRef.current?.show(message, options);
|
|
156
|
-
};
|
|
157
|
-
$[10] = t3;
|
|
158
|
-
} else t3 = $[10];
|
|
159
|
-
const show = t3;
|
|
160
|
-
let t4;
|
|
161
|
-
if ($[11] !== element) {
|
|
162
|
-
t4 = [element, show];
|
|
163
|
-
$[11] = element;
|
|
164
|
-
$[12] = t4;
|
|
165
|
-
} else t4 = $[12];
|
|
166
|
-
return t4;
|
|
167
|
-
}
|
|
168
|
-
function SnackbarRegion({ state, position, offset, dim, zIndex, portalContainer, className, snackbarRef, onHoverStart, onHoverEnd, onActionClose }) {
|
|
169
|
-
const regionRef = (0, react.useRef)(null);
|
|
170
|
-
const pausedByFocusRef = (0, react.useRef)(false);
|
|
171
|
-
const { regionProps } = (0, react_aria_useToast.useToastRegion)({}, {
|
|
172
|
-
...state,
|
|
173
|
-
pauseAll() {
|
|
174
|
-
if (regionRef.current?.contains(document.activeElement)) {
|
|
175
|
-
pausedByFocusRef.current = true;
|
|
176
|
-
state.pauseAll();
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
resumeAll() {
|
|
180
|
-
if (pausedByFocusRef.current) {
|
|
181
|
-
pausedByFocusRef.current = false;
|
|
182
|
-
state.resumeAll();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}, regionRef);
|
|
186
|
-
const classNames = require_useClassNames.useClassNames("charcoal-snackbar-region", className);
|
|
187
|
-
if (state.visibleToasts.length === 0) return null;
|
|
188
|
-
const effectivePosition = state.visibleToasts.some((toast) => toast.content.button !== void 0) ? "bottom" : position;
|
|
189
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_Overlay.Overlay, {
|
|
190
|
-
disableFocusManagement: true,
|
|
191
|
-
portalContainer,
|
|
192
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
193
|
-
...regionProps,
|
|
194
|
-
ref: regionRef,
|
|
195
|
-
className: classNames,
|
|
196
|
-
"data-position": effectivePosition,
|
|
197
|
-
style: {
|
|
198
|
-
zIndex,
|
|
199
|
-
"--charcoal-snackbar-offset": `${offset}px`
|
|
200
|
-
},
|
|
201
|
-
children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarItem, {
|
|
202
|
-
toast,
|
|
203
|
-
state,
|
|
204
|
-
dim,
|
|
205
|
-
snackbarRef,
|
|
206
|
-
onHoverStart,
|
|
207
|
-
onHoverEnd,
|
|
208
|
-
onActionClose: () => {
|
|
209
|
-
onActionClose();
|
|
210
|
-
state.close(toast.key);
|
|
211
|
-
}
|
|
212
|
-
}, toast.key))
|
|
213
|
-
})
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function SnackbarItem({ toast, state, dim, snackbarRef, onHoverStart, onHoverEnd, onActionClose }) {
|
|
217
|
-
const { toastProps, contentProps, titleProps } = (0, react_aria_useToast.useToast)({ toast }, state, snackbarRef);
|
|
218
|
-
const { message, button } = toast.content;
|
|
219
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
220
|
-
...toastProps,
|
|
221
|
-
ref: snackbarRef,
|
|
222
|
-
className: "charcoal-snackbar",
|
|
223
|
-
"data-dim": dim,
|
|
224
|
-
"data-with-button": button !== void 0,
|
|
225
|
-
onPointerEnter: onHoverStart,
|
|
226
|
-
onPointerLeave: onHoverEnd,
|
|
227
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
228
|
-
...contentProps,
|
|
229
|
-
role: "status",
|
|
230
|
-
className: "charcoal-snackbar-content",
|
|
231
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
232
|
-
...titleProps,
|
|
233
|
-
className: "charcoal-snackbar-label",
|
|
234
|
-
children: message
|
|
235
|
-
})
|
|
236
|
-
}), button !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SnackbarAction, {
|
|
237
|
-
button,
|
|
238
|
-
dim,
|
|
239
|
-
onClose: onActionClose
|
|
240
|
-
})]
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
function SnackbarAction({ button, dim, onClose }) {
|
|
244
|
-
const { onClick, variant, children: buttonChildren, ...buttonProps } = button;
|
|
245
|
-
function handleButtonClick(event) {
|
|
246
|
-
onClick?.(event);
|
|
247
|
-
onClose();
|
|
248
|
-
}
|
|
249
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolymorphicButton, {
|
|
250
|
-
...buttonProps,
|
|
251
|
-
size: "S",
|
|
252
|
-
variant: variant ?? (dim ? "Navigation" : void 0),
|
|
253
|
-
onClick: handleButtonClick,
|
|
254
|
-
children: buttonChildren
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function PolymorphicButton({ component, ...props }) {
|
|
258
|
-
if (component === void 0 || component === "button") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_index.default, { ...props });
|
|
259
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_index.default, {
|
|
260
|
-
...props,
|
|
261
|
-
component
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
//#endregion
|
|
266
|
-
exports.default = Snackbar;
|
|
267
|
-
exports.useSnackbar = useSnackbar;
|
|
268
|
-
//# sourceMappingURL=index2.cjs.map
|