@cerberus-design/react 0.18.3 → 0.18.4

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 (160) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.cts +87 -25
  2. package/build/legacy/components/FileStatus.cjs +34 -26
  3. package/build/legacy/components/FileStatus.cjs.map +1 -1
  4. package/build/legacy/components/Text.cjs +17 -23
  5. package/build/legacy/components/Text.cjs.map +1 -1
  6. package/build/legacy/components/checkbox/checkbox.cjs +17 -23
  7. package/build/legacy/components/checkbox/checkbox.cjs.map +1 -1
  8. package/build/legacy/components/checkbox/index.cjs +17 -23
  9. package/build/legacy/components/checkbox/index.cjs.map +1 -1
  10. package/build/legacy/components/cta-dialog/index.cjs +44 -35
  11. package/build/legacy/components/cta-dialog/index.cjs.map +1 -1
  12. package/build/legacy/components/cta-dialog/provider.cjs +44 -35
  13. package/build/legacy/components/cta-dialog/provider.cjs.map +1 -1
  14. package/build/legacy/components/date-picker/date-picker.cjs.map +1 -1
  15. package/build/legacy/components/date-picker/day-view.d.cts +1 -1
  16. package/build/legacy/components/date-picker/index.cjs +29 -21
  17. package/build/legacy/components/date-picker/index.cjs.map +1 -1
  18. package/build/legacy/components/date-picker/index.d.cts +6 -0
  19. package/build/legacy/components/date-picker/input.cjs +2 -2
  20. package/build/legacy/components/date-picker/input.cjs.map +1 -1
  21. package/build/legacy/components/date-picker/range-input.cjs +2 -9
  22. package/build/legacy/components/date-picker/range-input.cjs.map +1 -1
  23. package/build/legacy/components/deprecated/Label.cjs.map +1 -1
  24. package/build/legacy/components/dialog/close-icon-trigger.cjs.map +1 -1
  25. package/build/legacy/components/dialog/dialog.cjs +2 -2
  26. package/build/legacy/components/dialog/dialog.cjs.map +1 -1
  27. package/build/legacy/components/dialog/index.cjs +2 -2
  28. package/build/legacy/components/dialog/index.cjs.map +1 -1
  29. package/build/legacy/components/dialog/index.d.cts +1 -0
  30. package/build/legacy/components/dialog/parts.cjs +2 -2
  31. package/build/legacy/components/dialog/parts.cjs.map +1 -1
  32. package/build/legacy/components/dialog/primitives.cjs +2 -2
  33. package/build/legacy/components/dialog/primitives.cjs.map +1 -1
  34. package/build/legacy/components/field/field.cjs +15 -9
  35. package/build/legacy/components/field/field.cjs.map +1 -1
  36. package/build/legacy/components/field/helper-text.cjs +53 -0
  37. package/build/legacy/components/field/helper-text.cjs.map +1 -0
  38. package/build/legacy/components/field/helper-text.d.cts +1 -0
  39. package/build/legacy/components/field/index.cjs +15 -9
  40. package/build/legacy/components/field/index.cjs.map +1 -1
  41. package/build/legacy/components/field/parts.cjs +0 -1
  42. package/build/legacy/components/field/parts.cjs.map +1 -1
  43. package/build/legacy/components/field/primitives.cjs +0 -1
  44. package/build/legacy/components/field/primitives.cjs.map +1 -1
  45. package/build/legacy/context/confirm-modal.cjs +85 -58
  46. package/build/legacy/context/confirm-modal.cjs.map +1 -1
  47. package/build/legacy/context/field.cjs.map +1 -1
  48. package/build/legacy/context/prompt-modal.cjs +120 -118
  49. package/build/legacy/context/prompt-modal.cjs.map +1 -1
  50. package/build/legacy/index.cjs +767 -715
  51. package/build/legacy/index.cjs.map +1 -1
  52. package/build/legacy/index.d.cts +11 -0
  53. package/build/legacy/types.cjs.map +1 -1
  54. package/build/legacy/types.d.cts +1 -0
  55. package/build/modern/_tsup-dts-rollup.d.ts +87 -25
  56. package/build/modern/chunk-2U2JYN3D.js +15 -0
  57. package/build/modern/chunk-2U2JYN3D.js.map +1 -0
  58. package/build/modern/chunk-ADI4DOEW.js +17 -0
  59. package/build/modern/chunk-ADI4DOEW.js.map +1 -0
  60. package/build/modern/{chunk-GBCF6DOS.js → chunk-AN65HXHS.js} +2 -2
  61. package/build/modern/{chunk-Z2KBUTCO.js → chunk-BMDNCJUB.js} +2 -2
  62. package/build/modern/chunk-BMDNCJUB.js.map +1 -0
  63. package/build/modern/{chunk-F3XFJHGR.js → chunk-D7PY357P.js} +2 -2
  64. package/build/modern/{chunk-ILROS7ST.js → chunk-DVCTN3GN.js} +2 -2
  65. package/build/modern/{chunk-NP73HOHI.js → chunk-GJBUGESH.js} +3 -3
  66. package/build/modern/{chunk-NP73HOHI.js.map → chunk-GJBUGESH.js.map} +1 -1
  67. package/build/modern/{chunk-KABRV6TB.js → chunk-JXWNDJJW.js} +3 -3
  68. package/build/modern/{chunk-SSR3CWJZ.js → chunk-LUGOJGMO.js} +4 -4
  69. package/build/modern/chunk-LUGOJGMO.js.map +1 -0
  70. package/build/modern/{chunk-3IT3V3YA.js → chunk-M3TZCQ7J.js} +4 -4
  71. package/build/modern/{chunk-WEL43I6Y.js → chunk-OK3VJFQL.js} +1 -2
  72. package/build/modern/{chunk-WEL43I6Y.js.map → chunk-OK3VJFQL.js.map} +1 -1
  73. package/build/modern/{chunk-ADZRQNW3.js → chunk-P7FPAUWN.js} +3 -9
  74. package/build/modern/chunk-P7FPAUWN.js.map +1 -0
  75. package/build/modern/{chunk-OY7BOKWW.js → chunk-QBA6KLL7.js} +2 -2
  76. package/build/modern/chunk-RMSM3XPV.js +218 -0
  77. package/build/modern/chunk-RMSM3XPV.js.map +1 -0
  78. package/build/modern/{chunk-LEBDLXJE.js → chunk-RTLS6K4E.js} +9 -6
  79. package/build/modern/chunk-RTLS6K4E.js.map +1 -0
  80. package/build/modern/{chunk-A5UXCB4L.js → chunk-SHBKM6EW.js} +43 -34
  81. package/build/modern/chunk-SHBKM6EW.js.map +1 -0
  82. package/build/modern/{chunk-CEJIKL6N.js → chunk-T44C3KQO.js} +1 -1
  83. package/build/modern/chunk-T44C3KQO.js.map +1 -0
  84. package/build/modern/{chunk-V6EAWUCQ.js → chunk-TRT6OCHJ.js} +2 -2
  85. package/build/modern/chunk-WSOITM7D.js +182 -0
  86. package/build/modern/chunk-WSOITM7D.js.map +1 -0
  87. package/build/modern/chunk-ZPHPCKAG.js +41 -0
  88. package/build/modern/chunk-ZPHPCKAG.js.map +1 -0
  89. package/build/modern/components/FileStatus.js +5 -4
  90. package/build/modern/components/Text.js +1 -1
  91. package/build/modern/components/admonition/admonition.js +2 -2
  92. package/build/modern/components/admonition/index.js +2 -2
  93. package/build/modern/components/checkbox/checkbox.js +2 -2
  94. package/build/modern/components/checkbox/index.js +2 -2
  95. package/build/modern/components/cta-dialog/index.js +5 -5
  96. package/build/modern/components/cta-dialog/provider.js +5 -5
  97. package/build/modern/components/date-picker/date-picker.js +1 -1
  98. package/build/modern/components/date-picker/day-view.d.ts +1 -1
  99. package/build/modern/components/date-picker/index.d.ts +6 -0
  100. package/build/modern/components/date-picker/index.js +16 -5
  101. package/build/modern/components/date-picker/input.js +1 -1
  102. package/build/modern/components/date-picker/range-input.js +1 -2
  103. package/build/modern/components/deprecated/Label.js +5 -4
  104. package/build/modern/components/dialog/close-icon-trigger.js +2 -2
  105. package/build/modern/components/dialog/dialog.js +2 -2
  106. package/build/modern/components/dialog/index.d.ts +1 -0
  107. package/build/modern/components/dialog/index.js +4 -4
  108. package/build/modern/components/dialog/parts.js +2 -2
  109. package/build/modern/components/dialog/primitives.js +1 -1
  110. package/build/modern/components/field/field.js +3 -2
  111. package/build/modern/components/field/helper-text.d.ts +1 -0
  112. package/build/modern/components/field/helper-text.js +11 -0
  113. package/build/modern/components/field/index.js +4 -3
  114. package/build/modern/components/field/parts.js +2 -2
  115. package/build/modern/components/field/primitives.js +1 -1
  116. package/build/modern/components/notifications/index.js +1 -1
  117. package/build/modern/context/confirm-modal.js +5 -5
  118. package/build/modern/context/field.js +1 -1
  119. package/build/modern/context/prompt-modal.js +10 -9
  120. package/build/modern/index.d.ts +11 -0
  121. package/build/modern/index.js +52 -40
  122. package/build/modern/index.js.map +1 -1
  123. package/build/modern/types.d.ts +1 -0
  124. package/package.json +10 -9
  125. package/src/components/Text.tsx +20 -23
  126. package/src/components/cta-dialog/provider.tsx +6 -1
  127. package/src/components/date-picker/date-picker.tsx +8 -5
  128. package/src/components/date-picker/index.ts +10 -0
  129. package/src/components/date-picker/input.tsx +1 -1
  130. package/src/components/date-picker/range-input.tsx +9 -24
  131. package/src/components/dialog/dialog.tsx +4 -2
  132. package/src/components/dialog/index.ts +4 -0
  133. package/src/components/dialog/primitives.tsx +7 -4
  134. package/src/components/field/field.tsx +11 -9
  135. package/src/components/field/helper-text.tsx +20 -0
  136. package/src/components/field/primitives.tsx +0 -3
  137. package/src/context/confirm-modal.tsx +52 -30
  138. package/src/context/prompt-modal.tsx +36 -31
  139. package/src/types.ts +21 -0
  140. package/build/modern/chunk-A5UXCB4L.js.map +0 -1
  141. package/build/modern/chunk-ADZRQNW3.js.map +0 -1
  142. package/build/modern/chunk-CEJIKL6N.js.map +0 -1
  143. package/build/modern/chunk-DHKSNGQX.js +0 -156
  144. package/build/modern/chunk-DHKSNGQX.js.map +0 -1
  145. package/build/modern/chunk-L64HQGLQ.js +0 -47
  146. package/build/modern/chunk-L64HQGLQ.js.map +0 -1
  147. package/build/modern/chunk-LEBDLXJE.js.map +0 -1
  148. package/build/modern/chunk-P7DWMM56.js +0 -210
  149. package/build/modern/chunk-P7DWMM56.js.map +0 -1
  150. package/build/modern/chunk-SSR3CWJZ.js.map +0 -1
  151. package/build/modern/chunk-U3ISYEUF.js +0 -1
  152. package/build/modern/chunk-Z2KBUTCO.js.map +0 -1
  153. /package/build/modern/{chunk-GBCF6DOS.js.map → chunk-AN65HXHS.js.map} +0 -0
  154. /package/build/modern/{chunk-F3XFJHGR.js.map → chunk-D7PY357P.js.map} +0 -0
  155. /package/build/modern/{chunk-ILROS7ST.js.map → chunk-DVCTN3GN.js.map} +0 -0
  156. /package/build/modern/{chunk-KABRV6TB.js.map → chunk-JXWNDJJW.js.map} +0 -0
  157. /package/build/modern/{chunk-3IT3V3YA.js.map → chunk-M3TZCQ7J.js.map} +0 -0
  158. /package/build/modern/{chunk-OY7BOKWW.js.map → chunk-QBA6KLL7.js.map} +0 -0
  159. /package/build/modern/{chunk-V6EAWUCQ.js.map → chunk-TRT6OCHJ.js.map} +0 -0
  160. /package/build/modern/{chunk-U3ISYEUF.js.map → components/field/helper-text.js.map} +0 -0
@@ -18,8 +18,8 @@ export function DatePickerInput(props: DatePickerInputProps) {
18
18
  <DatePickerTrigger />
19
19
  <DatePickerParts.Input
20
20
  {...props}
21
- placeholder={props.placeholder ?? 'DD MMM YYYY'}
22
21
  maxLength={11}
22
+ placeholder={props.placeholder ?? 'DD MMM YYYY'}
23
23
  />
24
24
  </DatePickerParts.Control>
25
25
  )
@@ -1,21 +1,13 @@
1
- 'use client'
2
-
3
- import type { DatePickerInputProps } from '@ark-ui/react/date-picker'
4
- import { useMemo, type InputHTMLAttributes } from 'react'
1
+ import { type DatePickerInputProps } from '@ark-ui/react/date-picker'
5
2
  import { DatePickerParts } from './parts'
6
3
  import { DatePickerTrigger } from './trigger'
7
4
 
8
- export interface RangePickerInputProps
9
- extends Omit<DatePickerInputProps, 'defaultValue'> {
10
- /**
11
- * The defaultValue to add for the inputs. The first item is the start date
12
- * and the second item is the end date.
13
- */
14
- defaultValue?: [
15
- InputHTMLAttributes<HTMLInputElement>['defaultValue'],
16
- InputHTMLAttributes<HTMLInputElement>['defaultValue'],
17
- ]
18
- }
5
+ /**
6
+ * This private module contains the RangePickerInput component.
7
+ * @module RangePickerInput
8
+ */
9
+
10
+ export type RangePickerInputProps = DatePickerInputProps
19
11
 
20
12
  /**
21
13
  * An abstraction of the DatePicker input that wraps the input and the
@@ -23,26 +15,19 @@ export interface RangePickerInputProps
23
15
  * @definition [datePicker docs](https://cerberus.digitalu.design/react/date-picker)
24
16
  */
25
17
  export function RangePickerInput(props: RangePickerInputProps) {
26
- const { defaultValue, ...nativeProps } = props
27
-
28
- const startDate = useMemo(() => defaultValue?.[0], [defaultValue])
29
- const endDate = useMemo(() => defaultValue?.[1], [defaultValue])
30
-
31
18
  return (
32
19
  <DatePickerParts.Control data-range>
33
20
  <DatePickerTrigger />
34
21
  <DatePickerParts.Input
35
- {...nativeProps}
22
+ {...props}
36
23
  data-range-input
37
- defaultValue={startDate}
38
24
  placeholder={props.placeholder ?? 'DD MMM YYYY'}
39
25
  maxLength={11}
40
26
  index={0}
41
27
  />
42
28
  <DatePickerParts.Input
43
- {...nativeProps}
29
+ {...props}
44
30
  data-range-input
45
- defaultValue={endDate}
46
31
  data-range-end-input
47
32
  placeholder={props.placeholder ?? 'DD MMM YYYY'}
48
33
  maxLength={11}
@@ -1,5 +1,6 @@
1
1
  import type { DialogContentProps } from '@ark-ui/react/dialog'
2
2
  import type { DialogVariantProps } from 'styled-system/recipes'
3
+ import type { WithCss } from '../../types'
3
4
  import { Portal } from '../Portal'
4
5
  import { DialogBackdrop, DialogContent, DialogPositioner } from './primitives'
5
6
 
@@ -9,8 +10,9 @@ import { DialogBackdrop, DialogContent, DialogPositioner } from './primitives'
9
10
  */
10
11
 
11
12
  export interface DialogProps
12
- extends Omit<DialogContentProps, 'size'>,
13
- DialogVariantProps {}
13
+ extends Omit<DialogContentProps, 'size' | 'style'>,
14
+ DialogVariantProps,
15
+ WithCss {}
14
16
 
15
17
  /**
16
18
  * An abstraction of the Dialog primitives that controls the content of the
@@ -2,3 +2,7 @@ export * from './parts'
2
2
  export * from './primitives'
3
3
  export * from './close-icon-trigger'
4
4
  export * from './dialog'
5
+
6
+ export interface OpenChangeDetails {
7
+ open: boolean
8
+ }
@@ -8,8 +8,9 @@ import {
8
8
  type DialogTitleProps,
9
9
  type DialogTriggerProps,
10
10
  } from '@ark-ui/react/dialog'
11
- import { cx } from 'styled-system/css'
11
+ import { css, cx } from 'styled-system/css'
12
12
  import { dialog, type DialogVariantProps } from 'styled-system/recipes'
13
+ import type { WithCss } from '../../types'
13
14
 
14
15
  /**
15
16
  * This module contains the primitives of the Dialog component.
@@ -65,13 +66,15 @@ export function DialogPositioner(props: DialogPositionerProps) {
65
66
  /**
66
67
  * The visible content of the dialog.
67
68
  */
68
- export function DialogContent(props: DialogContentProps & DialogVariantProps) {
69
- const { size, ...contentProps } = props
69
+ export function DialogContent(
70
+ props: DialogContentProps & DialogVariantProps & WithCss,
71
+ ) {
72
+ const { size, css: customStyles, ...contentProps } = props
70
73
  const styles = dialog({ size })
71
74
  return (
72
75
  <Dialog.Content
73
76
  {...contentProps}
74
- className={cx(styles.content, contentProps.className)}
77
+ className={cx(styles.content, css(customStyles), contentProps.className)}
75
78
  />
76
79
  )
77
80
  }
@@ -8,6 +8,7 @@ import {
8
8
  } from './primitives'
9
9
  import { HStack } from 'styled-system/jsx'
10
10
  import { Show } from '../Show'
11
+ import { HelperText } from './helper-text'
11
12
 
12
13
  export interface FieldProps extends FieldRootProps {
13
14
  /**
@@ -62,16 +63,17 @@ export function Field(props: FieldProps) {
62
63
 
63
64
  {fieldProps.children}
64
65
 
65
- <Show when={fieldProps.helperText && !statusProps.invalid}>
66
- <HStack justifyContent="space-between" w="full">
67
- <FieldHelperText>{fieldProps.helperText}</FieldHelperText>
68
- <Show when={fieldProps.secondaryHelperText}>
69
- <FieldHelperText>{fieldProps.secondaryHelperText}</FieldHelperText>
70
- </Show>
71
- </HStack>
72
- </Show>
66
+ <HStack justifyContent="space-between" w="full">
67
+ <HelperText invalid={statusProps.invalid}>
68
+ {fieldProps.helperText}
69
+ </HelperText>
70
+
71
+ <FieldErrorText>{fieldProps.errorText}</FieldErrorText>
73
72
 
74
- <FieldErrorText>{fieldProps.errorText}</FieldErrorText>
73
+ <Show when={fieldProps.secondaryHelperText}>
74
+ <FieldHelperText>{fieldProps.secondaryHelperText}</FieldHelperText>
75
+ </Show>
76
+ </HStack>
75
77
  </FieldRoot>
76
78
  )
77
79
  }
@@ -0,0 +1,20 @@
1
+ import type { PropsWithChildren } from 'react'
2
+ import { FieldHelperText } from './primitives'
3
+
4
+ interface HelperTextProps {
5
+ invalid?: boolean
6
+ }
7
+
8
+ /**
9
+ * The HelperText component is an abstraction for hiding the helper text
10
+ * when the field is invalid. Ark UI assumes people want the helper text
11
+ * to always be visible, so this is a workaround for that.
12
+ */
13
+ export function HelperText(props: PropsWithChildren<HelperTextProps>) {
14
+ if (props.invalid) return null
15
+ return (
16
+ <FieldHelperText data-has-content={Boolean(props.children)}>
17
+ {props.children}
18
+ </FieldHelperText>
19
+ )
20
+ }
@@ -124,9 +124,6 @@ export function FieldInput(props: FieldInputProps) {
124
124
  */
125
125
  export function FieldHelperText(props: FieldHelperTextProps) {
126
126
  const styles = field()
127
-
128
- if (!props.children) return null
129
-
130
127
  return (
131
128
  <Field.HelperText
132
129
  {...props}
@@ -22,6 +22,7 @@ import {
22
22
  DialogDescription,
23
23
  DialogHeading,
24
24
  DialogProvider,
25
+ type OpenChangeDetails,
25
26
  } from '../components/dialog'
26
27
  import { useCerberusContext } from './cerberus'
27
28
 
@@ -75,12 +76,10 @@ export type ShowConfirmModalOptions =
75
76
  | NonDestructiveConfirmModalOptions
76
77
  | DestructiveConfirmOptions
77
78
 
78
- export type ShowResult =
79
- | ((value: boolean | PromiseLike<boolean>) => void)
80
- | null
79
+ export type ShowResult = ((value: boolean | null) => void) | null
81
80
 
82
81
  export interface ConfirmModalValue {
83
- show: (options: ShowConfirmModalOptions) => Promise<boolean>
82
+ show: (options: ShowConfirmModalOptions) => Promise<boolean | null>
84
83
  }
85
84
 
86
85
  const ConfirmModalContext = createContext<ConfirmModalValue | null>(null)
@@ -142,7 +141,7 @@ export function ConfirmModal(
142
141
 
143
142
  const handleShow = useCallback(
144
143
  (options: ShowConfirmModalOptions) => {
145
- return new Promise<boolean>((resolve) => {
144
+ return new Promise<boolean | null>((resolve) => {
146
145
  setContent({ ...options })
147
146
  setOpen(true)
148
147
  resolveRef.current = resolve
@@ -151,6 +150,17 @@ export function ConfirmModal(
151
150
  [setOpen, setContent],
152
151
  )
153
152
 
153
+ const handleOpenChange = useCallback(
154
+ ({ open }: OpenChangeDetails) => {
155
+ setOpen(open)
156
+ if (!open) {
157
+ resolveRef.current?.(null)
158
+ resolveRef.current = null
159
+ }
160
+ },
161
+ [setOpen],
162
+ )
163
+
154
164
  const value = useMemo(
155
165
  () => ({
156
166
  show: handleShow,
@@ -162,36 +172,48 @@ export function ConfirmModal(
162
172
  <ConfirmModalContext.Provider value={value}>
163
173
  {props.children}
164
174
 
165
- <DialogProvider open={open} onOpenChange={(e) => setOpen(e.open)}>
166
- <Dialog size="sm">
167
- <VStack gap="xl" w="full">
168
- <VStack alignItems="flex-start" gap="md" w="full">
169
- <HStack
170
- alignSelf="center"
171
- justify="center"
172
- paddingBlockEnd="md"
173
- w="full"
174
- >
175
- <Show
176
- when={palette === 'danger'}
177
- fallback={
178
- <Avatar
179
- gradient="charon-light"
180
- fallback={<ConfirmIcon size={24} />}
181
- />
182
- }
183
- >
175
+ <DialogProvider open={open} onOpenChange={handleOpenChange}>
176
+ <Dialog
177
+ size="sm"
178
+ style={{
179
+ '--dialog-content-min-h': 'auto',
180
+ }}
181
+ >
182
+ <VStack
183
+ alignItems="flex-start"
184
+ gap="md"
185
+ justify="space-between"
186
+ w="full"
187
+ >
188
+ <HStack
189
+ alignSelf="center"
190
+ justify="center"
191
+ paddingBlockEnd="md"
192
+ w="full"
193
+ >
194
+ <Show
195
+ when={palette === 'danger'}
196
+ fallback={
184
197
  <Avatar
185
- gradient="hades-dark"
198
+ gradient="charon-light"
186
199
  fallback={<ConfirmIcon size={24} />}
187
200
  />
188
- </Show>
189
- </HStack>
190
- <DialogHeading>{content?.heading}</DialogHeading>
201
+ }
202
+ >
203
+ <Avatar
204
+ gradient="hades-dark"
205
+ fallback={<ConfirmIcon size={24} />}
206
+ />
207
+ </Show>
208
+ </HStack>
209
+
210
+ <DialogHeading>{content?.heading}</DialogHeading>
211
+
212
+ <Show when={content?.description}>
191
213
  <DialogDescription>{content?.description}</DialogDescription>
192
- </VStack>
214
+ </Show>
193
215
 
194
- <HStack gap="4" w="full">
216
+ <HStack gap="md" pt="md" w="full">
195
217
  <Button
196
218
  autoFocus
197
219
  className={css({
@@ -176,33 +176,42 @@ export function PromptModal(
176
176
  {props.children}
177
177
 
178
178
  <DialogProvider open={open} onOpenChange={(e) => setOpen(e.open)}>
179
- <Dialog size="sm">
180
- <VStack gap="xl" w="full">
181
- <VStack alignItems="flex-start" gap="md" w="full">
182
- <HStack
183
- alignSelf="center"
184
- justify="center"
185
- paddingBlockEnd="md"
186
- w="full"
187
- >
188
- <Show
189
- when={palette === 'danger'}
190
- fallback={
191
- <Avatar
192
- gradient="charon-light"
193
- fallback={<PromptIcon size={24} />}
194
- />
195
- }
196
- >
179
+ <Dialog
180
+ size="sm"
181
+ style={{
182
+ '--dialog-content-min-h': 'auto',
183
+ }}
184
+ >
185
+ <VStack
186
+ alignItems="flex-start"
187
+ h="full"
188
+ justify="space-between"
189
+ w="full"
190
+ >
191
+ <HStack
192
+ alignSelf="center"
193
+ justify="center"
194
+ paddingBlockEnd="md"
195
+ w="full"
196
+ >
197
+ <Show
198
+ when={palette === 'danger'}
199
+ fallback={
197
200
  <Avatar
198
- gradient="hades-dark"
201
+ gradient="charon-light"
199
202
  fallback={<PromptIcon size={24} />}
200
203
  />
201
- </Show>
202
- </HStack>
203
- <DialogHeading>{content?.heading}</DialogHeading>
204
- <DialogDescription>{content?.description}</DialogDescription>
205
- </VStack>
204
+ }
205
+ >
206
+ <Avatar
207
+ gradient="hades-dark"
208
+ fallback={<PromptIcon size={24} />}
209
+ />
210
+ </Show>
211
+ </HStack>
212
+
213
+ <DialogHeading>{content?.heading}</DialogHeading>
214
+ <DialogDescription>{content?.description}</DialogDescription>
206
215
 
207
216
  <VStack
208
217
  alignItems="flex-start"
@@ -210,18 +219,14 @@ export function PromptModal(
210
219
  marginBlockEnd="lg"
211
220
  w="full"
212
221
  >
213
- <FieldRoot
214
- ids={{
215
- control: 'confirm',
216
- }}
217
- invalid={!isValid}
218
- >
222
+ <FieldRoot invalid={!isValid}>
219
223
  <FieldLabel
220
224
  className={hstack({
221
225
  gap: 'xs',
222
- justify: 'flex-start !important',
226
+ justify: 'flex-start',
223
227
  marginBlockEnd: 'xs',
224
228
  textStyle: 'label-md',
229
+ w: 'initial',
225
230
  })}
226
231
  >
227
232
  Type
package/src/types.ts CHANGED
@@ -1 +1,22 @@
1
+ import type { CSSProperties } from 'react'
2
+ import type { SystemStyleObject } from 'styled-system/types'
3
+
4
+ export interface WithCss {
5
+ /**
6
+ * The CSS styles to apply to the component.
7
+ * Can be a single style object or an array of style objects.
8
+ */
9
+ css?: SystemStyleObject | SystemStyleObject[]
10
+ /**
11
+ * The strict CSS styles to apply to the component. This will override any
12
+ * other styles applied to the component and is only recommended for advanced
13
+ * use cases.
14
+ *
15
+ * In most cases, you should use the `css` prop instead.
16
+ */
17
+ style?: CSSProperties | Record<string, number | string>
18
+ }
19
+
20
+ // types
21
+
1
22
  export type Positions = 'top' | 'right' | 'bottom' | 'left'
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/cta-dialog/provider.tsx"],"sourcesContent":["'use client'\n\nimport {\n useCallback,\n useContext,\n useMemo,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n type ReactNode,\n} from 'react'\nimport { HStack, VStack } from 'styled-system/jsx'\nimport { useCerberusContext } from '../../context/cerberus'\nimport { Show } from '../Show'\nimport { For } from '../for'\nimport { Avatar } from '../avatar/avatar'\nimport {\n Dialog,\n DialogDescription,\n DialogHeading,\n DialogProvider,\n} from '../dialog'\nimport { DialogCloseIconTrigger } from '../dialog/close-icon-trigger'\nimport type { CTAButtonAction, CTAModalActionReturn } from './utils'\nimport {\n CTAModalContext,\n type CTAModalValue,\n type ShowCTAModalOptions,\n} from './context'\nimport { TriggerItem } from './trigger-item'\n\n/**\n * This module provides the provider and hook for the cta modal.\n * @module 'react/cta-modal/provider'\n */\n\n/**\n * Provides a CTA modal to the app.\n * @see https://cerberus.digitalu.design/react/cta-modal\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <CTAModal>\n * <SomeFeatureSection />\n * </CTAModal>\n *\n * // Use the hook to show the cta modal.\n * const cta = useCTAModal()\n *\n * const handleClick = useCallback(async () => {\n * const userConsent = await cta.show({\n * heading: 'Create or copy a Cohort',\n * description:\n * 'Create a new cohort or copy and existing one.',\n * icon: <Copy size={24} />,\n * actions: [\n * {\n * text: 'Create Cohort',\n * onClick: () => {},\n * {\n * text: 'Copy Cohort',\n * onClick: () => {}\n * }\n * })\n * setConsent(userConsent)\n * }, [cta])\n * ```\n */\nexport function CTAModal(props: PropsWithChildren<object>) {\n const [open, setOpen] = useState<boolean>(false)\n const [content, setContent] = useState<ShowCTAModalOptions | null>(null)\n const confirmIcon = content?.icon\n\n const { icons } = useCerberusContext()\n const { confirmModal: FallbackIcon } = icons\n\n const handleShow = useCallback(\n (options: ShowCTAModalOptions) => {\n setContent({ ...options })\n setOpen(true)\n },\n [setOpen],\n )\n\n const handleActionClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n const index = Number(event.currentTarget.getAttribute('data-index'))\n const contentActions = content?.actions as CTAModalActionReturn\n const action = contentActions._actions[index] as CTAButtonAction\n action?.handleClick?.(event)\n setOpen(false)\n },\n [content, setOpen],\n )\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <CTAModalContext.Provider value={value}>\n {props.children}\n\n <DialogProvider open={open} onOpenChange={(e) => setOpen(e.open)}>\n <Dialog size=\"sm\">\n <DialogCloseIconTrigger />\n\n <VStack gap=\"xl\" w=\"full\">\n <VStack alignItems=\"flex-start\" gap=\"md\" w=\"full\">\n <VStack gap=\"lg\" w=\"full\">\n <Avatar\n gradient=\"charon-light\"\n fallback={\n <Show\n when={confirmIcon}\n fallback={<FallbackIcon size={24} />}\n >\n {confirmIcon}\n </Show>\n }\n />\n <DialogHeading>{content?.heading}</DialogHeading>\n <DialogDescription>{content?.description}</DialogDescription>\n </VStack>\n </VStack>\n\n <HStack gap=\"md\" w=\"full\">\n <For each={content?.actions._actions}>\n {(action, index) => (\n <Show\n key={index}\n when={content?.actions?.type === 'btnAction'}\n fallback={\n <TriggerItem asChild>{action as ReactNode}</TriggerItem>\n }\n >\n <TriggerItem data-index={index} onClick={handleActionClick}>\n {(action as CTAButtonAction)?.text}\n </TriggerItem>\n </Show>\n )}\n </For>\n </HStack>\n </VStack>\n </Dialog>\n </DialogProvider>\n </CTAModalContext.Provider>\n )\n}\n\nexport function useCTAModal(): CTAModalValue {\n const context = useContext(CTAModalContext)\n if (context === null) {\n throw new Error('useCTAModal must be used within a CTAModal Provider')\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,QAAQ,cAAc;AAiGrB,cAII,YAJJ;AAxCH,SAAS,SAAS,OAAkC;AACzD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAkB,KAAK;AAC/C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAqC,IAAI;AACvE,QAAM,cAAc,SAAS;AAE7B,QAAM,EAAE,MAAM,IAAI,mBAAmB;AACrC,QAAM,EAAE,cAAc,aAAa,IAAI;AAEvC,QAAM,aAAa;AAAA,IACjB,CAAC,YAAiC;AAChC,iBAAW,EAAE,GAAG,QAAQ,CAAC;AACzB,cAAQ,IAAI;AAAA,IACd;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,oBAAoB;AAAA,IACxB,CAAC,UAAyC;AACxC,YAAM,QAAQ,OAAO,MAAM,cAAc,aAAa,YAAY,CAAC;AACnE,YAAM,iBAAiB,SAAS;AAChC,YAAM,SAAS,eAAe,SAAS,KAAK;AAC5C,cAAQ,cAAc,KAAK;AAC3B,cAAQ,KAAK;AAAA,IACf;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,MAAM;AAAA,IACR;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,SACE,qBAAC,gBAAgB,UAAhB,EAAyB,OACvB;AAAA,UAAM;AAAA,IAEP,oBAAC,kBAAe,MAAY,cAAc,CAAC,MAAM,QAAQ,EAAE,IAAI,GAC7D,+BAAC,UAAO,MAAK,MACX;AAAA,0BAAC,0BAAuB;AAAA,MAExB,qBAAC,UAAO,KAAI,MAAK,GAAE,QACjB;AAAA,4BAAC,UAAO,YAAW,cAAa,KAAI,MAAK,GAAE,QACzC,+BAAC,UAAO,KAAI,MAAK,GAAE,QACjB;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,UAAS;AAAA,cACT,UACE;AAAA,gBAAC;AAAA;AAAA,kBACC,MAAM;AAAA,kBACN,UAAU,oBAAC,gBAAa,MAAM,IAAI;AAAA,kBAEjC;AAAA;AAAA,cACH;AAAA;AAAA,UAEJ;AAAA,UACA,oBAAC,iBAAe,mBAAS,SAAQ;AAAA,UACjC,oBAAC,qBAAmB,mBAAS,aAAY;AAAA,WAC3C,GACF;AAAA,QAEA,oBAAC,UAAO,KAAI,MAAK,GAAE,QACjB,8BAAC,OAAI,MAAM,SAAS,QAAQ,UACzB,WAAC,QAAQ,UACR;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM,SAAS,SAAS,SAAS;AAAA,YACjC,UACE,oBAAC,eAAY,SAAO,MAAE,kBAAoB;AAAA,YAG5C,8BAAC,eAAY,cAAY,OAAO,SAAS,mBACrC,kBAA4B,MAChC;AAAA;AAAA,UARK;AAAA,QASP,GAEJ,GACF;AAAA,SACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,cAA6B;AAC3C,QAAM,UAAU,WAAW,eAAe;AAC1C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/date-picker/range-input.tsx"],"sourcesContent":["'use client'\n\nimport type { DatePickerInputProps } from '@ark-ui/react/date-picker'\nimport { useMemo, type InputHTMLAttributes } from 'react'\nimport { DatePickerParts } from './parts'\nimport { DatePickerTrigger } from './trigger'\n\nexport interface RangePickerInputProps\n extends Omit<DatePickerInputProps, 'defaultValue'> {\n /**\n * The defaultValue to add for the inputs. The first item is the start date\n * and the second item is the end date.\n */\n defaultValue?: [\n InputHTMLAttributes<HTMLInputElement>['defaultValue'],\n InputHTMLAttributes<HTMLInputElement>['defaultValue'],\n ]\n}\n\n/**\n * An abstraction of the DatePicker input that wraps the input and the\n * triggers to open the DatePicker and clear the value.\n * @definition [datePicker docs](https://cerberus.digitalu.design/react/date-picker)\n */\nexport function RangePickerInput(props: RangePickerInputProps) {\n const { defaultValue, ...nativeProps } = props\n\n const startDate = useMemo(() => defaultValue?.[0], [defaultValue])\n const endDate = useMemo(() => defaultValue?.[1], [defaultValue])\n\n return (\n <DatePickerParts.Control data-range>\n <DatePickerTrigger />\n <DatePickerParts.Input\n {...nativeProps}\n data-range-input\n defaultValue={startDate}\n placeholder={props.placeholder ?? 'DD MMM YYYY'}\n maxLength={11}\n index={0}\n />\n <DatePickerParts.Input\n {...nativeProps}\n data-range-input\n defaultValue={endDate}\n data-range-end-input\n placeholder={props.placeholder ?? 'DD MMM YYYY'}\n maxLength={11}\n index={1}\n />\n </DatePickerParts.Control>\n )\n}\n"],"mappings":";;;;;;;;AAGA,SAAS,eAAyC;AA4B9C,SACE,KADF;AAPG,SAAS,iBAAiB,OAA8B;AAC7D,QAAM,EAAE,cAAc,GAAG,YAAY,IAAI;AAEzC,QAAM,YAAY,QAAQ,MAAM,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;AACjE,QAAM,UAAU,QAAQ,MAAM,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;AAE/D,SACE,qBAAC,gBAAgB,SAAhB,EAAwB,cAAU,MACjC;AAAA,wBAAC,qBAAkB;AAAA,IACnB;AAAA,MAAC,gBAAgB;AAAA,MAAhB;AAAA,QACE,GAAG;AAAA,QACJ,oBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,aAAa,MAAM,eAAe;AAAA,QAClC,WAAW;AAAA,QACX,OAAO;AAAA;AAAA,IACT;AAAA,IACA;AAAA,MAAC,gBAAgB;AAAA,MAAhB;AAAA,QACE,GAAG;AAAA,QACJ,oBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,wBAAoB;AAAA,QACpB,aAAa,MAAM,eAAe;AAAA,QAClC,WAAW;AAAA,QACX,OAAO;AAAA;AAAA,IACT;AAAA,KACF;AAEJ;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/date-picker/date-picker.tsx"],"sourcesContent":["import type { DatePickerRootProps } from '@ark-ui/react/date-picker'\nimport { DatePickerParts } from './parts'\n\n/**\n * This module contains an abstraction of the DatePicker.Root primitive.\n * @module 'date-picker/root'\n */\n\n/**\n * DatePicker component is an abstraction of the DatePickerRoot primitive which\n * is the context provider to the DatePicker.\n * @description [Cerberus Docs](https://cerberus.digitalu.design/react/date-picker)\n * @description [Ark Docs](https://ark-ui.com/react/docs/components/date-picker)\n */\nexport function DatePicker(props: DatePickerRootProps) {\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 // ref: https://github.com/chakra-ui/ark/issues/3112#event-16047829195\n\n // const handleFormat = useCallback((value: DateValue) => {\n // return formatISOToMilitary(value.toString())\n // }, [])\n\n return (\n <DatePickerParts.Root\n {...props}\n positioning={{\n placement: 'bottom-start',\n }}\n />\n )\n}\n"],"mappings":";;;;;AAwBI;AAVG,SAAS,WAAW,OAA4B;AASrD,SACE;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACE,GAAG;AAAA,MACJ,aAAa;AAAA,QACX,WAAW;AAAA,MACb;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1,156 +0,0 @@
1
- import {
2
- Dialog
3
- } from "./chunk-Z2KBUTCO.js";
4
- import {
5
- DialogCloseTrigger,
6
- DialogDescription,
7
- DialogHeading,
8
- DialogProvider
9
- } from "./chunk-SSR3CWJZ.js";
10
- import {
11
- Button
12
- } from "./chunk-GB7W3YNU.js";
13
- import {
14
- Avatar
15
- } from "./chunk-CF4TCMJI.js";
16
- import {
17
- useCerberusContext
18
- } from "./chunk-GITT5645.js";
19
- import {
20
- Show
21
- } from "./chunk-VEAC4I3F.js";
22
-
23
- // src/context/confirm-modal.tsx
24
- import {
25
- createContext,
26
- useCallback,
27
- useContext,
28
- useMemo,
29
- useRef,
30
- useState
31
- } from "react";
32
- import { css } from "styled-system/css";
33
- import { HStack, VStack } from "styled-system/jsx";
34
- import { jsx, jsxs } from "react/jsx-runtime";
35
- var ConfirmModalContext = createContext(null);
36
- function ConfirmModal(props) {
37
- const [open, setOpen] = useState(false);
38
- const [content, setContent] = useState(null);
39
- const resolveRef = useRef(null);
40
- const kind = content?.kind ?? "non-destructive";
41
- const { icons } = useCerberusContext();
42
- const { confirmModal: ConfirmIcon } = icons;
43
- const palette = useMemo(
44
- () => kind === "destructive" ? "danger" : "action",
45
- [kind]
46
- );
47
- const handleChoice = useCallback(
48
- (e) => {
49
- const target = e.currentTarget;
50
- if (target.value === "true") {
51
- resolveRef.current?.(true);
52
- }
53
- resolveRef.current?.(false);
54
- setOpen(false);
55
- },
56
- [setOpen]
57
- );
58
- const handleShow = useCallback(
59
- (options) => {
60
- return new Promise((resolve) => {
61
- setContent({ ...options });
62
- setOpen(true);
63
- resolveRef.current = resolve;
64
- });
65
- },
66
- [setOpen, setContent]
67
- );
68
- const value = useMemo(
69
- () => ({
70
- show: handleShow
71
- }),
72
- [handleShow]
73
- );
74
- return /* @__PURE__ */ jsxs(ConfirmModalContext.Provider, { value, children: [
75
- props.children,
76
- /* @__PURE__ */ jsx(DialogProvider, { open, onOpenChange: (e) => setOpen(e.open), children: /* @__PURE__ */ jsx(Dialog, { size: "sm", children: /* @__PURE__ */ jsxs(VStack, { gap: "xl", w: "full", children: [
77
- /* @__PURE__ */ jsxs(VStack, { alignItems: "flex-start", gap: "md", w: "full", children: [
78
- /* @__PURE__ */ jsx(
79
- HStack,
80
- {
81
- alignSelf: "center",
82
- justify: "center",
83
- paddingBlockEnd: "md",
84
- w: "full",
85
- children: /* @__PURE__ */ jsx(
86
- Show,
87
- {
88
- when: palette === "danger",
89
- fallback: /* @__PURE__ */ jsx(
90
- Avatar,
91
- {
92
- gradient: "charon-light",
93
- fallback: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 })
94
- }
95
- ),
96
- children: /* @__PURE__ */ jsx(
97
- Avatar,
98
- {
99
- gradient: "hades-dark",
100
- fallback: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 })
101
- }
102
- )
103
- }
104
- )
105
- }
106
- ),
107
- /* @__PURE__ */ jsx(DialogHeading, { children: content?.heading }),
108
- /* @__PURE__ */ jsx(DialogDescription, { children: content?.description })
109
- ] }),
110
- /* @__PURE__ */ jsxs(HStack, { gap: "4", w: "full", children: [
111
- /* @__PURE__ */ jsx(
112
- Button,
113
- {
114
- autoFocus: true,
115
- className: css({
116
- w: "1/2"
117
- }),
118
- name: "confirm",
119
- onClick: handleChoice,
120
- palette,
121
- value: "true",
122
- children: content?.actionText
123
- }
124
- ),
125
- /* @__PURE__ */ jsx(DialogCloseTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
126
- Button,
127
- {
128
- className: css({
129
- w: "1/2"
130
- }),
131
- name: "cancel",
132
- onClick: handleChoice,
133
- usage: "outlined",
134
- value: "false",
135
- children: content?.cancelText
136
- }
137
- ) })
138
- ] })
139
- ] }) }) })
140
- ] });
141
- }
142
- function useConfirmModal() {
143
- const context = useContext(ConfirmModalContext);
144
- if (context === null) {
145
- throw new Error(
146
- "useConfirmModal must be used within a ConfirmModal Provider"
147
- );
148
- }
149
- return context;
150
- }
151
-
152
- export {
153
- ConfirmModal,
154
- useConfirmModal
155
- };
156
- //# sourceMappingURL=chunk-DHKSNGQX.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/context/confirm-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n type ReactNode,\n} from 'react'\nimport { css } from 'styled-system/css'\nimport { HStack, VStack } from 'styled-system/jsx'\nimport { Button } from '../components/button/button'\nimport { Show } from '../components/Show'\nimport { Avatar } from '../components/avatar/avatar'\nimport {\n Dialog,\n DialogCloseTrigger,\n DialogDescription,\n DialogHeading,\n DialogProvider,\n} from '../components/dialog'\nimport { useCerberusContext } from './cerberus'\n\n/**\n * This module provides a context and hook for the confirm modal.\n * @module\n */\n\nexport interface BaseConfirmOptions {\n /**\n * The heading of the confirm modal.\n */\n heading: string\n /**\n * The text for the action button.\n */\n actionText: string\n /**\n * The text for the cancel button.\n */\n cancelText: string\n}\n\nexport interface DestructiveConfirmOptions extends BaseConfirmOptions {\n /**\n * The kind of confirm modal to show.\n */\n kind?: 'destructive'\n /**\n * The description of the confirm modal. Can only be a string for destructive confirm modals.\n */\n description?: string\n}\n\nexport interface NonDestructiveConfirmModalOptions extends BaseConfirmOptions {\n /**\n * The kind of confirm modal to show.\n * @default 'non-destructive'\n */\n kind?: 'non-destructive'\n /**\n * The description of the confirm modal. Can be a ReactNode for non-destructive kind if you need to display text links.\n * @example\n * ```tsx\n * description: <>Use a Fragment because we put the content within a Paragraph tag.</>\n */\n description?: ReactNode\n}\n\nexport type ShowConfirmModalOptions =\n | NonDestructiveConfirmModalOptions\n | DestructiveConfirmOptions\n\nexport type ShowResult =\n | ((value: boolean | PromiseLike<boolean>) => void)\n | null\n\nexport interface ConfirmModalValue {\n show: (options: ShowConfirmModalOptions) => Promise<boolean>\n}\n\nconst ConfirmModalContext = createContext<ConfirmModalValue | null>(null)\n\nexport type ConfirmModalProviderProps = PropsWithChildren<unknown>\n\n/**\n * Provides a confirm modal to the app.\n * @see https://cerberus.digitalu.design/react/confirm-modal\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <ConfirmModal>\n * <SomeFeatureSection />\n * </ConfirmModal>\n *\n * // Use the hook to show the confirm modal.\n * const confirm = useConfirmModal()\n *\n * const handleClick = useCallback(async () => {\n * const userConsent = await confirm.show({\n * heading: 'Add new payment method?',\n * description:\n * 'This will add a new payment method to your account to be billed for future purchases.',\n * actionText: 'Yes, add payment method',\n * cancelText: 'No, cancel',\n * })\n * setConsent(userConsent)\n * }, [confirm])\n * ```\n */\nexport function ConfirmModal(\n props: PropsWithChildren<ConfirmModalProviderProps>,\n) {\n const [open, setOpen] = useState<boolean>(false)\n const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)\n const resolveRef = useRef<ShowResult>(null)\n const kind = content?.kind ?? 'non-destructive'\n\n const { icons } = useCerberusContext()\n const { confirmModal: ConfirmIcon } = icons\n\n const palette = useMemo(\n () => (kind === 'destructive' ? 'danger' : 'action'),\n [kind],\n )\n\n const handleChoice = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(true)\n }\n resolveRef.current?.(false)\n setOpen(false)\n },\n [setOpen],\n )\n\n const handleShow = useCallback(\n (options: ShowConfirmModalOptions) => {\n return new Promise<boolean>((resolve) => {\n setContent({ ...options })\n setOpen(true)\n resolveRef.current = resolve\n })\n },\n [setOpen, setContent],\n )\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <ConfirmModalContext.Provider value={value}>\n {props.children}\n\n <DialogProvider open={open} onOpenChange={(e) => setOpen(e.open)}>\n <Dialog size=\"sm\">\n <VStack gap=\"xl\" w=\"full\">\n <VStack alignItems=\"flex-start\" gap=\"md\" w=\"full\">\n <HStack\n alignSelf=\"center\"\n justify=\"center\"\n paddingBlockEnd=\"md\"\n w=\"full\"\n >\n <Show\n when={palette === 'danger'}\n fallback={\n <Avatar\n gradient=\"charon-light\"\n fallback={<ConfirmIcon size={24} />}\n />\n }\n >\n <Avatar\n gradient=\"hades-dark\"\n fallback={<ConfirmIcon size={24} />}\n />\n </Show>\n </HStack>\n <DialogHeading>{content?.heading}</DialogHeading>\n <DialogDescription>{content?.description}</DialogDescription>\n </VStack>\n\n <HStack gap=\"4\" w=\"full\">\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <DialogCloseTrigger asChild>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </DialogCloseTrigger>\n </HStack>\n </VStack>\n </Dialog>\n </DialogProvider>\n </ConfirmModalContext.Provider>\n )\n}\n\nexport function useConfirmModal(): ConfirmModalValue {\n const context = useContext(ConfirmModalContext)\n if (context === null) {\n throw new Error(\n 'useConfirmModal must be used within a ConfirmModal Provider',\n )\n }\n return context\n}\n"],"mappings":"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","names":[]}