@cerberus-design/react 1.0.0-rc.4 → 1.0.0-rc.6

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 (210) hide show
  1. package/dist/panda.buildinfo.json +23 -0
  2. package/package.json +9 -4
  3. package/src/components/AnimatingUploadIcon.tsx +0 -83
  4. package/src/components/accordion/index.ts +0 -3
  5. package/src/components/accordion/item-group.tsx +0 -70
  6. package/src/components/accordion/item-indicator.tsx +0 -27
  7. package/src/components/accordion/parts.ts +0 -53
  8. package/src/components/accordion/primitives.tsx +0 -86
  9. package/src/components/admonition/admonition.tsx +0 -62
  10. package/src/components/admonition/index.ts +0 -3
  11. package/src/components/admonition/match-avatar.tsx +0 -52
  12. package/src/components/admonition/parts.ts +0 -53
  13. package/src/components/admonition/primitives.tsx +0 -77
  14. package/src/components/avatar/avatar.tsx +0 -51
  15. package/src/components/avatar/index.ts +0 -5
  16. package/src/components/avatar/parts.ts +0 -37
  17. package/src/components/avatar/primitives.tsx +0 -38
  18. package/src/components/button/button.tsx +0 -62
  19. package/src/components/button/index.ts +0 -3
  20. package/src/components/button/parts.ts +0 -32
  21. package/src/components/button/primitives.tsx +0 -41
  22. package/src/components/carousel/carousel.tsx +0 -55
  23. package/src/components/carousel/index.ts +0 -3
  24. package/src/components/carousel/parts.ts +0 -71
  25. package/src/components/carousel/primitives.ts +0 -58
  26. package/src/components/checkbox/checkbox-icon.tsx +0 -39
  27. package/src/components/checkbox/checkbox.tsx +0 -42
  28. package/src/components/checkbox/index.ts +0 -3
  29. package/src/components/checkbox/parts.ts +0 -59
  30. package/src/components/checkbox/primitives.tsx +0 -77
  31. package/src/components/circular-progress/circular-progress.tsx +0 -49
  32. package/src/components/circular-progress/index.ts +0 -2
  33. package/src/components/circular-progress/primitives.ts +0 -80
  34. package/src/components/clipboard/copy-indicator.tsx +0 -22
  35. package/src/components/clipboard/copy-text.tsx +0 -13
  36. package/src/components/clipboard/index.ts +0 -2
  37. package/src/components/clipboard/parts.ts +0 -74
  38. package/src/components/clipboard/primitives.ts +0 -56
  39. package/src/components/clipboard/trigger.tsx +0 -14
  40. package/src/components/collapsible/index.ts +0 -2
  41. package/src/components/collapsible/parts.ts +0 -53
  42. package/src/components/collapsible/primitives.tsx +0 -53
  43. package/src/components/combobox/combobox.tsx +0 -67
  44. package/src/components/combobox/index.ts +0 -6
  45. package/src/components/combobox/item-group.tsx +0 -19
  46. package/src/components/combobox/item.tsx +0 -30
  47. package/src/components/combobox/parts.ts +0 -101
  48. package/src/components/combobox/primitives.tsx +0 -146
  49. package/src/components/combobox/use-stateful-collection.ts +0 -65
  50. package/src/components/cta-dialog/context.tsx +0 -38
  51. package/src/components/cta-dialog/index.ts +0 -2
  52. package/src/components/cta-dialog/provider.tsx +0 -186
  53. package/src/components/cta-dialog/trigger-item.tsx +0 -54
  54. package/src/components/cta-dialog/utils.ts +0 -57
  55. package/src/components/date-picker/calendar.tsx +0 -47
  56. package/src/components/date-picker/content.tsx +0 -21
  57. package/src/components/date-picker/date-picker.tsx +0 -20
  58. package/src/components/date-picker/day-view.tsx +0 -82
  59. package/src/components/date-picker/index.ts +0 -16
  60. package/src/components/date-picker/input.tsx +0 -26
  61. package/src/components/date-picker/month-view.tsx +0 -49
  62. package/src/components/date-picker/parts.ts +0 -167
  63. package/src/components/date-picker/primitives.tsx +0 -235
  64. package/src/components/date-picker/range-input.tsx +0 -38
  65. package/src/components/date-picker/trigger.tsx +0 -28
  66. package/src/components/date-picker/view-control-group.tsx +0 -54
  67. package/src/components/date-picker/year-view.tsx +0 -47
  68. package/src/components/dialog/close-icon-trigger.tsx +0 -36
  69. package/src/components/dialog/dialog.tsx +0 -42
  70. package/src/components/dialog/index.ts +0 -8
  71. package/src/components/dialog/parts.ts +0 -71
  72. package/src/components/dialog/primitives.tsx +0 -83
  73. package/src/components/feature-flag/feature-flag.tsx +0 -21
  74. package/src/components/feature-flag/index.ts +0 -1
  75. package/src/components/field/error-text.tsx +0 -19
  76. package/src/components/field/field.tsx +0 -93
  77. package/src/components/field/helper-text.tsx +0 -20
  78. package/src/components/field/index.ts +0 -7
  79. package/src/components/field/input.tsx +0 -47
  80. package/src/components/field/parts.ts +0 -77
  81. package/src/components/field/primitives.tsx +0 -135
  82. package/src/components/field/start-indicator.tsx +0 -23
  83. package/src/components/field/status-indicator.tsx +0 -58
  84. package/src/components/fieldset/fieldset.tsx +0 -54
  85. package/src/components/fieldset/index.ts +0 -3
  86. package/src/components/fieldset/parts.ts +0 -47
  87. package/src/components/fieldset/primitives.tsx +0 -48
  88. package/src/components/file-upload/file-status.tsx +0 -271
  89. package/src/components/file-upload/file-uploader.tsx +0 -60
  90. package/src/components/file-upload/helpers.ts +0 -28
  91. package/src/components/file-upload/img-preview.tsx +0 -41
  92. package/src/components/file-upload/index.ts +0 -6
  93. package/src/components/file-upload/parts.tsx +0 -132
  94. package/src/components/file-upload/primitives.ts +0 -161
  95. package/src/components/file-upload/utils.ts +0 -20
  96. package/src/components/for/for.tsx +0 -38
  97. package/src/components/for/index.ts +0 -1
  98. package/src/components/group/index.ts +0 -1
  99. package/src/components/group/primitives.ts +0 -7
  100. package/src/components/icon-button/button.tsx +0 -41
  101. package/src/components/icon-button/index.tsx +0 -2
  102. package/src/components/icon-button/primitives.ts +0 -19
  103. package/src/components/menu/index.ts +0 -2
  104. package/src/components/menu/menu.tsx +0 -144
  105. package/src/components/menu/primitives.ts +0 -84
  106. package/src/components/notifications/center.tsx +0 -88
  107. package/src/components/notifications/close-trigger.tsx +0 -21
  108. package/src/components/notifications/index.ts +0 -5
  109. package/src/components/notifications/match-icon.tsx +0 -41
  110. package/src/components/notifications/parts.ts +0 -53
  111. package/src/components/notifications/primitives.tsx +0 -66
  112. package/src/components/notifications/toaster.ts +0 -13
  113. package/src/components/notifications/types.ts +0 -44
  114. package/src/components/number-input/decrement-trigger.tsx +0 -16
  115. package/src/components/number-input/increment-trigger.tsx +0 -16
  116. package/src/components/number-input/index.ts +0 -3
  117. package/src/components/number-input/input.tsx +0 -33
  118. package/src/components/number-input/parts.ts +0 -65
  119. package/src/components/number-input/primitives.tsx +0 -74
  120. package/src/components/pagination/compact.tsx +0 -25
  121. package/src/components/pagination/index.ts +0 -6
  122. package/src/components/pagination/item-list.tsx +0 -34
  123. package/src/components/pagination/item.tsx +0 -6
  124. package/src/components/pagination/pagination.tsx +0 -53
  125. package/src/components/pagination/parts.ts +0 -65
  126. package/src/components/pagination/primitives.ts +0 -41
  127. package/src/components/pagination/triggers.tsx +0 -55
  128. package/src/components/pin-input/index.ts +0 -3
  129. package/src/components/pin-input/input.tsx +0 -22
  130. package/src/components/pin-input/parts.ts +0 -53
  131. package/src/components/pin-input/primitives.tsx +0 -46
  132. package/src/components/portal/index.ts +0 -1
  133. package/src/components/portal/portal.tsx +0 -28
  134. package/src/components/progress/index.ts +0 -2
  135. package/src/components/progress/primitives.ts +0 -37
  136. package/src/components/progress/progress-bar.tsx +0 -80
  137. package/src/components/radio/index.ts +0 -3
  138. package/src/components/radio/parts.ts +0 -65
  139. package/src/components/radio/primitives.tsx +0 -92
  140. package/src/components/radio/radio.tsx +0 -35
  141. package/src/components/rating/index.ts +0 -8
  142. package/src/components/rating/parts.tsx +0 -65
  143. package/src/components/rating/primitives.tsx +0 -64
  144. package/src/components/rating/rating.tsx +0 -75
  145. package/src/components/select/index.ts +0 -5
  146. package/src/components/select/option-group.tsx +0 -32
  147. package/src/components/select/option.tsx +0 -42
  148. package/src/components/select/parts.ts +0 -113
  149. package/src/components/select/primitives.tsx +0 -147
  150. package/src/components/select/select.tsx +0 -110
  151. package/src/components/show/index.ts +0 -1
  152. package/src/components/show/show.tsx +0 -48
  153. package/src/components/spinner/index.ts +0 -1
  154. package/src/components/spinner/spinner.tsx +0 -81
  155. package/src/components/split-button/button.tsx +0 -63
  156. package/src/components/split-button/index.tsx +0 -1
  157. package/src/components/switch/index.ts +0 -3
  158. package/src/components/switch/parts.ts +0 -53
  159. package/src/components/switch/primitives.tsx +0 -51
  160. package/src/components/switch/switch-indicator.tsx +0 -9
  161. package/src/components/switch/switch.tsx +0 -27
  162. package/src/components/table/index.ts +0 -3
  163. package/src/components/table/parts.ts +0 -83
  164. package/src/components/table/primitives.tsx +0 -115
  165. package/src/components/table/table.tsx +0 -73
  166. package/src/components/tabs/index.ts +0 -3
  167. package/src/components/tabs/parts.ts +0 -53
  168. package/src/components/tabs/primitives.tsx +0 -47
  169. package/src/components/tabs/tabs.tsx +0 -48
  170. package/src/components/tag/closable.tsx +0 -47
  171. package/src/components/tag/index.ts +0 -2
  172. package/src/components/tag/primitives.ts +0 -19
  173. package/src/components/tag/tag.tsx +0 -39
  174. package/src/components/text/index.ts +0 -1
  175. package/src/components/text/text.tsx +0 -55
  176. package/src/components/theme/index.ts +0 -1
  177. package/src/components/theme/theme.tsx +0 -34
  178. package/src/components/toggle/index.ts +0 -2
  179. package/src/components/toggle/parts.ts +0 -32
  180. package/src/components/toggle/primitives.tsx +0 -27
  181. package/src/components/tooltip/index.ts +0 -3
  182. package/src/components/tooltip/parts.ts +0 -59
  183. package/src/components/tooltip/primitives.ts +0 -56
  184. package/src/components/tooltip/tooltip.tsx +0 -46
  185. package/src/config/defineIcons.ts +0 -24
  186. package/src/config/icons/checkbox.icons.tsx +0 -98
  187. package/src/config/icons/default.ts +0 -69
  188. package/src/config/icons/pinned.icons.tsx +0 -31
  189. package/src/config/icons/sort.icons.tsx +0 -19
  190. package/src/config/index.ts +0 -41
  191. package/src/config/types.ts +0 -53
  192. package/src/context/cerberus.tsx +0 -53
  193. package/src/context/confirm-modal.tsx +0 -276
  194. package/src/context/feature-flags.tsx +0 -63
  195. package/src/context/field.tsx +0 -70
  196. package/src/context/navMenu.tsx +0 -89
  197. package/src/context/prompt-modal.tsx +0 -315
  198. package/src/context/theme.tsx +0 -83
  199. package/src/hooks/useModal.ts +0 -63
  200. package/src/hooks/useRootColors.ts +0 -72
  201. package/src/hooks/useTheme.ts +0 -121
  202. package/src/index.client.ts +0 -30
  203. package/src/index.ts +0 -76
  204. package/src/system/factory.ts +0 -32
  205. package/src/system/index.ts +0 -47
  206. package/src/system/primitive-factory.tsx +0 -180
  207. package/src/system/types.ts +0 -88
  208. package/src/types.ts +0 -23
  209. package/src/utils/index.ts +0 -51
  210. package/src/utils/localStorage.ts +0 -28
@@ -1,24 +0,0 @@
1
- import { defaultIcons } from './icons/default'
2
- import type { DefinedIcons, IconType } from './types'
3
-
4
- /**
5
- * Defines the icons that will be used in Cerberus React components via the
6
- * CerberusProvider.
7
- * @param icons The icons that will be used in Cerberus React components.
8
- * @returns Icons object compatible with the CerberusProvider SystemConfig.
9
- * @example
10
- * ```tsx
11
- * const icons = defineIcons({
12
- * accordionIndicator: MyAccordionIndicatorIcon,
13
- * ...
14
- * })
15
- * ```
16
- */
17
- export function defineIcons<T extends IconType>(
18
- icons: DefinedIcons<T>,
19
- ): Required<DefinedIcons<T>> {
20
- return {
21
- ...defaultIcons,
22
- ...icons,
23
- } as Required<DefinedIcons<T>>
24
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * This module contains substitute icons for the Checkbox component.
3
- * @module
4
- */
5
-
6
- /**
7
- * Checkmark icon for Checkbox component
8
- */
9
- export function CheckmarkIcon() {
10
- return (
11
- <svg
12
- aria-hidden="true"
13
- xmlns="http://www.w3.org/2000/svg"
14
- fill="none"
15
- role="img"
16
- viewBox="0 0 24 24"
17
- >
18
- <path
19
- fill="currentColor"
20
- d="M9.714 18 4 12.335l1.818-1.764 3.896 3.824L18.181 6 20 7.803 9.714 18Z"
21
- />
22
- </svg>
23
- )
24
- }
25
-
26
- /**
27
- * Indeterminate icon for Checkbox component
28
- */
29
- export function IndeterminateIcon() {
30
- return (
31
- <svg
32
- aria-hidden="true"
33
- xmlns="http://www.w3.org/2000/svg"
34
- role="img"
35
- fill="none"
36
- viewBox="0 0 24 24"
37
- >
38
- <path fill="currentColor" d="M4 11h16v2.667H4z" />
39
- </svg>
40
- )
41
- }
42
-
43
- /**
44
- * Animated checkmark icon for Clipboard.Indicator component
45
- */
46
- export function AnimatedCheckmarkIcon() {
47
- return (
48
- <svg
49
- aria-hidden="true"
50
- role="img"
51
- xmlns="http://www.w3.org/2000/svg"
52
- viewBox="0 0 24 24"
53
- >
54
- <path
55
- fill="none"
56
- stroke="currentColor"
57
- strokeDasharray={24}
58
- strokeDashoffset={24}
59
- strokeLinejoin="round"
60
- strokeWidth={2}
61
- d="M5 11l6 6l10 -10"
62
- >
63
- <animate
64
- fill="freeze"
65
- attributeName="stroke-dashoffset"
66
- dur="0.28s"
67
- values="24;0"
68
- ></animate>
69
- </path>
70
- </svg>
71
- )
72
- }
73
-
74
- /**
75
- * Copy icon for Clipboard.Indicator component
76
- */
77
- export function CopyIcon() {
78
- return (
79
- <svg
80
- xmlns="http://www.w3.org/2000/svg"
81
- aria-hidden="true"
82
- role="img"
83
- viewBox="0 0 32 32"
84
- >
85
- <title>copy</title>
86
- <path
87
- d="M28 10v18H10V10zm0-2H10a2 2 0 0 0-2 2v18a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V10a2 2 0 0 0-2-2"
88
- fill="currentColor"
89
- />
90
- <path d="M4 18H2V4a2 2 0 0 1 2-2h14v2H4Z" fill="currentColor" />
91
- <path
92
- fill="none"
93
- d="M0 0h32v32H0z"
94
- data-name="&lt;Transparent Rectangle&gt;"
95
- />
96
- </svg>
97
- )
98
- }
@@ -1,69 +0,0 @@
1
- import {
2
- Calendar,
3
- CaretDown,
4
- Checkmark,
5
- CheckmarkOutline,
6
- ChevronDown,
7
- ChevronLeft,
8
- ChevronRight,
9
- ChevronUp,
10
- Close,
11
- CloudUpload,
12
- Information,
13
- OverflowMenuVertical,
14
- Restart,
15
- TrashCan,
16
- UserFilled,
17
- Warning,
18
- WarningAlt,
19
- WarningFilled,
20
- } from '@carbon/icons-react'
21
- import { AnimatingUploadIcon } from '../../components/AnimatingUploadIcon'
22
- import { DefinedIcons } from '../types'
23
- import { CheckmarkIcon, IndeterminateIcon } from './checkbox.icons'
24
- import {
25
- PinLeftFilledIcon,
26
- PinLeftIcon,
27
- PinRightFilledIcon,
28
- PinRightIcon,
29
- } from './pinned.icons'
30
- import { SortAscIcon, SortDescIcon } from './sort.icons'
31
-
32
- /**
33
- * Fallback icons when there is no custom set provided by the user.
34
- */
35
- export const defaultIcons: Required<DefinedIcons> = {
36
- accordionIndicator: ChevronDown,
37
- avatar: UserFilled,
38
- calendar: Calendar,
39
- calendarPrev: ChevronLeft,
40
- calendarNext: ChevronRight,
41
- caretDown: CaretDown,
42
- checkbox: CheckmarkIcon,
43
- close: Close,
44
- confirmModal: Information,
45
- dangerNotification: WarningFilled,
46
- decrement: ChevronDown,
47
- delete: TrashCan,
48
- fileUploader: AnimatingUploadIcon,
49
- increment: ChevronUp,
50
- indeterminate: IndeterminateIcon,
51
- infoNotification: Information,
52
- invalid: WarningFilled,
53
- invalidAlt: Warning,
54
- moreVertical: OverflowMenuVertical,
55
- pinLeft: PinLeftIcon,
56
- pinLeftFilled: PinLeftFilledIcon,
57
- pinRight: PinRightIcon,
58
- pinRightFilled: PinRightFilledIcon,
59
- promptModal: Information,
60
- redo: Restart,
61
- selectArrow: ChevronDown,
62
- selectChecked: Checkmark,
63
- sortAsc: SortAscIcon,
64
- sortDesc: SortDescIcon,
65
- successNotification: CheckmarkOutline,
66
- toggleChecked: Checkmark,
67
- waitingFileUploader: CloudUpload,
68
- warningNotification: WarningAlt,
69
- }
@@ -1,31 +0,0 @@
1
- import { CarbonIconProps, Pin, PinFilled } from '@carbon/icons-react'
2
- import { PropsWithChildren } from 'react'
3
- import { Box } from 'styled-system/jsx'
4
-
5
- export function PinLeftIcon(props: CarbonIconProps) {
6
- return <Pin {...props} />
7
- }
8
-
9
- export function PinLeftFilledIcon(props: CarbonIconProps) {
10
- return <PinFilled {...props} />
11
- }
12
-
13
- export function PinRightIcon(props: CarbonIconProps) {
14
- return (
15
- <FlippedContainer>
16
- <Pin {...props} />
17
- </FlippedContainer>
18
- )
19
- }
20
-
21
- export function PinRightFilledIcon(props: CarbonIconProps) {
22
- return (
23
- <FlippedContainer>
24
- <PinFilled {...props} />
25
- </FlippedContainer>
26
- )
27
- }
28
-
29
- function FlippedContainer(props: PropsWithChildren) {
30
- return <Box transform="scaleX(-1)" {...props} />
31
- }
@@ -1,19 +0,0 @@
1
- import { CarbonIconProps, SortAscending } from '@carbon/icons-react'
2
- import { PropsWithChildren } from 'react'
3
- import { Box } from 'styled-system/jsx'
4
-
5
- export function SortAscIcon(props: CarbonIconProps) {
6
- return <SortAscending {...props} />
7
- }
8
-
9
- export function SortDescIcon(props: CarbonIconProps) {
10
- return (
11
- <FlippedContainer>
12
- <SortAscending {...props} />
13
- </FlippedContainer>
14
- )
15
- }
16
-
17
- function FlippedContainer(props: PropsWithChildren) {
18
- return <Box transform="rotate(180deg)" {...props} />
19
- }
@@ -1,41 +0,0 @@
1
- import { defaultIcons } from './icons/default'
2
- import type { SystemConfig } from './types'
3
-
4
- /**
5
- * Create a system configuration object to be used on the CerberusProvider.
6
- * @param options The system configuration options you want to customize.
7
- * @returns A CerberusProvider-compatible system configuration object.
8
- * @example
9
- * ```tsx
10
- * const icons = defineIcons({
11
- * accordionIndicator: MyAccordionIndicatorIcon,
12
- * ...
13
- * })
14
- * const config = makeSystemConfig({
15
- * icons,
16
- * })
17
- *
18
- * // In your app
19
- * <CerberusProvider config={config}>
20
- * <App />
21
- * </CerberusProvider>
22
- * ```
23
- */
24
- export function makeSystemConfig(options?: SystemConfig): SystemConfig {
25
- if (!options) {
26
- return {
27
- icons: defaultIcons,
28
- }
29
- }
30
-
31
- return {
32
- ...options,
33
- icons: {
34
- ...defaultIcons,
35
- ...options.icons,
36
- },
37
- }
38
- }
39
-
40
- export * from './defineIcons'
41
- export * from './types'
@@ -1,53 +0,0 @@
1
- import type { ElementType } from 'react'
2
-
3
- /**
4
- * This module contains the types for the Cerberus React configuration.
5
- * @module config.types
6
- */
7
-
8
- export interface SystemConfig {
9
- /**
10
- * The icons that will be used in Cerberus React components.
11
- */
12
- icons: Required<DefinedIcons>
13
- }
14
-
15
- export interface DefinedIcons<T extends IconType = IconType> {
16
- accordionIndicator?: T
17
- avatar?: T
18
- calendar?: T
19
- calendarPrev?: T
20
- calendarNext?: T
21
- caretDown?: T
22
- checkbox?: T
23
- close?: T
24
- confirmModal?: T
25
- decrement?: T
26
- delete?: T
27
- dangerNotification?: T
28
- fileUploader?: T
29
- indeterminate?: T
30
- increment?: T
31
- infoNotification?: T
32
- invalid?: T
33
- invalidAlt?: T
34
- moreVertical?: T
35
- pinLeft?: T
36
- pinLeftFilled?: T
37
- pinRight?: T
38
- pinRightFilled?: T
39
- promptModal?: T
40
- redo?: T
41
- selectArrow?: T
42
- selectChecked?: T
43
- sortAsc?: T
44
- sortDesc?: T
45
- successNotification?: T
46
- toggleChecked?: T
47
- waitingFileUploader?: T
48
- warningNotification?: T
49
- }
50
-
51
- // types
52
-
53
- export type IconType = ElementType
@@ -1,53 +0,0 @@
1
- 'use client'
2
-
3
- import {
4
- createContext,
5
- useContext,
6
- useMemo,
7
- type PropsWithChildren,
8
- } from 'react'
9
- import { makeSystemConfig, type SystemConfig } from '../config'
10
-
11
- /**
12
- * This module contains the Cerberus configuration context and helpers.
13
- * @module context/cerberus
14
- */
15
-
16
- type CerberusContextValue = SystemConfig
17
-
18
- const CerberusContext = createContext<CerberusContextValue | null>(null)
19
-
20
- interface CerberusProviderProps {
21
- config?: SystemConfig
22
- }
23
-
24
- /**
25
- * Cerberus configuration provider.
26
- * @param props.config The Cerberus configuration created with
27
- * `makeSystemConfig` helper.
28
- */
29
- export function CerberusProvider(
30
- props: PropsWithChildren<CerberusProviderProps>,
31
- ) {
32
- const value = useMemo(() => {
33
- return props.config || makeSystemConfig()
34
- }, [props.config])
35
-
36
- return (
37
- <CerberusContext.Provider value={value}>
38
- {props.children}
39
- </CerberusContext.Provider>
40
- )
41
- }
42
-
43
- /**
44
- * Returns the Cerberus configuration context.
45
- * @returns The Cerberus configuration context.
46
- */
47
- export function useCerberusContext() {
48
- const context = useContext(CerberusContext)
49
- if (!context) {
50
- throw new Error('useCerberus must be used within a CerberusProvider')
51
- }
52
- return context
53
- }
@@ -1,276 +0,0 @@
1
- 'use client'
2
-
3
- import {
4
- createContext,
5
- useCallback,
6
- useContext,
7
- useMemo,
8
- useRef,
9
- useState,
10
- type MouseEvent,
11
- type PropsWithChildren,
12
- type ReactNode,
13
- } from 'react'
14
- import { css } from 'styled-system/css'
15
- import { HStack, VStack } from 'styled-system/jsx'
16
- import { Button } from '../components/button/button'
17
- import { Show } from '../components/show/index'
18
- import { Avatar } from '../components/avatar/avatar'
19
- import {
20
- Dialog,
21
- DialogCloseTrigger,
22
- DialogDescription,
23
- DialogHeading,
24
- DialogProvider,
25
- type OpenChangeDetails,
26
- type DialogRootProps,
27
- } from '../components/dialog'
28
- import { useCerberusContext } from './cerberus'
29
-
30
- /**
31
- * This module provides a context and hook for the confirm modal.
32
- * @module
33
- */
34
-
35
- export interface BaseConfirmOptions {
36
- /**
37
- * The heading of the confirm modal.
38
- */
39
- heading: string
40
- /**
41
- * The text for the action button.
42
- */
43
- actionText: string
44
- /**
45
- * The text for the cancel button.
46
- */
47
- cancelText: string
48
- /**
49
- * Whether to show the avatar icon at the top of the modal.
50
- * @default true
51
- */
52
- showAvatar?: boolean
53
- }
54
-
55
- export interface DestructiveConfirmOptions extends BaseConfirmOptions {
56
- /**
57
- * The kind of confirm modal to show.
58
- */
59
- kind?: 'destructive'
60
- /**
61
- * The description of the confirm modal. Can only be a string for destructive confirm modals.
62
- */
63
- description?: ReactNode
64
- }
65
-
66
- export interface NonDestructiveConfirmModalOptions extends BaseConfirmOptions {
67
- /**
68
- * The kind of confirm modal to show.
69
- * @default 'non-destructive'
70
- */
71
- kind?: 'non-destructive'
72
- /**
73
- * The description of the confirm modal. Can be a ReactNode for non-destructive kind if you need to display text links.
74
- * @example
75
- * ```tsx
76
- * description: <>Use a Fragment because we put the content within a Paragraph tag.</>
77
- */
78
- description?: ReactNode
79
- }
80
-
81
- export type ShowConfirmModalOptions =
82
- | NonDestructiveConfirmModalOptions
83
- | DestructiveConfirmOptions
84
-
85
- export type ShowResult = ((value: boolean | null) => void) | null
86
-
87
- export interface ConfirmModalValue {
88
- show: (options: ShowConfirmModalOptions) => Promise<boolean | null>
89
- }
90
-
91
- const ConfirmModalContext = createContext<ConfirmModalValue | null>(null)
92
-
93
- export type ConfirmModalProviderProps = PropsWithChildren<DialogRootProps>
94
-
95
- /**
96
- * Provides a confirm modal to the app.
97
- * @see https://cerberus.digitalu.design/react/confirm-modal
98
- * @example
99
- * ```tsx
100
- * // Wrap the Provider around the root of the feature.
101
- * <ConfirmModal>
102
- * <SomeFeatureSection />
103
- * </ConfirmModal>
104
- *
105
- * // Use the hook to show the confirm modal.
106
- * const confirm = useConfirmModal()
107
- *
108
- * const handleClick = useCallback(async () => {
109
- * const userConsent = await confirm.show({
110
- * heading: 'Add new payment method?',
111
- * description:
112
- * 'This will add a new payment method to your account to be billed for future purchases.',
113
- * actionText: 'Yes, add payment method',
114
- * cancelText: 'No, cancel',
115
- * })
116
- * setConsent(userConsent)
117
- * }, [confirm])
118
- * ```
119
- */
120
- export function ConfirmModal(
121
- props: PropsWithChildren<ConfirmModalProviderProps>,
122
- ) {
123
- const { children, ...rootProps } = props
124
- const [open, setOpen] = useState<boolean>(false)
125
- const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)
126
-
127
- const resolveRef = useRef<ShowResult>(null)
128
-
129
- const showAvatar = content?.showAvatar ?? true
130
- const kind = content?.kind ?? 'non-destructive'
131
-
132
- const { icons } = useCerberusContext()
133
- const { confirmModal: ConfirmIcon } = icons
134
-
135
- const palette = useMemo(
136
- () => (kind === 'destructive' ? 'danger' : 'action'),
137
- [kind],
138
- )
139
-
140
- const handleChoice = useCallback(
141
- (e: MouseEvent<HTMLButtonElement>) => {
142
- const target = e.currentTarget as HTMLButtonElement
143
- if (target.value === 'true') {
144
- resolveRef.current?.(true)
145
- }
146
- resolveRef.current?.(false)
147
- setOpen(false)
148
- },
149
- [setOpen],
150
- )
151
-
152
- const handleShow = useCallback(
153
- (options: ShowConfirmModalOptions) => {
154
- return new Promise<boolean | null>((resolve) => {
155
- setContent({ ...options })
156
- setOpen(true)
157
- resolveRef.current = resolve
158
- })
159
- },
160
- [setOpen, setContent],
161
- )
162
-
163
- const handleOpenChange = useCallback(
164
- ({ open }: OpenChangeDetails) => {
165
- setOpen(open)
166
- if (!open) {
167
- resolveRef.current?.(null)
168
- resolveRef.current = null
169
- }
170
- },
171
- [setOpen],
172
- )
173
-
174
- const value = useMemo(
175
- () => ({
176
- show: handleShow,
177
- }),
178
- [handleShow],
179
- )
180
-
181
- return (
182
- <ConfirmModalContext.Provider value={value}>
183
- {children}
184
-
185
- <DialogProvider
186
- lazyMount
187
- open={open}
188
- onOpenChange={handleOpenChange}
189
- unmountOnExit
190
- {...rootProps}
191
- >
192
- <Dialog
193
- size="sm"
194
- style={{
195
- '--dialog-content-min-h': 'auto',
196
- }}
197
- >
198
- <VStack
199
- alignItems="flex-start"
200
- gap="md"
201
- justify="space-between"
202
- w="full"
203
- >
204
- <Show when={showAvatar}>
205
- <HStack
206
- alignSelf="center"
207
- justify="center"
208
- paddingBlockEnd="md"
209
- w="full"
210
- >
211
- <Show
212
- when={palette === 'danger'}
213
- fallback={
214
- <Avatar
215
- gradient="charon-light"
216
- fallback={<ConfirmIcon size={24} />}
217
- />
218
- }
219
- >
220
- <Avatar
221
- gradient="hades-dark"
222
- fallback={<ConfirmIcon size={24} />}
223
- />
224
- </Show>
225
- </HStack>
226
- </Show>
227
-
228
- <DialogHeading>{content?.heading}</DialogHeading>
229
-
230
- <Show when={content?.description}>
231
- <DialogDescription>{content?.description}</DialogDescription>
232
- </Show>
233
-
234
- <HStack gap="md" pt="md" w="full">
235
- <Button
236
- autoFocus
237
- className={css({
238
- w: '1/2',
239
- })}
240
- name="confirm"
241
- onClick={handleChoice}
242
- palette={palette}
243
- value="true"
244
- >
245
- {content?.actionText}
246
- </Button>
247
- <DialogCloseTrigger asChild>
248
- <Button
249
- className={css({
250
- w: '1/2',
251
- })}
252
- name="cancel"
253
- onClick={handleChoice}
254
- usage="outlined"
255
- value="false"
256
- >
257
- {content?.cancelText}
258
- </Button>
259
- </DialogCloseTrigger>
260
- </HStack>
261
- </VStack>
262
- </Dialog>
263
- </DialogProvider>
264
- </ConfirmModalContext.Provider>
265
- )
266
- }
267
-
268
- export function useConfirmModal(): ConfirmModalValue {
269
- const context = useContext(ConfirmModalContext)
270
- if (context === null) {
271
- throw new Error(
272
- 'useConfirmModal must be used within a ConfirmModal Provider',
273
- )
274
- }
275
- return context
276
- }