@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.
- package/build/legacy/_tsup-dts-rollup.d.ts +144 -5
- package/build/legacy/{chunk-7BB66W4A.js → chunk-4EMJR2AY.js} +2 -2
- package/build/legacy/{chunk-OLQQB53X.js → chunk-BEYPMC73.js} +2 -2
- package/build/legacy/{chunk-3RZUW5KH.js → chunk-DB2OA5PU.js} +3 -3
- package/build/legacy/{chunk-GIHAFJYX.js → chunk-GVNPFXKL.js} +9 -2
- package/build/legacy/chunk-GVNPFXKL.js.map +1 -0
- package/build/legacy/{chunk-ANXV7JDK.js → chunk-IL5ELPTT.js} +2 -2
- package/build/legacy/chunk-NWMNEJGU.js +16 -0
- package/build/legacy/chunk-NWMNEJGU.js.map +1 -0
- package/build/legacy/chunk-SINTHADQ.js +22 -0
- package/build/legacy/chunk-SINTHADQ.js.map +1 -0
- package/build/legacy/chunk-SPGBCV6A.js +70 -0
- package/build/legacy/chunk-SPGBCV6A.js.map +1 -0
- package/build/legacy/chunk-TAJBSUS7.js +99 -0
- package/build/legacy/chunk-TAJBSUS7.js.map +1 -0
- package/build/legacy/{chunk-DCI4IKCI.js → chunk-X5JR5LSC.js} +2 -2
- package/build/legacy/{chunk-DED42MIR.js → chunk-XB4ZRAH4.js} +2 -2
- package/build/legacy/components/FileUploader.js +3 -3
- package/build/legacy/components/Input.js +3 -3
- package/build/legacy/components/Notification.js +12 -0
- package/build/legacy/components/Notification.js.map +1 -0
- package/build/legacy/components/NotificationDescription.js +7 -0
- package/build/legacy/components/NotificationDescription.js.map +1 -0
- package/build/legacy/components/NotificationHeading.js +7 -0
- package/build/legacy/components/NotificationHeading.js.map +1 -0
- package/build/legacy/components/Toggle.js +3 -3
- package/build/legacy/config/cerbIcons.js +1 -1
- package/build/legacy/config/defineIcons.js +2 -2
- package/build/legacy/context/confirm-modal.js +3 -3
- package/build/legacy/context/notification-center.js +19 -0
- package/build/legacy/context/notification-center.js.map +1 -0
- package/build/legacy/context/prompt-modal.js +4 -4
- package/build/legacy/index.js +37 -19
- package/build/legacy/index.js.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +144 -5
- package/build/modern/chunk-32E6OUMD.js +99 -0
- package/build/modern/chunk-32E6OUMD.js.map +1 -0
- package/build/modern/{chunk-2NSXMFKX.js → chunk-3YORUZIQ.js} +2 -2
- package/build/modern/{chunk-OLQQB53X.js → chunk-BEYPMC73.js} +2 -2
- package/build/modern/{chunk-DKHQ5GBY.js → chunk-BMQ7I2PL.js} +3 -3
- package/build/modern/{chunk-GIHAFJYX.js → chunk-GVNPFXKL.js} +9 -2
- package/build/modern/chunk-GVNPFXKL.js.map +1 -0
- package/build/modern/{chunk-ANXV7JDK.js → chunk-IL5ELPTT.js} +2 -2
- package/build/modern/chunk-NWMNEJGU.js +16 -0
- package/build/modern/chunk-NWMNEJGU.js.map +1 -0
- package/build/modern/chunk-OCBED5GL.js +70 -0
- package/build/modern/chunk-OCBED5GL.js.map +1 -0
- package/build/modern/chunk-SINTHADQ.js +22 -0
- package/build/modern/chunk-SINTHADQ.js.map +1 -0
- package/build/modern/{chunk-DED42MIR.js → chunk-XB4ZRAH4.js} +2 -2
- package/build/modern/{chunk-SHNZS357.js → chunk-ZPWSMCZ5.js} +2 -2
- package/build/modern/components/FileUploader.js +3 -3
- package/build/modern/components/Input.js +3 -3
- package/build/modern/components/Notification.js +12 -0
- package/build/modern/components/Notification.js.map +1 -0
- package/build/modern/components/NotificationDescription.js +7 -0
- package/build/modern/components/NotificationDescription.js.map +1 -0
- package/build/modern/components/NotificationHeading.js +7 -0
- package/build/modern/components/NotificationHeading.js.map +1 -0
- package/build/modern/components/Toggle.js +3 -3
- package/build/modern/config/cerbIcons.js +1 -1
- package/build/modern/config/defineIcons.js +2 -2
- package/build/modern/context/confirm-modal.js +3 -3
- package/build/modern/context/notification-center.js +19 -0
- package/build/modern/context/notification-center.js.map +1 -0
- package/build/modern/context/prompt-modal.js +4 -4
- package/build/modern/index.js +37 -19
- package/build/modern/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Notification.tsx +94 -0
- package/src/components/NotificationDescription.tsx +31 -0
- package/src/components/NotificationHeading.tsx +28 -0
- package/src/config/cerbIcons.ts +19 -6
- package/src/context/notification-center.tsx +159 -0
- package/src/index.ts +4 -0
- package/build/legacy/chunk-GIHAFJYX.js.map +0 -1
- package/build/modern/chunk-GIHAFJYX.js.map +0 -1
- /package/build/legacy/{chunk-7BB66W4A.js.map → chunk-4EMJR2AY.js.map} +0 -0
- /package/build/legacy/{chunk-OLQQB53X.js.map → chunk-BEYPMC73.js.map} +0 -0
- /package/build/legacy/{chunk-3RZUW5KH.js.map → chunk-DB2OA5PU.js.map} +0 -0
- /package/build/legacy/{chunk-ANXV7JDK.js.map → chunk-IL5ELPTT.js.map} +0 -0
- /package/build/legacy/{chunk-DCI4IKCI.js.map → chunk-X5JR5LSC.js.map} +0 -0
- /package/build/legacy/{chunk-DED42MIR.js.map → chunk-XB4ZRAH4.js.map} +0 -0
- /package/build/modern/{chunk-2NSXMFKX.js.map → chunk-3YORUZIQ.js.map} +0 -0
- /package/build/modern/{chunk-OLQQB53X.js.map → chunk-BEYPMC73.js.map} +0 -0
- /package/build/modern/{chunk-DKHQ5GBY.js.map → chunk-BMQ7I2PL.js.map} +0 -0
- /package/build/modern/{chunk-ANXV7JDK.js.map → chunk-IL5ELPTT.js.map} +0 -0
- /package/build/modern/{chunk-DED42MIR.js.map → chunk-XB4ZRAH4.js.map} +0 -0
- /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":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|