@cerberus-design/react 0.14.2-next-58af9c8 → 0.14.2-next-9116729

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 (75) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.cts +186 -45
  2. package/build/legacy/components/DatePicker.client.cjs +12 -6
  3. package/build/legacy/components/DatePicker.client.cjs.map +1 -1
  4. package/build/legacy/components/Dialog.cjs +86 -0
  5. package/build/legacy/components/Dialog.cjs.map +1 -0
  6. package/build/legacy/components/Dialog.client.cjs +95 -0
  7. package/build/legacy/components/Dialog.client.cjs.map +1 -0
  8. package/build/legacy/components/Modal.cjs.map +1 -1
  9. package/build/legacy/components/ModalDescription.cjs.map +1 -1
  10. package/build/legacy/components/ModalHeader.cjs.map +1 -1
  11. package/build/legacy/components/ModalHeading.cjs.map +1 -1
  12. package/build/legacy/context/confirm-modal.cjs.map +1 -1
  13. package/build/legacy/context/cta-modal.cjs.map +1 -1
  14. package/build/legacy/context/notification-center.cjs +2 -2
  15. package/build/legacy/context/notification-center.cjs.map +1 -1
  16. package/build/legacy/context/prompt-modal.cjs.map +1 -1
  17. package/build/legacy/index.cjs +608 -517
  18. package/build/legacy/index.cjs.map +1 -1
  19. package/build/modern/_tsup-dts-rollup.d.ts +186 -45
  20. package/build/modern/chunk-6BN3XKQF.js +42 -0
  21. package/build/modern/chunk-6BN3XKQF.js.map +1 -0
  22. package/build/modern/{chunk-2UXE5PDG.js → chunk-7NN3SJ7W.js} +1 -1
  23. package/build/modern/chunk-7NN3SJ7W.js.map +1 -0
  24. package/build/modern/{chunk-YLMGZAKU.js → chunk-JAROS4Q3.js} +6 -6
  25. package/build/modern/chunk-JAROS4Q3.js.map +1 -0
  26. package/build/modern/{chunk-BE4EOU2P.js → chunk-JIRW4XOJ.js} +1 -1
  27. package/build/modern/chunk-JIRW4XOJ.js.map +1 -0
  28. package/build/modern/{chunk-YJI4Y7BH.js → chunk-MUTAYS3P.js} +5 -5
  29. package/build/modern/{chunk-XY6WL55R.js → chunk-NUMM4TNC.js} +1 -1
  30. package/build/modern/chunk-NUMM4TNC.js.map +1 -0
  31. package/build/modern/{chunk-USYM6XU6.js → chunk-O6LFWUHI.js} +4 -4
  32. package/build/modern/{chunk-XDDLXEFV.js → chunk-R4RFWDBM.js} +8 -8
  33. package/build/modern/chunk-TFL56AYR.js +56 -0
  34. package/build/modern/chunk-TFL56AYR.js.map +1 -0
  35. package/build/modern/{chunk-ZHBHPMTP.js → chunk-VGEK2DQB.js} +8 -8
  36. package/build/modern/{chunk-D252JE4V.js → chunk-YKKNWILF.js} +20 -14
  37. package/build/modern/chunk-YKKNWILF.js.map +1 -0
  38. package/build/modern/{chunk-Q7BRMIBR.js → chunk-ZL6ZITLA.js} +1 -1
  39. package/build/modern/chunk-ZL6ZITLA.js.map +1 -0
  40. package/build/modern/components/DatePicker.client.js +4 -4
  41. package/build/modern/components/Dialog.client.js +10 -0
  42. package/build/modern/components/Dialog.client.js.map +1 -0
  43. package/build/modern/components/Dialog.js +24 -0
  44. package/build/modern/components/Dialog.js.map +1 -0
  45. package/build/modern/components/FileStatus.js +2 -2
  46. package/build/modern/components/Modal.js +1 -1
  47. package/build/modern/components/ModalDescription.js +1 -1
  48. package/build/modern/components/ModalHeader.js +1 -1
  49. package/build/modern/components/ModalHeading.js +1 -1
  50. package/build/modern/context/confirm-modal.js +5 -5
  51. package/build/modern/context/cta-modal.js +6 -6
  52. package/build/modern/context/notification-center.js +2 -2
  53. package/build/modern/context/prompt-modal.js +6 -6
  54. package/build/modern/index.js +78 -54
  55. package/build/modern/index.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/components/DatePicker.client.tsx +32 -8
  58. package/src/components/Dialog.client.tsx +39 -0
  59. package/src/components/Dialog.tsx +165 -0
  60. package/src/components/Modal.tsx +1 -16
  61. package/src/components/ModalDescription.tsx +1 -8
  62. package/src/components/ModalHeader.tsx +1 -10
  63. package/src/components/ModalHeading.tsx +1 -8
  64. package/src/context/notification-center.tsx +2 -2
  65. package/src/index.ts +2 -0
  66. package/build/modern/chunk-2UXE5PDG.js.map +0 -1
  67. package/build/modern/chunk-BE4EOU2P.js.map +0 -1
  68. package/build/modern/chunk-D252JE4V.js.map +0 -1
  69. package/build/modern/chunk-Q7BRMIBR.js.map +0 -1
  70. package/build/modern/chunk-XY6WL55R.js.map +0 -1
  71. package/build/modern/chunk-YLMGZAKU.js.map +0 -1
  72. /package/build/modern/{chunk-YJI4Y7BH.js.map → chunk-MUTAYS3P.js.map} +0 -0
  73. /package/build/modern/{chunk-USYM6XU6.js.map → chunk-O6LFWUHI.js.map} +0 -0
  74. /package/build/modern/{chunk-XDDLXEFV.js.map → chunk-R4RFWDBM.js.map} +0 -0
  75. /package/build/modern/{chunk-ZHBHPMTP.js.map → chunk-VGEK2DQB.js.map} +0 -0
@@ -25,6 +25,7 @@ import {
25
25
  import { IconButton } from './IconButton'
26
26
  import { Button } from './Button'
27
27
  import { useCerberusContext } from '../context/cerberus'
28
+ import { useMemo, type InputHTMLAttributes } from 'react'
28
29
 
29
30
  /**
30
31
  * This module contains the DatePicker client family components.
@@ -172,6 +173,18 @@ export function DatePickerInput(props: DatePickerInputProps) {
172
173
  )
173
174
  }
174
175
 
176
+ export interface RangePickerInputProps
177
+ extends Omit<DatePickerInputProps, 'defaultValue'> {
178
+ /**
179
+ * The defaultValue to add for the inputs. The first item is the start date
180
+ * and the second item is the end date.
181
+ */
182
+ defaultValue?: [
183
+ InputHTMLAttributes<HTMLInputElement>['defaultValue'],
184
+ InputHTMLAttributes<HTMLInputElement>['defaultValue'],
185
+ ]
186
+ }
187
+
175
188
  /**
176
189
  * The input component for the DatePicker that uses ranges.
177
190
  * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)
@@ -186,26 +199,33 @@ export function DatePickerInput(props: DatePickerInputProps) {
186
199
  * </Field>
187
200
  * ```
188
201
  */
189
- export function RangePickerInput(props: DatePickerInputProps) {
202
+ export function RangePickerInput(props: RangePickerInputProps) {
190
203
  const { invalid, ...fieldStates } = useFieldContext()
204
+ const { defaultValue, ...nativeProps } = props
205
+
206
+ const startDate = useMemo(() => defaultValue?.[0], [defaultValue])
207
+ const endDate = useMemo(() => defaultValue?.[1], [defaultValue])
208
+
191
209
  return (
192
210
  <ArkDP.Control data-range className={datePickerStyles.control}>
193
211
  <DatePickerTrigger />
194
212
  <ArkDP.Input
195
- {...props}
213
+ {...nativeProps}
196
214
  {...fieldStates}
197
215
  {...(invalid && { 'aria-invalid': true })}
198
216
  data-range-input
217
+ defaultValue={startDate}
199
218
  className={cx(props.className, datePickerStyles.input)}
200
219
  placeholder={props.placeholder ?? 'DD MMM YYYY'}
201
220
  maxLength={11}
202
221
  index={0}
203
222
  />
204
223
  <ArkDP.Input
205
- {...props}
224
+ {...nativeProps}
206
225
  {...fieldStates}
207
226
  {...(invalid && { 'aria-invalid': true })}
208
227
  data-range-input
228
+ defaultValue={endDate}
209
229
  data-range-end-input
210
230
  className={cx(props.className, datePickerStyles.input)}
211
231
  placeholder={props.placeholder ?? 'DD MMM YYYY'}
@@ -230,10 +250,14 @@ export function RangePickerInput(props: DatePickerInputProps) {
230
250
  * </Field>
231
251
  * ```
232
252
  */
233
- export function DatePickerContent(props: DatePickerContentProps) {
234
- const { children, ...contentProps } = props
253
+ export function DatePickerContent(
254
+ props: DatePickerContentProps & {
255
+ withModal?: boolean
256
+ },
257
+ ) {
258
+ const { children, withModal, ...contentProps } = props
235
259
  return (
236
- <Portal>
260
+ <Portal disabled={withModal ?? false}>
237
261
  <ArkDP.Positioner className={datePickerStyles.positioner}>
238
262
  <ArkDP.Content
239
263
  {...contentProps}
@@ -426,9 +450,9 @@ export function DatePickerYearView(props: Omit<DatePickerViewProps, 'view'>) {
426
450
  * </Field>
427
451
  * ```
428
452
  */
429
- export function DatePickerCalendar() {
453
+ export function DatePickerCalendar(props: { withModal?: boolean }) {
430
454
  return (
431
- <DatePickerContent>
455
+ <DatePickerContent withModal={props.withModal}>
432
456
  <DatePickerDayView />
433
457
  <DatePickerMonthView />
434
458
  <DatePickerYearView />
@@ -0,0 +1,39 @@
1
+ 'use client'
2
+
3
+ import {
4
+ Dialog as ArkDialog,
5
+ type DialogCloseTriggerProps,
6
+ } from '@ark-ui/react'
7
+ import { dialog } from '@cerberus/styled-system/recipes'
8
+ import { cx } from '@cerberus/styled-system/css'
9
+ import { IconButton } from './IconButton'
10
+ import { useCerberusContext } from '../context/cerberus'
11
+
12
+ /**
13
+ * This module contains client-side components for the Dialog family.
14
+ * @module @cerberus-design/react/dialog
15
+ */
16
+
17
+ export function DialogCloseIconTrigger(props: DialogCloseTriggerProps) {
18
+ const { icons } = useCerberusContext()
19
+ const { close: CloseIcon } = icons
20
+
21
+ const styles = dialog()
22
+
23
+ return (
24
+ <ArkDialog.CloseTrigger
25
+ {...props}
26
+ className={cx(props.className, styles.closeTrigger)}
27
+ asChild
28
+ >
29
+ <IconButton
30
+ ariaLabel="Close dialog"
31
+ palette="action"
32
+ size="lg"
33
+ usage="ghost"
34
+ >
35
+ <CloseIcon />
36
+ </IconButton>
37
+ </ArkDialog.CloseTrigger>
38
+ )
39
+ }
@@ -0,0 +1,165 @@
1
+ import {
2
+ Dialog as ArkDialog,
3
+ type DialogContentProps as ArkDialogContentProps,
4
+ type DialogRootProps,
5
+ type DialogTitleProps,
6
+ } from '@ark-ui/react'
7
+ import {
8
+ dialog,
9
+ type DialogVariantProps,
10
+ } from '@cerberus/styled-system/recipes'
11
+ import { Portal } from './Portal'
12
+ import { cx } from '@cerberus/styled-system/css'
13
+
14
+ export type DialogProviderProps = DialogRootProps
15
+
16
+ /**
17
+ * The provider that controls the dialog components.
18
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
19
+ * @example
20
+ * ```tsx
21
+ * <DialogProvider>
22
+ * <DialogTrigger asChild>
23
+ * <Button>Open Dialog</Button>
24
+ * </DialogTrigger>
25
+ * <Dialog>
26
+ * <Text>Dialog Content</Text>
27
+ * <DialogCloseTrigger>Close</DialogCloseTrigger>
28
+ * </Dialog>
29
+ * </DialogProvider>
30
+ * ```
31
+ */
32
+ export function DialogProvider(props: DialogProviderProps) {
33
+ return <ArkDialog.Root {...props} />
34
+ }
35
+
36
+ export interface DialogProps
37
+ extends Omit<ArkDialogContentProps, 'size'>,
38
+ DialogVariantProps {}
39
+
40
+ /**
41
+ * The content of the dialog. Must be used within the `DialogProvider` component.
42
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
43
+ * @example
44
+ * ```tsx
45
+ * <DialogProvider>
46
+ * <DialogTrigger asChild>
47
+ * <Button>Open Dialog</Button>
48
+ * </DialogTrigger>
49
+ * <Dialog>
50
+ * <Text>Dialog Content</Text>
51
+ * </Dialog>
52
+ * </DialogProvider>
53
+ * ```
54
+ */
55
+ export function Dialog(props: DialogProps) {
56
+ const { size, ...contentProps } = props
57
+ const styles = dialog({ size })
58
+ return (
59
+ <Portal>
60
+ <DialogBackdrop className={styles.backdrop} />
61
+ <DialogPositioner className={styles.positioner}>
62
+ <DialogContent className={styles.content} {...contentProps} />
63
+ </DialogPositioner>
64
+ </Portal>
65
+ )
66
+ }
67
+
68
+ /**
69
+ * The heading of the dialog. Must be used within the `DialogContent` component.
70
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
71
+ * @example
72
+ * ```tsx
73
+ * <DialogProvider>
74
+ * <DialogTrigger asChild>
75
+ * <Button>Open Dialog</Button>
76
+ * </DialogTrigger>
77
+ * <Dialog>
78
+ * <DialogHeading>Dialog Title</DialogHeading>
79
+ * <Text>Dialog Content</Text>
80
+ * </Dialog>
81
+ * </DialogProvider>
82
+ * ```
83
+ */
84
+ export function DialogHeading(props: DialogTitleProps) {
85
+ const styles = dialog()
86
+ return (
87
+ <ArkDialog.Title {...props} className={cx(props.className, styles.title)} />
88
+ )
89
+ }
90
+
91
+ /**
92
+ * The description of the dialog. Must be used within the `DialogContent` component.
93
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
94
+ * @example
95
+ * ```tsx
96
+ * <DialogProvider>
97
+ * <DialogTrigger asChild>
98
+ * <Button>Open Dialog</Button>
99
+ * </DialogTrigger>
100
+ * <Dialog>
101
+ * <DialogHeading>Dialog Title</DialogHeading>
102
+ * <DialogDescription>Dialog Description</DialogDescription>
103
+ * </Dialog>
104
+ * </DialogProvider>
105
+ * ```
106
+ */
107
+ export function DialogDescription(props: DialogTitleProps) {
108
+ const styles = dialog()
109
+ return (
110
+ <ArkDialog.Description
111
+ {...props}
112
+ className={cx(props.className, styles.description)}
113
+ />
114
+ )
115
+ }
116
+
117
+ /**
118
+ * The trigger that opens the dialog. Must be used within the `DialogProvider`
119
+ * component.
120
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
121
+ * @example
122
+ * ```tsx
123
+ * <DialogTrigger asChild>
124
+ * <Button>Open Dialog</Button>
125
+ * </DialogTrigger>
126
+ * ```
127
+ */
128
+ export const DialogTrigger = ArkDialog.Trigger
129
+
130
+ /**
131
+ * The trigger that closes the dialog. Must be used within the `DialogProvider`
132
+ * component.
133
+ * @definition [Dialog docs](https://cerberus.digitalu.design/react/dialog)
134
+ * @example
135
+ * ```tsx
136
+ * <DialogProvider>
137
+ * <DialogTrigger asChild>
138
+ * <Button>Open Dialog</Button>
139
+ * </DialogTrigger>
140
+ * <Dialog>
141
+ * <Text>Dialog Content</Text>
142
+ * <DialogCloseTrigger>Close</DialogCloseTrigger>
143
+ * </Dialog>
144
+ * </DialogProvider>
145
+ * ```
146
+ */
147
+ export const DialogCloseTrigger = ArkDialog.CloseTrigger
148
+
149
+ /**
150
+ * The backdrop of the dialog. Must be used within the `DialogProvider`
151
+ * component.
152
+ */
153
+ export const DialogBackdrop = ArkDialog.Backdrop
154
+
155
+ /**
156
+ * The positioner of the dialog. Must be used within the `DialogProvider`
157
+ * component.
158
+ */
159
+ export const DialogPositioner = ArkDialog.Positioner
160
+
161
+ /**
162
+ * The content of the dialog. Must be used within the `DialogProvider`
163
+ * component.
164
+ */
165
+ export const DialogContent = ArkDialog.Content
@@ -22,21 +22,6 @@ function ModalEl(props: ModalProps, ref: ForwardedRef<HTMLDialogElement>) {
22
22
  }
23
23
 
24
24
  /**
25
- * The Modal component is the root element for a customizable modal.
26
- * @see https://cerberus.digitalu.design/react/modal
27
- * @example
28
- * ```tsx
29
- * const { modalRef } = useModal()
30
- *
31
- * <Modal ref={modalRef}>
32
- * <Avatar icon={SomeIcon} />
33
- * <ModalHeader>
34
- * <ModalHeading>Modal Heading</ModalHeading>
35
- * <ModalDescription>Modal description</ModalDescription>
36
- * </ModalHeader>
37
- *
38
- * {props.children}
39
- * </Modal>
40
- * ```
25
+ * @deprecated use `Dialog` instead
41
26
  */
42
27
  export const Modal = forwardRef(ModalEl)
@@ -10,14 +10,7 @@ import type { HTMLAttributes } from 'react'
10
10
  export type ModalDescriptionProps = HTMLAttributes<HTMLParagraphElement>
11
11
 
12
12
  /**
13
- * The ModalDescription component is a heading element for a customizable modal.
14
- * @see https://cerberus.digitalu.design/react/modal
15
- * @example
16
- * ```tsx
17
- * <Modal>
18
- * <ModalDescription>Modal Heading</ModalDescription>
19
- * </Modal>
20
- * ```
13
+ * @deprecated use `DialogDescription` instead
21
14
  */
22
15
  export function ModalDescription(props: ModalDescriptionProps) {
23
16
  return <p {...props} className={cx(props.className, modal().description)} />
@@ -10,16 +10,7 @@ import type { HTMLAttributes } from 'react'
10
10
  export type ModalHeaderProps = HTMLAttributes<HTMLDivElement>
11
11
 
12
12
  /**
13
- * The ModalHeader component is a header element for a customizable modal.
14
- * @see https://cerberus.digitalu.design/react/modal
15
- * @example
16
- * ```tsx
17
- * <Modal>
18
- * <ModalHeader>
19
- * <h2>Modal Heading</h2>
20
- * </ModalHeader>
21
- * </Modal>
22
- * ```
13
+ * @deprecated there is no replacement for this component
23
14
  */
24
15
  export function ModalHeader(props: ModalHeaderProps) {
25
16
  return (
@@ -10,14 +10,7 @@ import type { HTMLAttributes } from 'react'
10
10
  export type ModalHeadingProps = HTMLAttributes<HTMLParagraphElement>
11
11
 
12
12
  /**
13
- * The ModalHeading component is a heading element for a customizable modal.
14
- * @see https://cerberus.digitalu.design/react/modal
15
- * @example
16
- * ```tsx
17
- * <Modal>
18
- * <ModalHeading>Modal Heading</ModalHeading>
19
- * </Modal>
20
- * ```
13
+ * @deprecated use `DialogHeading` instead
21
14
  */
22
15
  export function ModalHeading(props: ModalHeadingProps) {
23
16
  return <p {...props} className={cx(props.className, modal().heading)} />
@@ -109,7 +109,7 @@ export function NotificationCenter(
109
109
  id,
110
110
  state: 'closed',
111
111
  })
112
- setTimeout(() => {
112
+ window.setTimeout(() => {
113
113
  removeNotification(dispatch, id)
114
114
  }, 150)
115
115
  },
@@ -125,7 +125,7 @@ export function NotificationCenter(
125
125
  state: 'open',
126
126
  })
127
127
 
128
- setTimeout(() => {
128
+ window.setTimeout(() => {
129
129
  closeNotification(id)
130
130
  }, timeout)
131
131
  },
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ export * from './components/Checkbox'
15
15
  export * from './components/CircularProgress'
16
16
  export * from './components/DatePicker.client'
17
17
  export * from './components/DatePicker.server'
18
+ export * from './components/Dialog'
19
+ export * from './components/Dialog.client'
18
20
  export * from './components/Droppable'
19
21
  export * from './components/FieldMessage'
20
22
  export * from './components/FeatureFlag'
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/ModalHeading.tsx"],"sourcesContent":["import { cx } from '@cerberus/styled-system/css'\nimport { modal } from '@cerberus/styled-system/recipes'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalHeading component for a customizable modal.\n * @module\n */\n\nexport type ModalHeadingProps = HTMLAttributes<HTMLParagraphElement>\n\n/**\n * The ModalHeading component is a heading element for a customizable modal.\n * @see https://cerberus.digitalu.design/react/modal\n * @example\n * ```tsx\n * <Modal>\n * <ModalHeading>Modal Heading</ModalHeading>\n * </Modal>\n * ```\n */\nexport function ModalHeading(props: ModalHeadingProps) {\n return <p {...props} className={cx(props.className, modal().heading)} />\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AAqBb;AADF,SAAS,aAAa,OAA0B;AACrD,SAAO,oBAAC,OAAG,GAAG,OAAO,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,OAAO,GAAG;AACxE;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/Modal.tsx"],"sourcesContent":["import { cx } from '@cerberus/styled-system/css'\nimport { modal } from '@cerberus/styled-system/recipes'\nimport { forwardRef, type ForwardedRef, type HTMLAttributes } from 'react'\n\n/**\n * This module contains the Modal root component for a customizable modal.\n * @module\n */\n\n// Modal\n\nexport type ModalProps = HTMLAttributes<HTMLDialogElement>\n\nfunction ModalEl(props: ModalProps, ref: ForwardedRef<HTMLDialogElement>) {\n return (\n <dialog\n {...props}\n className={cx(props.className, modal().dialog)}\n ref={ref}\n />\n )\n}\n\n/**\n * The Modal component is the root element for a customizable modal.\n * @see https://cerberus.digitalu.design/react/modal\n * @example\n * ```tsx\n * const { modalRef } = useModal()\n *\n * <Modal ref={modalRef}>\n * <Avatar icon={SomeIcon} />\n * <ModalHeader>\n * <ModalHeading>Modal Heading</ModalHeading>\n * <ModalDescription>Modal description</ModalDescription>\n * </ModalHeader>\n *\n * {props.children}\n * </Modal>\n * ```\n */\nexport const Modal = forwardRef(ModalEl)\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,kBAA0D;AAa/D;AAFJ,SAAS,QAAQ,OAAmB,KAAsC;AACxE,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,MAAM;AAAA,MAC7C;AAAA;AAAA,EACF;AAEJ;AAoBO,IAAM,QAAQ,WAAW,OAAO;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/DatePicker.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n DatePicker as ArkDP,\n type DatePickerContentProps,\n type DatePickerInputProps,\n type DatePickerRootProps,\n type DatePickerTriggerProps,\n type DatePickerViewControlProps,\n type DatePickerViewProps,\n} from '@ark-ui/react'\nimport { Portal } from './Portal'\nimport { datePicker, iconButton } from '@cerberus/styled-system/recipes'\nimport { css, cx } from '@cerberus/styled-system/css'\nimport { useFieldContext } from '../context/field'\nimport {\n DatePickerView,\n DatePickerContext,\n DatePickerTable,\n DatePickerTableHeader,\n DatePickerTableCellTrigger,\n DatePickerTableCell,\n DatePickerViewControl,\n} from './DatePicker.server'\nimport { IconButton } from './IconButton'\nimport { Button } from './Button'\nimport { useCerberusContext } from '../context/cerberus'\n\n/**\n * This module contains the DatePicker client family components.\n * @module DatePicker:client\n */\n\n// We are not exposing this to the public API\nconst datePickerStyles = datePicker()\n\n/**\n * The main context provider for the DatePicker family components.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePicker(props: DatePickerRootProps) {\n const states = useFieldContext()\n\n // TODO: Remove this once the bug is fixed: https://github.com/chakra-ui/ark/issues/3112\n\n // There is a bug with the Root component that causes random date selection\n // onBlur after the first selection if the format prop is used.\n // const handleFormat = useCallback((value: DateValue) => {\n // return formatISOToMilitary(value.toString())\n // }, [])\n\n return (\n <ArkDP.Root\n {...props}\n {...states}\n positioning={{\n placement: 'bottom-start',\n }}\n />\n )\n}\n\n/**\n * An abstraction of the DatePicker control that contains the prev, view, and\n * next triggers which control the calendar output.\n * @definition [datePicker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <DatePickerViewControlGroup />\n * ```\n */\nexport function DatePickerViewControlGroup(props: DatePickerViewControlProps) {\n const { icons } = useCerberusContext()\n const { calendarPrev: PrevIcon, calendarNext: NextIcon } = icons\n return (\n <DatePickerViewControl {...props}>\n <ArkDP.PrevTrigger asChild>\n <IconButton ariaLabel=\"Previous\" size=\"sm\">\n <PrevIcon />\n </IconButton>\n </ArkDP.PrevTrigger>\n\n <ArkDP.ViewTrigger asChild>\n <Button\n className={css({\n h: '2rem',\n paddingInline: 'md',\n })}\n shape=\"rounded\"\n size=\"sm\"\n usage=\"ghost\"\n >\n <ArkDP.RangeText />\n </Button>\n </ArkDP.ViewTrigger>\n\n <ArkDP.NextTrigger asChild>\n <IconButton ariaLabel=\"Next\" size=\"sm\">\n <NextIcon />\n </IconButton>\n </ArkDP.NextTrigger>\n </DatePickerViewControl>\n )\n}\n\n/**\n * The trigger component for the DatePicker which opens the calendar.\n * @definition [datePicker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <DatePickerTrigger />\n * ```\n */\nexport function DatePickerTrigger(props: DatePickerTriggerProps) {\n const { icons } = useCerberusContext()\n const { calendar: CalendarIcon } = icons\n return (\n <ArkDP.Trigger\n {...props}\n className={cx(\n props.className,\n iconButton({\n size: 'sm',\n usage: 'ghost',\n }),\n datePickerStyles.trigger,\n )}\n >\n <CalendarIcon />\n </ArkDP.Trigger>\n )\n}\n\n/**\n * The input component for the DatePicker.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerInput(props: DatePickerInputProps) {\n const { invalid, ...fieldStates } = useFieldContext()\n return (\n <ArkDP.Control className={datePickerStyles.control}>\n <DatePickerTrigger />\n <ArkDP.Input\n {...props}\n {...fieldStates}\n {...(invalid && { 'aria-invalid': true })}\n className={cx(props.className, datePickerStyles.input)}\n placeholder={props.placeholder ?? 'DD MMM YYYY'}\n maxLength={11}\n />\n </ArkDP.Control>\n )\n}\n\n/**\n * The input component for the DatePicker that uses ranges.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\" selection=\"range\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <RangePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function RangePickerInput(props: DatePickerInputProps) {\n const { invalid, ...fieldStates } = useFieldContext()\n return (\n <ArkDP.Control data-range className={datePickerStyles.control}>\n <DatePickerTrigger />\n <ArkDP.Input\n {...props}\n {...fieldStates}\n {...(invalid && { 'aria-invalid': true })}\n data-range-input\n className={cx(props.className, datePickerStyles.input)}\n placeholder={props.placeholder ?? 'DD MMM YYYY'}\n maxLength={11}\n index={0}\n />\n <ArkDP.Input\n {...props}\n {...fieldStates}\n {...(invalid && { 'aria-invalid': true })}\n data-range-input\n data-range-end-input\n className={cx(props.className, datePickerStyles.input)}\n placeholder={props.placeholder ?? 'DD MMM YYYY'}\n maxLength={11}\n index={1}\n />\n </ArkDP.Control>\n )\n}\n\n/**\n * The content component for the DatePicker which contains the calendar.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerContent(props: DatePickerContentProps) {\n const { children, ...contentProps } = props\n return (\n <Portal>\n <ArkDP.Positioner className={datePickerStyles.positioner}>\n <ArkDP.Content\n {...contentProps}\n className={cx(contentProps.className, datePickerStyles.content)}\n >\n {children}\n </ArkDP.Content>\n </ArkDP.Positioner>\n </Portal>\n )\n}\n\n/**\n * The day view component for the DatePicker.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerDayView(props: Omit<DatePickerViewProps, 'view'>) {\n function isToday(date: ArkDP.DateValue): boolean {\n const today = new Date()\n const formatted = today.toISOString().split('T')[0]\n const arkDate = `${date.year}-${String(date.month).padStart(2, '0')}-${String(date.day).padStart(2, '0')}`\n return formatted === arkDate\n }\n\n function isPastDay(date: ArkDP.DateValue): boolean {\n const today = new Date()\n const arkDate = `${date.year}-${String(date.month).padStart(2, '0')}-${String(date.day).padStart(2, '0')}`\n return new Date(arkDate) < today\n }\n\n function getDayValue(date: ArkDP.DateValue): 'today' | 'past' | 'future' {\n if (isToday(date)) return 'today'\n if (isPastDay(date)) return 'past'\n return 'future'\n }\n\n return (\n <DatePickerView {...props} view=\"day\">\n <DatePickerContext>\n {(datePicker) => (\n <>\n <DatePickerViewControlGroup />\n\n <DatePickerTable>\n <ArkDP.TableHead>\n <ArkDP.TableRow>\n {datePicker.weekDays.map((weekDay, id) => (\n <DatePickerTableHeader key={id}>\n {weekDay.narrow}\n </DatePickerTableHeader>\n ))}\n </ArkDP.TableRow>\n </ArkDP.TableHead>\n\n <ArkDP.TableBody>\n {datePicker.weeks.map((week, id) => (\n <ArkDP.TableRow key={id}>\n {week.map((day, id) => (\n <DatePickerTableCell key={id} value={day}>\n <DatePickerTableCellTrigger\n data-date={getDayValue(day)}\n >\n {day.day}\n </DatePickerTableCellTrigger>\n </DatePickerTableCell>\n ))}\n </ArkDP.TableRow>\n ))}\n </ArkDP.TableBody>\n </DatePickerTable>\n </>\n )}\n </DatePickerContext>\n </DatePickerView>\n )\n}\n\n/**\n * The month view component for the DatePicker.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerMonthView(props: Omit<DatePickerViewProps, 'view'>) {\n return (\n <ArkDP.View {...props} view=\"month\">\n <ArkDP.Context>\n {(datePicker) => (\n <>\n <DatePickerViewControlGroup />\n\n <DatePickerTable>\n <ArkDP.TableBody>\n {datePicker\n .getMonthsGrid({ columns: 4, format: 'short' })\n .map((months, id) => (\n <ArkDP.TableRow key={id}>\n {months.map((month, id) => (\n <DatePickerTableCell key={id} value={month.value}>\n <DatePickerTableCellTrigger>\n {month.label}\n </DatePickerTableCellTrigger>\n </DatePickerTableCell>\n ))}\n </ArkDP.TableRow>\n ))}\n </ArkDP.TableBody>\n </DatePickerTable>\n </>\n )}\n </ArkDP.Context>\n </ArkDP.View>\n )\n}\n\n/**\n * The year view component for the DatePicker.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerYearView(props: Omit<DatePickerViewProps, 'view'>) {\n return (\n <ArkDP.View {...props} view=\"year\">\n <ArkDP.Context>\n {(datePicker) => (\n <>\n <DatePickerViewControlGroup />\n\n <DatePickerTable>\n <ArkDP.TableBody>\n {datePicker.getYearsGrid({ columns: 4 }).map((years, id) => (\n <ArkDP.TableRow key={id}>\n {years.map((year, id) => (\n <DatePickerTableCell key={id} value={year.value}>\n <DatePickerTableCellTrigger>\n {year.label}\n </DatePickerTableCellTrigger>\n </DatePickerTableCell>\n ))}\n </ArkDP.TableRow>\n ))}\n </ArkDP.TableBody>\n </DatePickerTable>\n </>\n )}\n </ArkDP.Context>\n </ArkDP.View>\n )\n}\n\n/**\n * An abstraction of the DatePicker content components that contain the\n * different calendar views and controls.\n * @definition [Date Picker docs](https://cerberus.digitalu.design/react/date-picker)\n * @example\n * ```tsx\n * <Field>\n * <DatePicker name=\"start_date\">\n * <DatePickerLabel>Start date</DatePickerLabel>\n * <DatePickerInput />\n * <DatePickerCalendar />\n * </DatePicker>\n * </Field>\n * ```\n */\nexport function DatePickerCalendar() {\n return (\n <DatePickerContent>\n <DatePickerDayView />\n <DatePickerMonthView />\n <DatePickerYearView />\n </DatePickerContent>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE,cAAc;AAAA,OAOT;AAEP,SAAS,YAAY,kBAAkB;AACvC,SAAS,KAAK,UAAU;AAiDpB,SAgOM,UAhON,KAuBA,YAvBA;AA5BJ,IAAM,mBAAmB,WAAW;AAgB7B,SAAS,WAAW,OAA4B;AACrD,QAAM,SAAS,gBAAgB;AAU/B,SACE;AAAA,IAAC,MAAM;AAAA,IAAN;AAAA,MACE,GAAG;AAAA,MACH,GAAG;AAAA,MACJ,aAAa;AAAA,QACX,WAAW;AAAA,MACb;AAAA;AAAA,EACF;AAEJ;AAWO,SAAS,2BAA2B,OAAmC;AAC5E,QAAM,EAAE,MAAM,IAAI,mBAAmB;AACrC,QAAM,EAAE,cAAc,UAAU,cAAc,SAAS,IAAI;AAC3D,SACE,qBAAC,yBAAuB,GAAG,OACzB;AAAA,wBAAC,MAAM,aAAN,EAAkB,SAAO,MACxB,8BAAC,cAAW,WAAU,YAAW,MAAK,MACpC,8BAAC,YAAS,GACZ,GACF;AAAA,IAEA,oBAAC,MAAM,aAAN,EAAkB,SAAO,MACxB;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,IAAI;AAAA,UACb,GAAG;AAAA,UACH,eAAe;AAAA,QACjB,CAAC;AAAA,QACD,OAAM;AAAA,QACN,MAAK;AAAA,QACL,OAAM;AAAA,QAEN,8BAAC,MAAM,WAAN,EAAgB;AAAA;AAAA,IACnB,GACF;AAAA,IAEA,oBAAC,MAAM,aAAN,EAAkB,SAAO,MACxB,8BAAC,cAAW,WAAU,QAAO,MAAK,MAChC,8BAAC,YAAS,GACZ,GACF;AAAA,KACF;AAEJ;AAUO,SAAS,kBAAkB,OAA+B;AAC/D,QAAM,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AC,8BAA2B;AAAA,IAE5B,oBAAC,mBACC,8BAAC,MAAM,WAAN,EACE,UAAAA,YAAW,aAAa,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,OACnD,oBAAC,MAAM,UAAN,EACE,gBAAM,IAAI,CAAC,MAAMC,QAChB,oBAAC,uBAA6B,OAAO,KAAK,OACxC,8BAAC,8BACE,eAAK,OACR,KAHwBA,GAI1B,CACD,KAPkB,EAQrB,CACD,GACH,GACF;AAAA,KACF,GAEJ,GACF;AAEJ;AAiBO,SAAS,qBAAqB;AACnC,SACE,qBAAC,qBACC;AAAA,wBAAC,qBAAkB;AAAA,IACnB,oBAAC,uBAAoB;AAAA,IACrB,oBAAC,sBAAmB;AAAA,KACtB;AAEJ;","names":["datePicker","id"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/ModalDescription.tsx"],"sourcesContent":["import { cx } from '@cerberus/styled-system/css'\nimport { modal } from '@cerberus/styled-system/recipes'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalDescription component for a customizable modal.\n * @module\n */\n\nexport type ModalDescriptionProps = HTMLAttributes<HTMLParagraphElement>\n\n/**\n * The ModalDescription component is a heading element for a customizable modal.\n * @see https://cerberus.digitalu.design/react/modal\n * @example\n * ```tsx\n * <Modal>\n * <ModalDescription>Modal Heading</ModalDescription>\n * </Modal>\n * ```\n */\nexport function ModalDescription(props: ModalDescriptionProps) {\n return <p {...props} className={cx(props.className, modal().description)} />\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AAqBb;AADF,SAAS,iBAAiB,OAA8B;AAC7D,SAAO,oBAAC,OAAG,GAAG,OAAO,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,WAAW,GAAG;AAC5E;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/ModalHeader.tsx"],"sourcesContent":["import { cx } from '@cerberus/styled-system/css'\nimport { vstack } from '@cerberus/styled-system/patterns'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalHeader component for a customizable modal.\n * @module\n */\n\nexport type ModalHeaderProps = HTMLAttributes<HTMLDivElement>\n\n/**\n * The ModalHeader component is a header element for a customizable modal.\n * @see https://cerberus.digitalu.design/react/modal\n * @example\n * ```tsx\n * <Modal>\n * <ModalHeader>\n * <h2>Modal Heading</h2>\n * </ModalHeader>\n * </Modal>\n * ```\n */\nexport function ModalHeader(props: ModalHeaderProps) {\n return (\n <div\n {...props}\n className={cx(\n props.className,\n vstack({\n alignItems: 'flex-start',\n gap: 'md',\n position: 'relative',\n }),\n )}\n />\n )\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,cAAc;AAwBnB;AAFG,SAAS,YAAY,OAAyB;AACnD,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,UACL,YAAY;AAAA,UACZ,KAAK;AAAA,UACL,UAAU;AAAA,QACZ,CAAC;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/context/notification-center.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useReducer,\n type MouseEvent,\n type PropsWithChildren,\n type ReactNode,\n} from 'react'\nimport { Show } from '../components/Show'\nimport { NotificationHeading } from '../components/NotificationHeading'\nimport { NotificationDescription } from '../components/NotificationDescription'\nimport { Notification } from '../components/Notification'\nimport { animateIn, vstack } from '@cerberus/styled-system/patterns'\nimport { Portal, type PortalProps } from '../components/Portal'\nimport { notification } from '@cerberus/styled-system/recipes'\nimport { Button } from '../components/Button'\nimport { cx } from '@cerberus/styled-system/css'\nimport {\n addNotification,\n clearNotificationState,\n notificationCenterReducer,\n removeNotification,\n updateNotificationState,\n} from './notification-center/store'\n\n/**\n * This module provides a context and hook for notifications.\n * @module\n */\n\nexport interface NotifyOptions {\n /**\n * The palette of the notification.\n * @default 'info'\n */\n palette: 'info' | 'success' | 'warning' | 'danger'\n /**\n * The heading of the notification.\n */\n heading: string\n /**\n * The unique id of the notification.\n */\n id?: string\n /**\n * The description of the notification.\n */\n description?: ReactNode\n /**\n * The action to take when the notification is closed\n */\n onClose?: () => void\n}\n\nexport interface NotificationsValue {\n notify: (options: NotifyOptions) => void\n}\n\nconst NotificationsContext = createContext<NotificationsValue | null>(null)\n\nexport type NotificationsProviderProps = PortalProps & {\n /**\n * The duration in milliseconds to show the notification.\n * @default 6000\n */\n duration?: number\n}\n\n/**\n * Provides a notification center to the app.\n * @see https://cerberus.digitalu.design/react/notification\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <Notifications>\n * <SomeFeatureSection />\n * </Notifications>\n *\n * // Use the hook to show a notification.\n * const notify = useNotifications()\n *\n * const handleClick = useCallback(() => {\n * notify({\n * palette: 'info',\n * heading: 'New feature!',\n * description: 'We have added a new feature to the app.',\n * })\n * }, [notify])\n * ```\n */\nexport function NotificationCenter(\n props: PropsWithChildren<NotificationsProviderProps>,\n) {\n const [state, dispatch] = useReducer(notificationCenterReducer, [])\n const styles = notification()\n\n const timeout = useMemo<number>(\n () => props.duration || 6000,\n [props.duration],\n )\n\n const closeNotification = useCallback(\n (id: string) => {\n updateNotificationState(dispatch, {\n id,\n state: 'closed',\n })\n setTimeout(() => {\n removeNotification(dispatch, id)\n }, 150)\n },\n [dispatch],\n )\n\n const handleNotify = useCallback(\n (options: NotifyOptions) => {\n const id = `${options.palette}:${state.length + 1}`\n addNotification(dispatch, {\n ...options,\n id,\n state: 'open',\n })\n\n setTimeout(() => {\n closeNotification(id)\n }, timeout)\n },\n [dispatch, state, timeout, closeNotification],\n )\n\n const handleClose = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n closeNotification(target.value)\n },\n [closeNotification],\n )\n\n const handleCloseAll = useCallback(() => {\n state.forEach((item) => {\n if (item.onClose) item.onClose()\n })\n // we don't want to animate out for this one\n clearNotificationState(dispatch)\n }, [state, dispatch])\n\n const value = useMemo(\n () => ({\n notify: handleNotify,\n }),\n [handleNotify],\n )\n\n // For some reason, the vstack pattern alignItems is not registering here.\n // So we are forcing it with the style prop.\n\n return (\n <NotificationsContext.Provider value={value}>\n {props.children}\n\n <Show when={state.length > 0}>\n <Portal container={props.container}>\n <div className={styles.center}>\n <Show when={state.length >= 4}>\n <Button\n className={cx(styles.closeAll, animateIn())}\n onClick={handleCloseAll}\n palette=\"action\"\n shape=\"rounded\"\n size=\"sm\"\n usage=\"ghost\"\n >\n Close all\n </Button>\n </Show>\n\n <div\n className={vstack({\n alignItems: 'flex-end',\n gap: '4',\n })}\n style={{\n alignItems: 'flex-end',\n }}\n >\n {state.map((option) => (\n <MatchNotification\n key={option.id}\n {...option}\n onClose={handleClose}\n open={option.state}\n />\n ))}\n </div>\n </div>\n </Portal>\n </Show>\n </NotificationsContext.Provider>\n )\n}\n\ninterface MatchNotificationProps extends Omit<NotifyOptions, 'onClose'> {\n open: 'open' | 'closed'\n onClose: (e: MouseEvent<HTMLButtonElement>) => void\n key: string | undefined\n}\n\nfunction MatchNotification(props: MatchNotificationProps) {\n const { palette, id, onClose, heading, description, open } = props\n const sharedProps = useMemo(\n () => ({\n id: id!,\n open: true,\n onClose,\n 'data-state': open,\n }),\n [id, open, onClose],\n )\n\n switch (palette) {\n case 'success':\n return (\n <Notification {...sharedProps} palette=\"success\">\n <NotificationHeading palette=\"success\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"success\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'warning':\n return (\n <Notification {...sharedProps} palette=\"warning\">\n <NotificationHeading palette=\"warning\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"warning\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'danger':\n return (\n <Notification {...sharedProps} palette=\"danger\">\n <NotificationHeading palette=\"danger\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"danger\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n\n case 'info':\n default:\n return (\n <Notification {...sharedProps} palette=\"info\">\n <NotificationHeading palette=\"info\">{heading}</NotificationHeading>\n <NotificationDescription palette=\"info\">\n {description}\n </NotificationDescription>\n </Notification>\n )\n }\n}\n\n/**\n * The hook to use the NotificationCenter.\n * @returns The notify method to trigger a notification.\n * @example\n * ```tsx\n * const {notify} = useNotificationCenter()\n * notify({\n * palette: 'info',\n * heading: 'New feature',\n * description: 'We have added a new feature to the app.',\n * })\n * ```\n */\nexport function useNotificationCenter(): NotificationsValue {\n const context = useContext(NotificationsContext)\n if (!context) {\n throw new Error(\n 'useNotificationCenter must be used within a NotificationsProvider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAKP,SAAS,WAAW,cAAc;AAElC,SAAS,oBAAoB;AAE7B,SAAS,UAAU;AAkJT,SAEI,KAFJ;AAxGV,IAAM,uBAAuB,cAAyC,IAAI;AAgCnE,SAAS,mBACd,OACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,2BAA2B,CAAC,CAAC;AAClE,QAAM,SAAS,aAAa;AAE5B,QAAM,UAAU;AAAA,IACd,MAAM,MAAM,YAAY;AAAA,IACxB,CAAC,MAAM,QAAQ;AAAA,EACjB;AAEA,QAAM,oBAAoB;AAAA,IACxB,CAAC,OAAe;AACd,8BAAwB,UAAU;AAAA,QAChC;AAAA,QACA,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,MAAM;AACf,2BAAmB,UAAU,EAAE;AAAA,MACjC,GAAG,GAAG;AAAA,IACR;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,YAA2B;AAC1B,YAAM,KAAK,GAAG,QAAQ,OAAO,IAAI,MAAM,SAAS,CAAC;AACj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