@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,135 +0,0 @@
1
- import {
2
- Field,
3
- type FieldHelperTextProps as ArkFieldHelperTextProps,
4
- type FieldInputProps as ArkFieldInputProps,
5
- type FieldLabelProps as ArkFieldLabelProps,
6
- type FieldRootProps as ArkFieldRootProps,
7
- type FieldTextareaProps as ArkFieldTextareaProps,
8
- type FieldRequiredIndicatorProps as ArkFieldRequiredIndicatorProps,
9
- } from '@ark-ui/react/field'
10
- import { ark, type HTMLArkProps } from '@ark-ui/react'
11
- import { field, type FieldVariantProps } from 'styled-system/recipes'
12
- import { css, cx } from 'styled-system/css'
13
- import {
14
- createCerberusPrimitive,
15
- type CerberusPrimitiveProps,
16
- } from '../../system/index'
17
- import { CerberusFieldInput } from './input'
18
- import { CerberusFieldErrorText } from './error-text'
19
-
20
- /**
21
- * This module contains all the primitives of the Field component.
22
- * @module 'field'
23
- */
24
-
25
- const { withSlotRecipe, withNoRecipe } = createCerberusPrimitive(field)
26
-
27
- // Root
28
-
29
- export type FieldRootProps = CerberusPrimitiveProps<
30
- ArkFieldRootProps & FieldVariantProps
31
- >
32
- export const FieldRoot = withSlotRecipe(Field.Root, 'root')
33
-
34
- // Label
35
-
36
- function FieldLabelEl(props: FieldLabelProps) {
37
- const { children, hideLabel, className, ...nativeProps } = props
38
- return (
39
- <Field.Label
40
- {...nativeProps}
41
- className={cx(className, hideLabel && css({ srOnly: true }))}
42
- >
43
- {children}
44
- <Field.RequiredIndicator>(required)</Field.RequiredIndicator>
45
- </Field.Label>
46
- )
47
- }
48
-
49
- export type FieldLabelProps = CerberusPrimitiveProps<ArkFieldLabelProps> & {
50
- /**
51
- * Whether to hide the label visually while keeping it accessible to screen readers.
52
- */
53
- hideLabel?: boolean
54
- }
55
- export const FieldLabel = withSlotRecipe(FieldLabelEl, 'label')
56
-
57
- // Required Indicator
58
-
59
- function FieldRequiredIndicatorEl(props: FieldRequiredIndicatorProps) {
60
- return (
61
- <Field.RequiredIndicator {...props}>(required)</Field.RequiredIndicator>
62
- )
63
- }
64
-
65
- export type FieldRequiredIndicatorProps =
66
- CerberusPrimitiveProps<ArkFieldRequiredIndicatorProps>
67
- export const FieldRequiredIndicator = withNoRecipe(FieldRequiredIndicatorEl)
68
-
69
- // Input
70
-
71
- export type FieldInputRootProps = CerberusPrimitiveProps<
72
- HTMLArkProps<'div'> & FieldVariantProps
73
- >
74
- export const FieldInputRoot = withSlotRecipe(ark.div, 'inputRoot')
75
-
76
- export type FieldInputProps = CerberusPrimitiveProps<
77
- ArkFieldInputProps & FieldVariantProps
78
- >
79
- export const FieldInput = withSlotRecipe(Field.Input, 'input')
80
-
81
- // Helper Text
82
-
83
- export type FieldHelperTextProps =
84
- CerberusPrimitiveProps<ArkFieldHelperTextProps>
85
- export const FieldHelperText = withSlotRecipe(Field.HelperText, 'helperText')
86
-
87
- // Error Text
88
-
89
- export type FieldErrorTextProps =
90
- CerberusPrimitiveProps<ArkFieldHelperTextProps>
91
- export const FieldErrorText = withSlotRecipe(
92
- CerberusFieldErrorText,
93
- 'errorText',
94
- )
95
-
96
- // Textarea
97
-
98
- export type FieldTextareaProps = CerberusPrimitiveProps<ArkFieldTextareaProps>
99
- export const FieldTextarea = withSlotRecipe(Field.Textarea, 'textarea')
100
-
101
- /**
102
- * A named export for the FieldInput component.
103
- * @description [Field Docs](https://cerberus.digitalu.design/react/field)
104
- * @example
105
- * ```tsx
106
- * import { Input } from '@cerberus/react'
107
- *
108
- * <Field
109
- * label="Enter your email"
110
- * helperText="We'll never share your email with anyone else."
111
- * errorText="Email is required."
112
- * required
113
- * >
114
- * <Input type="email" />
115
- * </Field>
116
- * ```
117
- */
118
- export const Input = CerberusFieldInput
119
-
120
- /**
121
- * A named export for the FieldTextarea component.
122
- * @description [Field Docs](https://cerberus.digitalu.design/react/field)
123
- * @example
124
- * ```tsx
125
- * import { Textarea } from '@cerberus/react'
126
- *
127
- * <Field
128
- * label="Comments"
129
- * helperText="Your comments are valuable to us."
130
- * >
131
- * <Textarea />
132
- * </Field>
133
- * ```
134
- */
135
- export const Textarea = FieldTextarea
@@ -1,23 +0,0 @@
1
- import { cx } from 'styled-system/css'
2
- import { field } from 'styled-system/recipes'
3
- import type { HTMLAttributes } from 'react'
4
-
5
- export type FieldIndicatorProps = HTMLAttributes<HTMLSpanElement>
6
-
7
- /**
8
- * The start indicator displays an indicator at the start of the Input.
9
- * @description [Field Docs](https://cerberus.digitalu.design/react/field)
10
- */
11
- export function FieldStartIndicator(props: FieldIndicatorProps) {
12
- const styles = field()
13
-
14
- if (!props.children) return null
15
-
16
- return (
17
- <span
18
- {...props}
19
- data-part="start-indicator"
20
- className={cx(props.className, styles.startIndicator)}
21
- />
22
- )
23
- }
@@ -1,58 +0,0 @@
1
- 'use client'
2
-
3
- import { useFieldContext } from '@ark-ui/react'
4
- import { cx } from 'styled-system/css'
5
- import { field } from 'styled-system/recipes'
6
- import { useCerberusContext } from '../../context/cerberus'
7
- import type { HTMLAttributes, ReactNode } from 'react'
8
-
9
- export interface FieldStatusIndicatorProps extends HTMLAttributes<HTMLSpanElement> {
10
- /**
11
- * The fallback content to display when the field is valid.
12
- */
13
- fallback?: ReactNode
14
- }
15
-
16
- /**
17
- * The invalid status indicator for the Field component.
18
- * @description [Field Docs](https://cerberus.digitalu.design/react/field)
19
- * @example
20
- * ```tsx
21
- * <FieldRoot>
22
- * <FieldStatusIndicator />
23
- * </FieldRoot>
24
- * ```
25
- */
26
- export function FieldStatusIndicator(props: FieldStatusIndicatorProps) {
27
- const { fallback, ...nativeProps } = props
28
-
29
- const fieldContext = useFieldContext()
30
- const styles = field()
31
-
32
- const { icons } = useCerberusContext()
33
- const { invalid: InvalidIcon } = icons
34
-
35
- if (fieldContext?.invalid) {
36
- return (
37
- <span
38
- {...nativeProps}
39
- aria-hidden="true"
40
- data-invalid
41
- className={cx(nativeProps.className, styles.statusIndicator)}
42
- >
43
- <InvalidIcon />
44
- </span>
45
- )
46
- }
47
-
48
- return (
49
- <span
50
- {...nativeProps}
51
- aria-hidden="true"
52
- data-part="end-indicator"
53
- className={cx(nativeProps.className, styles.endIndicator)}
54
- >
55
- {fallback}
56
- </span>
57
- )
58
- }
@@ -1,54 +0,0 @@
1
- import { splitProps } from '../../utils'
2
- import { FieldsetParts } from './parts'
3
- import type { FieldsetRootProps } from './primitives'
4
-
5
- /**
6
- * This module contains the Fieldset component.
7
- * @module Fieldset
8
- */
9
-
10
- export interface FieldsetProps extends FieldsetRootProps {
11
- /**
12
- * The legend/title/label of the fieldset group.
13
- */
14
- legend?: string
15
- /**
16
- * The description text for the fieldset group.
17
- */
18
- helperText?: string
19
- /**
20
- * The error text for the fieldset group shown when the field is invalid.
21
- */
22
- errorText?: string
23
- }
24
-
25
- /**
26
- * A component used for grouping related fields in a form that is an
27
- * abstraction of the Fieldset primitives.
28
- * @description [Fieldset Docs](https://cerberus.digitalu.design/react/fieldset)
29
- * @description [Primitive Docs](https://ark-ui.com/react/docs/components/fieldset)
30
- */
31
- export function Fieldset(props: FieldsetProps) {
32
- const [fieldsetProps, { usage }, rootProps] = splitProps(
33
- props,
34
- ['legend', 'helperText', 'errorText', 'children'],
35
- ['usage'],
36
- )
37
-
38
- return (
39
- <FieldsetParts.Root {...rootProps}>
40
- <FieldsetParts.Legend usage={usage}>
41
- {fieldsetProps.legend}
42
- </FieldsetParts.Legend>
43
- <FieldsetParts.HelperText usage={usage}>
44
- {fieldsetProps.helperText}
45
- </FieldsetParts.HelperText>
46
-
47
- {fieldsetProps.children}
48
-
49
- <FieldsetParts.ErrorText>
50
- {fieldsetProps.errorText}
51
- </FieldsetParts.ErrorText>
52
- </FieldsetParts.Root>
53
- )
54
- }
@@ -1,3 +0,0 @@
1
- export * from './fieldset'
2
- export * from './parts'
3
- export * from './primitives'
@@ -1,47 +0,0 @@
1
- import type { ElementType } from 'react'
2
- import {
3
- FieldsetErrorText,
4
- FieldsetHelperText,
5
- FieldsetLegend,
6
- FieldsetRoot,
7
- } from './primitives'
8
-
9
- /**
10
- * This module contains the parts of the Field component.
11
- * @module 'field/parts'
12
- */
13
-
14
- interface FieldsetPartsValue {
15
- /**
16
- * The container of the field.
17
- */
18
- Root: ElementType
19
- /**
20
- * The label of the field.
21
- */
22
- Legend: ElementType
23
- /**
24
- * The text that displays when the field is valid.
25
- */
26
- HelperText: ElementType
27
- /**
28
- * The text that displays when the field is invalid.
29
- */
30
- ErrorText: ElementType
31
- }
32
-
33
- /**
34
- * An Object containing the parts of the Field component. For users that
35
- * prefer Object component syntax.
36
- *
37
- * @remarks
38
- *
39
- * When using object component syntax, you import the FieldParts object and
40
- * the entire family of components vs. only what you use.
41
- */
42
- export const FieldsetParts: FieldsetPartsValue = {
43
- Root: FieldsetRoot,
44
- Legend: FieldsetLegend,
45
- HelperText: FieldsetHelperText,
46
- ErrorText: FieldsetErrorText,
47
- }
@@ -1,48 +0,0 @@
1
- import {
2
- Fieldset,
3
- type FieldsetHelperTextProps as ArkFieldsetHelperText,
4
- type FieldsetLegendProps as ArkFieldsetLegendProps,
5
- type FieldsetRootProps as ArkFieldsetRootProps,
6
- } from '@ark-ui/react/fieldset'
7
- import { fieldset, type FieldsetVariantProps } from 'styled-system/recipes'
8
- import {
9
- createCerberusPrimitive,
10
- type CerberusPrimitiveProps,
11
- } from '../../system/index'
12
-
13
- /**
14
- * This module contains all the primitives of the Fieldset component.
15
- * @module 'react/fieldset'
16
- */
17
-
18
- const { withSlotRecipe } = createCerberusPrimitive(fieldset)
19
-
20
- // Root
21
-
22
- export const FieldsetRoot = withSlotRecipe(Fieldset.Root, 'root')
23
- export type FieldsetRootProps = CerberusPrimitiveProps<
24
- ArkFieldsetRootProps & FieldsetVariantProps
25
- >
26
-
27
- // Legend
28
-
29
- export type FieldsetLegendProps = CerberusPrimitiveProps<
30
- ArkFieldsetLegendProps & FieldsetVariantProps
31
- >
32
- export const FieldsetLegend = withSlotRecipe(Fieldset.Legend, 'legend')
33
-
34
- // Helper Text
35
-
36
- export type FieldsetHelperTextProps = CerberusPrimitiveProps<
37
- ArkFieldsetHelperText & FieldsetVariantProps
38
- >
39
- export const FieldsetHelperText = withSlotRecipe(
40
- Fieldset.HelperText,
41
- 'helperText',
42
- )
43
-
44
- // Error Text
45
-
46
- export type FieldsetErrorTextProps =
47
- CerberusPrimitiveProps<ArkFieldsetHelperText>
48
- export const FieldsetErrorText = withSlotRecipe(Fieldset.ErrorText, 'errorText')
@@ -1,271 +0,0 @@
1
- 'use client'
2
-
3
- import {
4
- useCallback,
5
- useMemo,
6
- type HTMLAttributes,
7
- type MouseEvent,
8
- } from 'react'
9
- import { VStack } from 'styled-system/jsx'
10
- import { css, cx } from 'styled-system/css'
11
- import { hstack } from 'styled-system/patterns'
12
- import { fileStatus, type FileStatusVariantProps } from 'styled-system/recipes'
13
- import { useCerberusContext } from '../../context/cerberus'
14
- import { Avatar } from '../avatar/avatar'
15
- import { Field, FieldHelperText } from '../field/index'
16
- import { IconButton } from '../icon-button/index'
17
- import { ProgressBar, type ProgressBarProps } from '../progress/index'
18
- import { Text } from '../text/index'
19
-
20
- /**
21
- * This module contains the FileStatus component.
22
- * @module
23
- */
24
-
25
- /**
26
- * The available values of the fileStatus helper Object.
27
- * @example
28
- * ```tsx
29
- * import { fileStatus } from '@cerberus/react'
30
- * processStatus.TODO // 'todo'
31
- * ```
32
- */
33
- export type FileStatusKey = (typeof processStatus)[keyof typeof processStatus]
34
-
35
- /**
36
- * The actions that can be performed on a file.
37
- */
38
- export type FileStatusActions = 'cancel' | 'retry' | 'delete'
39
- export interface FileBaseStatusProps extends Omit<
40
- HTMLAttributes<HTMLDivElement>,
41
- 'onClick'
42
- > {
43
- /**
44
- * A unique identifier for the file status. Required for accessibility.
45
- */
46
- id: string
47
- /**
48
- * The name of the file.
49
- */
50
- file: string
51
- /**
52
- * The percentage of the file that has been processed.
53
- */
54
- now: ProgressBarProps['now']
55
- /**
56
- * The status of the file.
57
- */
58
- status: processStatus
59
- /**
60
- * The action to perform on the file when a user clicks the
61
- * button located at the end of the status card.
62
- * @param status - The status of the file.
63
- * @param e - The event object.
64
- * @example
65
- * ```tsx
66
- * <FileStatus file="file.txt" now={0} status={processStatus.TODO} action={(status, e) => console.log(status, e)} />
67
- * ```
68
- * @default () => {}
69
- */
70
- onClick: (status: FileStatusActions, e: MouseEvent<HTMLButtonElement>) => void
71
- }
72
- export type FileStatusProps = FileBaseStatusProps & FileStatusVariantProps
73
-
74
- /**
75
- * A helper object to represent the status of a file.
76
- * @example
77
- * ```tsx
78
- * import { fileStatus } from '@cerberus/react'
79
- * processStatus.TODO // 'todo'
80
- * ```
81
- */
82
- export const enum processStatus {
83
- TODO = 'todo',
84
- PROCESSING = 'processing',
85
- DONE = 'done',
86
- ERROR = 'error',
87
- }
88
-
89
- /**
90
- * A component that displays the status of a file during file processing.
91
- * @see https://cerberus.digitalu.design/react/file-uploader
92
- * @example
93
- * ```tsx
94
- * <FileStatus file="file.txt" now={0} status={processStatus.TODO} action={(status, e) => console.log(status, e)} />
95
- * ```
96
- */
97
- export function FileStatus(props: FileStatusProps) {
98
- const { file, now, status, onClick, ...nativeProps } = props
99
- const actionLabel = useMemo(() => getStatusActionLabel(status), [status])
100
- const palette = useMemo(() => getPalette(status), [status])
101
- const modalIconPalette = useMemo(() => getModalIconPalette(status), [status])
102
- const styles = useMemo(() => {
103
- switch (status as processStatus) {
104
- case processStatus.TODO:
105
- return fileStatus({ status: 'todo' })
106
- case processStatus.PROCESSING:
107
- return fileStatus({ status: 'processing' })
108
- case processStatus.DONE:
109
- return fileStatus({ status: 'done' })
110
- case processStatus.ERROR:
111
- return fileStatus({ status: 'error' })
112
- default:
113
- return fileStatus()
114
- }
115
- }, [status])
116
-
117
- const handleClick = useCallback(
118
- (e: MouseEvent<HTMLButtonElement>) => {
119
- const actionStatus = getStatusActionLabel(
120
- status,
121
- ).toLocaleLowerCase() as FileStatusActions
122
- onClick(actionStatus, e)
123
- },
124
- [onClick, status],
125
- )
126
-
127
- return (
128
- <div
129
- {...nativeProps}
130
- className={cx(nativeProps.className, styles.root, hstack())}
131
- >
132
- <Avatar
133
- gradient={modalIconPalette}
134
- fallback={<MatchFileStatusIcon size={24} status={status} />}
135
- />
136
-
137
- <VStack alignItems="flex-start" gap="0.12rem" w="full">
138
- <Text as="small" color="page.text.initial" textStyle="label-sm">
139
- {file}
140
- </Text>
141
- <ProgressBar
142
- id={props.id}
143
- label="File upload status"
144
- now={now}
145
- size="sm"
146
- />
147
- <Field label="" invalid={modalIconPalette === 'hades-dark'}>
148
- <FieldHelperText
149
- className={css({
150
- color: 'page.text.100',
151
- })}
152
- id={`help:${file}`}
153
- >
154
- <MatchFileStatusText status={status} now={now} />
155
- </FieldHelperText>
156
- </Field>
157
- </VStack>
158
-
159
- <IconButton
160
- ariaLabel={actionLabel}
161
- onClick={handleClick}
162
- palette={palette}
163
- size="sm"
164
- >
165
- <MatchStatusAction status={status} />
166
- </IconButton>
167
- </div>
168
- )
169
- }
170
-
171
- interface FileStatusElProps {
172
- status: FileStatusProps['status']
173
- size?: 16 | 20 | 24 | 32
174
- now?: number
175
- }
176
-
177
- function MatchFileStatusIcon(props: FileStatusElProps) {
178
- const { icons } = useCerberusContext()
179
- const {
180
- waitingFileUploader: TodoIcon,
181
- fileUploader: FileUploaderIcon,
182
- invalidAlt: InvalidIcon,
183
- successNotification: DoneIcon,
184
- } = icons
185
-
186
- switch (props.status as processStatus) {
187
- case processStatus.TODO:
188
- return <TodoIcon size={props.size} />
189
- case processStatus.PROCESSING:
190
- return <FileUploaderIcon size={props.size} />
191
- case processStatus.DONE:
192
- return <DoneIcon size={props.size} />
193
- case processStatus.ERROR:
194
- return <InvalidIcon size={props.size} />
195
- default:
196
- throw new Error('Unknown status')
197
- }
198
- }
199
-
200
- function MatchFileStatusText(props: FileStatusElProps) {
201
- switch (props.status as processStatus) {
202
- case processStatus.TODO:
203
- return 'Waiting to upload'
204
- case processStatus.PROCESSING:
205
- return `${props.now}% Complete`
206
- case processStatus.DONE:
207
- return 'File uploaded successfully'
208
- case processStatus.ERROR:
209
- return 'There was an error uploading the file'
210
- default:
211
- throw new Error('Invalid status')
212
- }
213
- }
214
-
215
- function MatchStatusAction(props: FileStatusElProps) {
216
- const { icons } = useCerberusContext()
217
- const { close: CloseIcon, redo: RedoIcon, delete: TrashIcon } = icons
218
- switch (props.status as processStatus) {
219
- case processStatus.TODO:
220
- case processStatus.PROCESSING:
221
- return <CloseIcon />
222
- case processStatus.ERROR:
223
- return <RedoIcon />
224
- case processStatus.DONE:
225
- return <TrashIcon />
226
- default:
227
- throw new Error('Invalid status')
228
- }
229
- }
230
-
231
- function getStatusActionLabel(status: FileStatusKey) {
232
- switch (status) {
233
- case processStatus.TODO:
234
- case processStatus.PROCESSING:
235
- return 'Cancel'
236
- case processStatus.ERROR:
237
- return 'Retry'
238
- case processStatus.DONE:
239
- return 'Delete'
240
- default:
241
- return ''
242
- }
243
- }
244
-
245
- function getPalette(status: FileStatusKey) {
246
- switch (status) {
247
- case processStatus.TODO:
248
- case processStatus.PROCESSING:
249
- return 'danger'
250
- case processStatus.ERROR:
251
- return 'action'
252
- case processStatus.DONE:
253
- return 'danger'
254
- default:
255
- return 'action'
256
- }
257
- }
258
-
259
- function getModalIconPalette(status: FileStatusKey) {
260
- switch (status) {
261
- case processStatus.TODO:
262
- case processStatus.PROCESSING:
263
- return 'charon-light'
264
- case processStatus.ERROR:
265
- return 'hades-dark'
266
- case processStatus.DONE:
267
- return 'thanatos-dark'
268
- default:
269
- return 'charon-light'
270
- }
271
- }
@@ -1,60 +0,0 @@
1
- 'use client'
2
-
3
- import { PropsWithChildren } from 'react'
4
- import { useCerberusContext } from '../../context/cerberus'
5
- import { splitProps } from '../../utils'
6
- import { Show } from '../show/index'
7
- import { Avatar } from '../avatar/avatar'
8
- import { formatFileTypes } from './utils'
9
- import { ImgPreview } from './img-preview'
10
- import { FileUploadParts } from './parts'
11
- import { FileUploadRootProps } from './primitives'
12
-
13
- export interface FileUploaderProps extends FileUploadRootProps {
14
- /**
15
- * The optional heading to display in the FileUploader component.
16
- */
17
- heading?: string
18
- /**
19
- * Show a preview of the uploaded image.
20
- */
21
- showPreview?: boolean
22
- }
23
-
24
- /**
25
- * A component that allows the user to upload files.
26
- * @see https://cerberus.digitalu.design/docs/components/file-uploader
27
- */
28
- export function FileUploader(props: PropsWithChildren<FileUploaderProps>) {
29
- const [elProps, rootProps] = splitProps(props, ['heading', 'showPreview'])
30
- const { showPreview = true } = elProps
31
-
32
- const { icons } = useCerberusContext()
33
- const { waitingFileUploader: Icon } = icons
34
-
35
- return (
36
- <FileUploadParts.Root {...rootProps}>
37
- <FileUploadParts.Dropzone>
38
- <FileUploadParts.Icon>
39
- <Avatar gradient="charon-light" fallback={<Icon />} />
40
- </FileUploadParts.Icon>
41
-
42
- <FileUploadParts.Content>
43
- <Show when={elProps.heading}>
44
- <FileUploadParts.Heading>{elProps.heading}</FileUploadParts.Heading>
45
- </Show>
46
- Import {formatFileTypes(rootProps.accept)} files
47
- <FileUploadParts.Description>
48
- Drag and drop files or click to upload
49
- </FileUploadParts.Description>
50
- </FileUploadParts.Content>
51
- </FileUploadParts.Dropzone>
52
-
53
- <Show when={showPreview} fallback={<>{props.children}</>}>
54
- {() => <ImgPreview />}
55
- </Show>
56
-
57
- <FileUploadParts.HiddenInput />
58
- </FileUploadParts.Root>
59
- )
60
- }