@sanity/ui 4.2.0 → 5.0.0-alpha.10

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 (339) hide show
  1. package/README.md +194 -28
  2. package/bin/sanity-ui.js +14 -0
  3. package/dist/_chunks-es/LazyRefractor.js +20 -0
  4. package/dist/_chunks-es/LazyRefractor.js.map +1 -0
  5. package/dist/cli/checks.js +148 -0
  6. package/dist/cli/config.js +23 -0
  7. package/dist/cli/detect.js +181 -0
  8. package/dist/cli/doctor.js +49 -0
  9. package/dist/cli/index.js +69 -0
  10. package/dist/cli/init.js +189 -0
  11. package/dist/cli/install.js +79 -0
  12. package/dist/cli/log.js +66 -0
  13. package/dist/cli/selfPackage.js +11 -0
  14. package/dist/cli/styles.js +185 -0
  15. package/dist/cli/test-utils.js +8 -0
  16. package/dist/cli/tsconfig.js +236 -0
  17. package/dist/cli/types.js +1 -0
  18. package/dist/cli/versions.js +45 -0
  19. package/dist/index.d.ts +1203 -1469
  20. package/dist/index.js +2123 -1989
  21. package/dist/index.js.map +1 -1
  22. package/dist/polyfills.d.ts +1 -0
  23. package/dist/polyfills.js +5 -0
  24. package/dist/polyfills.js.map +1 -0
  25. package/dist/styles.css +1 -547
  26. package/package.json +57 -58
  27. package/src/cli/checks.test.ts +38 -0
  28. package/src/cli/checks.ts +200 -0
  29. package/src/cli/config.ts +44 -0
  30. package/src/cli/detect.test.ts +191 -0
  31. package/src/cli/detect.ts +205 -0
  32. package/src/cli/doctor.test.ts +52 -0
  33. package/src/cli/doctor.ts +65 -0
  34. package/src/cli/index.ts +77 -0
  35. package/src/cli/init.ts +225 -0
  36. package/src/cli/install.test.ts +52 -0
  37. package/src/cli/install.ts +108 -0
  38. package/src/cli/log.ts +79 -0
  39. package/src/cli/selfPackage.ts +14 -0
  40. package/src/cli/styles.test.ts +130 -0
  41. package/src/cli/styles.ts +205 -0
  42. package/src/cli/test-utils.ts +10 -0
  43. package/src/cli/tsconfig.test.ts +174 -0
  44. package/src/cli/tsconfig.ts +282 -0
  45. package/src/cli/types.ts +77 -0
  46. package/src/cli/versions.test.ts +35 -0
  47. package/src/cli/versions.ts +41 -0
  48. package/src/components/badge/Badge.tsx +53 -0
  49. package/src/components/badge/badge.css +6 -0
  50. package/src/components/badge/badge.props.ts +31 -0
  51. package/src/components/box/Box.tsx +30 -0
  52. package/src/components/box/box.css +4 -0
  53. package/src/components/box/box.props.ts +29 -0
  54. package/src/components/button/Button.tsx +78 -0
  55. package/src/components/button/button.css +72 -0
  56. package/src/components/button/button.props.ts +122 -0
  57. package/src/components/card/Card.tsx +31 -0
  58. package/src/components/card/card.css +4 -0
  59. package/src/components/card/card.props.ts +58 -0
  60. package/src/components/checkbox/Checkbox.tsx +64 -0
  61. package/src/components/checkbox/checkbox.css +100 -0
  62. package/src/components/checkbox/checkbox.props.ts +33 -0
  63. package/src/components/code/Code.tsx +38 -0
  64. package/src/components/code/LazyRefractor.tsx +9 -0
  65. package/src/components/code/code.css +40 -0
  66. package/src/components/code/code.props.ts +44 -0
  67. package/src/components/container/Container.tsx +30 -0
  68. package/src/components/container/container.css +4 -0
  69. package/src/components/container/container.props.ts +28 -0
  70. package/src/components/dialog/Dialog.tsx +139 -0
  71. package/src/components/dialog/dialog.css +49 -0
  72. package/src/components/dialog/dialog.props.ts +45 -0
  73. package/src/components/divider/Divider.tsx +23 -0
  74. package/src/components/divider/divider.props.ts +9 -0
  75. package/src/components/eyebrow/Eyebrow.tsx +54 -0
  76. package/src/components/eyebrow/eyebrow.css +11 -0
  77. package/src/components/eyebrow/eyebrow.props.ts +28 -0
  78. package/src/components/flex/Flex.tsx +30 -0
  79. package/src/components/flex/flex.css +4 -0
  80. package/src/components/flex/flex.props.ts +33 -0
  81. package/src/components/grid/Grid.tsx +30 -0
  82. package/src/components/grid/grid.css +4 -0
  83. package/src/components/grid/grid.props.ts +33 -0
  84. package/src/components/h-stack/HStack.tsx +34 -0
  85. package/src/components/h-stack/hStack.props.ts +17 -0
  86. package/src/components/heading/Heading.tsx +54 -0
  87. package/src/components/heading/heading.css +9 -0
  88. package/src/components/heading/heading.props.ts +31 -0
  89. package/src/components/icon/Icon.tsx +24 -0
  90. package/src/components/icon/icon.css +17 -0
  91. package/src/components/icon/icon.props.ts +35 -0
  92. package/src/components/icon-button/IconButton.tsx +32 -0
  93. package/src/components/icon-button/iconButton.props.ts +31 -0
  94. package/src/components/index.css +28 -0
  95. package/src/components/indicator/Indicator.tsx +42 -0
  96. package/src/components/indicator/indicator.css +4 -0
  97. package/src/components/indicator/indicator.props.ts +24 -0
  98. package/src/components/indicator-stack/IndicatorStack.tsx +31 -0
  99. package/src/components/indicator-stack/indicator-stack.css +7 -0
  100. package/src/components/indicator-stack/indicatorStack.props.ts +15 -0
  101. package/src/components/inline/Inline.tsx +38 -0
  102. package/src/components/inline/inline.css +4 -0
  103. package/src/components/inline/inline.props.ts +100 -0
  104. package/src/components/label/Label.tsx +34 -0
  105. package/src/components/label/label.css +3 -0
  106. package/src/components/label/label.props.ts +25 -0
  107. package/src/components/link/Link.tsx +29 -0
  108. package/src/components/link/link.css +12 -0
  109. package/src/components/link/link.props.ts +23 -0
  110. package/src/components/list/List.tsx +167 -0
  111. package/src/components/list/list.css +25 -0
  112. package/src/components/list/list.props.ts +130 -0
  113. package/src/components/popover/Popover.tsx +85 -0
  114. package/src/components/popover/popover.css +21 -0
  115. package/src/components/popover/popover.props.ts +38 -0
  116. package/src/components/press-area/PressArea.tsx +29 -0
  117. package/src/components/press-area/press-area.css +22 -0
  118. package/src/components/press-area/pressArea.props.ts +16 -0
  119. package/src/components/radio/Radio.tsx +48 -0
  120. package/src/components/radio/radio.css +97 -0
  121. package/src/components/radio/radio.props.ts +25 -0
  122. package/src/components/skip-to-content/SkipToContent.tsx +35 -0
  123. package/src/components/skip-to-content/skip-to-content.css +9 -0
  124. package/src/components/skip-to-content/skipToContent.props.ts +25 -0
  125. package/src/components/spinner/Spinner.tsx +28 -0
  126. package/src/components/spinner/spinner.css +10 -0
  127. package/src/components/spinner/spinner.props.ts +19 -0
  128. package/src/components/switch/Switch.tsx +48 -0
  129. package/src/components/switch/switch.css +119 -0
  130. package/src/components/switch/switch.props.ts +25 -0
  131. package/src/components/text/Text.tsx +53 -0
  132. package/src/components/text/text.css +9 -0
  133. package/src/components/text/text.props.ts +28 -0
  134. package/src/components/tooltip/Tooltip.tsx +97 -0
  135. package/src/components/tooltip/tooltip.css +31 -0
  136. package/src/components/tooltip/tooltip.props.ts +36 -0
  137. package/src/components/tooltip-group/TooltipGroup.tsx +64 -0
  138. package/src/components/tooltip-group/tooltipGroup.props.ts +15 -0
  139. package/src/components/v-stack/VStack.tsx +32 -0
  140. package/src/components/v-stack/vStack.props.ts +17 -0
  141. package/src/components/visually-hidden/VisuallyHidden.tsx +29 -0
  142. package/src/components/visually-hidden/visually-hidden.css +9 -0
  143. package/src/components/visually-hidden/visuallyHidden.props.ts +23 -0
  144. package/src/css/classes/dynamic/flex-child.css +5 -0
  145. package/src/css/classes/dynamic/grid-child.css +8 -0
  146. package/src/css/classes/dynamic/grid-parent.css +6 -0
  147. package/src/css/classes/dynamic/height.css +5 -0
  148. package/src/css/classes/dynamic/index.css +7 -0
  149. package/src/css/classes/dynamic/line-clamp.css +5 -0
  150. package/src/css/classes/dynamic/readme.md +3 -0
  151. package/src/css/classes/dynamic/width.css +7 -0
  152. package/src/css/classes/dynamic/z-index.css +3 -0
  153. package/src/css/classes/generic/display.css +10 -0
  154. package/src/css/classes/generic/flex.css +24 -0
  155. package/src/css/classes/generic/grid.css +7 -0
  156. package/src/css/classes/generic/index.css +7 -0
  157. package/src/css/classes/generic/overflow.css +19 -0
  158. package/src/css/classes/generic/placement.css +202 -0
  159. package/src/css/classes/generic/position.css +7 -0
  160. package/src/css/classes/generic/readme.md +3 -0
  161. package/src/css/classes/generic/text-align.css +5 -0
  162. package/src/css/classes/index.css +4 -0
  163. package/src/css/classes/local/animation.css +4 -0
  164. package/src/css/classes/local/border.css +20 -0
  165. package/src/css/classes/local/index.css +6 -0
  166. package/src/css/classes/local/readme.md +3 -0
  167. package/src/css/classes/local/text-overflow.css +5 -0
  168. package/src/css/classes/local/text-trim.css +45 -0
  169. package/src/css/classes/local/tone.css +75 -0
  170. package/src/css/classes/local/top-anchor.css +4 -0
  171. package/src/css/classes/system/color.css +223 -0
  172. package/src/css/classes/system/container.css +8 -0
  173. package/src/css/classes/system/font-family.css +2 -0
  174. package/src/css/classes/system/font-weight.css +4 -0
  175. package/src/css/classes/system/gap.css +37 -0
  176. package/src/css/classes/system/index.css +10 -0
  177. package/src/css/classes/system/inset.css +56 -0
  178. package/src/css/classes/system/margin.css +148 -0
  179. package/src/css/classes/system/padding.css +78 -0
  180. package/src/css/classes/system/radius.css +10 -0
  181. package/src/css/classes/system/readme.md +3 -0
  182. package/src/css/classes/system/shadow.css +6 -0
  183. package/src/css/classes/system/typography.css +31 -0
  184. package/src/css/global/font-face.css +20 -0
  185. package/src/css/global/index.css +2 -0
  186. package/src/css/global/reset.css +76 -0
  187. package/src/css/tokens/index.css +3 -0
  188. package/src/css/tokens/opacity.css +6 -0
  189. package/src/css/tokens/semantic.css +25 -0
  190. package/src/css/tokens/surface.css +27 -0
  191. package/src/hooks/useIsClient.ts +10 -0
  192. package/src/index.css +18 -0
  193. package/src/index.ts +65 -0
  194. package/src/polyfills.ts +15 -0
  195. package/src/props/border.ts +51 -0
  196. package/src/props/flexChild.ts +29 -0
  197. package/src/props/flexParent.ts +47 -0
  198. package/src/props/gap.ts +31 -0
  199. package/src/props/gridChild.ts +50 -0
  200. package/src/props/gridParent.ts +45 -0
  201. package/src/props/height.ts +29 -0
  202. package/src/props/layout.ts +44 -0
  203. package/src/props/margin.ts +59 -0
  204. package/src/props/overflow.ts +30 -0
  205. package/src/props/padding.ts +59 -0
  206. package/src/props/placement.ts +16 -0
  207. package/src/props/position.ts +52 -0
  208. package/src/props/shadow.ts +15 -0
  209. package/src/props/tone.ts +15 -0
  210. package/src/props/typography.ts +62 -0
  211. package/src/props/width.ts +29 -0
  212. package/src/props/zIndex.ts +15 -0
  213. package/src/styles.css.d.ts +1 -0
  214. package/src/styles.css.node.js +2 -0
  215. package/src/styles.css.test.ts +24 -0
  216. package/src/types/Button.ts +8 -0
  217. package/src/types/Code.ts +6 -0
  218. package/src/types/Container.ts +3 -0
  219. package/src/types/Density.ts +3 -0
  220. package/src/types/Display.ts +11 -0
  221. package/src/types/Eyebrow.ts +3 -0
  222. package/src/types/Flex.ts +22 -0
  223. package/src/types/FontWeight.ts +3 -0
  224. package/src/types/Grid.ts +3 -0
  225. package/src/types/Heading.ts +6 -0
  226. package/src/types/Icon.ts +3 -0
  227. package/src/types/Interactive.ts +8 -0
  228. package/src/types/List.ts +2 -0
  229. package/src/types/Overflow.ts +3 -0
  230. package/src/types/Placement.ts +16 -0
  231. package/src/types/Position.ts +3 -0
  232. package/src/types/PropDef.ts +73 -0
  233. package/src/types/Radius.ts +3 -0
  234. package/src/types/Responsive.ts +10 -0
  235. package/src/types/Shadow.ts +3 -0
  236. package/src/types/Space.ts +15 -0
  237. package/src/types/Text.ts +3 -0
  238. package/src/types/TextAlign.ts +3 -0
  239. package/src/types/Tone.ts +3 -0
  240. package/src/utils/getProps.test.ts +156 -0
  241. package/src/utils/getProps.ts +156 -0
  242. package/src/utils/mergeTriggerProps.ts +66 -0
  243. package/src/utils/renderPortal.tsx +14 -0
  244. package/src/utils/suffixClassName.ts +5 -0
  245. package/src/version.ts +3 -0
  246. package/LICENSE +0 -21
  247. package/dist/_system-CTe2lb5l.d.ts +0 -40
  248. package/dist/_system-CTe2lb5l.d.ts.map +0 -1
  249. package/dist/arrow-BmX6qbAS.js +0 -170
  250. package/dist/arrow-BmX6qbAS.js.map +0 -1
  251. package/dist/autocomplete.d.ts +0 -140
  252. package/dist/autocomplete.d.ts.map +0 -1
  253. package/dist/autocomplete.js +0 -470
  254. package/dist/autocomplete.js.map +0 -1
  255. package/dist/breadcrumbs.d.ts +0 -18
  256. package/dist/breadcrumbs.d.ts.map +0 -1
  257. package/dist/breadcrumbs.js +0 -119
  258. package/dist/breadcrumbs.js.map +0 -1
  259. package/dist/button-BNyKSDyA.js +0 -180
  260. package/dist/button-BNyKSDyA.js.map +0 -1
  261. package/dist/button-dnqMFkWg.d.ts +0 -76
  262. package/dist/button-dnqMFkWg.d.ts.map +0 -1
  263. package/dist/card-C0a0wQTc.d.ts +0 -7
  264. package/dist/card-C0a0wQTc.d.ts.map +0 -1
  265. package/dist/code.d.ts +0 -20
  266. package/dist/code.d.ts.map +0 -1
  267. package/dist/code.js +0 -90
  268. package/dist/code.js.map +0 -1
  269. package/dist/codeFontStyle-84SMhFtI.js +0 -11
  270. package/dist/codeFontStyle-84SMhFtI.js.map +0 -1
  271. package/dist/component-DVlwaWB-.d.ts +0 -25
  272. package/dist/component-DVlwaWB-.d.ts.map +0 -1
  273. package/dist/element-BYgCE_iK.js +0 -51
  274. package/dist/element-BYgCE_iK.js.map +0 -1
  275. package/dist/factory-BzXTX8_Q.js +0 -3056
  276. package/dist/factory-BzXTX8_Q.js.map +0 -1
  277. package/dist/flex-DmbDG2ks.js +0 -76
  278. package/dist/flex-DmbDG2ks.js.map +0 -1
  279. package/dist/font-EtfxKPUz.d.ts +0 -49
  280. package/dist/font-EtfxKPUz.d.ts.map +0 -1
  281. package/dist/getElementRef-Jw7gY0eV.js +0 -102
  282. package/dist/getElementRef-Jw7gY0eV.js.map +0 -1
  283. package/dist/getScopedTheme-C-sZsyAz.js +0 -267
  284. package/dist/getScopedTheme-C-sZsyAz.js.map +0 -1
  285. package/dist/getTheme_v2-y09KqtEb.js +0 -487
  286. package/dist/getTheme_v2-y09KqtEb.js.map +0 -1
  287. package/dist/grid-6JSgMj1O.js +0 -115
  288. package/dist/grid-6JSgMj1O.js.map +0 -1
  289. package/dist/helpers-C8xxXAQC.js +0 -63
  290. package/dist/helpers-C8xxXAQC.js.map +0 -1
  291. package/dist/hotkeys-CaHsQlsO.js +0 -168
  292. package/dist/hotkeys-CaHsQlsO.js.map +0 -1
  293. package/dist/index.d.ts.map +0 -1
  294. package/dist/layer-Bl5R3uNR.js +0 -61
  295. package/dist/layer-Bl5R3uNR.js.map +0 -1
  296. package/dist/layer-ChlP9Ik6.d.ts +0 -242
  297. package/dist/layer-ChlP9Ik6.d.ts.map +0 -1
  298. package/dist/menu.d.ts +0 -146
  299. package/dist/menu.d.ts.map +0 -1
  300. package/dist/menu.js +0 -626
  301. package/dist/menu.js.map +0 -1
  302. package/dist/popover-B7-28L8y.js +0 -408
  303. package/dist/popover-B7-28L8y.js.map +0 -1
  304. package/dist/popover-CMlQeKn0.d.ts +0 -96
  305. package/dist/popover-CMlQeKn0.d.ts.map +0 -1
  306. package/dist/popover.d.ts +0 -2
  307. package/dist/popover.js +0 -3
  308. package/dist/refractor-CC48DwHi.js +0 -20
  309. package/dist/refractor-CC48DwHi.js.map +0 -1
  310. package/dist/responsiveFont-CilwaORG.js +0 -55
  311. package/dist/responsiveFont-CilwaORG.js.map +0 -1
  312. package/dist/rgba-BSYaEUW6.d.ts +0 -846
  313. package/dist/rgba-BSYaEUW6.d.ts.map +0 -1
  314. package/dist/selectable-B0GUIL74.d.ts +0 -7
  315. package/dist/selectable-B0GUIL74.d.ts.map +0 -1
  316. package/dist/stack-rsNFPq2-.js +0 -112
  317. package/dist/stack-rsNFPq2-.js.map +0 -1
  318. package/dist/styles-css.d.ts +0 -2
  319. package/dist/styles-css.js +0 -4
  320. package/dist/textInput-pSfQjkmx.js +0 -313
  321. package/dist/textInput-pSfQjkmx.js.map +0 -1
  322. package/dist/theme.d.ts +0 -280
  323. package/dist/theme.d.ts.map +0 -1
  324. package/dist/theme.js +0 -55
  325. package/dist/theme.js.map +0 -1
  326. package/dist/toast.d.ts +0 -73
  327. package/dist/toast.d.ts.map +0 -1
  328. package/dist/toast.js +0 -302
  329. package/dist/toast.js.map +0 -1
  330. package/dist/tooltip.d.ts +0 -88
  331. package/dist/tooltip.d.ts.map +0 -1
  332. package/dist/tooltip.js +0 -435
  333. package/dist/tooltip.js.map +0 -1
  334. package/dist/useClickOutsideEvent-wGLGWBZN.js +0 -36
  335. package/dist/useClickOutsideEvent-wGLGWBZN.js.map +0 -1
  336. package/dist/useElementSize-BJvbGHq8.js +0 -51
  337. package/dist/useElementSize-BJvbGHq8.js.map +0 -1
  338. package/dist/useLayer-D1usxIE0.js +0 -712
  339. package/dist/useLayer-D1usxIE0.js.map +0 -1
@@ -0,0 +1,3 @@
1
+ export const RADIUS = [0, 1, 2, 3, 4, 5, 6, 'full'] as const
2
+ /** @public */
3
+ export type Radius = (typeof RADIUS)[number]
@@ -0,0 +1,10 @@
1
+ /** @public */
2
+ export type Responsive<T> =
3
+ | T
4
+ | []
5
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 1})
6
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 2})
7
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 3})
8
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 4})
9
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 5})
10
+ | ([T | undefined | null, ...(T | undefined | null)[]] & {length: 6})
@@ -0,0 +1,3 @@
1
+ export const SHADOW = [0, 1, 2, 3, 4, 5] as const
2
+ /** @public */
3
+ export type Shadow = (typeof SHADOW)[number]
@@ -0,0 +1,15 @@
1
+ export const SPACE = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as const
2
+ /** @public */
3
+ export type Space = (typeof SPACE)[number]
4
+
5
+ export const SPACE_AUTO = [...SPACE, 'auto'] as const
6
+ /** @public */
7
+ export type SpaceAuto = (typeof SPACE_AUTO)[number]
8
+
9
+ export const SPACE_INHERIT = [...SPACE, 'inherit'] as const
10
+ /** @public */
11
+ export type SpaceInherit = (typeof SPACE_INHERIT)[number]
12
+
13
+ export const SPACE_AUTO_NEGATIVE = [-9, -8, -7, -6, -5, -4, -3, -2, -1, ...SPACE, 'auto'] as const
14
+ /** @public */
15
+ export type SpaceAutoNegative = (typeof SPACE_AUTO_NEGATIVE)[number]
@@ -0,0 +1,3 @@
1
+ export const TEXT_SIZE = [0, 1, 2, 3, 4] as const
2
+ /** @public */
3
+ export type TextSize = (typeof TEXT_SIZE)[number]
@@ -0,0 +1,3 @@
1
+ export const TEXT_ALIGN = ['left', 'center', 'right', 'justify'] as const
2
+ /** @public */
3
+ export type TextAlign = (typeof TEXT_ALIGN)[number]
@@ -0,0 +1,3 @@
1
+ export const TONE = ['neutral', 'positive', 'suggest', 'caution', 'critical'] as const
2
+ /** @public */
3
+ export type Tone = (typeof TONE)[number]
@@ -0,0 +1,156 @@
1
+ import {describe, expect, it} from 'vitest'
2
+
3
+ import {cardProps} from '../components/card/card.props'
4
+ import {layoutProps} from '../props/layout'
5
+ import {typographyProps} from '../props/typography'
6
+ import {getProps} from './getProps'
7
+
8
+ describe('getProps', () => {
9
+ it('generates className based on an union', () => {
10
+ const result = getProps({padding: 1}, layoutProps)
11
+ expect(result.className).toBe('sui-p1')
12
+ expect(result.style).toEqual({})
13
+ })
14
+
15
+ it('does not generate className based on union if value is unsupported', () => {
16
+ const result = getProps({padding: 10}, layoutProps)
17
+ expect(result.className).toBe('')
18
+ expect(result.style).toEqual({})
19
+ })
20
+
21
+ it('merges existing className', () => {
22
+ const result = getProps({className: 'test', padding: 1}, layoutProps)
23
+ expect(result.className).toBe('test sui-p1')
24
+ expect(result.style).toEqual({})
25
+ })
26
+
27
+ it('generates className and style based on a string', () => {
28
+ const result = getProps({width: '100px'}, layoutProps)
29
+ expect(result.className).toBe('sui-width')
30
+ expect(result.style).toEqual({'--width': '100px'})
31
+ })
32
+
33
+ it('merges existing style', () => {
34
+ const result = getProps({width: '100px', style: {display: 'block'}}, layoutProps)
35
+ expect(result.className).toBe('sui-width')
36
+ expect(result.style).toEqual({'--width': '100px', 'display': 'block'})
37
+ })
38
+
39
+ it('generates className based on a boolean', () => {
40
+ const result = getProps({border: true}, layoutProps)
41
+ expect(result.className).toBe('sui-border')
42
+ expect(result.style).toEqual({})
43
+ })
44
+
45
+ it('generates className based on a number', () => {
46
+ const result = getProps({flexGrow: 1.5}, layoutProps)
47
+ expect(result.className).toBe('sui-flex-grow')
48
+ expect(result.style).toEqual({'--flex-grow': 1.5})
49
+ })
50
+
51
+ it('generates className based on a composite', () => {
52
+ const result = getProps({density: 'regular'}, cardProps)
53
+ expect(result.className).toBe('sui-gap3 sui-p4 sui-radius3')
54
+ expect(result.style).toEqual({})
55
+ })
56
+
57
+ it('generates multiple classNames', () => {
58
+ const result = getProps({border: true, padding: 1}, layoutProps)
59
+ expect(result.className).toBe('sui-border sui-p1')
60
+ expect(result.style).toEqual({})
61
+ })
62
+
63
+ it('preserves undefined props', () => {
64
+ const result = getProps({padding: 1, id: 'test'}, layoutProps)
65
+ expect(result.className).toBe('sui-p1')
66
+ expect(result['id']).toEqual('test')
67
+ })
68
+
69
+ it('preserves non-styling props', () => {
70
+ const result = getProps({padding: 1, as: 'div'}, layoutProps)
71
+ expect(result.className).toBe('sui-p1')
72
+ expect(result.style).toEqual({})
73
+ expect(result['as']).toEqual('div')
74
+ })
75
+
76
+ it('preserves non-styling responsive props', () => {
77
+ const result = getProps({padding: 1, items: [{label: 'One'}, {label: 'Two'}]}, layoutProps)
78
+ expect(result.className).toBe('sui-p1')
79
+ expect(result.style).toEqual({})
80
+ expect(result['items']).toEqual([{label: 'One'}, {label: 'Two'}])
81
+ })
82
+
83
+ it('generates responsive className based on unions', () => {
84
+ const result = getProps({padding: [1, 2, 3]}, layoutProps)
85
+ expect(result.className).toBe('sui-p1 sui-p2-bp-1 sui-p3-bp-2')
86
+ expect(result.style).toEqual({})
87
+ })
88
+
89
+ it('generates responsive className and style based on strings', () => {
90
+ const result = getProps({width: ['100px', '200px', '300px']}, layoutProps)
91
+ expect(result.className).toBe('sui-width sui-width-bp-1 sui-width-bp-2')
92
+ expect(result.style).toEqual({
93
+ '--width': '100px',
94
+ '--width-bp-1': '200px',
95
+ '--width-bp-2': '300px',
96
+ })
97
+ })
98
+
99
+ it('generates responsive className based on booleans', () => {
100
+ const result = getProps({border: [true, false, true]}, layoutProps)
101
+ expect(result.className).toBe('sui-border sui-border-none-bp-1 sui-border-bp-2')
102
+ expect(result.style).toEqual({})
103
+ })
104
+
105
+ it('generates responsive className based on composites', () => {
106
+ const result = getProps({density: ['compact', 'regular']}, cardProps)
107
+ expect(result.className).toBe(
108
+ 'sui-gap2 sui-gap3-bp-1 sui-p3 sui-p4-bp-1 sui-radius2 sui-radius3-bp-1',
109
+ )
110
+ expect(result.style).toEqual({})
111
+ })
112
+
113
+ it('does not generate responsive className with more values than breakpoints', () => {
114
+ const result = getProps({padding: [1, 2, 3, 4, 5, 6, 7, 8]}, layoutProps)
115
+ expect(result.className).toBe(
116
+ 'sui-p1 sui-p2-bp-1 sui-p3-bp-2 sui-p4-bp-3 sui-p5-bp-4 sui-p6-bp-5',
117
+ )
118
+ expect(result.style).toEqual({})
119
+ })
120
+
121
+ it('generates responsive className with undefined values', () => {
122
+ const result = getProps({padding: [1, 2, undefined, 3]}, layoutProps)
123
+ expect(result.className).toBe('sui-p1 sui-p2-bp-1 sui-p3-bp-3')
124
+ expect(result.style).toEqual({})
125
+ })
126
+
127
+ it('generates responsive className with null values', () => {
128
+ const result = getProps({padding: [1, 2, null, 3]}, layoutProps)
129
+ expect(result.className).toBe('sui-p1 sui-p2-bp-1 sui-p3-bp-3')
130
+ expect(result.style).toEqual({})
131
+ })
132
+
133
+ it('generates responsive className without unsupported values', () => {
134
+ const result = getProps({padding: [1, 2, 10, 3]}, layoutProps)
135
+ expect(result.className).toBe('sui-p1 sui-p2-bp-1 sui-p3-bp-3')
136
+ expect(result.style).toEqual({})
137
+ })
138
+
139
+ it('generates className based on a conditional', () => {
140
+ const result = getProps({truncate: 1}, typographyProps)
141
+ expect(result.className).toBe('sui-text-overflow')
142
+ expect(result.style).toEqual({})
143
+ })
144
+
145
+ it('generates className and style based on a conditional', () => {
146
+ const result = getProps({truncate: 3}, typographyProps)
147
+ expect(result.className).toBe('sui-line-clamp')
148
+ expect(result.style).toEqual({'--line-clamp': 3})
149
+ })
150
+
151
+ it('generates responsive className and style based on a conditional', () => {
152
+ const result = getProps({truncate: [1, 3]}, typographyProps)
153
+ expect(result.className).toBe('sui-text-overflow sui-line-clamp-bp-1')
154
+ expect(result.style).toEqual({'--line-clamp-bp-1': 3})
155
+ })
156
+ })
@@ -0,0 +1,156 @@
1
+ import clsx from 'clsx'
2
+
3
+ import {type PropDef} from '../types/PropDef'
4
+
5
+ const PREFIX = 'sui'
6
+ const BREAKPOINTS_LENGTH = 6
7
+
8
+ interface ComponentProps {
9
+ className?: string | undefined
10
+ style?: React.CSSProperties | undefined
11
+ [key: string]: any
12
+ }
13
+
14
+ export function getProps(
15
+ componentProps?: ComponentProps,
16
+ propDefs?: Record<string, PropDef>,
17
+ ): ComponentProps {
18
+ const {allComponentProps, allPropDefs} = flattenCompositeProps(componentProps, propDefs)
19
+ const restProps: ComponentProps = {}
20
+ let className = componentProps?.className || ''
21
+ let style = componentProps?.style || {}
22
+
23
+ for (const key in allComponentProps) {
24
+ const propDef = allPropDefs?.[key]
25
+ const propValue = allComponentProps[key]
26
+
27
+ if (
28
+ !((propDef && 'className' in propDef && propDef.className) || propDef?.type === 'conditional')
29
+ ) {
30
+ restProps[key] = propValue
31
+ continue
32
+ }
33
+
34
+ if (Array.isArray(propValue)) {
35
+ // @TODO: consider fixing this O(n^2) time complexity
36
+ // oxlint-disable-next-line no-accumulating-spread
37
+ for (let i = 0, len = Math.min(propValue.length, BREAKPOINTS_LENGTH); i < len; i++) {
38
+ const resolvedPropDef = getResolvedPropDef(propValue[i], propDef)
39
+
40
+ if (!resolvedPropDef) {
41
+ continue
42
+ }
43
+
44
+ className = clsx(className, getClassName(propValue[i], resolvedPropDef, i))
45
+ style = {...style, ...getStyle(propValue[i], resolvedPropDef, i)}
46
+ }
47
+ } else {
48
+ const resolvedPropDef = getResolvedPropDef(propValue, propDef)
49
+
50
+ if (!resolvedPropDef) {
51
+ restProps[key] = propValue
52
+ continue
53
+ }
54
+
55
+ className = clsx(className, getClassName(propValue, resolvedPropDef))
56
+ style = {...style, ...getStyle(propValue, resolvedPropDef)}
57
+ }
58
+ }
59
+
60
+ return {...restProps, className, style}
61
+ }
62
+
63
+ function getResolvedPropDef(propValue: any, propDef?: PropDef) {
64
+ if (propDef?.type !== 'conditional') {
65
+ return propDef
66
+ }
67
+
68
+ const resolvedPropDef = propDef.resolve(propValue)
69
+
70
+ if (!(resolvedPropDef && 'className' in resolvedPropDef && resolvedPropDef.className)) {
71
+ return null
72
+ }
73
+
74
+ return resolvedPropDef
75
+ }
76
+
77
+ function getClassName(propValue: any, propDef: PropDef, bp?: number) {
78
+ if (propDef.type === 'union' && propDef.values?.includes(propValue)) {
79
+ /* Note: This may need updating depending on the final CSS classname formatting */
80
+ return `${PREFIX}-${propDef.className}${typeof propValue === 'string' ? `-${propValue}` : propValue}${bp ? `-bp-${bp}` : ''}`
81
+ }
82
+
83
+ if (propDef.type === 'string' || propDef.type === 'number') {
84
+ return `${PREFIX}-${propDef.className}${bp ? `-bp-${bp}` : ''}`
85
+ }
86
+
87
+ if (propDef.type === 'boolean') {
88
+ if (propValue) {
89
+ return `${PREFIX}-${propDef.className}${bp ? `-bp-${bp}` : ''}`
90
+ }
91
+
92
+ if (!propValue && propDef.inverseClassName) {
93
+ return `${PREFIX}-${propDef.inverseClassName}${bp ? `-bp-${bp}` : ''}`
94
+ }
95
+ }
96
+
97
+ return ''
98
+ }
99
+
100
+ function getStyle(propValue: any, propDef: PropDef, bp?: number) {
101
+ if ((propDef.type === 'string' || propDef.type === 'number') && propDef.variable) {
102
+ return {
103
+ [`${propDef.variable}${bp ? `-bp-${bp}` : ''}`]: propValue,
104
+ }
105
+ }
106
+
107
+ return {}
108
+ }
109
+
110
+ export function flattenCompositeProps(
111
+ componentProps?: ComponentProps,
112
+ propDefs?: Record<string, PropDef>,
113
+ ) {
114
+ const props = {
115
+ allComponentProps: {} as ComponentProps,
116
+ allPropDefs: {} as Record<string, PropDef>,
117
+ }
118
+
119
+ for (const key in componentProps) {
120
+ if (propDefs?.[key] && propDefs?.[key].type === 'composite') {
121
+ for (const compositeKey in propDefs?.[key].composition) {
122
+ const compositeValue = getCompositeValue(componentProps[key], propDefs[key], compositeKey)
123
+
124
+ props.allComponentProps[compositeKey] = compositeValue
125
+ props.allPropDefs[compositeKey] = propDefs[key].composition[compositeKey]
126
+ ?.propDef as PropDef
127
+ }
128
+ } else {
129
+ props.allComponentProps[key] = componentProps[key]
130
+ props.allPropDefs[key] = propDefs?.[key] as PropDef
131
+ }
132
+ }
133
+
134
+ return props
135
+ }
136
+
137
+ function getCompositeValue(propValue: any, propDef: PropDef, key: string) {
138
+ if (!('composition' in propDef)) {
139
+ return
140
+ }
141
+
142
+ const mapping = propDef.composition[key]?.['mapping']
143
+ let compositeValue
144
+
145
+ if (Array.isArray(propValue)) {
146
+ compositeValue = []
147
+
148
+ for (let i = 0, len = propValue.length; i < len; i++) {
149
+ compositeValue[i] = mapping?.[propValue[i]]
150
+ }
151
+ } else {
152
+ compositeValue = mapping?.[propValue]
153
+ }
154
+
155
+ return compositeValue
156
+ }
@@ -0,0 +1,66 @@
1
+ function isReactEventHandler(key: string, value: unknown): value is (e: never) => void {
2
+ return /^on[A-Z]/.test(key) && typeof value === 'function'
3
+ }
4
+
5
+ function chainEventHandlers<E>(
6
+ ...handlers: (((e: E) => void) | undefined)[]
7
+ ): ((e: E) => void) | undefined {
8
+ const defined = handlers.filter(Boolean) as ((e: E) => void)[]
9
+
10
+ if (defined.length === 0) {
11
+ return undefined
12
+ }
13
+
14
+ if (defined.length === 1) {
15
+ return defined[0]
16
+ }
17
+
18
+ return (e: E) => {
19
+ for (const handler of defined) {
20
+ handler(e)
21
+ }
22
+ }
23
+ }
24
+
25
+ export function mergeTriggerProps(
26
+ childProps: Record<string, unknown>,
27
+ forwardedProps?: Record<string, unknown>,
28
+ ownProps?: Record<string, unknown>,
29
+ ) {
30
+ const result: Record<string, unknown> = {}
31
+
32
+ for (const source of [forwardedProps, ownProps]) {
33
+ if (!source) {
34
+ continue
35
+ }
36
+
37
+ for (const [key, value] of Object.entries(source)) {
38
+ if (key === 'style') {
39
+ continue
40
+ }
41
+
42
+ if (isReactEventHandler(key, value)) {
43
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
44
+ continue
45
+ }
46
+
47
+ if (value !== undefined) {
48
+ result[key] = value
49
+ }
50
+ }
51
+ }
52
+
53
+ result['style'] = {
54
+ ...(childProps['style'] as object),
55
+ ...(forwardedProps?.['style'] as object),
56
+ ...(ownProps?.['style'] as object),
57
+ }
58
+
59
+ for (const [key, value] of Object.entries(childProps)) {
60
+ if (isReactEventHandler(key, value)) {
61
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
62
+ }
63
+ }
64
+
65
+ return result
66
+ }
@@ -0,0 +1,14 @@
1
+ import {type ReactNode} from 'react'
2
+ import {createPortal} from 'react-dom'
3
+
4
+ export function renderPortal(node: ReactNode, mounted: boolean, portal?: boolean) {
5
+ if (!portal) {
6
+ return node
7
+ }
8
+
9
+ if (!mounted) {
10
+ return null
11
+ }
12
+
13
+ return createPortal(node, document.body)
14
+ }
@@ -0,0 +1,5 @@
1
+ import {HASH} from '../version'
2
+
3
+ export function suffixClassName(className: string) {
4
+ return `${className}-${HASH}`
5
+ }
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ // This file is generated by scripts/write-version.js. Do not edit.
2
+ export const VERSION = '500alpha10'
3
+ export const HASH = 'ad9fa1'
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Sanity.io
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,40 +0,0 @@
1
- /** @public */
2
- declare const THEME_COLOR_SCHEMES: readonly ['light', 'dark'];
3
- /** @public */
4
- declare const THEME_COLOR_BLEND_MODES: readonly ['multiply', 'screen'];
5
- /** @public */
6
- declare const THEME_COLOR_CARD_TONES: readonly ['transparent', 'default', 'neutral', 'primary', 'suggest', 'positive', 'caution', 'critical'];
7
- /** @public */
8
- declare const THEME_COLOR_STATE_TONES: readonly ['default', 'neutral', 'primary', 'suggest', 'positive', 'caution', 'critical'];
9
- /** @public */
10
- declare const THEME_COLOR_STATES: readonly ['enabled', 'hovered', 'pressed', 'selected', 'disabled'];
11
- /** @public */
12
- declare const THEME_COLOR_BUTTON_MODES: readonly ['default', 'ghost', 'bleed'];
13
- /** @public */
14
- declare const THEME_COLOR_INPUT_MODES: readonly ['default', 'invalid'];
15
- /** @public */
16
- declare const THEME_COLOR_INPUT_STATES: readonly ['enabled', 'hovered', 'readOnly', 'disabled'];
17
- /** @public */
18
- declare const THEME_COLOR_AVATAR_COLORS: import("@sanity/color").ColorHueKey[];
19
- /**
20
- * @public
21
- */
22
- type ThemeColorSchemeKey = (typeof THEME_COLOR_SCHEMES)[number];
23
- /** @public */
24
- type ThemeColorBlendModeKey = (typeof THEME_COLOR_BLEND_MODES)[number];
25
- /** @public */
26
- type ThemeColorCardToneKey = (typeof THEME_COLOR_CARD_TONES)[number];
27
- /** @public */
28
- type ThemeColorButtonModeKey = (typeof THEME_COLOR_BUTTON_MODES)[number];
29
- /** @public */
30
- type ThemeColorStateKey = (typeof THEME_COLOR_STATES)[number];
31
- /** @public */
32
- type ThemeColorStateToneKey = (typeof THEME_COLOR_STATE_TONES)[number];
33
- /** @public */
34
- type ThemeColorInputModeKey = (typeof THEME_COLOR_INPUT_MODES)[number];
35
- /** @public */
36
- type ThemeColorInputStateKey = (typeof THEME_COLOR_INPUT_STATES)[number];
37
- /** @public */
38
- type ThemeColorAvatarColorKey = (typeof THEME_COLOR_AVATAR_COLORS)[number];
39
- export { THEME_COLOR_STATES as _, ThemeColorInputModeKey as a, ThemeColorStateKey as c, THEME_COLOR_BLEND_MODES as d, THEME_COLOR_BUTTON_MODES as f, THEME_COLOR_SCHEMES as g, THEME_COLOR_INPUT_STATES as h, ThemeColorCardToneKey as i, ThemeColorStateToneKey as l, THEME_COLOR_INPUT_MODES as m, ThemeColorBlendModeKey as n, ThemeColorInputStateKey as o, THEME_COLOR_CARD_TONES as p, ThemeColorButtonModeKey as r, ThemeColorSchemeKey as s, ThemeColorAvatarColorKey as t, THEME_COLOR_AVATAR_COLORS as u, THEME_COLOR_STATE_TONES as v };
40
- //# sourceMappingURL=_system-CTe2lb5l.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_system-CTe2lb5l.d.ts","names":[],"sources":["../src/theme/system/color/_constants.ts","../src/theme/system/color/_system.ts"],"mappings":"AAGA;cAAa;;cAGA;;cAGA;;cAYA;;cAWA;;cAGA;;cAGA;;cAGA;;cAGA,mDAAyB;;;;KC7B1B,8BAA8B;;KAG9B,iCAAiC;;KAGjC,gCAAgC;;KAGhC,kCAAkC;;KAGlC,6BAA6B;;KAG7B,iCAAiC;;KAGjC,iCAAiC;;KAGjC,kCAAkC;;KAGlC,mCAAmC"}