@charcoal-ui/react 6.1.0-beta.4 → 6.1.0-beta.6
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/NotificationRegion.cjs +10 -6
- package/dist/components/Notification/NotificationRegion.cjs.map +1 -1
- package/dist/components/Notification/NotificationRegion.d.ts +2 -1
- package/dist/components/Notification/NotificationRegion.d.ts.map +1 -1
- package/dist/components/Notification/NotificationRegion.js +11 -7
- package/dist/components/Notification/NotificationRegion.js.map +1 -1
- package/dist/components/Notification/Snackbar/index.d.ts +2 -1
- package/dist/components/Notification/Snackbar/index.d.ts.map +1 -1
- package/dist/components/Notification/Snackbar/index2.cjs +3 -4
- package/dist/components/Notification/Snackbar/index2.cjs.map +1 -1
- package/dist/components/Notification/Snackbar/index2.js +3 -4
- package/dist/components/Notification/Snackbar/index2.js.map +1 -1
- package/dist/components/Notification/useNotificationQueue.cjs +5 -8
- package/dist/components/Notification/useNotificationQueue.cjs.map +1 -1
- package/dist/components/Notification/useNotificationQueue.d.ts +2 -4
- package/dist/components/Notification/useNotificationQueue.d.ts.map +1 -1
- package/dist/components/Notification/useNotificationQueue.js +5 -8
- package/dist/components/Notification/useNotificationQueue.js.map +1 -1
- package/dist/index.css +748 -740
- package/dist/layered.css +748 -740
- package/dist/layered.css.map +1 -1
- package/package.json +4 -7
- package/src/components/Notification/NotificationRegion.tsx +12 -7
- package/src/components/Notification/Snackbar/__snapshots__/index.css.snap +2 -0
- package/src/components/Notification/Snackbar/index.css +2 -0
- package/src/components/Notification/Snackbar/index.story.tsx +4 -0
- package/src/components/Notification/Snackbar/index.test.tsx +26 -7
- package/src/components/Notification/Snackbar/index.tsx +7 -6
- package/src/components/Notification/Toast/__snapshots__/index.css.snap +2 -0
- package/src/components/Notification/Toast/index.css +2 -0
- package/src/components/Notification/Toast/index.story.tsx +4 -0
- package/src/components/Notification/Toast/index.test.tsx +5 -2
- package/src/components/Notification/__snapshots__/layout.css.snap +8 -4
- package/src/components/Notification/layout.css +8 -4
- package/src/components/Notification/useNotificationQueue.ts +7 -18
|
@@ -8,8 +8,7 @@ import { NotificationRegion } from '../NotificationRegion'
|
|
|
8
8
|
import { useNotificationQueue } from '../useNotificationQueue'
|
|
9
9
|
import type { NotificationProps, Position } from '../types'
|
|
10
10
|
|
|
11
|
-
export type SnackbarCloseReason =
|
|
12
|
-
'timeout' | 'replaced' | 'action' | 'close' | 'unmounted'
|
|
11
|
+
export type SnackbarCloseReason = 'action' | 'unmounted'
|
|
13
12
|
|
|
14
13
|
export type SnackbarRootAttributes = {
|
|
15
14
|
[key: `data-${string}`]: string | number | boolean | undefined
|
|
@@ -18,6 +17,7 @@ export type SnackbarRootAttributes = {
|
|
|
18
17
|
export type ShowSnackbarOptions = {
|
|
19
18
|
action?: ReactNode
|
|
20
19
|
onClose?: (reason: SnackbarCloseReason) => void
|
|
20
|
+
/** スナックバー自体にdata属性を渡せる */
|
|
21
21
|
rootAttributes?: SnackbarRootAttributes
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -62,22 +62,23 @@ export function useSnackbar(props: UseSnackbarProps = {}) {
|
|
|
62
62
|
...regionProps
|
|
63
63
|
} = props
|
|
64
64
|
const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } =
|
|
65
|
-
useNotificationQueue<SnackbarContent,
|
|
65
|
+
useNotificationQueue<SnackbarContent, 'action'>('snackbar', {
|
|
66
66
|
duration,
|
|
67
67
|
order,
|
|
68
68
|
animateReplace: true,
|
|
69
|
-
timeoutReason: 'timeout',
|
|
70
|
-
unmountedReason: 'unmounted',
|
|
71
69
|
})
|
|
72
70
|
|
|
73
71
|
function show(message: ReactNode, options: ShowSnackbarOptions = {}) {
|
|
72
|
+
const onClose = options.onClose
|
|
74
73
|
enqueue(
|
|
75
74
|
{
|
|
76
75
|
message,
|
|
77
76
|
action: options.action,
|
|
78
77
|
rootAttributes: options.rootAttributes,
|
|
79
78
|
},
|
|
80
|
-
|
|
79
|
+
onClose === undefined
|
|
80
|
+
? undefined
|
|
81
|
+
: (reason) => onClose(reason ?? 'unmounted'),
|
|
81
82
|
)
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
.charcoal-toast-region[data-position='top'] {
|
|
6
|
+
position: sticky;
|
|
6
7
|
--charcoal-toast-enter-offset: calc(-1 * var(--charcoal-space-30));
|
|
7
8
|
top: calc(
|
|
8
9
|
env(safe-area-inset-top, 0px) + max(var(--charcoal-toast-offset), 16px)
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
.charcoal-toast-region[data-position='bottom'] {
|
|
14
|
+
position: fixed;
|
|
13
15
|
--charcoal-toast-enter-offset: var(--charcoal-space-30);
|
|
14
16
|
bottom: calc(
|
|
15
17
|
env(safe-area-inset-bottom, 0px) + max(var(--charcoal-toast-offset), 16px)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
--charcoal-toast-offset: 16px;
|
|
3
3
|
|
|
4
4
|
&[data-position='top'] {
|
|
5
|
+
position: sticky;
|
|
5
6
|
--charcoal-toast-enter-offset: calc(-1 * var(--charcoal-space-30));
|
|
6
7
|
|
|
7
8
|
top: calc(
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
&[data-position='bottom'] {
|
|
14
|
+
position: fixed;
|
|
13
15
|
--charcoal-toast-enter-offset: var(--charcoal-space-30);
|
|
14
16
|
|
|
15
17
|
bottom: calc(
|
|
@@ -50,6 +50,10 @@ export default {
|
|
|
50
50
|
control: { type: 'number', min: 0, step: 1 },
|
|
51
51
|
table: { category: 'Hook', defaultValue: { summary: '16' } },
|
|
52
52
|
},
|
|
53
|
+
headerOffset: {
|
|
54
|
+
control: { type: 'number', min: 0, step: 1 },
|
|
55
|
+
table: { category: 'Hook', defaultValue: { summary: '0' } },
|
|
56
|
+
},
|
|
53
57
|
duration: {
|
|
54
58
|
control: { type: 'number', min: 0, step: 500 },
|
|
55
59
|
description: '表示時間(ミリ秒)',
|
|
@@ -177,7 +177,10 @@ describe('Toast', () => {
|
|
|
177
177
|
|
|
178
178
|
show('保存しました', { type: 'success' })
|
|
179
179
|
|
|
180
|
-
expect(
|
|
180
|
+
expect(document.querySelector('.charcoal-toast-region')).toHaveAttribute(
|
|
181
|
+
'data-position',
|
|
182
|
+
'top',
|
|
183
|
+
)
|
|
181
184
|
})
|
|
182
185
|
|
|
183
186
|
it('places a toast at the bottom when requested', () => {
|
|
@@ -185,7 +188,7 @@ describe('Toast', () => {
|
|
|
185
188
|
|
|
186
189
|
show('保存しました', { type: 'success' })
|
|
187
190
|
|
|
188
|
-
expect(
|
|
191
|
+
expect(document.querySelector('.charcoal-toast-region')).toHaveAttribute(
|
|
189
192
|
'data-position',
|
|
190
193
|
'bottom',
|
|
191
194
|
)
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
.charcoal-notification-region {
|
|
2
|
-
position: fixed;
|
|
3
2
|
left: 0;
|
|
4
3
|
right: 0;
|
|
5
|
-
display: grid;
|
|
6
|
-
justify-content: center;
|
|
7
|
-
pointer-events: none;
|
|
8
4
|
box-sizing: border-box;
|
|
5
|
+
position: absolute;
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
align-items: center;
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
top: 0;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
.charcoal-notification {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
.charcoal-notification-region {
|
|
2
|
-
position: fixed;
|
|
3
2
|
left: 0;
|
|
4
3
|
right: 0;
|
|
5
|
-
display: grid;
|
|
6
|
-
justify-content: center;
|
|
7
|
-
pointer-events: none;
|
|
8
4
|
box-sizing: border-box;
|
|
5
|
+
position: absolute;
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
align-items: center;
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
top: 0;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
.charcoal-notification {
|
|
@@ -7,7 +7,7 @@ const ANIMATION_DURATION_MS = 300
|
|
|
7
7
|
|
|
8
8
|
type QueueItem<TContent, TCloseReason> = {
|
|
9
9
|
content: TContent
|
|
10
|
-
onClose?: (reason
|
|
10
|
+
onClose?: (reason?: TCloseReason) => void
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function useNotificationQueue<
|
|
@@ -19,14 +19,10 @@ export function useNotificationQueue<
|
|
|
19
19
|
duration: durationOption,
|
|
20
20
|
order = 'queue',
|
|
21
21
|
animateReplace = false,
|
|
22
|
-
timeoutReason,
|
|
23
|
-
unmountedReason,
|
|
24
22
|
}: {
|
|
25
23
|
duration?: number
|
|
26
24
|
order?: NotificationOrder
|
|
27
25
|
animateReplace?: boolean
|
|
28
|
-
timeoutReason?: TCloseReason
|
|
29
|
-
unmountedReason?: TCloseReason
|
|
30
26
|
} = {},
|
|
31
27
|
) {
|
|
32
28
|
const itemRef = useRef<HTMLDivElement>(null)
|
|
@@ -36,7 +32,7 @@ export function useNotificationQueue<
|
|
|
36
32
|
const isShowingRef = useRef(false)
|
|
37
33
|
const activeRef = useRef<{
|
|
38
34
|
key: string
|
|
39
|
-
onClose?: (reason
|
|
35
|
+
onClose?: (reason?: TCloseReason) => void
|
|
40
36
|
reason?: TCloseReason
|
|
41
37
|
notified: boolean
|
|
42
38
|
}>()
|
|
@@ -65,10 +61,7 @@ export function useNotificationQueue<
|
|
|
65
61
|
update()
|
|
66
62
|
if (active !== undefined && !active.notified) {
|
|
67
63
|
active.notified = true
|
|
68
|
-
|
|
69
|
-
if (reason !== undefined) {
|
|
70
|
-
active.onClose?.(reason)
|
|
71
|
-
}
|
|
64
|
+
active.onClose?.(active.reason)
|
|
72
65
|
}
|
|
73
66
|
playNextRef.current?.()
|
|
74
67
|
}
|
|
@@ -116,7 +109,7 @@ export function useNotificationQueue<
|
|
|
116
109
|
complete()
|
|
117
110
|
}
|
|
118
111
|
},
|
|
119
|
-
[name
|
|
112
|
+
[name],
|
|
120
113
|
)
|
|
121
114
|
|
|
122
115
|
const state = useToastState<TContent>({
|
|
@@ -129,16 +122,13 @@ export function useNotificationQueue<
|
|
|
129
122
|
const active = activeRef.current
|
|
130
123
|
if (active !== undefined && !active.notified) {
|
|
131
124
|
active.notified = true
|
|
132
|
-
|
|
133
|
-
if (reason !== undefined) {
|
|
134
|
-
active.onClose?.(reason)
|
|
135
|
-
}
|
|
125
|
+
active.onClose?.(active.reason)
|
|
136
126
|
}
|
|
137
127
|
activeRef.current = undefined
|
|
138
128
|
queueRef.current = []
|
|
139
129
|
isShowingRef.current = false
|
|
140
130
|
}
|
|
141
|
-
}, [
|
|
131
|
+
}, [])
|
|
142
132
|
|
|
143
133
|
function playNext() {
|
|
144
134
|
const next = queueRef.current.shift()
|
|
@@ -163,7 +153,7 @@ export function useNotificationQueue<
|
|
|
163
153
|
|
|
164
154
|
function enqueue(
|
|
165
155
|
content: TContent,
|
|
166
|
-
onClose?: (reason
|
|
156
|
+
onClose?: (reason?: TCloseReason) => void,
|
|
167
157
|
) {
|
|
168
158
|
const duration =
|
|
169
159
|
typeof durationOption === 'number' && Number.isFinite(durationOption)
|
|
@@ -181,7 +171,6 @@ export function useNotificationQueue<
|
|
|
181
171
|
const active = activeRef.current
|
|
182
172
|
if (active === undefined) return
|
|
183
173
|
|
|
184
|
-
active.reason = 'replaced' as TCloseReason
|
|
185
174
|
replaceRef.current = !animateReplace
|
|
186
175
|
hoverRef.current.active = false
|
|
187
176
|
const pending = hoverRef.current.pending
|