@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,72 +0,0 @@
1
- 'use client'
2
-
3
- import { useCallback, useEffect, useMemo, useReducer } from 'react'
4
-
5
- /**
6
- * This module provides a hook to get Cerberus colors from the document root.
7
- * @module useRootColors
8
- */
9
-
10
- export interface RootColorsResult {
11
- /**
12
- * A record of Cerberus colors where the key is the token name provided and the value is the color hex.
13
- */
14
- colors: Record<string, string>
15
- /**
16
- * A function to refetch the Cerberus colors from the document root. Useful when you need the latest colors after a theme/mode change.
17
- */
18
- refetch: () => Promise<void>
19
- }
20
-
21
- /**
22
- * This hook returns a record of Cerberus colors from the document root.
23
- * This is useful when you are working with a component that uses the `<canvas>`
24
- * element.
25
- * @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).
26
- * @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.
27
- */
28
- export function useRootColors(colors: string[] = []): RootColorsResult {
29
- const [state, dispatch] = useReducer(rootColorsReducer, {})
30
-
31
- const handleRefetch = useCallback(() => {
32
- return new Promise<void>((resolve) => {
33
- dispatch(formatColors(colors))
34
- resolve()
35
- })
36
- }, [colors])
37
-
38
- useEffect(() => {
39
- if (Object.keys(state).length === colors.length) return
40
- dispatch(formatColors(colors))
41
- }, [colors, state])
42
-
43
- // reducer is already memoized
44
- return useMemo(
45
- () => ({ colors: state, refetch: handleRefetch }),
46
- [state, handleRefetch],
47
- )
48
- }
49
-
50
- function formatColors(colors: string[]): Record<string, string> {
51
- const rootStyles = getComputedStyle(document.body)
52
- return colors.reduce(
53
- (acc, color) => {
54
- const formattedColor = color
55
- .replace(/([a-z])([A-Z])/g, '$1-$2')
56
- .toLowerCase()
57
- .replaceAll('.', '-')
58
- acc[color] = rootStyles
59
- .getPropertyValue(`--cerberus-colors-${formattedColor}`)
60
- .trim()
61
- return acc
62
- },
63
- {} as Record<string, string>,
64
- )
65
- }
66
-
67
- function rootColorsReducer(
68
- state: Record<string, string>,
69
- action: Record<string, string>,
70
- ): Record<string, string> {
71
- return { ...state, ...action }
72
- }
@@ -1,121 +0,0 @@
1
- 'use client'
2
-
3
- import {
4
- useCallback,
5
- useEffect,
6
- useLayoutEffect,
7
- useMemo,
8
- useState,
9
- } from 'react'
10
- import {
11
- type ColorModes,
12
- type CustomThemes,
13
- type DefaultThemes,
14
- type ThemeContextValue,
15
- } from '../context/theme'
16
-
17
- /**
18
- * This module provides a hook for using the theme.
19
- * @module
20
- */
21
-
22
- export const THEME_KEY = 'cerberus-theme'
23
- export const MODE_KEY = 'cerberus-mode'
24
-
25
- export interface UseThemeOptions<T extends string = DefaultThemes> {
26
- /**
27
- * Whether to cache the theme in local storage.
28
- */
29
- cache?: boolean
30
- /**
31
- * Called when the theme is updated.
32
- */
33
- updateTheme?: (theme: T) => void
34
- /**
35
- * Called when the color mode is updated.
36
- */
37
- updateMode?: (mode: ColorModes) => void
38
- }
39
-
40
- /**
41
- * Provides a hook for using the theme for a single instance of the application.
42
- * @see https://cerberus.digitalu.design/react/use-theme
43
- * @param defaultTheme The default theme.
44
- * @param defaultColorMode The default color mode.
45
- * @param options Additional options.
46
- */
47
- export function useTheme<C extends string = DefaultThemes>(
48
- defaultTheme: CustomThemes<C> = 'cerberus',
49
- defaultColorMode: ColorModes = 'light',
50
- options: UseThemeOptions<C> = {},
51
- ): ThemeContextValue<C> {
52
- const { updateMode, updateTheme, cache } = options
53
- const [theme, setTheme] = useState<CustomThemes<C>>(defaultTheme)
54
- const [colorMode, setColorMode] = useState<ColorModes>(defaultColorMode)
55
-
56
- const handleThemeChange = useCallback(
57
- (newTheme: C) => {
58
- setTheme(newTheme)
59
- updateTheme?.(newTheme)
60
- },
61
- [updateTheme],
62
- )
63
-
64
- const handleColorModeChange = useCallback(
65
- (newMode: ColorModes) => {
66
- setColorMode(newMode)
67
- updateMode?.(newMode)
68
- },
69
- [updateMode],
70
- )
71
-
72
- useLayoutEffect(() => {
73
- const theme = localStorage.getItem(THEME_KEY)
74
- if (theme) {
75
- setTheme(theme as CustomThemes<C>)
76
- }
77
- }, [])
78
-
79
- useLayoutEffect(() => {
80
- const mode = localStorage.getItem(MODE_KEY)
81
- if (mode) {
82
- setColorMode(mode as ColorModes)
83
- }
84
- }, [])
85
-
86
- useEffect(() => {
87
- const root = document.documentElement
88
- root.dataset.pandaTheme = theme
89
-
90
- if (cache) {
91
- localStorage.setItem(THEME_KEY, theme)
92
- }
93
- }, [theme, cache])
94
-
95
- useEffect(() => {
96
- const root = document.documentElement
97
-
98
- if (colorMode === 'system') {
99
- root.dataset.colorMode = window.matchMedia('(prefers-color-scheme: dark)')
100
- .matches
101
- ? 'dark'
102
- : 'light'
103
- } else {
104
- root.dataset.colorMode = colorMode
105
- }
106
-
107
- if (cache) {
108
- localStorage.setItem(MODE_KEY, colorMode)
109
- }
110
- }, [colorMode, cache])
111
-
112
- return useMemo(
113
- () => ({
114
- theme,
115
- mode: colorMode,
116
- updateTheme: handleThemeChange,
117
- updateMode: handleColorModeChange,
118
- }),
119
- [theme, colorMode, handleThemeChange, handleColorModeChange],
120
- )
121
- }
@@ -1,30 +0,0 @@
1
- 'use client'
2
-
3
- // Unstyled Ark Goodies
4
-
5
- export {
6
- AccordionRootProvider,
7
- useAccordion,
8
- useCollapsible,
9
- useCollapsibleContext,
10
- DialogRootProvider,
11
- useDialog,
12
- FileUploadRootProvider,
13
- useFileUpload,
14
- usePagination,
15
- usePaginationContext,
16
- // utilities
17
- ClientOnly,
18
- DownloadTrigger,
19
- FocusTrap,
20
- Format,
21
- Frame,
22
- Highlight,
23
- JsonTreeView,
24
- useJsonTreeView,
25
- Presence,
26
- EnvironmentProvider,
27
- useEnvironmentContext,
28
- LocaleProvider,
29
- useLocaleContext,
30
- } from '@ark-ui/react'
package/src/index.ts DELETED
@@ -1,76 +0,0 @@
1
- /**
2
- * This module is the entry point for the Cerberus React package.
3
- * @module
4
- */
5
-
6
- // components
7
-
8
- export * from './components/admonition/index'
9
- export * from './components/accordion/index'
10
- export * from './components/avatar/index'
11
- export * from './components/button/index'
12
- export * from './components/carousel/index'
13
- export * from './components/checkbox/index'
14
- export * from './components/circular-progress/index'
15
- export * from './components/clipboard/index'
16
- export * from './components/collapsible/index'
17
- export * from './components/combobox/index'
18
- export * from './components/cta-dialog/index'
19
- export * from './components/date-picker/index'
20
- export * from './components/dialog/index'
21
- export * from './components/feature-flag/index'
22
- export * from './components/field/index'
23
- export * from './components/fieldset/index'
24
- export * from './components/file-upload/index'
25
- export * from './components/for/index'
26
- export * from './components/group/index'
27
- export * from './components/icon-button/index'
28
- export * from './components/menu/index'
29
- export * from './components/notifications/index'
30
- export * from './components/number-input/index'
31
- export * from './components/pagination/index'
32
- export * from './components/pin-input/index'
33
- export * from './components/portal/index'
34
- export * from './components/progress/index'
35
- export * from './components/radio/index'
36
- export * from './components/rating/index'
37
- export * from './components/select/index'
38
- export * from './components/show/index'
39
- export * from './components/spinner/index'
40
- export * from './components/split-button/index'
41
- export * from './components/switch/index'
42
- export * from './components/table/index'
43
- export * from './components/tabs/index'
44
- export * from './components/tag/index'
45
- export * from './components/text/index'
46
- export * from './components/theme/index'
47
- export * from './components/toggle/index'
48
- export * from './components/tooltip/index'
49
-
50
- // context
51
-
52
- export * from './context/cerberus'
53
- export * from './context/confirm-modal'
54
- export * from './context/feature-flags'
55
- export * from './context/navMenu'
56
- export * from './context/prompt-modal'
57
- export * from './context/theme'
58
-
59
- // hooks
60
-
61
- export * from './hooks/useTheme'
62
- export * from './hooks/useRootColors'
63
-
64
- // utils
65
-
66
- export * from './config/index'
67
- export * from './utils/index'
68
- export * from './system/index'
69
-
70
- // shared types
71
-
72
- export * from './types'
73
-
74
- // 3rd party exports
75
-
76
- export * from './index.client'
@@ -1,32 +0,0 @@
1
- import { ark } from '@ark-ui/react/factory'
2
- import { cerberus } from 'styled-system/jsx/factory'
3
-
4
- function cerberusFactory(component: keyof typeof ark) {
5
- const arkComponent = ark[component]
6
-
7
- if (arkComponent) {
8
- return cerberus(arkComponent)
9
- }
10
-
11
- throw new Error(
12
- `Component "${String(component)}" is not a valid Cerberus component. Please check the component name.`,
13
- )
14
- }
15
-
16
- const cache = new Map()
17
-
18
- // Create a proxy that handles both function calls and property access
19
- export const cerberusFactoryProxy = new Proxy(cerberusFactory, {
20
- apply(target, thisArg, argArray) {
21
- // Handle function calls like cerberus('button')
22
- // @ts-expect-error: Ignore type error for dynamic property access
23
- return target.apply(thisArg, argArray)
24
- },
25
- get(_target, el: keyof typeof ark) {
26
- // Handle property access like cerberus.button
27
- if (!cache.has(el)) {
28
- cache.set(el, cerberusFactory(el))
29
- }
30
- return cache.get(el) as ReturnType<typeof cerberusFactory>
31
- },
32
- })
@@ -1,47 +0,0 @@
1
- import { CerberusPrimitive } from './primitive-factory'
2
- import type { CerberusFactory, CerberusPrimitiveRecipe } from './types'
3
- import { cerberusFactoryProxy } from './factory'
4
-
5
- /**
6
- * This module contains the user interface for creating Cerberus primitives.
7
- * @module @cerberus/core/system/create-cerb-primitive
8
- */
9
-
10
- /**
11
- * A factory function that creates a Cerberus primitive instance with the given
12
- * recipe.
13
- * @param recipe
14
- * @returns An object with three methods: `withNoRecipe`, `withRecipe`, and `withSlotRecipe` that
15
- * apply the recipes and special Cerberus helpers like `css`.
16
- *
17
- * @example
18
- * ```tsx
19
- * const { withRecipe } = createCerberusPrimitive(myCustomRecipe);
20
- * export const Button = withRecipe(MyCustomButton)
21
- * ```
22
- */
23
- export function createCerberusPrimitive<T extends CerberusPrimitiveRecipe>(
24
- recipe?: T,
25
- ) {
26
- return new CerberusPrimitive(recipe)
27
- }
28
-
29
- /**
30
- * A utility function to access Cerberus components by their name.
31
- * @param component - The name of the Cerberus component to access.
32
- * @returns The Cerberus component corresponding to the provided name.
33
- * @throws An error if the component name is not valid.
34
- *
35
- * @example
36
- * ```tsx
37
- * import { cerberus } from '@cerberus/react'
38
- * const Button = cerberus('button')
39
- *
40
- * <Button css={{ color: 'blue' }} asChild>
41
- * <Link href="/some-page">Click me</Link>
42
- * </Button>
43
- * ```
44
- */
45
- export const cerberus = cerberusFactoryProxy as CerberusFactory
46
-
47
- export * from './types'
@@ -1,180 +0,0 @@
1
- import { ark } from '@ark-ui/react/factory'
2
- import { forwardRef, type ElementType } from 'react'
3
- import { css, cx, type Styles } from 'styled-system/css'
4
- import { cerberus } from 'styled-system/jsx/factory'
5
- import type {
6
- CerberusComponent,
7
- RecipeVariantRecord,
8
- } from 'styled-system/types'
9
- import type { ExtractProps } from '../types'
10
- import type {
11
- CerberusPrimitiveEl,
12
- CerberusPrimitiveProps,
13
- CerberusPrimitiveRecipe,
14
- CerberusRecipe,
15
- CerberusSlotRecipe,
16
- WithRecipeOptions,
17
- } from './types'
18
-
19
- /**
20
- * This module contains a factory for creating Cerberus primitives.
21
- * @module @cerberus/core/system/factory
22
- */
23
-
24
- export class CerberusPrimitive {
25
- recipe: CerberusPrimitiveRecipe | null
26
-
27
- constructor(recipe?: CerberusPrimitiveRecipe) {
28
- this.recipe = recipe ?? null
29
- }
30
-
31
- private setupStyledComponent<T extends ElementType>(
32
- component: T | CerberusPrimitiveEl<T>,
33
- ): CerberusComponent<T> {
34
- const arkComponent = ark[component as keyof typeof ark]
35
-
36
- if (typeof component !== 'string') {
37
- return cerberus(component)
38
- }
39
-
40
- if (arkComponent) {
41
- return cerberus(arkComponent)
42
- }
43
-
44
- throw new Error(`Unknown component: ${component}`)
45
- }
46
-
47
- /**
48
- * Creates a Cerberus component with bare features and no recipe.
49
- * @param Component - The React component to enhance with Cerberus features.
50
- * Can be a string or a component reference.
51
- * @returns A new React component that applies Cerberus features to the
52
- * original component.
53
- *
54
- * @example
55
- * ```ts
56
- * const { withNoRecipe } = createCerberusPrimitive(buttonRecipe)
57
- * const Button = withNoRecipe('button')
58
- * ```
59
- */
60
- withNoRecipe = <T extends ElementType>(
61
- Component: T | CerberusPrimitiveEl<T>,
62
- options?: WithRecipeOptions,
63
- ) => {
64
- type Props = ExtractProps<T>
65
- const { defaultProps } = options || {}
66
- const El = this.setupStyledComponent<T>(Component)
67
-
68
- const CerbComponent = (props: CerberusPrimitiveProps<Props>) => {
69
- return <El {...defaultProps} {...props} />
70
- }
71
-
72
- const ElName = typeof El === 'string' ? El : El.displayName || El.name
73
- CerbComponent.displayName = `Cerberus.${ElName}`
74
-
75
- return CerbComponent
76
- }
77
-
78
- /**
79
- * Creates a Cerberus component with the given recipe.
80
- * @param Component - The React component to enhance with the recipe.
81
- * @param options - Options for the recipe.
82
- * @returns A new React component that applies the recipe to the original
83
- * component.
84
- */
85
- withRecipe = <T extends ElementType>(
86
- Component: T,
87
- options?: WithRecipeOptions,
88
- ) => {
89
- type Props = ExtractProps<T>
90
- const { defaultProps } = options || {}
91
- const El = this.setupStyledComponent<T>(Component)
92
-
93
- const recipe = this.recipe as CerberusRecipe
94
-
95
- const CerbComponent = forwardRef<unknown, CerberusPrimitiveProps<Props>>(
96
- (internalProps, ref) => {
97
- const { css: customCss, ...restOfInternalProps } = internalProps
98
-
99
- const [variantOptions, nativeProps] =
100
- recipe.splitVariantProps(restOfInternalProps)
101
- const recipeStyles = recipe(variantOptions)
102
-
103
- // Safely access className
104
- const className =
105
- typeof nativeProps.className === 'string'
106
- ? nativeProps.className
107
- : undefined
108
-
109
- return (
110
- <El
111
- {...defaultProps}
112
- {...(nativeProps as Props)}
113
- ref={ref}
114
- className={cx(className, recipeStyles, css(customCss as Styles))}
115
- />
116
- )
117
- },
118
- )
119
-
120
- const ElName = typeof El === 'string' ? El : El.displayName || El.name
121
- CerbComponent.displayName = ElName
122
-
123
- return CerbComponent
124
- }
125
-
126
- /**
127
- * Creates a Cerberus component with a slot recipe applied.
128
- * @param Component - The React component to enhance with Cerberus features.
129
- * @param recipe - The slot recipe to apply to the component.
130
- * @returns A new React component that applies Cerberus features and the
131
- * specified slot recipe to the original component.
132
- * @example
133
- * ```typescript
134
- * const { withSlotRecipe } = createCerberusPrimitive(field)
135
- * const Field = withSlotRecipe(RawField, field)
136
- * ```
137
- */
138
- withSlotRecipe = <T extends ElementType>(
139
- Component: T,
140
- slot: keyof RecipeVariantRecord,
141
- options?: WithRecipeOptions,
142
- ) => {
143
- type Props = ExtractProps<T>
144
- const { defaultProps } = options || {}
145
- const El = this.setupStyledComponent<T>(Component)
146
-
147
- const recipe = this.recipe as CerberusSlotRecipe<typeof slot>
148
-
149
- const CerbComponent = forwardRef<unknown, CerberusPrimitiveProps<Props>>(
150
- (internalProps, ref) => {
151
- const { css: customCss, ...restOfInternalProps } = internalProps
152
-
153
- const [variantOptions, nativeProps] =
154
- recipe.splitVariantProps(restOfInternalProps)
155
- const styles = recipe(variantOptions)
156
- const slotStyles = styles[slot as keyof typeof styles]
157
-
158
- // Safely access className
159
- const className =
160
- typeof nativeProps.className === 'string'
161
- ? nativeProps.className
162
- : undefined
163
-
164
- return (
165
- <El
166
- {...defaultProps}
167
- {...(nativeProps as Props)}
168
- ref={ref}
169
- className={cx(className, slotStyles, css(customCss as Styles))}
170
- />
171
- )
172
- },
173
- )
174
-
175
- const ElName = typeof El === 'string' ? El : El.displayName || El.name
176
- CerbComponent.displayName = ElName
177
-
178
- return CerbComponent
179
- }
180
- }
@@ -1,88 +0,0 @@
1
- import type { ark } from '@ark-ui/react/factory'
2
- import type { CSSProperties, ElementType, PropsWithChildren } from 'react'
3
- import type {
4
- AsProps,
5
- Assign,
6
- ComponentProps,
7
- Dict,
8
- JsxHTMLProps,
9
- JsxStyleProps,
10
- RecipeVariantFn,
11
- RecipeVariantRecord,
12
- SlotRecipeVariantFn,
13
- SlotRecipeVariantRecord,
14
- UnstyledProps,
15
- } from 'styled-system/types'
16
-
17
- // Method signatures for recipes
18
-
19
- type RecipeBase = {
20
- splitVariantProps: (
21
- props: Record<string, unknown>,
22
- ) => [Record<string, unknown>, Record<string, unknown>]
23
- }
24
-
25
- export type CerberusRecipe = RecipeVariantFn<RecipeVariantRecord> & RecipeBase
26
- export type CerberusSlotRecipe<T extends string> = SlotRecipeVariantFn<
27
- string,
28
- SlotRecipeVariantRecord<T>
29
- > &
30
- RecipeBase
31
-
32
- export type CerberusPrimitiveRecipe =
33
- | CerberusRecipe
34
- | CerberusSlotRecipe<string>
35
-
36
- export type WithRecipeOptions = {
37
- defaultProps?: Record<string, unknown>
38
- }
39
-
40
- export interface BaseCerberusProps
41
- extends ArkFactoryProps, JsxStyleProps, Dict, UnstyledProps, AsProps {
42
- /**
43
- * The CSS styles applied to the component. Supports CSS Properties
44
- * declarations and style objects.
45
- */
46
- style?: CSSProperties | Record<string, string>
47
- }
48
-
49
- export type CerberusProps<
50
- T extends ElementType,
51
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
52
- P extends Dict = {},
53
- > = JsxHTMLProps<
54
- ComponentProps<T> & UnstyledProps & AsProps & ArkFactoryProps,
55
- Assign<JsxStyleProps, P>
56
- >
57
-
58
- // Primitive Response
59
-
60
- export type CerberusPrimitiveProps<T> = PropsWithChildren<BaseCerberusProps> & T
61
-
62
- export type CerberusPrimitiveEl<T extends ElementType = ElementType> =
63
- ElementType<CerberusProps<T>>
64
-
65
- // Factory
66
-
67
- export interface ArkFactoryProps {
68
- /**
69
- * If true, the component will render as a child as the provided element
70
- * passing all the given props to the child.
71
- */
72
- asChild?: boolean
73
- }
74
-
75
- export type ArkPropsWithRef<T extends keyof typeof ark> = {
76
- [K in keyof (typeof ark)[T]]: K extends 'asChild' ? never : (typeof ark)[T][K]
77
- } & ArkFactoryProps
78
-
79
- export type CerberusFactoryFn = <T extends Record<string, unknown>>(
80
- component: keyof typeof ark,
81
- defaultProps?: T,
82
- ) => CerberusPrimitiveEl
83
-
84
- export type CerberusFactoryObject = {
85
- [K in keyof typeof ark]: CerberusPrimitiveEl
86
- }
87
-
88
- export type CerberusFactory = CerberusFactoryFn & CerberusFactoryObject
package/src/types.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { ComponentType, ElementType, JSX } from 'react'
2
-
3
- // types
4
-
5
- export type Positions = 'top' | 'right' | 'bottom' | 'left'
6
-
7
- /**
8
- * Utility type to enforce never on all properties of a given type.
9
- */
10
- export type EnforceNoProperties<T> = {
11
- [K in keyof T]: never
12
- }
13
-
14
- /**
15
- * Utility type to extract props for string elements or custom components
16
- */
17
- export type ExtractProps<T> = T extends keyof JSX.IntrinsicElements
18
- ? JSX.IntrinsicElements[T]
19
- : T extends ComponentType<infer P>
20
- ? P
21
- : T extends ElementType<infer P>
22
- ? P
23
- : Record<string, unknown>