@saas-ui/react 2.11.2 → 3.0.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. package/CHANGELOG.md +13 -148
  2. package/dist/chunk-32JGENDB.js +19 -0
  3. package/dist/chunk-FZW2DYK3.js +19 -0
  4. package/dist/chunk-KHRLZUV4.js +35 -0
  5. package/dist/chunk-KTLWEUNW.js +1 -0
  6. package/dist/chunk-PKI6YH2V.js +31 -0
  7. package/dist/chunk-RTMS5TJN.js +10 -0
  8. package/dist/chunk-VBIVLREP.js +45 -0
  9. package/dist/chunk-VDXTEASE.js +117 -0
  10. package/dist/components/app-shell/index.cjs +68 -0
  11. package/dist/components/app-shell/index.d.cts +30 -0
  12. package/dist/components/app-shell/index.d.ts +30 -0
  13. package/dist/components/app-shell/index.js +45 -0
  14. package/dist/components/breadcrumbs/index.cjs +60 -0
  15. package/dist/components/breadcrumbs/index.d.cts +18 -0
  16. package/dist/components/breadcrumbs/index.d.ts +18 -0
  17. package/dist/components/breadcrumbs/index.js +37 -0
  18. package/dist/components/button/index.cjs +65 -0
  19. package/dist/components/button/index.d.cts +12 -0
  20. package/dist/components/button/index.d.ts +12 -0
  21. package/dist/components/button/index.js +45 -0
  22. package/dist/components/checkbox/index.cjs +45 -0
  23. package/dist/components/checkbox/index.d.cts +11 -0
  24. package/dist/components/checkbox/index.d.ts +11 -0
  25. package/dist/components/checkbox/index.js +20 -0
  26. package/dist/components/close-button/index.cjs +142 -0
  27. package/dist/components/close-button/index.d.cts +8 -0
  28. package/dist/components/close-button/index.d.ts +8 -0
  29. package/dist/components/close-button/index.js +9 -0
  30. package/dist/components/command/index.cjs +56 -0
  31. package/dist/components/command/index.d.cts +6 -0
  32. package/dist/components/command/index.d.ts +6 -0
  33. package/dist/components/command/index.js +33 -0
  34. package/dist/components/dialog/index.cjs +243 -0
  35. package/dist/components/dialog/index.d.cts +27 -0
  36. package/dist/components/dialog/index.d.ts +27 -0
  37. package/dist/components/dialog/index.js +73 -0
  38. package/dist/components/drawer/index.cjs +237 -0
  39. package/dist/components/drawer/index.d.cts +28 -0
  40. package/dist/components/drawer/index.d.ts +28 -0
  41. package/dist/components/drawer/index.js +65 -0
  42. package/dist/components/icon-badge/index.cjs +70 -0
  43. package/dist/components/icon-badge/index.d.cts +16 -0
  44. package/dist/components/icon-badge/index.d.ts +16 -0
  45. package/dist/components/icon-badge/index.js +38 -0
  46. package/dist/components/icons/index.cjs +155 -0
  47. package/dist/components/icons/index.d.cts +19 -0
  48. package/dist/components/icons/index.d.ts +19 -0
  49. package/dist/components/icons/index.js +35 -0
  50. package/dist/components/input-group/index.cjs +56 -0
  51. package/dist/components/input-group/index.d.cts +13 -0
  52. package/dist/components/input-group/index.d.ts +13 -0
  53. package/dist/components/input-group/index.js +8 -0
  54. package/dist/components/link/index.cjs +71 -0
  55. package/dist/components/link/index.d.cts +13 -0
  56. package/dist/components/link/index.d.ts +13 -0
  57. package/dist/components/link/index.js +20 -0
  58. package/dist/components/loading-overlay/index.cjs +1921 -0
  59. package/dist/components/loading-overlay/index.d.cts +13 -0
  60. package/dist/components/loading-overlay/index.d.ts +13 -0
  61. package/dist/components/loading-overlay/index.js +1878 -0
  62. package/dist/components/navbar/index.cjs +65 -0
  63. package/dist/components/navbar/index.d.cts +18 -0
  64. package/dist/components/navbar/index.d.ts +18 -0
  65. package/dist/components/navbar/index.js +42 -0
  66. package/dist/components/number-input/index.cjs +82 -0
  67. package/dist/components/number-input/index.d.cts +13 -0
  68. package/dist/components/number-input/index.d.ts +13 -0
  69. package/dist/components/number-input/index.js +32 -0
  70. package/dist/components/password-input/index.cjs +284 -0
  71. package/dist/components/password-input/index.d.cts +18 -0
  72. package/dist/components/password-input/index.d.ts +18 -0
  73. package/dist/components/password-input/index.js +231 -0
  74. package/dist/components/persona/index.cjs +181 -0
  75. package/dist/components/persona/index.d.cts +93 -0
  76. package/dist/components/persona/index.d.ts +93 -0
  77. package/dist/components/persona/index.js +149 -0
  78. package/dist/components/pin-input/index.cjs +51 -0
  79. package/dist/components/pin-input/index.d.cts +12 -0
  80. package/dist/components/pin-input/index.d.ts +12 -0
  81. package/dist/components/pin-input/index.js +26 -0
  82. package/dist/components/radio/index.cjs +48 -0
  83. package/dist/components/radio/index.d.cts +12 -0
  84. package/dist/components/radio/index.d.ts +12 -0
  85. package/dist/components/radio/index.js +22 -0
  86. package/dist/components/search-input/index.cjs +244 -0
  87. package/dist/components/search-input/index.d.cts +15 -0
  88. package/dist/components/search-input/index.d.ts +15 -0
  89. package/dist/components/search-input/index.js +120 -0
  90. package/dist/components/select/index.cjs +233 -0
  91. package/dist/components/select/index.d.cts +32 -0
  92. package/dist/components/select/index.d.ts +32 -0
  93. package/dist/components/select/index.js +100 -0
  94. package/dist/components/sidebar/index.cjs +134 -0
  95. package/dist/components/sidebar/index.d.cts +85 -0
  96. package/dist/components/sidebar/index.d.ts +85 -0
  97. package/dist/components/sidebar/index.js +108 -0
  98. package/dist/components/spinner/index.cjs +44 -0
  99. package/dist/components/spinner/index.d.cts +10 -0
  100. package/dist/components/spinner/index.d.ts +10 -0
  101. package/dist/components/spinner/index.js +8 -0
  102. package/dist/components/steps/index.cjs +191 -0
  103. package/dist/components/steps/index.d.cts +31 -0
  104. package/dist/components/steps/index.d.ts +31 -0
  105. package/dist/components/steps/index.js +71 -0
  106. package/dist/components/switch/index.cjs +48 -0
  107. package/dist/components/switch/index.d.cts +18 -0
  108. package/dist/components/switch/index.d.ts +18 -0
  109. package/dist/components/switch/index.js +23 -0
  110. package/dist/index.cjs +8460 -0
  111. package/dist/index.d.cts +26 -0
  112. package/dist/index.d.ts +25 -7
  113. package/dist/index.js +8395 -36
  114. package/package.json +26 -22
  115. package/src/components/app-shell/app-shell.recipe.ts +52 -0
  116. package/src/components/app-shell/app-shell.stories.tsx +51 -0
  117. package/src/components/app-shell/app-shell.tsx +94 -0
  118. package/src/components/app-shell/index.ts +3 -0
  119. package/src/components/breadcrumbs/breadcrumb.stories.tsx +17 -0
  120. package/src/components/breadcrumbs/breadcrumb.tsx +36 -0
  121. package/src/components/breadcrumbs/index.ts +1 -0
  122. package/src/components/breadcrumbs/namespace.ts +8 -0
  123. package/src/components/button/button.recipe.ts +182 -0
  124. package/src/components/button/button.stories.tsx +99 -0
  125. package/src/components/button/button.tsx +55 -0
  126. package/src/components/button/index.ts +2 -0
  127. package/src/components/checkbox/checkbox.tsx +26 -0
  128. package/src/components/checkbox/index.ts +2 -0
  129. package/src/components/close-button/close-button.stories.tsx +12 -0
  130. package/src/components/close-button/close-button.tsx +18 -0
  131. package/src/components/close-button/index.ts +2 -0
  132. package/src/components/command/command.recipe.ts +17 -0
  133. package/src/components/command/command.stories.tsx +47 -0
  134. package/src/components/command/command.tsx +50 -0
  135. package/src/components/command/index.ts +1 -0
  136. package/src/components/dialog/dialog.tsx +67 -0
  137. package/src/components/dialog/index.ts +1 -0
  138. package/src/components/dialog/namespace.ts +18 -0
  139. package/src/components/drawer/drawer.tsx +57 -0
  140. package/src/components/drawer/index.ts +3 -0
  141. package/src/components/drawer/namespace.ts +19 -0
  142. package/src/components/grid-list/grid-list.recipe.ts +113 -0
  143. package/src/components/icon-badge/icon-badge.recipe.ts +57 -0
  144. package/src/components/icon-badge/icon-badge.stories.tsx +38 -0
  145. package/src/components/icon-badge/icon-badge.tsx +59 -0
  146. package/src/components/icon-badge/index.ts +2 -0
  147. package/src/components/icons/create-icon.tsx +41 -0
  148. package/src/components/icons/icons.tsx +119 -0
  149. package/src/components/icons/index.ts +1 -0
  150. package/src/components/input-group/index.ts +1 -0
  151. package/src/components/input-group/input-group.tsx +46 -0
  152. package/src/components/link/index.ts +2 -0
  153. package/src/components/link/link.stories.tsx +17 -0
  154. package/src/components/link/link.test.tsx +33 -0
  155. package/src/components/link/link.tsx +27 -0
  156. package/src/components/loading-overlay/index.ts +1 -0
  157. package/src/components/loading-overlay/loading-overlay.recipe.ts +61 -0
  158. package/src/components/loading-overlay/loading-overlay.stories.tsx +68 -0
  159. package/src/components/loading-overlay/loading-overlay.tsx +54 -0
  160. package/src/components/loading-overlay/namespace.ts +7 -0
  161. package/src/components/navbar/index.ts +1 -0
  162. package/src/components/navbar/namespace.ts +9 -0
  163. package/src/components/navbar/navbar.recipe.ts +109 -0
  164. package/src/components/navbar/navbar.stories.tsx +435 -0
  165. package/src/components/navbar/navbar.test.tsx +49 -0
  166. package/src/components/navbar/navbar.tsx +39 -0
  167. package/src/components/number-input/index.ts +2 -0
  168. package/src/components/number-input/number-input.tsx +41 -0
  169. package/src/components/password-input/index.ts +2 -0
  170. package/src/components/password-input/password-input.tsx +93 -0
  171. package/src/components/persona/index.ts +2 -0
  172. package/src/components/persona/namespace.ts +18 -0
  173. package/src/components/persona/persona-primitive.tsx +220 -0
  174. package/src/components/persona/persona.recipe.ts +94 -0
  175. package/src/components/persona/persona.stories.tsx +101 -0
  176. package/src/components/persona/persona.tsx +142 -0
  177. package/src/components/pin-input/index.ts +2 -0
  178. package/src/components/pin-input/pin-input.tsx +36 -0
  179. package/src/components/radio/index.ts +2 -0
  180. package/src/components/radio/radio.tsx +27 -0
  181. package/src/components/search-input/index.ts +2 -0
  182. package/src/components/search-input/search-input.stories.tsx +63 -0
  183. package/src/components/search-input/search-input.tsx +134 -0
  184. package/src/components/select/index.ts +1 -0
  185. package/src/components/select/namespace.ts +18 -0
  186. package/src/components/select/select.tsx +135 -0
  187. package/src/components/sidebar/index.ts +7 -0
  188. package/src/components/sidebar/namespace.ts +27 -0
  189. package/src/components/sidebar/sidebar-item.recipe.ts +65 -0
  190. package/src/components/sidebar/sidebar.recipe.ts +237 -0
  191. package/src/components/sidebar/sidebar.stories.tsx +903 -0
  192. package/src/components/sidebar/sidebar.tsx +208 -0
  193. package/src/components/spinner/index.ts +2 -0
  194. package/src/components/spinner/spinner.stories.tsx +19 -0
  195. package/src/components/spinner/spinner.tsx +21 -0
  196. package/src/components/steps/index.ts +1 -0
  197. package/src/components/steps/namespace.ts +16 -0
  198. package/src/components/steps/steps.tsx +82 -0
  199. package/src/components/switch/index.ts +3 -0
  200. package/src/components/switch/switch.tsx +39 -0
  201. package/src/compositions/accordion.tsx +47 -0
  202. package/src/compositions/action-bar.tsx +40 -0
  203. package/src/compositions/alert.tsx +51 -0
  204. package/src/compositions/avatar.tsx +74 -0
  205. package/src/compositions/blockquote.tsx +31 -0
  206. package/src/compositions/checkbox-card.tsx +57 -0
  207. package/src/compositions/checkbox.tsx +25 -0
  208. package/src/compositions/clipboard.tsx +107 -0
  209. package/src/compositions/color-mode.tsx +65 -0
  210. package/src/compositions/data-list.tsx +37 -0
  211. package/src/compositions/empty-state.tsx +34 -0
  212. package/src/compositions/field.tsx +33 -0
  213. package/src/compositions/file-button.tsx +166 -0
  214. package/src/compositions/hover-card.tsx +35 -0
  215. package/src/compositions/link-button.tsx +12 -0
  216. package/src/compositions/menu.tsx +108 -0
  217. package/src/compositions/native-select.tsx +57 -0
  218. package/src/compositions/pagination.tsx +207 -0
  219. package/src/compositions/popover.tsx +58 -0
  220. package/src/compositions/progress-circle.tsx +37 -0
  221. package/src/compositions/progress.tsx +40 -0
  222. package/src/compositions/prose.tsx +264 -0
  223. package/src/compositions/provider.tsx +12 -0
  224. package/src/compositions/radio-card.tsx +57 -0
  225. package/src/compositions/radio.tsx +24 -0
  226. package/src/compositions/rating.tsx +27 -0
  227. package/src/compositions/segmented-control.tsx +47 -0
  228. package/src/compositions/skeleton.tsx +44 -0
  229. package/src/compositions/slider.tsx +53 -0
  230. package/src/compositions/stat.tsx +75 -0
  231. package/src/compositions/status.tsx +29 -0
  232. package/src/compositions/stepper-input.tsx +49 -0
  233. package/src/compositions/tag.tsx +39 -0
  234. package/src/compositions/timeline.tsx +17 -0
  235. package/src/compositions/toaster.tsx +43 -0
  236. package/src/compositions/toggle-tip.tsx +62 -0
  237. package/src/compositions/tooltip.tsx +46 -0
  238. package/src/index.ts +6 -7
  239. package/src/preset.ts +9 -0
  240. package/src/provider/index.ts +4 -0
  241. package/src/provider/sui-provider.tsx +34 -0
  242. package/src/provider/use-link.test.tsx +60 -0
  243. package/src/provider/use-link.tsx +13 -0
  244. package/src/styled-system/create-recipe-context.tsx +91 -0
  245. package/src/styled-system/create-slot-recipe-context.tsx +188 -0
  246. package/src/styled-system/empty.ts +7 -0
  247. package/src/styled-system/factory.types.ts +11 -0
  248. package/src/theme/animation-styles.ts +53 -0
  249. package/src/theme/breakpoints.ts +11 -0
  250. package/src/theme/conditions.ts +26 -0
  251. package/src/theme/fluid-font-sizes.ts +65 -0
  252. package/src/theme/global-css.ts +94 -0
  253. package/src/theme/index.ts +72 -0
  254. package/src/theme/layer-styles.ts +116 -0
  255. package/src/theme/recipes/chakra/accordion.ts +145 -0
  256. package/src/theme/recipes/chakra/action-bar.ts +62 -0
  257. package/src/theme/recipes/chakra/alert.ts +157 -0
  258. package/src/theme/recipes/chakra/avatar.ts +141 -0
  259. package/src/theme/recipes/chakra/badge.ts +67 -0
  260. package/src/theme/recipes/chakra/blockquote.ts +83 -0
  261. package/src/theme/recipes/chakra/breadcrumb.ts +94 -0
  262. package/src/theme/recipes/chakra/card.ts +99 -0
  263. package/src/theme/recipes/chakra/checkbox-card.ts +212 -0
  264. package/src/theme/recipes/chakra/checkbox.ts +70 -0
  265. package/src/theme/recipes/chakra/checkmark.ts +83 -0
  266. package/src/theme/recipes/chakra/code.ts +17 -0
  267. package/src/theme/recipes/chakra/collapsible.ts +20 -0
  268. package/src/theme/recipes/chakra/container.ts +26 -0
  269. package/src/theme/recipes/chakra/data-list.ts +80 -0
  270. package/src/theme/recipes/chakra/dialog.ts +225 -0
  271. package/src/theme/recipes/chakra/drawer.ts +201 -0
  272. package/src/theme/recipes/chakra/editable.ts +88 -0
  273. package/src/theme/recipes/chakra/empty-state.ts +88 -0
  274. package/src/theme/recipes/chakra/field.ts +68 -0
  275. package/src/theme/recipes/chakra/fieldset.ts +62 -0
  276. package/src/theme/recipes/chakra/file-upload.ts +96 -0
  277. package/src/theme/recipes/chakra/heading.ts +27 -0
  278. package/src/theme/recipes/chakra/hover-card.ts +68 -0
  279. package/src/theme/recipes/chakra/icon.ts +30 -0
  280. package/src/theme/recipes/chakra/input-addon.ts +40 -0
  281. package/src/theme/recipes/chakra/input.ts +96 -0
  282. package/src/theme/recipes/chakra/kbd.ts +60 -0
  283. package/src/theme/recipes/chakra/link.ts +37 -0
  284. package/src/theme/recipes/chakra/list.ts +67 -0
  285. package/src/theme/recipes/chakra/mark.ts +27 -0
  286. package/src/theme/recipes/chakra/menu.ts +124 -0
  287. package/src/theme/recipes/chakra/native-select.ts +140 -0
  288. package/src/theme/recipes/chakra/number-input.ts +115 -0
  289. package/src/theme/recipes/chakra/pin-input.ts +27 -0
  290. package/src/theme/recipes/chakra/popover.ts +86 -0
  291. package/src/theme/recipes/chakra/progress-circle.ts +94 -0
  292. package/src/theme/recipes/chakra/progress.ts +127 -0
  293. package/src/theme/recipes/chakra/radio-card.ts +220 -0
  294. package/src/theme/recipes/chakra/radio-group.ts +72 -0
  295. package/src/theme/recipes/chakra/radiomark.ts +107 -0
  296. package/src/theme/recipes/chakra/rating-group.ts +94 -0
  297. package/src/theme/recipes/chakra/segment-group.ts +117 -0
  298. package/src/theme/recipes/chakra/select.ts +282 -0
  299. package/src/theme/recipes/chakra/separator.ts +51 -0
  300. package/src/theme/recipes/chakra/skeleton.ts +53 -0
  301. package/src/theme/recipes/chakra/skip-nav-link.ts +34 -0
  302. package/src/theme/recipes/chakra/slider.ts +178 -0
  303. package/src/theme/recipes/chakra/spinner.ts +32 -0
  304. package/src/theme/recipes/chakra/stat.ts +79 -0
  305. package/src/theme/recipes/chakra/status.ts +48 -0
  306. package/src/theme/recipes/chakra/steps.ts +218 -0
  307. package/src/theme/recipes/chakra/switch.ts +167 -0
  308. package/src/theme/recipes/chakra/table.ts +172 -0
  309. package/src/theme/recipes/chakra/tabs.ts +280 -0
  310. package/src/theme/recipes/chakra/tag.ts +131 -0
  311. package/src/theme/recipes/chakra/textarea.ts +88 -0
  312. package/src/theme/recipes/chakra/timeline.ts +138 -0
  313. package/src/theme/recipes/chakra/toast.ts +96 -0
  314. package/src/theme/recipes/chakra/tooltip.ts +40 -0
  315. package/src/theme/recipes.ts +46 -0
  316. package/src/theme/semantic-tokens/colors.ts +403 -0
  317. package/src/theme/semantic-tokens/radii.ts +7 -0
  318. package/src/theme/semantic-tokens/shadows.ts +52 -0
  319. package/src/theme/slot-recipes.ts +104 -0
  320. package/src/theme/text-styles.ts +39 -0
  321. package/src/theme/tokens/animations.ts +8 -0
  322. package/src/theme/tokens/aspect-ratios.ts +10 -0
  323. package/src/theme/tokens/blurs.ts +12 -0
  324. package/src/theme/tokens/borders.ts +9 -0
  325. package/src/theme/tokens/colors.ts +177 -0
  326. package/src/theme/tokens/cursor.ts +12 -0
  327. package/src/theme/tokens/durations.ts +11 -0
  328. package/src/theme/tokens/easings.ts +10 -0
  329. package/src/theme/tokens/font-sizes.ts +20 -0
  330. package/src/theme/tokens/font-weights.ts +13 -0
  331. package/src/theme/tokens/fonts.ts +15 -0
  332. package/src/theme/tokens/keyframes.ts +173 -0
  333. package/src/theme/tokens/letter-spacing.ts +9 -0
  334. package/src/theme/tokens/line-heights.ts +19 -0
  335. package/src/theme/tokens/radius.ts +18 -0
  336. package/src/theme/tokens/sizes.ts +71 -0
  337. package/src/theme/tokens/spacing.ts +38 -0
  338. package/src/theme/tokens/z-indices.ts +34 -0
  339. package/src/theme/utils.ts +46 -0
  340. package/dist/index.d.mts +0 -8
  341. package/dist/index.js.map +0 -1
  342. package/dist/index.mjs +0 -11
  343. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,34 @@
1
+ import * as React from 'react'
2
+
3
+ import { ChakraProvider, ChakraProviderProps } from '@chakra-ui/react'
4
+
5
+ export interface SuiContextValue {
6
+ linkComponent?: React.ElementType<any>
7
+ }
8
+
9
+ export const SuiContext = React.createContext<SuiContextValue>({})
10
+
11
+ export interface SuiProviderProps extends ChakraProviderProps {
12
+ linkComponent?: React.ElementType<any>
13
+ children: React.ReactNode
14
+ onError?: (error: Error, errorInfo: React.ErrorInfo) => void
15
+ }
16
+
17
+ export function SuiProvider(props: SuiProviderProps) {
18
+ const { linkComponent, onError, children, ...rest } = props
19
+
20
+ const context = React.useMemo(
21
+ () => ({
22
+ linkComponent,
23
+ }),
24
+ [],
25
+ )
26
+
27
+ return (
28
+ <SuiContext.Provider value={context}>
29
+ <ChakraProvider {...rest}>{children}</ChakraProvider>
30
+ </SuiContext.Provider>
31
+ )
32
+ }
33
+
34
+ export const useSui = (): SuiContextValue => React.useContext(SuiContext)
@@ -0,0 +1,60 @@
1
+ import * as React from 'react'
2
+ import { hooks, render } from '@saas-ui/test-utils'
3
+
4
+ import { SaasProvider, useLink } from './index'
5
+
6
+ const DummyComponent = ({ href = '' }) => {
7
+ const LinkWrapper = useLink()
8
+
9
+ if (LinkWrapper) {
10
+ return (
11
+ <LinkWrapper href={href}>
12
+ <a>Link</a>
13
+ </LinkWrapper>
14
+ )
15
+ }
16
+ return <a>Link</a>
17
+ }
18
+
19
+ const Link = ({
20
+ href = '',
21
+ children,
22
+ }: {
23
+ href: string
24
+ children: React.ReactNode
25
+ }) => {
26
+ return (
27
+ <>
28
+ {React.Children.map(children, (child) => {
29
+ if (React.isValidElement(child)) {
30
+ return React.cloneElement<any>(child, {
31
+ href,
32
+ })
33
+ }
34
+ return child
35
+ })}
36
+ </>
37
+ )
38
+ }
39
+
40
+ const renderLink = (ui: React.ReactNode) => {
41
+ return render(<SaasProvider linkComponent={Link}>{ui}</SaasProvider>, {
42
+ withSaasProvider: false,
43
+ })
44
+ }
45
+
46
+ test('it should not throw without context', () => {
47
+ const { result } = hooks.render(() => useLink())
48
+ })
49
+
50
+ test('it should render', () => {
51
+ const { getByText } = renderLink(<DummyComponent />)
52
+
53
+ expect(getByText('Link')).toBeInTheDocument()
54
+ })
55
+
56
+ test('it should render with href', () => {
57
+ const { getByText } = renderLink(<DummyComponent href="/test" />)
58
+
59
+ expect(getByText('Link')).toHaveAttribute('href', '/test')
60
+ })
@@ -0,0 +1,13 @@
1
+ import React from 'react'
2
+
3
+ import { chakra } from '@chakra-ui/react'
4
+
5
+ import { useSui } from './sui-provider'
6
+
7
+ export function useLink(): React.ElementType {
8
+ const context = useSui()
9
+ if (context?.linkComponent) {
10
+ return context.linkComponent
11
+ }
12
+ return chakra.a
13
+ }
@@ -0,0 +1,91 @@
1
+ 'use client'
2
+
3
+ import { forwardRef } from 'react'
4
+
5
+ import {
6
+ type RecipeKey,
7
+ type UseRecipeOptions,
8
+ chakra,
9
+ createContext,
10
+ mergeProps,
11
+ useRecipe,
12
+ } from '@chakra-ui/react'
13
+ import { cx } from '@saas-ui/core/utils'
14
+
15
+ import { EMPTY_STYLES } from './empty.ts'
16
+ import type { JsxFactoryOptions } from './factory.types.ts'
17
+
18
+ const upperFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
19
+
20
+ export function createRecipeContext<K extends RecipeKey>(
21
+ options: UseRecipeOptions<K>,
22
+ ) {
23
+ const { key: recipeKey, recipe: recipeConfig } = options
24
+
25
+ const contextName = upperFirst(
26
+ recipeKey || (recipeConfig as any).className || 'Component',
27
+ )
28
+
29
+ const [PropsProvider, usePropsContext] = createContext<Record<string, any>>({
30
+ strict: false,
31
+ name: `${contextName}PropsContext`,
32
+ providerName: `${contextName}PropsContext`,
33
+ })
34
+
35
+ function useRecipeResult(props: any) {
36
+ const { unstyled, ...restProps } = props
37
+
38
+ const recipe = useRecipe({
39
+ key: recipeKey,
40
+ recipe: restProps.recipe || recipeConfig,
41
+ })
42
+
43
+ // @ts-ignore
44
+ const [variantProps, otherProps] = recipe.splitVariantProps(restProps)
45
+ const styles = unstyled ? EMPTY_STYLES : recipe(variantProps)
46
+
47
+ return {
48
+ styles,
49
+ className: recipe.className,
50
+ props: otherProps,
51
+ }
52
+ }
53
+
54
+ const withContext = <T, P>(
55
+ Component: React.ElementType<any>,
56
+ options?: JsxFactoryOptions<P>,
57
+ ): React.ForwardRefExoticComponent<
58
+ React.PropsWithoutRef<P> & React.RefAttributes<T>
59
+ > => {
60
+ const SuperComponent = chakra(Component, {}, options as any)
61
+ const StyledComponent = forwardRef<any, any>((inProps, ref) => {
62
+ const props = mergeProps(usePropsContext(), inProps)
63
+ const { styles, className, props: localProps } = useRecipeResult(props)
64
+
65
+ return (
66
+ <SuperComponent
67
+ {...localProps}
68
+ ref={ref}
69
+ css={[styles, props.css]}
70
+ className={cx(className, props.className)}
71
+ />
72
+ )
73
+ })
74
+
75
+ // @ts-expect-error
76
+ StyledComponent.displayName = Component.displayName || Component.name
77
+ return StyledComponent as any
78
+ }
79
+
80
+ function withPropsProvider<P>(): React.Provider<Partial<P>> {
81
+ return PropsProvider as any
82
+ }
83
+
84
+ return {
85
+ withContext,
86
+ PropsProvider,
87
+ withPropsProvider,
88
+ usePropsContext,
89
+ useRecipeResult,
90
+ }
91
+ }
@@ -0,0 +1,188 @@
1
+ 'use client'
2
+
3
+ import { forwardRef } from 'react'
4
+
5
+ import {
6
+ type SlotRecipeKey,
7
+ type UseSlotRecipeOptions,
8
+ chakra,
9
+ createContext,
10
+ mergeProps,
11
+ useSlotRecipe,
12
+ } from '@chakra-ui/react'
13
+ import type { SystemStyleObject } from '@chakra-ui/react'
14
+ import { cx } from '@saas-ui/core/utils'
15
+
16
+ import { EMPTY_SLOT_STYLES } from './empty.ts'
17
+ import type { JsxFactoryOptions } from './factory.types.ts'
18
+
19
+ type ConfigRecipeSlots = any
20
+
21
+ interface WrapElementProps<P> {
22
+ wrapElement?(element: React.ReactElement, props: P): React.ReactElement
23
+ }
24
+
25
+ interface WithRootProviderOptions<P> extends WrapElementProps<P> {
26
+ defaultProps?: Partial<P>
27
+ }
28
+
29
+ interface WithProviderOptions<P>
30
+ extends JsxFactoryOptions<P>,
31
+ WrapElementProps<P> {}
32
+
33
+ interface WithContextOptions<P> extends JsxFactoryOptions<P> {}
34
+
35
+ const upperFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
36
+
37
+ export const createSlotRecipeContext = <R extends SlotRecipeKey>(
38
+ options: UseSlotRecipeOptions<R>,
39
+ ) => {
40
+ const { key: recipeKey, recipe: recipeConfig } = options
41
+
42
+ const contextName = upperFirst(
43
+ recipeKey || (recipeConfig as any).className || 'Component',
44
+ )
45
+
46
+ const [StylesProvider, useStyles] = createContext<
47
+ Record<string, SystemStyleObject>
48
+ >({
49
+ name: `${contextName}StylesContext`,
50
+ errorMessage: `use${contextName}Styles returned is 'undefined'. Seems you forgot to wrap the components in "<${contextName}.Root />" `,
51
+ })
52
+
53
+ const [ClassNamesProvider, useClassNames] = createContext<
54
+ Record<string, string>
55
+ >({
56
+ name: `${contextName}ClassNameContext`,
57
+ errorMessage: `use${contextName}ClassNames returned is 'undefined'. Seems you forgot to wrap the components in "<${contextName}.Root />" `,
58
+ strict: false,
59
+ })
60
+
61
+ const [PropsProvider, usePropsContext] = createContext<Record<string, any>>({
62
+ strict: false,
63
+ name: `${contextName}PropsContext`,
64
+ providerName: `${contextName}PropsContext`,
65
+ defaultValue: {},
66
+ })
67
+
68
+ function useRecipeResult(props: any) {
69
+ const { unstyled, ...restProps } = props
70
+
71
+ const slotRecipe = useSlotRecipe({
72
+ key: recipeKey,
73
+ recipe: restProps.recipe || recipeConfig,
74
+ })
75
+
76
+ // @ts-ignore
77
+ const [variantProps, otherProps] = slotRecipe.splitVariantProps(restProps)
78
+ const styles = unstyled ? EMPTY_SLOT_STYLES : slotRecipe(variantProps)
79
+
80
+ return {
81
+ styles: styles as Record<string, SystemStyleObject>,
82
+ classNames: slotRecipe.classNameMap as Record<string, string>,
83
+ props: otherProps,
84
+ }
85
+ }
86
+
87
+ function withRootProvider<P>(
88
+ Component: React.ElementType<any>,
89
+ options: WithRootProviderOptions<P> = {},
90
+ ): React.FC<React.PropsWithoutRef<P>> {
91
+ const { defaultProps } = options
92
+
93
+ const StyledComponent = (inProps: any) => {
94
+ const props = mergeProps(defaultProps, usePropsContext(), inProps)
95
+ const { styles, classNames, props: rootProps } = useRecipeResult(props)
96
+
97
+ return (
98
+ <StylesProvider value={styles}>
99
+ <ClassNamesProvider value={classNames}>
100
+ <Component {...rootProps} />
101
+ </ClassNamesProvider>
102
+ </StylesProvider>
103
+ )
104
+ }
105
+
106
+ // @ts-expect-error
107
+ StyledComponent.displayName = Component.displayName || Component.name
108
+ return StyledComponent as any
109
+ }
110
+
111
+ const withProvider = <T, P>(
112
+ Component: React.ElementType<any>,
113
+ slot: R extends keyof ConfigRecipeSlots ? ConfigRecipeSlots[R] : string,
114
+ options?: WithProviderOptions<P>,
115
+ ): React.ForwardRefExoticComponent<
116
+ React.PropsWithoutRef<P> & React.RefAttributes<T>
117
+ > => {
118
+ const { defaultProps, ...restOptions } = options ?? {}
119
+ const SuperComponent = chakra(Component, {}, restOptions as any)
120
+
121
+ const StyledComponent = forwardRef<any, any>((inProps, ref) => {
122
+ const props = mergeProps(defaultProps ?? {}, usePropsContext(), inProps)
123
+ const { styles, props: rootProps, classNames } = useRecipeResult(props)
124
+ const className = classNames[slot as keyof typeof classNames]
125
+
126
+ const element = (
127
+ <StylesProvider value={styles}>
128
+ <ClassNamesProvider value={classNames}>
129
+ <SuperComponent
130
+ ref={ref}
131
+ {...rootProps}
132
+ css={[styles[slot], props.css]}
133
+ className={cx(props.className, className)}
134
+ />
135
+ </ClassNamesProvider>
136
+ </StylesProvider>
137
+ )
138
+
139
+ return options?.wrapElement?.(element, props) ?? element
140
+ })
141
+
142
+ // @ts-expect-error
143
+ StyledComponent.displayName = Component.displayName || Component.name
144
+
145
+ return StyledComponent as any
146
+ }
147
+
148
+ const withContext = <T, P>(
149
+ Component: React.ElementType<any>,
150
+ slot?: R extends keyof ConfigRecipeSlots ? ConfigRecipeSlots[R] : string,
151
+ options?: WithContextOptions<P>,
152
+ ): React.ForwardRefExoticComponent<
153
+ React.PropsWithoutRef<P> & React.RefAttributes<T>
154
+ > => {
155
+ const SuperComponent = chakra(Component, {}, options as any)
156
+ const StyledComponent = forwardRef<any, any>((props, ref) => {
157
+ const styles = useStyles()
158
+ const classNames = useClassNames()
159
+ const className = classNames?.[slot as keyof typeof classNames]
160
+
161
+ return (
162
+ <SuperComponent
163
+ {...props}
164
+ css={[slot ? styles[slot] : undefined, props.css]}
165
+ ref={ref}
166
+ className={cx(props.className, className)}
167
+ />
168
+ )
169
+ })
170
+
171
+ // @ts-expect-error
172
+ StyledComponent.displayName = Component.displayName || Component.name
173
+ return StyledComponent as any
174
+ }
175
+
176
+ return {
177
+ StylesProvider,
178
+ ClassNamesProvider,
179
+ PropsProvider,
180
+ usePropsContext,
181
+ useRecipeResult,
182
+ withProvider,
183
+ withContext,
184
+ withRootProvider,
185
+ useStyles,
186
+ useClassNames,
187
+ }
188
+ }
@@ -0,0 +1,7 @@
1
+ import type { SystemStyleObject } from '@chakra-ui/react'
2
+
3
+ export const EMPTY_STYLES = Object.freeze({} as SystemStyleObject)
4
+
5
+ export const EMPTY_SLOT_STYLES = Object.freeze(
6
+ {} as Record<string, SystemStyleObject>,
7
+ )
@@ -0,0 +1,11 @@
1
+ export type DataAttr = Record<
2
+ `data-${string}`,
3
+ string | number | undefined | null | boolean
4
+ >
5
+
6
+ export interface JsxFactoryOptions<TProps> {
7
+ forwardProps?: string[]
8
+ defaultProps?: Partial<TProps> & DataAttr
9
+ forwardAsChild?: boolean
10
+ shouldForwardProp?(prop: string, variantKeys: string[]): boolean
11
+ }
@@ -0,0 +1,53 @@
1
+ import { defineAnimationStyles } from '@chakra-ui/react'
2
+
3
+ export const animationStyles: any = defineAnimationStyles({
4
+ 'slide-fade-in': {
5
+ value: {
6
+ transformOrigin: 'var(--transform-origin)',
7
+ '&[data-placement^=top]': {
8
+ animationName: 'slide-from-bottom, fade-in',
9
+ },
10
+ '&[data-placement^=bottom]': {
11
+ animationName: 'slide-from-top, fade-in',
12
+ },
13
+ '&[data-placement^=left]': {
14
+ animationName: 'slide-from-right, fade-in',
15
+ },
16
+ '&[data-placement^=right]': {
17
+ animationName: 'slide-from-left, fade-in',
18
+ },
19
+ },
20
+ },
21
+
22
+ 'slide-fade-out': {
23
+ value: {
24
+ transformOrigin: 'var(--transform-origin)',
25
+ '&[data-placement^=top]': {
26
+ animationName: 'slide-to-bottom, fade-out',
27
+ },
28
+ '&[data-placement^=bottom]': {
29
+ animationName: 'slide-to-top, fade-out',
30
+ },
31
+ '&[data-placement^=left]': {
32
+ animationName: 'slide-to-right, fade-out',
33
+ },
34
+ '&[data-placement^=right]': {
35
+ animationName: 'slide-to-left, fade-out',
36
+ },
37
+ },
38
+ },
39
+
40
+ 'scale-fade-in': {
41
+ value: {
42
+ transformOrigin: 'var(--transform-origin)',
43
+ animationName: 'scale-in, fade-in',
44
+ },
45
+ },
46
+
47
+ 'scale-fade-out': {
48
+ value: {
49
+ transformOrigin: 'var(--transform-origin)',
50
+ animationName: 'scale-out, fade-out',
51
+ },
52
+ },
53
+ })
@@ -0,0 +1,11 @@
1
+ export const breakpointValues = {
2
+ sm: '480px',
3
+ md: '768px',
4
+ lg: '1024px',
5
+ xl: '1280px',
6
+ '2xl': '1536px',
7
+ }
8
+
9
+ export const breakpoints = Object.fromEntries(
10
+ Object.entries(breakpointValues).map(([key, value]) => [key, `${value}px`]),
11
+ )
@@ -0,0 +1,26 @@
1
+ import { defineConditions } from '@chakra-ui/react'
2
+
3
+ export const conditions = defineConditions({
4
+ collapsible: '&:is([data-scope=collapsible])',
5
+ groupCollapsible:
6
+ '.group:is([data-scope=collapsible]) &, [role=group]:is([data-scope=collapsible]) &',
7
+ groupOpen:
8
+ '.group:is([data-state=open]) &, [role=group]:is([data-state=open]) &',
9
+ groupFocus:
10
+ '.group:is(:focus, [data-focus]) &, [role=group]:is(:focus, [data-focus]) &',
11
+ groupHover:
12
+ '.group:is(:hover, [data-hover]):not(:disabled, [data-disabled]) &, [role=group]:is(:hover, [data-hover]):not(:disabled, [data-disabled]) &',
13
+ groupActive:
14
+ '.group:is(:active, [data-active]):not(:disabled, [data-disabled]) &, [role=group]:is(:active, [data-active]):not(:disabled, [data-disabled]) &',
15
+ groupFocusWithin: '.group:focus-within &, [role=group]:focus-within &',
16
+ groupFocusVisible:
17
+ '.group:is(:focus-visible, [data-focus-visible]) &, [role=group]:is(:focus-visible, [data-focus-visible]) &',
18
+ groupDisabled:
19
+ '.group:is(:disabled, [disabled], [data-disabled]) &, [role=group]:is(:disabled, [disabled], [data-disabled]) &',
20
+ groupChecked:
21
+ '.group:is(:checked, [data-checked], [aria-checked=true], [data-state=checked]) &, [role=group]:is(:checked, [data-checked], [aria-checked=true], [data-state=checked]) &',
22
+ groupExpanded:
23
+ '.group:is([aria-expanded=true], [data-expanded], [data-state=expanded]) &, [role=group]:is([aria-expanded=true], [data-expanded], [data-state=expanded]) &',
24
+ groupInvalid: '.group:invalid &, [role=group]:invalid &',
25
+ parentHover: 'button:hover > &, a:hover > &',
26
+ })
@@ -0,0 +1,65 @@
1
+ // const fluidFontSizes = {
2
+ // 'min-max': fluid({
3
+ // property: 'fluid-text-size',
4
+ // from: breakpointValues.sm,
5
+ // to: breakpointValues['2xl'],
6
+ // divider: 1,
7
+ // }),
8
+ // }
9
+
10
+ // 'fluid-text-size': {
11
+ // 'min-max': fluid({ property: 'fluid-text-size', from: BP_SM, to: BP_2XL, divider: 1 }),
12
+ // 'sm-md': fluid({ property: 'fluid-text-size', from: BP_SM, to: BP_MD, divider: 1 }),
13
+ // 'sm-lg': fluid({ property: 'fluid-text-size', from: BP_SM, to: BP_LG, divider: 1 }),
14
+ // 'sm-xl': fluid({ property: 'fluid-text-size', from: BP_SM, to: BP_XL, divider: 1 }),
15
+ // 'md-lg': fluid({ property: 'fluid-text-size', from: BP_MD, to: BP_LG, divider: 1 }),
16
+ // 'md-xl': fluid({ property: 'fluid-text-size', from: BP_MD, to: BP_XL, divider: 1 }),
17
+ // 'md-2xl': fluid({ property: 'fluid-text-size', from: BP_MD, to: BP_2XL, divider: 1 }),
18
+ // 'lg-xl': fluid({ property: 'fluid-text-size', from: BP_LG, to: BP_XL, divider: 1 }),
19
+ // 'lg-2xl': fluid({ property: 'fluid-text-size', from: BP_LG, to: BP_2XL, divider: 1 }),
20
+ // },
21
+
22
+ // {
23
+ // utilities: {
24
+ // fluidFontSize: {
25
+ // shorthand: ['fluidFontSize'],
26
+ // transform(value, args) {
27
+ // console.log(value, args)
28
+ // const val = 'min-max(sm, lg)'
29
+
30
+ // const match = val.match(/(\w+-\w+)\((\w+),\s*(\w+)\)/)
31
+
32
+ // if (!match) {
33
+ // return {}
34
+ // }
35
+
36
+ // const [, breakpoints, min, max] = match
37
+ // console.log(match)
38
+ // const minSize = args.token.raw(`fontSizes.${min}`)?.value
39
+ // const maxSize = args.token.raw(`fontSizes.${max}`)?.value
40
+ // console.log(minSize, maxSize)
41
+ // return {
42
+ // fontSize: `var(--fluid-text-size-${breakpoints})`,
43
+ // '--fluid-text-size-min': minSize,
44
+ // '--fluid-text-size-max': maxSize,
45
+ // }
46
+ // },
47
+ // },
48
+ // fluidFontSizeMin: {
49
+ // shorthand: ['fluidFontSizeMin'],
50
+ // transform(value, args) {
51
+ // return {
52
+ // '--fluid-text-size-min': value,
53
+ // }
54
+ // },
55
+ // },
56
+ // fluidFontSizeMax: {
57
+ // shorthand: ['fluidFontSizeMax'],
58
+ // transform(value, args) {
59
+ // return {
60
+ // '--fluid-text-size-max': value,
61
+ // }
62
+ // },
63
+ // },
64
+ // },
65
+ // },
@@ -0,0 +1,94 @@
1
+ import { defineGlobalStyles } from '@chakra-ui/react'
2
+
3
+ const empty = 'var(--chakra-empty,/*!*/ /*!*/)'
4
+
5
+ export const globalCss = defineGlobalStyles({
6
+ '*': {
7
+ fontFeatureSettings: '"cv11"',
8
+ '--ring-inset': empty,
9
+ '--ring-offset-width': '0px',
10
+ '--ring-offset-color': '#fff',
11
+ '--ring-color': 'rgba(66, 153, 225, 0.6)',
12
+ '--ring-offset-shadow': '0 0 #0000',
13
+ '--ring-shadow': '0 0 #0000',
14
+ ...Object.fromEntries(
15
+ [
16
+ 'brightness',
17
+ 'contrast',
18
+ 'grayscale',
19
+ 'hue-rotate',
20
+ 'invert',
21
+ 'saturate',
22
+ 'sepia',
23
+ 'drop-shadow',
24
+ ].map((prop) => [`--${prop}`, empty]),
25
+ ),
26
+ ...Object.fromEntries(
27
+ [
28
+ 'blur',
29
+ 'brightness',
30
+ 'contrast',
31
+ 'grayscale',
32
+ 'hue-rotate',
33
+ 'invert',
34
+ 'opacity',
35
+ 'saturate',
36
+ 'sepia',
37
+ ].map((prop) => [`--backdrop-${prop}`, empty]),
38
+ ),
39
+ '--global-font-mono': 'fonts.mono',
40
+ '--global-font-body': 'fonts.body',
41
+ '--global-color-border': 'colors.border',
42
+ '--cursor-button': 'default',
43
+ '--radius-factor': '1',
44
+ '--radius-full': '9999px',
45
+ '--scale-factor': '1',
46
+ },
47
+ body: {
48
+ color: 'fg',
49
+ bg: 'bg',
50
+ lineHeight: '1.5',
51
+ colorPalette: 'accent',
52
+ },
53
+ '*::placeholder': {
54
+ color: 'fg.subtle',
55
+ },
56
+ '*::selection': {
57
+ bg: 'colorPalette.muted/80',
58
+ },
59
+ '[data-radius="none"]': {
60
+ '--radius-factor': '0',
61
+ '--radius-full': '0',
62
+ },
63
+ '[data-radius="sm"]': {
64
+ '--radius-factor': '0.9',
65
+ '--radius-full': '0',
66
+ },
67
+ '[data-radius="md"]': {
68
+ '--radius-factor': '1',
69
+ '--radius-full': '0',
70
+ },
71
+ '[data-radius="lg"]': {
72
+ '--radius-factor': '1.5',
73
+ '--radius-full': '0',
74
+ },
75
+ '[data-radius="full"]': {
76
+ '--radius-factor': '1.5',
77
+ '--radius-full': '9999px',
78
+ },
79
+ '[data-scale="xs"]': {
80
+ '--scale-factor': '0.9',
81
+ },
82
+ '[data-scale="sm"]': {
83
+ '--scale-factor': '0.95',
84
+ },
85
+ '[data-scale="md"]': {
86
+ '--scale-factor': '1',
87
+ },
88
+ '[data-scale="lg"]': {
89
+ '--scale-factor': '1.05',
90
+ },
91
+ '[data-scale="xl"]': {
92
+ '--scale-factor': '1.1',
93
+ },
94
+ })