@opencode/ui 2.2.4 → 2.2.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.
Files changed (127) hide show
  1. package/dist/actions/button/button.d.ts +2 -2
  2. package/dist/actions/icon-button/icon-button.d.ts +1 -1
  3. package/dist/components/animated-number-machine.d.ts +95 -0
  4. package/dist/components/file-icon-machine.d.ts +40 -0
  5. package/dist/components/file-icon.d.ts +0 -2
  6. package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
  7. package/dist/components/image-flight-machine.d.ts +135 -0
  8. package/dist/components/image-zoom-machine.d.ts +95 -0
  9. package/dist/components/image-zoom.d.ts +6 -3
  10. package/dist/components/list.d.ts +2 -6
  11. package/dist/components/menu-scroll.d.ts +12 -0
  12. package/dist/components/popover-machine.d.ts +96 -0
  13. package/dist/components/popover.d.ts +2 -2
  14. package/dist/components/resize-handle-machine.d.ts +71 -0
  15. package/dist/components/resize-handle.d.ts +2 -0
  16. package/dist/components/scroll-view-machine.d.ts +68 -0
  17. package/dist/components/scroll-view.d.ts +2 -2
  18. package/dist/components/spinner.d.ts +11 -3
  19. package/dist/components/text-field-machine.d.ts +62 -0
  20. package/dist/components/text-reveal-machine.d.ts +90 -0
  21. package/dist/components/typewriter-machine.d.ts +62 -0
  22. package/dist/context/dialog-machine.d.ts +125 -0
  23. package/dist/context/dialog.d.ts +17 -16
  24. package/dist/data-display/line-comment/line-comment.d.ts +9 -0
  25. package/dist/data-display/line-comment/machine.d.ts +157 -0
  26. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  27. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  28. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  29. package/dist/feedback/toast/machine.d.ts +57 -0
  30. package/dist/feedback/toast/toast.d.ts +1 -1
  31. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  32. package/dist/forms/select/machine.d.ts +45 -0
  33. package/dist/forms/select/select.d.ts +4 -0
  34. package/dist/forms/text-input/text-input.d.ts +4 -2
  35. package/dist/forms/textarea/textarea.d.ts +1 -0
  36. package/dist/forms/typeahead/machine.d.ts +85 -0
  37. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  38. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  39. package/dist/hooks/list-machine.d.ts +150 -0
  40. package/dist/hooks/use-filtered-list.d.ts +21 -35
  41. package/dist/i18n/en.d.ts +5 -0
  42. package/dist/icons/catalog.d.ts +8 -0
  43. package/dist/navigation/menu/machine.d.ts +49 -0
  44. package/dist/navigation/menu/menu.d.ts +5 -3
  45. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  46. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  47. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  48. package/dist/overlays/tooltip/machine.d.ts +146 -0
  49. package/dist/theme/context.d.ts +38 -14
  50. package/dist/theme/machine.d.ts +174 -0
  51. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  52. package/package.json +19 -3
  53. package/src/actions/button/button.tsx +11 -6
  54. package/src/actions/icon-button/icon-button.tsx +17 -4
  55. package/src/components/animated-number-machine.ts +214 -0
  56. package/src/components/animated-number.tsx +134 -83
  57. package/src/components/file-icon-machine.ts +78 -0
  58. package/src/components/file-icon.tsx +96 -579
  59. package/src/components/file-icons/choose-icon-name.ts +574 -0
  60. package/src/components/image-flight-machine.ts +247 -0
  61. package/src/components/image-preview.css +5 -2
  62. package/src/components/image-preview.tsx +390 -252
  63. package/src/components/image-zoom-machine.ts +191 -0
  64. package/src/components/image-zoom.ts +22 -14
  65. package/src/components/list.tsx +46 -137
  66. package/src/components/menu-scroll.css +70 -0
  67. package/src/components/menu-scroll.tsx +161 -0
  68. package/src/components/popover-machine.ts +198 -0
  69. package/src/components/popover.tsx +157 -89
  70. package/src/components/resize-handle-machine.ts +174 -0
  71. package/src/components/resize-handle.tsx +116 -67
  72. package/src/components/scroll-view-machine.ts +244 -0
  73. package/src/components/scroll-view.tsx +163 -116
  74. package/src/components/spinner.css +18 -5
  75. package/src/components/spinner.tsx +28 -14
  76. package/src/components/text-field-machine.ts +102 -0
  77. package/src/components/text-field.tsx +78 -24
  78. package/src/components/text-reveal-machine.ts +184 -0
  79. package/src/components/text-reveal.tsx +96 -93
  80. package/src/components/typewriter-machine.ts +134 -0
  81. package/src/components/typewriter.tsx +50 -39
  82. package/src/context/dialog-machine.ts +280 -0
  83. package/src/context/dialog.tsx +168 -177
  84. package/src/data-display/line-comment/line-comment.tsx +196 -132
  85. package/src/data-display/line-comment/machine.ts +391 -0
  86. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  87. package/src/data-display/project-avatar/animation.ts +67 -38
  88. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  89. package/src/feedback/toast/machine.ts +115 -0
  90. package/src/feedback/toast/toast.tsx +55 -59
  91. package/src/forms/checkbox/checkbox-compact.css +169 -0
  92. package/src/forms/checkbox/checkbox.tsx +93 -31
  93. package/src/forms/search-list/search-list.css +5 -1
  94. package/src/forms/search-list/search-list.tsx +4 -4
  95. package/src/forms/select/machine.ts +81 -0
  96. package/src/forms/select/select.css +59 -17
  97. package/src/forms/select/select.tsx +67 -31
  98. package/src/forms/text-input/text-input.css +30 -16
  99. package/src/forms/text-input/text-input.tsx +6 -2
  100. package/src/forms/textarea/textarea.css +13 -8
  101. package/src/forms/textarea/textarea.tsx +3 -1
  102. package/src/forms/typeahead/machine.ts +253 -0
  103. package/src/forms/typeahead/typeahead.tsx +75 -66
  104. package/src/hooks/auto-scroll-machine.ts +261 -0
  105. package/src/hooks/create-auto-scroll.tsx +110 -205
  106. package/src/hooks/list-machine.ts +359 -0
  107. package/src/hooks/use-filtered-list.tsx +101 -112
  108. package/src/i18n/en.ts +6 -1
  109. package/src/icons/catalog.ts +8 -0
  110. package/src/navigation/menu/machine.ts +109 -0
  111. package/src/navigation/menu/menu.tsx +130 -22
  112. package/src/navigation/segmented-control/machine.ts +72 -0
  113. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  114. package/src/overlays/dialog/dialog.tsx +7 -1
  115. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  116. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  117. package/src/overlays/tooltip/machine.ts +303 -0
  118. package/src/overlays/tooltip/tooltip.tsx +157 -92
  119. package/src/styles/theme.css +10 -2
  120. package/src/styles/tokens/theme.css +13 -0
  121. package/src/theme/context.tsx +192 -269
  122. package/src/theme/machine.ts +508 -0
  123. package/src/theme/themes/oc-2.json +2 -0
  124. package/src/theme/v2/mapping.ts +12 -8
  125. package/src/typography/text-shimmer/machine.ts +90 -0
  126. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  127. package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
@@ -1,8 +1,18 @@
1
+ import { observeReducedMotion, prefersReducedMotion } from "../../motion/reduced"
2
+ import {
3
+ AVATAR_DISPOSED,
4
+ AVATAR_POINTER_LEFT,
5
+ AVATAR_REFRESH,
6
+ createAvatarClock,
7
+ INITIAL_AVATAR_ANIMATION_STATE,
8
+ selectAvatarPaintTime,
9
+ selectAvatarRunning,
10
+ transitionAvatarAnimation,
11
+ type AvatarAnimationEvent,
12
+ type AvatarAnimationState,
13
+ } from "./animation-machine"
1
14
  import { drawProjectIcon, type GeneratedProjectIcon } from "./generated"
2
15
 
3
- // The animation starts once the pointer rests on the avatar's row, so passing over a list does no drawing.
4
- const REST_MS = 150
5
-
6
16
  const HOVER_TARGET = 'a, button, [role="menuitem"], [role="option"], [data-titlebar-tab]'
7
17
 
8
18
  // Paints a generated avatar into `canvas`. The static frame is drawn once per icon and pixel size and copied into every
@@ -10,11 +20,14 @@ const HOVER_TARGET = 'a, button, [role="menuitem"], [role="option"], [data-title
10
20
  // row animates only that row's icon even when other rows show the same project. Only a hovered avatar runs an
11
21
  // animation loop, and it stops once the icon has eased back to its static frame.
12
22
  export function attachGeneratedAvatar(canvas: HTMLCanvasElement, icon: () => GeneratedProjectIcon) {
23
+ let state: AvatarAnimationState = INITIAL_AVATAR_ANIMATION_STATE
24
+ const clock = createAvatarClock()
13
25
  let frame = 0
14
- let time = 0
15
- let hovering = false
16
- let last = 0
17
- let entered = 0
26
+ let stopMotionObserver: (() => void) | undefined
27
+ // Reused every frame, so the loop allocates nothing.
28
+ const enterEvent = { type: "pointer.entered" as const, now: 0, reduced: false }
29
+ const frameEvent = { type: "frame" as const, now: 0 }
30
+ const motionEvent = { type: "motion.changed" as const, reduced: false }
18
31
 
19
32
  const paint = (draw: (ctx: CanvasRenderingContext2D, px: number) => void) => {
20
33
  const px = Math.max(1, Math.round((canvas.clientWidth || 16) * (window.devicePixelRatio || 1)))
@@ -25,60 +38,76 @@ export function attachGeneratedAvatar(canvas: HTMLCanvasElement, icon: () => Gen
25
38
  if (ctx) draw(ctx, px)
26
39
  }
27
40
 
28
- const paintStatic = () =>
29
- paint((ctx, px) => {
30
- ctx.clearRect(0, 0, px, px)
31
- const still = staticFrame(icon(), px)
41
+ const drawStatic = (ctx: CanvasRenderingContext2D, px: number) => {
42
+ ctx.clearRect(0, 0, px, px)
43
+ const still = staticFrame(icon(), px)
32
44
 
33
- if (still) ctx.drawImage(still, 0, 0)
34
- })
45
+ if (still) ctx.drawImage(still, 0, 0)
46
+ }
35
47
 
36
- const tick = (now: number) => {
37
- if (hovering && time === 0 && now - entered < REST_MS) {
38
- last = now
39
- frame = requestAnimationFrame(tick)
48
+ const drawAnimated = (ctx: CanvasRenderingContext2D, px: number) =>
49
+ drawProjectIcon(ctx, px, icon(), selectAvatarPaintTime(state, clock))
40
50
 
41
- return
42
- }
51
+ const dispatch = (event: AvatarAnimationEvent) => {
52
+ const prev = state
53
+ const next = transitionAvatarAnimation(prev, clock, event)
54
+ state = next.state
55
+
56
+ if (selectAvatarRunning(prev) !== selectAvatarRunning(state)) reconcile()
43
57
 
44
- const seconds = Math.min((now - last) / 1000, 0.1)
45
- last = now
46
- time = hovering ? time + seconds : time * Math.pow(0.002, seconds)
58
+ if (next.effect === "paint-static") paint(drawStatic)
47
59
 
48
- if (!hovering && time < 0.01) {
49
- time = 0
50
- frame = 0
51
- paintStatic()
60
+ if (next.effect === "paint-frame") paint(drawAnimated)
61
+ }
62
+
63
+ const reconcile = () => {
64
+ if (selectAvatarRunning(state)) {
65
+ stopMotionObserver = observeReducedMotion(onMotionChange)
66
+ frame = requestAnimationFrame(tick)
52
67
 
53
68
  return
54
69
  }
55
70
 
56
- paint((ctx, px) => drawProjectIcon(ctx, px, icon(), time))
57
- frame = requestAnimationFrame(tick)
71
+ cancelAnimationFrame(frame)
72
+ frame = 0
73
+ stopMotionObserver?.()
74
+ stopMotionObserver = undefined
58
75
  }
59
76
 
60
- const enter = () => {
61
- if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return
62
- hovering = true
77
+ const tick = (now: number) => {
78
+ frame = 0
79
+ frameEvent.now = now
80
+ dispatch(frameEvent)
81
+
82
+ if (selectAvatarRunning(state) && !frame) frame = requestAnimationFrame(tick)
83
+ }
63
84
 
64
- if (frame) return
65
- entered = last = performance.now()
66
- frame = requestAnimationFrame(tick)
85
+ const enter = () => {
86
+ enterEvent.now = performance.now()
87
+ enterEvent.reduced = prefersReducedMotion()
88
+ dispatch(enterEvent)
67
89
  }
68
90
 
69
- const leave = () => (hovering = false)
91
+ const leave = () => dispatch(AVATAR_POINTER_LEFT)
92
+
93
+ const onMotionChange = () => {
94
+ motionEvent.reduced = prefersReducedMotion()
95
+ dispatch(motionEvent)
96
+ }
70
97
 
71
98
  const target =
72
- canvas.closest<HTMLElement>(HOVER_TARGET) ?? canvas.closest<HTMLElement>('[data-component="project-avatar-v2"]') ?? canvas
99
+ canvas.closest<HTMLElement>(HOVER_TARGET) ??
100
+ canvas.closest<HTMLElement>('[data-component="project-avatar-v2"]') ??
101
+ canvas
73
102
 
74
103
  target.addEventListener("pointerenter", enter)
75
104
  target.addEventListener("pointerleave", leave)
76
105
 
77
106
  return {
78
107
  /** Repaints the static frame unless the avatar is animating, e.g. after the icon changed. */
79
- refresh: () => !frame && paintStatic(),
108
+ refresh: () => dispatch(AVATAR_REFRESH),
80
109
  dispose: () => {
81
- cancelAnimationFrame(frame)
110
+ dispatch(AVATAR_DISPOSED)
82
111
  target.removeEventListener("pointerenter", enter)
83
112
  target.removeEventListener("pointerleave", leave)
84
113
  },
@@ -2,7 +2,7 @@ import { type ComponentProps } from "solid-js"
2
2
  import { Spinner } from "../../components/spinner"
3
3
  import "./activity-ring.css"
4
4
 
5
- export function ActivityRing(props: ComponentProps<"svg">) {
5
+ export function ActivityRing(props: ComponentProps<typeof Spinner>) {
6
6
  return (
7
7
  <Spinner
8
8
  {...props}
@@ -0,0 +1,115 @@
1
+ export type ToastRegistryEntry<O> = {
2
+ readonly id: number
3
+ /** Same title, description, variant, timing and action labels coalesce into one toast. */
4
+ readonly key: string
5
+ readonly options: O
6
+ }
7
+
8
+ /**
9
+ * The toasts `showToast` and `toaster` have published and not yet seen close. Each entry lives from its publish
10
+ * until solid-sonner reports it closed (`onDismiss`, `onAutoClose`), `toaster.dismiss` closes it, or a later show
11
+ * finds it missing from solid-sonner's live toasts.
12
+ */
13
+ export type ToastRegistryState<O> = {
14
+ /** Last allocated id. IDs count down from `-1`: solid-sonner treats a falsy id as "dismiss every toast". */
15
+ readonly nextId: number
16
+ readonly entries: readonly ToastRegistryEntry<O>[]
17
+ }
18
+
19
+ export type ToastShownEvent<O> = {
20
+ readonly type: "toast.shown"
21
+ readonly key: string
22
+ readonly options: O
23
+ /** IDs solid-sonner still holds, from `toast.getToasts()`, which also lists toasts other code shows. */
24
+ readonly liveIds: ReadonlySet<number | string>
25
+ /** The newest of them, shown in front. */
26
+ readonly topmostLiveId: number | string | undefined
27
+ }
28
+
29
+ export type ToastRegistryEvent<O> =
30
+ | { readonly type: "custom.shown" }
31
+ | ToastShownEvent<O>
32
+ | { readonly type: "toast.released"; readonly id: number }
33
+ | { readonly type: "toast.dismissed"; readonly id?: number }
34
+
35
+ export type ToastRegistryEffect<O> =
36
+ | { readonly type: "sonner.publish"; readonly id: number; readonly options: O }
37
+ | { readonly type: "sonner.dismiss"; readonly id?: number }
38
+ | { readonly type: "dom.pulse"; readonly id: number }
39
+
40
+ export type ToastRegistryTransition<O> = {
41
+ readonly state: ToastRegistryState<O>
42
+ /** The toast a `toast.shown` event showed. */
43
+ readonly id?: number
44
+ readonly effects: readonly ToastRegistryEffect<O>[]
45
+ }
46
+
47
+ export function createToastRegistryState<O>(): ToastRegistryState<O> {
48
+ return { nextId: 0, entries: [] }
49
+ }
50
+
51
+ export function transitionToastRegistry<O>(
52
+ state: ToastRegistryState<O>,
53
+ event: ToastShownEvent<O>,
54
+ ): ToastRegistryTransition<O> & { readonly id: number }
55
+ export function transitionToastRegistry<O>(
56
+ state: ToastRegistryState<O>,
57
+ event: ToastRegistryEvent<O>,
58
+ ): ToastRegistryTransition<O>
59
+ export function transitionToastRegistry<O>(
60
+ state: ToastRegistryState<O>,
61
+ event: ToastRegistryEvent<O>,
62
+ ): ToastRegistryTransition<O> {
63
+ // A custom toast only takes an id: its caller owns its content and dismisses it through `toaster.dismiss`.
64
+ if (event.type === "custom.shown") return { state: { ...state, nextId: state.nextId - 1 }, effects: [] }
65
+
66
+ if (event.type === "toast.released") return { state: remove(state, event.id), effects: [] }
67
+
68
+ if (event.type === "toast.dismissed") {
69
+ const next = event.id === undefined ? { nextId: state.nextId, entries: [] } : remove(state, event.id)
70
+
71
+ return { state: next, effects: [{ type: "sonner.dismiss", id: event.id }] }
72
+ }
73
+
74
+ // An entry solid-sonner no longer holds was dismissed behind the registry's back.
75
+ const live = state.entries.filter((entry) => event.liveIds.has(entry.id))
76
+ const match = live.find((entry) => entry.key === event.key)
77
+
78
+ // The same toast is still in front: update it in place and pulse it rather than stacking a copy.
79
+ if (match && match.id === event.topmostLiveId) {
80
+ return {
81
+ state: {
82
+ nextId: state.nextId,
83
+ entries: live.map((entry) => (entry === match ? { ...entry, options: event.options } : entry)),
84
+ },
85
+ id: match.id,
86
+ effects: [
87
+ { type: "sonner.publish", id: match.id, options: event.options },
88
+ { type: "dom.pulse", id: match.id },
89
+ ],
90
+ }
91
+ }
92
+
93
+ // A buried copy moves to the front as a new toast.
94
+ const id = state.nextId - 1
95
+ const rest = match ? live.filter((entry) => entry !== match) : live
96
+
97
+ return {
98
+ state: { nextId: id, entries: [...rest, { id, key: event.key, options: event.options }] },
99
+ id,
100
+ effects: [
101
+ ...(match ? [{ type: "sonner.dismiss", id: match.id } as const] : []),
102
+ { type: "sonner.publish", id, options: event.options },
103
+ ],
104
+ }
105
+ }
106
+
107
+ export function selectToastOptions<O>(state: ToastRegistryState<O>, id: number) {
108
+ return state.entries.find((entry) => entry.id === id)?.options
109
+ }
110
+
111
+ function remove<O>(state: ToastRegistryState<O>, id: number) {
112
+ if (!state.entries.some((entry) => entry.id === id)) return state
113
+
114
+ return { nextId: state.nextId, entries: state.entries.filter((entry) => entry.id !== id) }
115
+ }
@@ -8,6 +8,13 @@ import { useI18n } from "../../context/i18n"
8
8
  import "../../actions/button/button.css"
9
9
  import "./toast.css"
10
10
  import { prefersReducedMotion } from "../../motion"
11
+ import {
12
+ createToastRegistryState,
13
+ selectToastOptions,
14
+ transitionToastRegistry,
15
+ type ToastRegistryEvent,
16
+ type ToastRegistryTransition,
17
+ } from "./machine"
11
18
 
12
19
  export interface ToastRegionProps extends ToasterProps {}
13
20
 
@@ -127,8 +134,6 @@ export const Toast = Object.assign(ToastRoot, {
127
134
  CloseButton: ToastCloseButton,
128
135
  })
129
136
 
130
- let toastV2Id = 0
131
-
132
137
  export const toaster = {
133
138
  show(
134
139
  render: (props: { toastId: number }) => JSX.Element,
@@ -139,7 +144,8 @@ export const toaster = {
139
144
  resize?: () => void
140
145
  },
141
146
  ) {
142
- const toastId = --toastV2Id
147
+ dispatchRegistry({ type: "custom.shown" })
148
+ const toastId = registry.nextId
143
149
  toast.custom((id) => render({ toastId: Number(id) }), {
144
150
  id: toastId,
145
151
  className: "toast-v2",
@@ -160,14 +166,9 @@ export const toaster = {
160
166
  return toastId
161
167
  },
162
168
  dismiss(toastId?: number) {
163
- if (toastId === undefined) {
164
- activeToastByKey.clear()
165
- activeToastById.clear()
166
- } else {
167
- releaseToast(activeToastById.get(toastId))
168
- }
169
+ dispatchRegistry({ type: "toast.dismissed", id: toastId })
169
170
 
170
- return toast.dismiss(toastId)
171
+ return toastId
171
172
  },
172
173
  }
173
174
 
@@ -188,16 +189,23 @@ export interface ToastOptions {
188
189
  actions?: ToastAction[]
189
190
  }
190
191
 
191
- interface ActiveToast {
192
- id: number
193
- key: string
194
- options: ToastOptions
195
- actions?: JSX.Element
192
+ let registry = createToastRegistryState<ToastOptions>()
193
+
194
+ function dispatchRegistry(event: ToastRegistryEvent<ToastOptions>) {
195
+ applyRegistry(transitionToastRegistry(registry, event))
196
196
  }
197
197
 
198
- const activeToastByKey = new Map<string, ActiveToast>()
198
+ function applyRegistry<T extends ToastRegistryTransition<ToastOptions>>(transition: T) {
199
+ registry = transition.state
200
+ transition.effects.forEach((effect) => {
201
+ if (effect.type === "sonner.publish") return publishToast(effect.id, effect.options)
199
202
 
200
- const activeToastById = new Map<number, ActiveToast>()
203
+ if (effect.type === "sonner.dismiss") return toast.dismiss(effect.id)
204
+ pulseToast(effect.id)
205
+ })
206
+
207
+ return transition
208
+ }
201
209
 
202
210
  export function showToast(options: ToastOptions | string) {
203
211
  // SAFETY: `options` is declared `ToastOptions | string`; `typeof` separates the string shorthand from the object.
@@ -213,56 +221,48 @@ export function showToast(options: ToastOptions | string) {
213
221
  actions: opts.actions?.map((action) => [action.label, action.variant]),
214
222
  })
215
223
 
216
- const active = activeToastByKey.get(key)
217
224
  const toasts = toast.getToasts()
218
225
 
219
- if (active && toasts.at(-1)?.id === active.id) {
220
- active.options = opts
221
- publishToast(active)
222
- pulseToast(active.id)
223
-
224
- return active.id
225
- }
226
-
227
- if (active && toasts.some((item) => item.id === active.id)) toaster.dismiss(active.id)
228
- releaseToast(active)
229
-
230
- const entry: ActiveToast = { id: --toastV2Id, key, options: opts }
231
- entry.actions = createToastActions(entry)
232
- activeToastByKey.set(key, entry)
233
- activeToastById.set(entry.id, entry)
234
- publishToast(entry)
235
-
236
- return entry.id
226
+ return applyRegistry(
227
+ transitionToastRegistry(registry, {
228
+ type: "toast.shown",
229
+ key,
230
+ options: opts,
231
+ liveIds: new Set(toasts.map((item) => item.id)),
232
+ topmostLiveId: toasts.at(-1)?.id,
233
+ }),
234
+ ).id
237
235
  }
238
236
 
239
- function publishToast(entry: ActiveToast) {
240
- const release = () => releaseToast(entry)
241
- toast(entry.options.title ?? "", {
242
- id: entry.id,
243
- description: entry.options.description,
237
+ function publishToast(id: number, options: ToastOptions) {
238
+ // solid-sonner calls these as the toast starts to leave, 200ms before it drops the toast from `getToasts()`.
239
+ const release = () => void dispatchRegistry({ type: "toast.released", id })
240
+ // `toast.message` updates a toast with the same id in place; `toast()` would append a duplicate record.
241
+ toast.message(options.title ?? "", {
242
+ id,
243
+ description: options.description,
244
244
  // SAFETY: solid-sonner inserts `icon` as a JSX child, and Solid calls a function child under the toast's render
245
245
  // owner; solid-sonner's type omits function children.
246
- icon: entry.options.icon as JSX.Element,
247
- action: entry.actions,
246
+ icon: options.icon as JSX.Element,
247
+ action: createToastActions(id, options.actions),
248
248
  closeButton: true,
249
- duration: entry.options.persistent ? Number.POSITIVE_INFINITY : entry.options.duration,
250
- className: `toast-v2 toast-v2--${entry.options.variant ?? "default"}`,
251
- testId: `toast-v2-${entry.id}`,
249
+ duration: options.persistent ? Number.POSITIVE_INFINITY : options.duration,
250
+ className: `toast-v2 toast-v2--${options.variant ?? "default"}`,
251
+ testId: `toast-v2-${id}`,
252
252
  unstyled: true,
253
253
  onDismiss: release,
254
254
  onAutoClose: release,
255
255
  })
256
256
  }
257
257
 
258
- function createToastActions(entry: ActiveToast) {
259
- if (!entry.options.actions?.length) return undefined
258
+ function createToastActions(id: number, actions: ToastAction[] | undefined) {
259
+ if (!actions?.length) return undefined
260
260
 
261
261
  return (
262
262
  <Toast.Actions>
263
263
  {/* Static map, not <For>: this JSX is created imperatively outside any Solid
264
264
  root, where a <For> computation would never be disposed. */}
265
- {entry.options.actions.map((action, index) => (
265
+ {actions.map((action, index) => (
266
266
  <button
267
267
  type="button"
268
268
  data-component="button-v2"
@@ -270,10 +270,14 @@ function createToastActions(entry: ActiveToast) {
270
270
  data-size="small"
271
271
  data-action-variant={action.variant ?? "primary"}
272
272
  onClick={() => {
273
- const onClick = entry.options.actions?.[index]?.onClick
273
+ // A toast that already closed, such as on a second click during its exit animation, runs nothing.
274
+ const options = selectToastOptions(registry, id)
275
+
276
+ if (!options) return
277
+ const onClick = options.actions?.[index]?.onClick
274
278
 
275
279
  if (onClick && onClick !== "dismiss") onClick()
276
- toaster.dismiss(entry.id)
280
+ toaster.dismiss(id)
277
281
  }}
278
282
  >
279
283
  {action.label}
@@ -293,14 +297,6 @@ function pulseToast(toastId: number) {
293
297
  })
294
298
  }
295
299
 
296
- function releaseToast(entry: ActiveToast | undefined) {
297
- if (!entry) return
298
-
299
- if (activeToastByKey.get(entry.key) === entry) activeToastByKey.delete(entry.key)
300
-
301
- if (activeToastById.get(entry.id) === entry) activeToastById.delete(entry.id)
302
- }
303
-
304
300
  export interface ToastPromiseOptions<T, U = unknown> {
305
301
  loading?: JSX.Element
306
302
  success?: (data: T) => JSX.Element
@@ -0,0 +1,169 @@
1
+ /* Vite can link this before the app entry CSS, so name every layer here or `components` ranks below Tailwind's base reset. */
2
+ @layer properties, theme, base, components, utilities;
3
+
4
+ @layer components {
5
+ [data-slot="checkbox-v2"] {
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 6px;
9
+ cursor: default;
10
+
11
+ &:where([data-disabled]) {
12
+ cursor: not-allowed;
13
+ }
14
+
15
+ &:where([data-readonly]) {
16
+ pointer-events: none;
17
+ }
18
+ }
19
+
20
+ [data-slot="checkbox-v2-error"] {
21
+ color: var(--v2-state-fg-danger);
22
+ font-size: 12px;
23
+ font-weight: 440;
24
+ line-height: var(--line-height-compact);
25
+ }
26
+
27
+ [data-slot="checkbox-v2-error"]:empty {
28
+ display: none;
29
+ }
30
+
31
+ [data-slot="checkbox-v2-row"] {
32
+ position: relative;
33
+ display: flex;
34
+ flex-direction: row;
35
+ align-items: flex-start;
36
+ gap: 8px;
37
+ }
38
+
39
+ [data-slot="checkbox-v2-input"] {
40
+ position: absolute;
41
+ width: 1px;
42
+ height: 1px;
43
+ padding: 0;
44
+ margin: -1px;
45
+ overflow: hidden;
46
+ clip: rect(0, 0, 0, 0);
47
+ white-space: nowrap;
48
+ border-width: 0;
49
+ }
50
+
51
+ /* 20px tall so the 16px control centres on the first 20px line of the label. */
52
+ [data-slot="checkbox-v2-control-stack"] {
53
+ position: relative;
54
+ width: 16px;
55
+ height: 20px;
56
+ flex: none;
57
+ }
58
+
59
+ [data-slot="checkbox-v2-control"] {
60
+ box-sizing: border-box;
61
+ position: absolute;
62
+ top: 2px;
63
+ left: 0;
64
+ width: 16px;
65
+ height: 16px;
66
+ border-radius: 4px;
67
+ color: var(--v2-icon-icon-contrast);
68
+ background: var(--v2-background-bg-base);
69
+ box-shadow: inset 0 0 0 0.5px var(--v2-border-border-strong);
70
+ transition:
71
+ background 85ms ease-out,
72
+ box-shadow 85ms ease-out;
73
+ }
74
+
75
+ [data-slot="checkbox-v2"][data-surface="layer-1"] [data-slot="checkbox-v2-control"] {
76
+ background: var(--v2-background-bg-layer-01);
77
+ }
78
+
79
+ [data-slot="checkbox-v2-indicator"] {
80
+ position: absolute;
81
+ inset: 0;
82
+ pointer-events: none;
83
+ }
84
+
85
+ [data-slot="checkbox-v2-text"] {
86
+ display: flex;
87
+ flex-direction: column;
88
+ justify-content: center;
89
+ align-items: flex-start;
90
+ gap: 6px;
91
+ min-width: 0;
92
+ }
93
+
94
+ [data-slot="checkbox-v2-label"] {
95
+ user-select: none;
96
+ color: var(--v2-text-text-base);
97
+ font-size: 13px;
98
+ font-weight: 440;
99
+ line-height: var(--line-height-base);
100
+ letter-spacing: -0.04px;
101
+ font-variation-settings: "slnt" 0;
102
+ }
103
+
104
+ [data-slot="checkbox-v2-description"] {
105
+ color: var(--v2-text-text-muted);
106
+ font-size: 11px;
107
+ font-weight: 440;
108
+ line-height: var(--line-height-tight);
109
+ letter-spacing: 0.05px;
110
+ user-select: none;
111
+ }
112
+
113
+ [data-slot="checkbox-v2"]:where(:not([data-readonly]))
114
+ [data-slot="checkbox-v2-input"]:focus-visible
115
+ ~ [data-slot="checkbox-v2-control-stack"]
116
+ [data-slot="checkbox-v2-control"] {
117
+ outline: 2px solid var(--v2-border-border-focus);
118
+ outline-offset: 2px;
119
+ }
120
+
121
+ @media (hover: hover) {
122
+ [data-slot="checkbox-v2"]:where(:hover):where(:not([data-disabled], [data-readonly], [data-invalid])):where(
123
+ :not([data-checked], [data-indeterminate])
124
+ )
125
+ [data-slot="checkbox-v2-control"] {
126
+ box-shadow:
127
+ inset 0 0 0 0.5px var(--v2-border-border-strong),
128
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover);
129
+ }
130
+
131
+ [data-slot="checkbox-v2"]:where([data-checked], [data-indeterminate]):where(:hover):where(
132
+ :not([data-disabled], [data-readonly])
133
+ )
134
+ [data-slot="checkbox-v2-control"] {
135
+ box-shadow:
136
+ inset 0 0 0 0.5px var(--v2-border-border-strong),
137
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-contrast-hover);
138
+ }
139
+ }
140
+
141
+ /* The depth gradient is Figma's white-to-clear fill at 20% opacity over the accent. */
142
+ [data-slot="checkbox-v2"]:where([data-checked], [data-indeterminate]) [data-slot="checkbox-v2-control"] {
143
+ background:
144
+ linear-gradient(180deg, var(--v2-alpha-light-20) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-accent);
145
+ }
146
+
147
+ [data-slot="checkbox-v2"]:where([data-invalid]):where(:not([data-checked], [data-indeterminate]))
148
+ [data-slot="checkbox-v2-control"] {
149
+ background: var(--v2-state-bg-danger);
150
+ box-shadow: inset 0 0 0 0.5px var(--v2-state-fg-danger);
151
+ }
152
+
153
+ [data-slot="checkbox-v2"] .checkbox-v2-icon {
154
+ position: absolute;
155
+ left: 50%;
156
+ top: 50%;
157
+ transform: translate(-50%, -50%);
158
+ display: none;
159
+ }
160
+
161
+ [data-slot="checkbox-v2"]:where([data-checked]):where(:not([data-indeterminate])) .checkbox-v2-icon--check,
162
+ [data-slot="checkbox-v2"]:where([data-indeterminate]) .checkbox-v2-icon--minus {
163
+ display: block;
164
+ }
165
+
166
+ [data-slot="checkbox-v2"]:where([data-disabled]) [data-slot="checkbox-v2-row"] {
167
+ opacity: 0.5;
168
+ }
169
+ }