@cerberus-design/react 0.7.4-next-92f76bb → 0.7.4-next-9a605c3

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 (89) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.ts +144 -5
  2. package/build/legacy/{chunk-7BB66W4A.js → chunk-4EMJR2AY.js} +2 -2
  3. package/build/legacy/{chunk-OLQQB53X.js → chunk-BEYPMC73.js} +2 -2
  4. package/build/legacy/{chunk-3RZUW5KH.js → chunk-DB2OA5PU.js} +3 -3
  5. package/build/legacy/{chunk-GIHAFJYX.js → chunk-GVNPFXKL.js} +9 -2
  6. package/build/legacy/chunk-GVNPFXKL.js.map +1 -0
  7. package/build/legacy/{chunk-ANXV7JDK.js → chunk-IL5ELPTT.js} +2 -2
  8. package/build/legacy/chunk-NWMNEJGU.js +16 -0
  9. package/build/legacy/chunk-NWMNEJGU.js.map +1 -0
  10. package/build/legacy/chunk-SINTHADQ.js +22 -0
  11. package/build/legacy/chunk-SINTHADQ.js.map +1 -0
  12. package/build/legacy/chunk-SPGBCV6A.js +70 -0
  13. package/build/legacy/chunk-SPGBCV6A.js.map +1 -0
  14. package/build/legacy/chunk-TAJBSUS7.js +99 -0
  15. package/build/legacy/chunk-TAJBSUS7.js.map +1 -0
  16. package/build/legacy/{chunk-DCI4IKCI.js → chunk-X5JR5LSC.js} +2 -2
  17. package/build/legacy/{chunk-DED42MIR.js → chunk-XB4ZRAH4.js} +2 -2
  18. package/build/legacy/components/FileUploader.js +3 -3
  19. package/build/legacy/components/Input.js +3 -3
  20. package/build/legacy/components/Notification.js +12 -0
  21. package/build/legacy/components/Notification.js.map +1 -0
  22. package/build/legacy/components/NotificationDescription.js +7 -0
  23. package/build/legacy/components/NotificationDescription.js.map +1 -0
  24. package/build/legacy/components/NotificationHeading.js +7 -0
  25. package/build/legacy/components/NotificationHeading.js.map +1 -0
  26. package/build/legacy/components/Toggle.js +3 -3
  27. package/build/legacy/config/cerbIcons.js +1 -1
  28. package/build/legacy/config/defineIcons.js +2 -2
  29. package/build/legacy/context/confirm-modal.js +3 -3
  30. package/build/legacy/context/notification-center.js +19 -0
  31. package/build/legacy/context/notification-center.js.map +1 -0
  32. package/build/legacy/context/prompt-modal.js +4 -4
  33. package/build/legacy/index.js +37 -19
  34. package/build/legacy/index.js.map +1 -1
  35. package/build/modern/_tsup-dts-rollup.d.ts +144 -5
  36. package/build/modern/chunk-32E6OUMD.js +99 -0
  37. package/build/modern/chunk-32E6OUMD.js.map +1 -0
  38. package/build/modern/{chunk-2NSXMFKX.js → chunk-3YORUZIQ.js} +2 -2
  39. package/build/modern/{chunk-OLQQB53X.js → chunk-BEYPMC73.js} +2 -2
  40. package/build/modern/{chunk-DKHQ5GBY.js → chunk-BMQ7I2PL.js} +3 -3
  41. package/build/modern/{chunk-GIHAFJYX.js → chunk-GVNPFXKL.js} +9 -2
  42. package/build/modern/chunk-GVNPFXKL.js.map +1 -0
  43. package/build/modern/{chunk-ANXV7JDK.js → chunk-IL5ELPTT.js} +2 -2
  44. package/build/modern/chunk-NWMNEJGU.js +16 -0
  45. package/build/modern/chunk-NWMNEJGU.js.map +1 -0
  46. package/build/modern/chunk-OCBED5GL.js +70 -0
  47. package/build/modern/chunk-OCBED5GL.js.map +1 -0
  48. package/build/modern/chunk-SINTHADQ.js +22 -0
  49. package/build/modern/chunk-SINTHADQ.js.map +1 -0
  50. package/build/modern/{chunk-DED42MIR.js → chunk-XB4ZRAH4.js} +2 -2
  51. package/build/modern/{chunk-SHNZS357.js → chunk-ZPWSMCZ5.js} +2 -2
  52. package/build/modern/components/FileUploader.js +3 -3
  53. package/build/modern/components/Input.js +3 -3
  54. package/build/modern/components/Notification.js +12 -0
  55. package/build/modern/components/Notification.js.map +1 -0
  56. package/build/modern/components/NotificationDescription.js +7 -0
  57. package/build/modern/components/NotificationDescription.js.map +1 -0
  58. package/build/modern/components/NotificationHeading.js +7 -0
  59. package/build/modern/components/NotificationHeading.js.map +1 -0
  60. package/build/modern/components/Toggle.js +3 -3
  61. package/build/modern/config/cerbIcons.js +1 -1
  62. package/build/modern/config/defineIcons.js +2 -2
  63. package/build/modern/context/confirm-modal.js +3 -3
  64. package/build/modern/context/notification-center.js +19 -0
  65. package/build/modern/context/notification-center.js.map +1 -0
  66. package/build/modern/context/prompt-modal.js +4 -4
  67. package/build/modern/index.js +37 -19
  68. package/build/modern/index.js.map +1 -1
  69. package/package.json +3 -3
  70. package/src/components/Notification.tsx +94 -0
  71. package/src/components/NotificationDescription.tsx +31 -0
  72. package/src/components/NotificationHeading.tsx +28 -0
  73. package/src/config/cerbIcons.ts +19 -6
  74. package/src/context/notification-center.tsx +159 -0
  75. package/src/index.ts +4 -0
  76. package/build/legacy/chunk-GIHAFJYX.js.map +0 -1
  77. package/build/modern/chunk-GIHAFJYX.js.map +0 -1
  78. /package/build/legacy/{chunk-7BB66W4A.js.map → chunk-4EMJR2AY.js.map} +0 -0
  79. /package/build/legacy/{chunk-OLQQB53X.js.map → chunk-BEYPMC73.js.map} +0 -0
  80. /package/build/legacy/{chunk-3RZUW5KH.js.map → chunk-DB2OA5PU.js.map} +0 -0
  81. /package/build/legacy/{chunk-ANXV7JDK.js.map → chunk-IL5ELPTT.js.map} +0 -0
  82. /package/build/legacy/{chunk-DCI4IKCI.js.map → chunk-X5JR5LSC.js.map} +0 -0
  83. /package/build/legacy/{chunk-DED42MIR.js.map → chunk-XB4ZRAH4.js.map} +0 -0
  84. /package/build/modern/{chunk-2NSXMFKX.js.map → chunk-3YORUZIQ.js.map} +0 -0
  85. /package/build/modern/{chunk-OLQQB53X.js.map → chunk-BEYPMC73.js.map} +0 -0
  86. /package/build/modern/{chunk-DKHQ5GBY.js.map → chunk-BMQ7I2PL.js.map} +0 -0
  87. /package/build/modern/{chunk-ANXV7JDK.js.map → chunk-IL5ELPTT.js.map} +0 -0
  88. /package/build/modern/{chunk-DED42MIR.js.map → chunk-XB4ZRAH4.js.map} +0 -0
  89. /package/build/modern/{chunk-SHNZS357.js.map → chunk-ZPWSMCZ5.js.map} +0 -0
@@ -0,0 +1,159 @@
1
+ 'use client'
2
+
3
+ import {
4
+ createContext,
5
+ useCallback,
6
+ useContext,
7
+ useMemo,
8
+ useState,
9
+ type MouseEvent,
10
+ type PropsWithChildren,
11
+ type ReactNode,
12
+ } from 'react'
13
+ import { Show } from '../components/Show'
14
+ import { NotificationHeading } from '../components/NotificationHeading'
15
+ import { NotificationDescription } from '../components/NotificationDescription'
16
+ import { Notification } from '../components/Notification'
17
+ import { vstack } from '@cerberus-design/styled-system/patterns'
18
+ import { Portal, type PortalProps } from '../components/Portal'
19
+ import { cx } from '@cerberus-design/styled-system/css'
20
+ import { notification } from '@cerberus-design/styled-system/recipes'
21
+
22
+ /**
23
+ * This module provides a context and hook for notifications.
24
+ * @module
25
+ */
26
+
27
+ export interface NotifyOptions {
28
+ palette: 'info' | 'success' | 'warning' | 'danger'
29
+ heading: string
30
+ id?: string
31
+ description?: ReactNode
32
+ onClose?: () => void
33
+ }
34
+
35
+ export interface NotificationsValue {
36
+ notify: (options: NotifyOptions) => void
37
+ }
38
+
39
+ const NotificationsContext = createContext<NotificationsValue | null>(null)
40
+
41
+ export interface NotificationsProviderProps extends PortalProps {}
42
+
43
+ /**
44
+ * Provides a notification center to the app.
45
+ * @example
46
+ * ```tsx
47
+ * // Wrap the Provider around the root of the feature.
48
+ * <Notifications>
49
+ * <SomeFeatureSection />
50
+ * </Notifications>
51
+ *
52
+ * // Use the hook to show a notification.
53
+ * const notify = useNotifications()
54
+ *
55
+ * const handleClick = useCallback(() => {
56
+ * notify({
57
+ * palette: 'info',
58
+ * heading: 'New feature!',
59
+ * description: 'We have added a new feature to the app.',
60
+ * })
61
+ * }, [notify])
62
+ * ```
63
+ */
64
+ export function NotificationCenter(
65
+ props: PropsWithChildren<NotificationsProviderProps>,
66
+ ) {
67
+ const [activeNotifications, setActiveNotifications] = useState<
68
+ NotifyOptions[]
69
+ >([])
70
+
71
+ const handleNotify = useCallback((options: NotifyOptions) => {
72
+ setActiveNotifications((prev) => {
73
+ const id = `${options.palette}:${prev.length + 1}`
74
+ return [...prev, { ...options, id }]
75
+ })
76
+ }, [])
77
+
78
+ const handleClose = useCallback((e: MouseEvent<HTMLButtonElement>) => {
79
+ const target = e.currentTarget as HTMLButtonElement
80
+ setActiveNotifications((prev) => {
81
+ const item = prev.find((option) => option.id === target.value)
82
+ if (item?.onClose) item.onClose()
83
+ return prev.filter((option) => option.id !== target.value)
84
+ })
85
+ }, [])
86
+
87
+ const value = useMemo(
88
+ () => ({
89
+ notify: handleNotify,
90
+ }),
91
+ [handleNotify],
92
+ )
93
+
94
+ // For some reason, the vstack pattern alignItems is not registering here.
95
+ // So we are forcing it with the style prop.
96
+
97
+ return (
98
+ <NotificationsContext.Provider value={value}>
99
+ {props.children}
100
+
101
+ <Show when={activeNotifications.length > 0}>
102
+ <Portal container={props.container}>
103
+ <div
104
+ className={cx(
105
+ notification().center,
106
+ vstack({
107
+ alignItems: 'flex-end',
108
+ gap: '4',
109
+ }),
110
+ )}
111
+ style={{
112
+ alignItems: 'flex-end',
113
+ }}
114
+ >
115
+ {activeNotifications.map((option) => (
116
+ <Notification
117
+ id={option.id!}
118
+ key={option.id}
119
+ onClose={handleClose}
120
+ open
121
+ palette={option.palette}
122
+ >
123
+ <NotificationHeading palette={option.palette}>
124
+ {option.heading}
125
+ </NotificationHeading>
126
+ <NotificationDescription palette={option.palette}>
127
+ {option.description}
128
+ </NotificationDescription>
129
+ </Notification>
130
+ ))}
131
+ </div>
132
+ </Portal>
133
+ </Show>
134
+ </NotificationsContext.Provider>
135
+ )
136
+ }
137
+
138
+ /**
139
+ * The hook to use the NotificationCenter.
140
+ * @returns The notify method to trigger a notification.
141
+ * @example
142
+ * ```tsx
143
+ * const {notify} = useNotificationCenter()
144
+ * notify({
145
+ * palette: 'info',
146
+ * heading: 'New feature',
147
+ * description: 'We have added a new feature to the app.',
148
+ * })
149
+ * ```
150
+ */
151
+ export function useNotificationCenter(): NotificationsValue {
152
+ const context = useContext(NotificationsContext)
153
+ if (!context) {
154
+ throw new Error(
155
+ 'useNotificationCenter must be used within a NotificationsProvider',
156
+ )
157
+ }
158
+ return context
159
+ }
package/src/index.ts CHANGED
@@ -21,6 +21,9 @@ export * from './components/ModalIcon'
21
21
  export * from './components/NavMenuTrigger'
22
22
  export * from './components/NavMenuList'
23
23
  export * from './components/NavMenuLink'
24
+ export * from './components/Notification'
25
+ export * from './components/NotificationHeading'
26
+ export * from './components/NotificationDescription'
24
27
  export * from './components/Portal'
25
28
  export * from './components/Radio'
26
29
  export * from './components/Tab'
@@ -37,6 +40,7 @@ export * from './context/confirm-modal'
37
40
  export * from './context/feature-flags'
38
41
  export * from './context/field'
39
42
  export * from './context/navMenu'
43
+ export * from './context/notification-center'
40
44
  export * from './context/prompt-modal'
41
45
  export * from './context/tabs'
42
46
  export * from './context/theme'
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import {\n Checkmark,\n CloudUpload,\n Information,\n WarningFilled,\n type CarbonIconType,\n} from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n confirmModal?: CarbonIconType | ElementType\n fileUploader?: CarbonIconType | ElementType\n promptModal?: CarbonIconType | ElementType\n invalid: CarbonIconType | ElementType\n toggleChecked?: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n confirmModal: Information,\n fileUploader: CloudUpload,\n promptModal: Information,\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAWA,IAAM,eAA6B;AAAA,EACxC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import {\n Checkmark,\n CloudUpload,\n Information,\n WarningFilled,\n type CarbonIconType,\n} from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n confirmModal?: CarbonIconType | ElementType\n fileUploader?: CarbonIconType | ElementType\n promptModal?: CarbonIconType | ElementType\n invalid: CarbonIconType | ElementType\n toggleChecked?: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n confirmModal: Information,\n fileUploader: CloudUpload,\n promptModal: Information,\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAWA,IAAM,eAA6B;AAAA,EACxC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,aAAa;AAAA,EACb,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}