@charcoal-ui/react 6.1.0-beta.3 → 6.1.0-beta.5

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.
Files changed (33) hide show
  1. package/dist/_lib/compat.d.ts +4 -3
  2. package/dist/_lib/compat.d.ts.map +1 -1
  3. package/dist/components/Notification/Snackbar/index.d.ts +5 -1
  4. package/dist/components/Notification/Snackbar/index.d.ts.map +1 -1
  5. package/dist/components/Notification/Snackbar/index2.cjs +13 -11
  6. package/dist/components/Notification/Snackbar/index2.cjs.map +1 -1
  7. package/dist/components/Notification/Snackbar/index2.js +14 -12
  8. package/dist/components/Notification/Snackbar/index2.js.map +1 -1
  9. package/dist/components/Notification/Toast/index2.js +20 -16
  10. package/dist/components/Notification/Toast/index2.js.map +1 -1
  11. package/dist/components/Notification/useNotificationQueue.cjs +11 -14
  12. package/dist/components/Notification/useNotificationQueue.cjs.map +1 -1
  13. package/dist/components/Notification/useNotificationQueue.d.ts +3 -4
  14. package/dist/components/Notification/useNotificationQueue.d.ts.map +1 -1
  15. package/dist/components/Notification/useNotificationQueue.js +11 -14
  16. package/dist/components/Notification/useNotificationQueue.js.map +1 -1
  17. package/dist/components/Pagination/index2.js +60 -52
  18. package/dist/components/Pagination/index2.js.map +1 -1
  19. package/dist/index.css +1322 -1323
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/layered.css +1322 -1323
  23. package/dist/layered.css.map +1 -1
  24. package/package.json +5 -5
  25. package/src/_lib/compat.ts +4 -3
  26. package/src/components/Carousel/__snapshots__/index.css.snap +4 -4
  27. package/src/components/Carousel/index.css +4 -4
  28. package/src/components/Notification/Snackbar/index.test.tsx +46 -9
  29. package/src/components/Notification/Snackbar/index.tsx +21 -6
  30. package/src/components/Notification/useNotificationQueue.ts +16 -26
  31. package/src/components/Pagination/__snapshots__/index.css.snap +0 -1
  32. package/src/components/Pagination/index.css +0 -1
  33. package/src/index.ts +1 -0
@@ -8,12 +8,16 @@ 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'
12
+
13
+ export type SnackbarRootAttributes = {
14
+ [key: `data-${string}`]: string | number | boolean | undefined
15
+ }
13
16
 
14
17
  export type ShowSnackbarOptions = {
15
18
  action?: ReactNode
16
19
  onClose?: (reason: SnackbarCloseReason) => void
20
+ rootAttributes?: SnackbarRootAttributes
17
21
  }
18
22
 
19
23
  type SnackbarBaseProps = {
@@ -35,6 +39,7 @@ export type UseSnackbarProps = Omit<NotificationProps, 'position'> & {
35
39
  type SnackbarContent = {
36
40
  message: ReactNode
37
41
  action?: ReactNode
42
+ rootAttributes?: SnackbarRootAttributes
38
43
  }
39
44
 
40
45
  const Snackbar = forwardRef<HTMLDivElement, SnackbarProps>(
@@ -56,15 +61,24 @@ export function useSnackbar(props: UseSnackbarProps = {}) {
56
61
  ...regionProps
57
62
  } = props
58
63
  const { state, itemRef, enqueue, close, onHoverStart, onHoverEnd } =
59
- useNotificationQueue<SnackbarContent, SnackbarCloseReason>('snackbar', {
64
+ useNotificationQueue<SnackbarContent, 'action'>('snackbar', {
60
65
  duration,
61
66
  order,
62
- timeoutReason: 'timeout',
63
- unmountedReason: 'unmounted',
67
+ animateReplace: true,
64
68
  })
65
69
 
66
70
  function show(message: ReactNode, options: ShowSnackbarOptions = {}) {
67
- enqueue({ message, action: options.action }, options.onClose)
71
+ const onClose = options.onClose
72
+ enqueue(
73
+ {
74
+ message,
75
+ action: options.action,
76
+ rootAttributes: options.rootAttributes,
77
+ },
78
+ onClose === undefined
79
+ ? undefined
80
+ : (reason) => onClose(reason ?? 'unmounted'),
81
+ )
68
82
  }
69
83
 
70
84
  const hasAction = state.visibleToasts.some(
@@ -80,6 +94,7 @@ export function useSnackbar(props: UseSnackbarProps = {}) {
80
94
  >
81
95
  {state.visibleToasts.map((toast) => (
82
96
  <NotificationItem
97
+ {...toast.content.rootAttributes}
83
98
  key={toast.key}
84
99
  name="snackbar"
85
100
  toast={toast}
@@ -7,7 +7,7 @@ const ANIMATION_DURATION_MS = 300
7
7
 
8
8
  type QueueItem<TContent, TCloseReason> = {
9
9
  content: TContent
10
- onClose?: (reason: TCloseReason) => void
10
+ onClose?: (reason?: TCloseReason) => void
11
11
  }
12
12
 
13
13
  export function useNotificationQueue<
@@ -18,13 +18,11 @@ export function useNotificationQueue<
18
18
  {
19
19
  duration: durationOption,
20
20
  order = 'queue',
21
- timeoutReason,
22
- unmountedReason,
21
+ animateReplace = false,
23
22
  }: {
24
23
  duration?: number
25
24
  order?: NotificationOrder
26
- timeoutReason?: TCloseReason
27
- unmountedReason?: TCloseReason
25
+ animateReplace?: boolean
28
26
  } = {},
29
27
  ) {
30
28
  const itemRef = useRef<HTMLDivElement>(null)
@@ -34,7 +32,7 @@ export function useNotificationQueue<
34
32
  const isShowingRef = useRef(false)
35
33
  const activeRef = useRef<{
36
34
  key: string
37
- onClose?: (reason: TCloseReason) => void
35
+ onClose?: (reason?: TCloseReason) => void
38
36
  reason?: TCloseReason
39
37
  notified: boolean
40
38
  }>()
@@ -57,24 +55,17 @@ export function useNotificationQueue<
57
55
  return
58
56
  }
59
57
 
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
58
  function finish() {
59
+ const active = activeRef.current
71
60
  activeRef.current = undefined
72
61
  update()
62
+ if (active !== undefined && !active.notified) {
63
+ active.notified = true
64
+ active.onClose?.(active.reason)
65
+ }
73
66
  playNextRef.current?.()
74
67
  }
75
68
 
76
- notifyActive()
77
-
78
69
  if (hoverRef.current.active) {
79
70
  hoverRef.current.pending = () => wrapUpdate(update, 'remove')
80
71
  return
@@ -90,6 +81,7 @@ export function useNotificationQueue<
90
81
  finish()
91
82
  return
92
83
  }
84
+
93
85
  const item: HTMLDivElement = itemRef.current
94
86
 
95
87
  // allow-discreteが Newly Available で使えないので、要素の削除をアニメーション完了まで待つ
@@ -117,7 +109,7 @@ export function useNotificationQueue<
117
109
  complete()
118
110
  }
119
111
  },
120
- [name, timeoutReason],
112
+ [name],
121
113
  )
122
114
 
123
115
  const state = useToastState<TContent>({
@@ -129,15 +121,14 @@ export function useNotificationQueue<
129
121
  return () => {
130
122
  const active = activeRef.current
131
123
  if (active !== undefined && !active.notified) {
132
- if (unmountedReason !== undefined) {
133
- active.onClose?.(unmountedReason)
134
- }
124
+ active.notified = true
125
+ active.onClose?.(active.reason)
135
126
  }
136
127
  activeRef.current = undefined
137
128
  queueRef.current = []
138
129
  isShowingRef.current = false
139
130
  }
140
- }, [unmountedReason])
131
+ }, [])
141
132
 
142
133
  function playNext() {
143
134
  const next = queueRef.current.shift()
@@ -162,7 +153,7 @@ export function useNotificationQueue<
162
153
 
163
154
  function enqueue(
164
155
  content: TContent,
165
- onClose?: (reason: TCloseReason) => void,
156
+ onClose?: (reason?: TCloseReason) => void,
166
157
  ) {
167
158
  const duration =
168
159
  typeof durationOption === 'number' && Number.isFinite(durationOption)
@@ -180,8 +171,7 @@ export function useNotificationQueue<
180
171
  const active = activeRef.current
181
172
  if (active === undefined) return
182
173
 
183
- active.reason = 'replaced' as TCloseReason
184
- replaceRef.current = true
174
+ replaceRef.current = !animateReplace
185
175
  hoverRef.current.active = false
186
176
  const pending = hoverRef.current.pending
187
177
  hoverRef.current.pending = undefined
@@ -39,7 +39,6 @@
39
39
  * Safari doesn't correctly repaint the elements when they're reordered in response to interaction.
40
40
  * This forces it to repaint them. This doesn't work if put on the parents either, has to be here.
41
41
  */
42
- /* stylelint-disable-next-line property-no-vendor-prefix */
43
42
  -webkit-transform: translateZ(0);
44
43
  color: var(--charcoal-color-text-tertiary-default);
45
44
  background-color: transparent;
@@ -39,7 +39,6 @@
39
39
  * Safari doesn't correctly repaint the elements when they're reordered in response to interaction.
40
40
  * This forces it to repaint them. This doesn't work if put on the parents either, has to be here.
41
41
  */
42
- /* stylelint-disable-next-line property-no-vendor-prefix */
43
42
  -webkit-transform: translateZ(0);
44
43
 
45
44
  color: var(--charcoal-color-text-tertiary-default);
package/src/index.ts CHANGED
@@ -112,6 +112,7 @@ export {
112
112
  type SnackbarProps as UnstableSnackbarProps,
113
113
  type UseSnackbarProps as unstable_UseSnackbarProps,
114
114
  type SnackbarCloseReason as unstable_SnackbarCloseReason,
115
+ type SnackbarRootAttributes as unstable_SnackbarRootAttributes,
115
116
  type ShowSnackbarOptions as unstable_ShowSnackbarOptions,
116
117
  } from './components/Notification/Snackbar'
117
118
  export {