@cognitap/radiant 0.0.18 → 0.0.20

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 (39) hide show
  1. package/CHANGELOG.md +9 -3
  2. package/dist/library/Progress.d.ts +12 -0
  3. package/dist/library/Progress.d.ts.map +1 -0
  4. package/dist/library/Progress.js +21 -0
  5. package/dist/library/Progress.js.map +1 -0
  6. package/dist/library/Toast.d.ts +49 -0
  7. package/dist/library/Toast.d.ts.map +1 -0
  8. package/dist/library/Toast.js +216 -0
  9. package/dist/library/Toast.js.map +1 -0
  10. package/dist/library/cn.d.ts.map +1 -1
  11. package/dist/library/cn.js +17 -0
  12. package/dist/library/cn.js.map +1 -1
  13. package/dist/library/index.d.ts +4 -0
  14. package/dist/library/index.d.ts.map +1 -1
  15. package/dist/library/index.js +2 -0
  16. package/dist/library/index.js.map +1 -1
  17. package/dist/library/internal/toast.d.ts +12 -0
  18. package/dist/library/internal/toast.d.ts.map +1 -0
  19. package/dist/library/internal/toast.js +37 -0
  20. package/dist/library/internal/toast.js.map +1 -0
  21. package/dist/library/react/useToastTimer.d.ts +3 -0
  22. package/dist/library/react/useToastTimer.d.ts.map +1 -0
  23. package/dist/library/react/useToastTimer.js +58 -0
  24. package/dist/library/react/useToastTimer.js.map +1 -0
  25. package/dist/library/styles.css +1 -1
  26. package/dist/library/themes/components.d.ts +26 -0
  27. package/dist/library/themes/components.d.ts.map +1 -1
  28. package/dist/library/themes/components.js +26 -0
  29. package/dist/library/themes/components.js.map +1 -1
  30. package/docs/architecture.md +3 -3
  31. package/docs/theming.md +1 -1
  32. package/package.json +1 -1
  33. package/src/Progress.tsx +64 -0
  34. package/src/Toast.tsx +381 -0
  35. package/src/cn.ts +17 -0
  36. package/src/index.ts +26 -0
  37. package/src/internal/toast.ts +43 -0
  38. package/src/react/useToastTimer.ts +64 -0
  39. package/src/themes/components.ts +26 -0
package/src/cn.ts CHANGED
@@ -9,6 +9,9 @@ const roleClasses = (prefix: string, leaf: string) =>
9
9
  export const cn: CnFunction = createCn({
10
10
  extend: {
11
11
  classGroups: {
12
+ right: ['right-(--rad-toast-inset)'],
13
+ bottom: ['bottom-(--rad-toast-inset)'],
14
+ z: ['z-(--rad-toast-z-index)'],
12
15
  'font-family': [
13
16
  ...roleClasses('font', 'family'),
14
17
  'font-(--rad-combobox-font-family)',
@@ -17,6 +20,7 @@ export const cn: CnFunction = createCn({
17
20
  'font-(--rad-tabs-font-family)'
18
21
  ],
19
22
  'font-weight': [
23
+ 'font-(--rad-toast-title-weight)',
20
24
  'font-(--rad-alert-title-weight)',
21
25
  'font-(--rad-tooltip-font-weight)',
22
26
  ...roleClasses('font', 'weight'),
@@ -26,6 +30,8 @@ export const cn: CnFunction = createCn({
26
30
  'font-(--rad-tabs-font-weight)'
27
31
  ],
28
32
  'font-size': [
33
+ 'text-(--rad-toast-title-size)',
34
+ 'text-(--rad-toast-description-size)',
29
35
  'text-(--rad-alert-title-size)',
30
36
  'text-(--rad-alert-description-size)',
31
37
  'text-(--rad-tooltip-font-size)',
@@ -38,6 +44,7 @@ export const cn: CnFunction = createCn({
38
44
  'text-(--rad-tabs-font-size)'
39
45
  ],
40
46
  h: [
47
+ 'h-(--rad-progress-height)',
41
48
  'h-(--rad-combobox-height)',
42
49
  'h-(--rad-select-height)',
43
50
  'h-(--rad-switch-height)',
@@ -45,6 +52,7 @@ export const cn: CnFunction = createCn({
45
52
  'h-(--rad-slider-length)'
46
53
  ],
47
54
  w: [
55
+ 'w-(--rad-toast-width)',
48
56
  'w-(--rad-menu-width)',
49
57
  'w-(--rad-popover-width)',
50
58
  'w-(--rad-switch-width)',
@@ -54,6 +62,7 @@ export const cn: CnFunction = createCn({
54
62
  'max-w': ['max-w-(--rad-tooltip-max-width)'],
55
63
  size: ['size-(--rad-slider-thumb-size)', 'size-(--rad-slider-track-size)'],
56
64
  gap: [
65
+ 'gap-(--rad-toast-gap)',
57
66
  'gap-(--rad-alert-gap)',
58
67
  'gap-(--rad-popover-gap)',
59
68
  'gap-(--rad-switch-gap)',
@@ -69,6 +78,7 @@ export const cn: CnFunction = createCn({
69
78
  'px-(--rad-tabs-trigger-padding)'
70
79
  ],
71
80
  p: [
81
+ 'p-(--rad-toast-padding)',
72
82
  'p-(--rad-alert-padding)',
73
83
  'p-(--rad-menu-padding)',
74
84
  'p-(--rad-menu-item-padding)',
@@ -80,6 +90,8 @@ export const cn: CnFunction = createCn({
80
90
  'p-(--rad-tabs-content-padding)'
81
91
  ],
82
92
  rounded: [
93
+ 'rounded-(--rad-progress-radius)',
94
+ 'rounded-(--rad-toast-radius)',
83
95
  'rounded-(--rad-alert-radius)',
84
96
  'rounded-(--rad-menu-radius)',
85
97
  'rounded-(--rad-menu-item-radius)',
@@ -101,6 +113,8 @@ export const cn: CnFunction = createCn({
101
113
  'rounded-(--rad-tabs-content-radius)'
102
114
  ],
103
115
  'border-w': [
116
+ 'border-(--rad-progress-border-width)',
117
+ 'border-(--rad-toast-border-width)',
104
118
  'border-(--rad-alert-border-width)',
105
119
  'border-(--rad-menu-border-width)',
106
120
  'border-(--rad-tooltip-border-width)',
@@ -113,6 +127,8 @@ export const cn: CnFunction = createCn({
113
127
  'border-(--rad-tabs-trigger-border-width)'
114
128
  ],
115
129
  'border-style': [
130
+ 'border-(--rad-progress-border-style)',
131
+ 'border-(--rad-toast-border-style)',
116
132
  'border-(--rad-alert-border-style)',
117
133
  'border-(--rad-menu-border-style)',
118
134
  'border-(--rad-tooltip-border-style)',
@@ -123,6 +139,7 @@ export const cn: CnFunction = createCn({
123
139
  'border-(--rad-switch-border-style)'
124
140
  ],
125
141
  shadow: [
142
+ 'shadow-(--rad-toast-shadow)',
126
143
  'shadow-(--rad-alert-shadow)',
127
144
  'shadow-(--rad-menu-shadow)',
128
145
  'shadow-(--rad-tooltip-shadow)',
package/src/index.ts CHANGED
@@ -262,3 +262,29 @@ export type {
262
262
  AlertTone,
263
263
  AlertHeadingLevel
264
264
  } from './Alert.js'
265
+
266
+ export {
267
+ ToastProvider,
268
+ ToastViewport,
269
+ Toast,
270
+ ToastTitle,
271
+ ToastDescription,
272
+ ToastAction,
273
+ ToastClose,
274
+ useToast
275
+ } from './Toast.js'
276
+ export type {
277
+ ToastProviderProps,
278
+ ToastViewportProps,
279
+ ToastProps,
280
+ ToastState,
281
+ ToastAnnouncement,
282
+ ToastTitleProps,
283
+ ToastDescriptionProps,
284
+ ToastActionProps,
285
+ ToastCloseProps,
286
+ ToastRenderProps
287
+ } from './Toast.js'
288
+
289
+ export { Progress } from './Progress.js'
290
+ export type { ProgressProps } from './Progress.js'
@@ -0,0 +1,43 @@
1
+ export function validateToastDuration(value: number) {
2
+ if (!Number.isFinite(value) || value < 0 || value > 2_147_483_647)
3
+ throw new TypeError('Toast duration must be between 0 and 2147483647 milliseconds.')
4
+ }
5
+
6
+ /** A paused interval retains its remaining time; an elapsed interval fires once. */
7
+ export function createToastTimer(
8
+ duration: number,
9
+ clock: {
10
+ now(): number
11
+ set(callback: () => void, delay: number): number
12
+ clear(id: number): void
13
+ },
14
+ elapsed: () => void
15
+ ) {
16
+ validateToastDuration(duration)
17
+ let remaining = duration
18
+ let deadline = 0
19
+ let timer: number | undefined
20
+ let ended = false
21
+ const pause = () => {
22
+ if (timer === undefined) return
23
+ clock.clear(timer)
24
+ timer = undefined
25
+ remaining = Math.max(0, deadline - clock.now())
26
+ }
27
+ return {
28
+ pause,
29
+ resume() {
30
+ if (!duration || ended || timer !== undefined) return
31
+ deadline = clock.now() + remaining
32
+ timer = clock.set(() => {
33
+ timer = undefined
34
+ ended = true
35
+ elapsed()
36
+ }, remaining)
37
+ },
38
+ destroy() {
39
+ pause()
40
+ ended = true
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,64 @@
1
+ 'use client'
2
+ import { useLayoutEffect, useRef, type RefObject } from 'react'
3
+ import { createToastTimer } from '../internal/toast.js'
4
+
5
+ export function useToastTimer(
6
+ ref: RefObject<HTMLElement | null>,
7
+ visible: boolean,
8
+ duration: number,
9
+ elapsed: () => void
10
+ ) {
11
+ const latest = useRef(elapsed)
12
+ useLayoutEffect(() => {
13
+ latest.current = elapsed
14
+ })
15
+ useLayoutEffect(() => {
16
+ const node = ref.current
17
+ if (!node || !visible || !duration) return
18
+ const doc = node.ownerDocument
19
+ const win = doc.defaultView!
20
+ const timer = createToastTimer(
21
+ duration,
22
+ {
23
+ now: () => win.performance.now(),
24
+ set: (fn, delay) => win.setTimeout(fn, delay),
25
+ clear: id => win.clearTimeout(id)
26
+ },
27
+ () => latest.current()
28
+ )
29
+ let hovering = node.matches(':hover')
30
+ const sync = () => {
31
+ const paused = hovering || node.contains(doc.activeElement) || doc.hidden
32
+ node.dataset.paused = String(paused)
33
+ if (paused) timer.pause()
34
+ else timer.resume()
35
+ }
36
+ const enter = (event: PointerEvent) => {
37
+ if (event.pointerType !== 'touch') {
38
+ hovering = true
39
+ sync()
40
+ }
41
+ }
42
+ const leave = (event: PointerEvent) => {
43
+ if (event.pointerType !== 'touch') {
44
+ hovering = false
45
+ sync()
46
+ }
47
+ }
48
+ node.addEventListener('pointerenter', enter)
49
+ node.addEventListener('pointerleave', leave)
50
+ node.addEventListener('focusin', sync)
51
+ node.addEventListener('focusout', sync)
52
+ doc.addEventListener('visibilitychange', sync)
53
+ sync()
54
+ return () => {
55
+ timer.destroy()
56
+ node.removeEventListener('pointerenter', enter)
57
+ node.removeEventListener('pointerleave', leave)
58
+ node.removeEventListener('focusin', sync)
59
+ node.removeEventListener('focusout', sync)
60
+ doc.removeEventListener('visibilitychange', sync)
61
+ delete node.dataset.paused
62
+ }
63
+ }, [ref, visible, duration])
64
+ }
@@ -410,6 +410,32 @@ export const componentRegistry = {
410
410
  titleWeight: 'weight',
411
411
  descriptionSize: 'css'
412
412
  },
413
+ toast: {
414
+ radius: 'css',
415
+ padding: 'css',
416
+ gap: 'css',
417
+ background: 'css',
418
+ color: 'css',
419
+ borderColor: 'css',
420
+ borderWidth: 'css',
421
+ borderStyle: 'css',
422
+ shadow: 'css',
423
+ titleSize: 'css',
424
+ titleWeight: 'weight',
425
+ descriptionSize: 'css',
426
+ width: 'css',
427
+ inset: 'css',
428
+ zIndex: 'number'
429
+ },
430
+ progress: {
431
+ height: 'css',
432
+ radius: 'css',
433
+ trackColor: 'css',
434
+ indicatorColor: 'css',
435
+ borderColor: 'css',
436
+ borderWidth: 'css',
437
+ borderStyle: 'css'
438
+ },
413
439
  radioGroup: { gap: 'css' }
414
440
  } as const
415
441