@42-central/ui-react 0.24.0 → 0.25.0

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 (208) hide show
  1. package/dist/{chunk-FUNTJZX7.js → chunk-2CL3FKEY.js} +3 -3
  2. package/dist/{chunk-FUNTJZX7.js.map → chunk-2CL3FKEY.js.map} +1 -1
  3. package/dist/{chunk-OZMSXYBX.js → chunk-36NWC4GV.js} +3 -3
  4. package/dist/{chunk-OZMSXYBX.js.map → chunk-36NWC4GV.js.map} +1 -1
  5. package/dist/{chunk-4FEOMQYR.js → chunk-54W6VAI3.js} +5 -5
  6. package/dist/{chunk-4FEOMQYR.js.map → chunk-54W6VAI3.js.map} +1 -1
  7. package/dist/{chunk-SZEOTXRZ.js → chunk-6II2DVYR.js} +5 -5
  8. package/dist/{chunk-SZEOTXRZ.js.map → chunk-6II2DVYR.js.map} +1 -1
  9. package/dist/{chunk-DJLNGWMM.js → chunk-6IRMKF5T.js} +3 -3
  10. package/dist/{chunk-DJLNGWMM.js.map → chunk-6IRMKF5T.js.map} +1 -1
  11. package/dist/{chunk-YPFSRZ3T.js → chunk-6UIQJJNJ.js} +3 -3
  12. package/dist/{chunk-YPFSRZ3T.js.map → chunk-6UIQJJNJ.js.map} +1 -1
  13. package/dist/{chunk-DT6LKNZF.js → chunk-7247WBTV.js} +5 -4
  14. package/dist/chunk-7247WBTV.js.map +1 -0
  15. package/dist/{chunk-6VYGK3Q3.js → chunk-7E7JNWOC.js} +16 -21
  16. package/dist/chunk-7E7JNWOC.js.map +1 -0
  17. package/dist/{chunk-C4NFRSOR.js → chunk-7HZBD4YZ.js} +4 -4
  18. package/dist/{chunk-C4NFRSOR.js.map → chunk-7HZBD4YZ.js.map} +1 -1
  19. package/dist/{chunk-JVG5ISPT.js → chunk-AHKMN3YQ.js} +3 -3
  20. package/dist/{chunk-JVG5ISPT.js.map → chunk-AHKMN3YQ.js.map} +1 -1
  21. package/dist/{chunk-UAYENYS2.js → chunk-AKXALCUN.js} +3 -3
  22. package/dist/{chunk-UAYENYS2.js.map → chunk-AKXALCUN.js.map} +1 -1
  23. package/dist/{chunk-BE2LWUHY.js → chunk-BMEJBY6H.js} +5 -3
  24. package/dist/chunk-BMEJBY6H.js.map +1 -0
  25. package/dist/{chunk-MXAACRWE.js → chunk-E52Z2FKU.js} +5 -5
  26. package/dist/{chunk-MXAACRWE.js.map → chunk-E52Z2FKU.js.map} +1 -1
  27. package/dist/chunk-F374BNL4.js +129 -0
  28. package/dist/chunk-F374BNL4.js.map +1 -0
  29. package/dist/{chunk-MRAJ45IM.js → chunk-FZSLSUSX.js} +4 -4
  30. package/dist/{chunk-MRAJ45IM.js.map → chunk-FZSLSUSX.js.map} +1 -1
  31. package/dist/{chunk-3L5GLI67.js → chunk-I4B3N3UX.js} +3 -3
  32. package/dist/{chunk-3L5GLI67.js.map → chunk-I4B3N3UX.js.map} +1 -1
  33. package/dist/{chunk-IPYHTCFL.js → chunk-IUK7OJXZ.js} +3 -3
  34. package/dist/{chunk-IPYHTCFL.js.map → chunk-IUK7OJXZ.js.map} +1 -1
  35. package/dist/{chunk-2MXWEIMD.js → chunk-KKLCHLCZ.js} +12 -11
  36. package/dist/chunk-KKLCHLCZ.js.map +1 -0
  37. package/dist/{chunk-YWTOW7PZ.js → chunk-LHUWOA2U.js} +8 -8
  38. package/dist/{chunk-YWTOW7PZ.js.map → chunk-LHUWOA2U.js.map} +1 -1
  39. package/dist/{chunk-6N6J2DOE.js → chunk-LIZWCWED.js} +3 -3
  40. package/dist/{chunk-6N6J2DOE.js.map → chunk-LIZWCWED.js.map} +1 -1
  41. package/dist/{chunk-O7LS6OZR.js → chunk-LMCUGYHT.js} +3 -3
  42. package/dist/{chunk-O7LS6OZR.js.map → chunk-LMCUGYHT.js.map} +1 -1
  43. package/dist/{chunk-DHJB4UJD.js → chunk-N5M4PDBK.js} +4 -4
  44. package/dist/{chunk-DHJB4UJD.js.map → chunk-N5M4PDBK.js.map} +1 -1
  45. package/dist/{chunk-DA4QII2N.js → chunk-NLSJ6T7V.js} +4 -4
  46. package/dist/{chunk-DA4QII2N.js.map → chunk-NLSJ6T7V.js.map} +1 -1
  47. package/dist/{chunk-UT3TOV2Q.js → chunk-OVT2KZHY.js} +3 -3
  48. package/dist/{chunk-UT3TOV2Q.js.map → chunk-OVT2KZHY.js.map} +1 -1
  49. package/dist/{chunk-SVKN5ZHX.js → chunk-PEHFWGTT.js} +16 -13
  50. package/dist/chunk-PEHFWGTT.js.map +1 -0
  51. package/dist/{chunk-J44FJ7PH.js → chunk-PFZMB3US.js} +4 -4
  52. package/dist/{chunk-J44FJ7PH.js.map → chunk-PFZMB3US.js.map} +1 -1
  53. package/dist/{chunk-IRNF274I.js → chunk-PI7X5YFJ.js} +3 -3
  54. package/dist/{chunk-IRNF274I.js.map → chunk-PI7X5YFJ.js.map} +1 -1
  55. package/dist/{chunk-F2FSHVO5.js → chunk-QZ4N5LYG.js} +7 -7
  56. package/dist/{chunk-F2FSHVO5.js.map → chunk-QZ4N5LYG.js.map} +1 -1
  57. package/dist/{chunk-E5H3YWZV.js → chunk-SAXWCGWR.js} +3 -3
  58. package/dist/{chunk-E5H3YWZV.js.map → chunk-SAXWCGWR.js.map} +1 -1
  59. package/dist/{chunk-SWVUXEBT.js → chunk-SCXXJDKQ.js} +3 -3
  60. package/dist/{chunk-SWVUXEBT.js.map → chunk-SCXXJDKQ.js.map} +1 -1
  61. package/dist/{chunk-D3JYDAUZ.js → chunk-T44RW5DW.js} +4 -4
  62. package/dist/{chunk-D3JYDAUZ.js.map → chunk-T44RW5DW.js.map} +1 -1
  63. package/dist/{chunk-FB2G4LNH.js → chunk-UDCCOUWR.js} +5 -5
  64. package/dist/{chunk-FB2G4LNH.js.map → chunk-UDCCOUWR.js.map} +1 -1
  65. package/dist/{chunk-TCFB23JT.js → chunk-WERJ44ZN.js} +3 -3
  66. package/dist/{chunk-TCFB23JT.js.map → chunk-WERJ44ZN.js.map} +1 -1
  67. package/dist/{chunk-QNKD2SQM.js → chunk-X3YIHN2U.js} +5 -5
  68. package/dist/{chunk-QNKD2SQM.js.map → chunk-X3YIHN2U.js.map} +1 -1
  69. package/dist/{chunk-VD6PB3VA.js → chunk-X6DESK37.js} +12 -3
  70. package/dist/chunk-X6DESK37.js.map +1 -0
  71. package/dist/{chunk-7AQ4MN4M.js → chunk-XUFCI262.js} +4 -4
  72. package/dist/{chunk-7AQ4MN4M.js.map → chunk-XUFCI262.js.map} +1 -1
  73. package/dist/{chunk-47LEAR6G.js → chunk-Y2G47ARQ.js} +6 -6
  74. package/dist/{chunk-47LEAR6G.js.map → chunk-Y2G47ARQ.js.map} +1 -1
  75. package/dist/{chunk-F342ZT7O.js → chunk-ZVECQBGG.js} +13 -7
  76. package/dist/chunk-ZVECQBGG.js.map +1 -0
  77. package/dist/components/action-icon/action-icon.d.ts.map +1 -1
  78. package/dist/components/action-icon/index.js +1 -1
  79. package/dist/components/alert/index.js +1 -1
  80. package/dist/components/ambient-background/index.js +5 -3
  81. package/dist/components/ambient-background/index.js.map +1 -1
  82. package/dist/components/ambient-background/starfield.d.ts.map +1 -1
  83. package/dist/components/app-shell/index.js +4 -4
  84. package/dist/components/autocomplete/index.js +3 -3
  85. package/dist/components/avatar/index.js +2 -2
  86. package/dist/components/badge/badge.d.ts.map +1 -1
  87. package/dist/components/badge/index.js +1 -1
  88. package/dist/components/button/index.js +1 -1
  89. package/dist/components/button-multi-select/index.js +3 -3
  90. package/dist/components/button-select/index.js +3 -3
  91. package/dist/components/calendar/index.js +4 -4
  92. package/dist/components/calendar-heatmap/index.js +2 -2
  93. package/dist/components/camera/index.js +10 -10
  94. package/dist/components/card/card.d.ts.map +1 -1
  95. package/dist/components/card/index.js +1 -1
  96. package/dist/components/carousel/index.js +2 -2
  97. package/dist/components/checkbox/checkbox.d.ts +3 -2
  98. package/dist/components/checkbox/checkbox.d.ts.map +1 -1
  99. package/dist/components/checkbox/index.js +2 -2
  100. package/dist/components/choice-card-group/index.js +2 -2
  101. package/dist/components/choice-card-group/index.js.map +1 -1
  102. package/dist/components/clipboard/index.js +3 -3
  103. package/dist/components/code-block/code-block.d.ts +6 -3
  104. package/dist/components/code-block/code-block.d.ts.map +1 -1
  105. package/dist/components/code-block/highlighter.d.ts +16 -15
  106. package/dist/components/code-block/highlighter.d.ts.map +1 -1
  107. package/dist/components/code-block/index.d.ts +2 -1
  108. package/dist/components/code-block/index.d.ts.map +1 -1
  109. package/dist/components/code-block/index.js +81 -10
  110. package/dist/components/code-block/index.js.map +1 -1
  111. package/dist/components/code-block/languages.d.ts +61 -0
  112. package/dist/components/code-block/languages.d.ts.map +1 -0
  113. package/dist/components/code-block/static.d.ts +2 -1
  114. package/dist/components/code-block/static.d.ts.map +1 -1
  115. package/dist/components/code-block/static.js +99 -10
  116. package/dist/components/code-block/static.js.map +1 -1
  117. package/dist/components/combobox/index.js +3 -3
  118. package/dist/components/combobox-list/index.js +5 -5
  119. package/dist/components/compare/index.js +2 -2
  120. package/dist/components/data-table/index.js +30 -30
  121. package/dist/components/data-table/index.js.map +1 -1
  122. package/dist/components/date-picker/index.js +12 -12
  123. package/dist/components/download-button/index.js +2 -2
  124. package/dist/components/drawer/index.js +4 -4
  125. package/dist/components/field/field.d.ts +3 -0
  126. package/dist/components/field/field.d.ts.map +1 -1
  127. package/dist/components/field/index.js +1 -1
  128. package/dist/components/file-item/index.js +5 -5
  129. package/dist/components/file-preview/index.js +5 -5
  130. package/dist/components/file-trigger/index.js +2 -2
  131. package/dist/components/file-upload/index.js +6 -6
  132. package/dist/components/gallery/index.js +2 -2
  133. package/dist/components/geodesic/a11y.d.ts +3 -3
  134. package/dist/components/geodesic/a11y.d.ts.map +1 -1
  135. package/dist/components/image-cropper/index.js +7 -7
  136. package/dist/components/indicator/index.js +1 -1
  137. package/dist/components/input/index.js +2 -2
  138. package/dist/components/kbd/index.js +3 -3
  139. package/dist/components/kbd/kbd.d.ts.map +1 -1
  140. package/dist/components/lightbox/index.js +7 -7
  141. package/dist/components/menu/index.js +2 -2
  142. package/dist/components/modal/index.js +4 -4
  143. package/dist/components/multi-combobox-list/index.js +5 -5
  144. package/dist/components/multi-select/index.js +6 -6
  145. package/dist/components/number-input/index.js +3 -3
  146. package/dist/components/overlays/index.js +6 -6
  147. package/dist/components/password-input/index.js +3 -3
  148. package/dist/components/photo-capture/index.js +14 -14
  149. package/dist/components/pills-input/index.js +5 -5
  150. package/dist/components/pin-input/index.js +2 -2
  151. package/dist/components/radio-group/index.js +1 -1
  152. package/dist/components/rating/index.js +1 -1
  153. package/dist/components/schedule/index.js +5 -5
  154. package/dist/components/segment-group/index.js +4 -4
  155. package/dist/components/select/index.js +4 -4
  156. package/dist/components/slider/index.js +2 -2
  157. package/dist/components/spotlight/index.js +9 -9
  158. package/dist/components/switch/index.js +14 -19
  159. package/dist/components/switch/index.js.map +1 -1
  160. package/dist/components/switch/switch.d.ts +1 -0
  161. package/dist/components/switch/switch.d.ts.map +1 -1
  162. package/dist/components/table/index.js +1 -1
  163. package/dist/components/table/table.d.ts.map +1 -1
  164. package/dist/components/tabs/index.js +3 -3
  165. package/dist/components/tags-input/index.js +5 -5
  166. package/dist/components/text-input/index.js +2 -2
  167. package/dist/components/textarea/index.js +2 -2
  168. package/dist/components/theme-icon/index.js +1 -1
  169. package/dist/components/theme-icon/theme-icon.d.ts.map +1 -1
  170. package/dist/components/time-input/index.js +7 -7
  171. package/dist/components/tree-multi-select/index.js +6 -6
  172. package/dist/components/tree-select/index.js +3 -3
  173. package/dist/index.js +4 -4
  174. package/dist/theme.css +28 -23
  175. package/package.json +1 -1
  176. package/src/components/action-icon/action-icon.tsx +3 -1
  177. package/src/components/ambient-background/starfield.tsx +4 -2
  178. package/src/components/badge/badge.tsx +11 -6
  179. package/src/components/button/button.tsx +1 -1
  180. package/src/components/card/card.tsx +10 -9
  181. package/src/components/checkbox/checkbox.test.tsx +17 -9
  182. package/src/components/checkbox/checkbox.tsx +26 -27
  183. package/src/components/choice-card-group/choice-card-group.tsx +3 -3
  184. package/src/components/code-block/code-block.tsx +7 -4
  185. package/src/components/code-block/highlighter.test.ts +79 -1
  186. package/src/components/code-block/highlighter.ts +76 -30
  187. package/src/components/code-block/index.ts +2 -0
  188. package/src/components/code-block/languages.ts +63 -0
  189. package/src/components/code-block/static.tsx +2 -1
  190. package/src/components/data-table/data-table-pagination.tsx +5 -5
  191. package/src/components/data-table/data-table-stack.tsx +2 -2
  192. package/src/components/field/field.tsx +14 -0
  193. package/src/components/kbd/kbd.tsx +2 -1
  194. package/src/components/switch/switch.test.tsx +15 -0
  195. package/src/components/switch/switch.tsx +27 -27
  196. package/src/components/table/table.test.tsx +1 -1
  197. package/src/components/table/table.tsx +14 -11
  198. package/src/components/theme-icon/theme-icon.tsx +46 -12
  199. package/src/theme.css +28 -23
  200. package/dist/chunk-2MXWEIMD.js.map +0 -1
  201. package/dist/chunk-6VYGK3Q3.js.map +0 -1
  202. package/dist/chunk-7CNDZZZ6.js +0 -95
  203. package/dist/chunk-7CNDZZZ6.js.map +0 -1
  204. package/dist/chunk-BE2LWUHY.js.map +0 -1
  205. package/dist/chunk-DT6LKNZF.js.map +0 -1
  206. package/dist/chunk-F342ZT7O.js.map +0 -1
  207. package/dist/chunk-SVKN5ZHX.js.map +0 -1
  208. package/dist/chunk-VD6PB3VA.js.map +0 -1
@@ -10,7 +10,13 @@ import { type IconMap, iconStroke, mergeIcons } from "../../lib/icons"
10
10
  import { props } from "../../lib/props"
11
11
  import type { Size } from "../../lib/sizes"
12
12
  import type { WithTestId } from "../../lib/test-id"
13
- import { FieldShell, fieldA11yProps, fieldLabel, fieldRoot, requiredMark } from "../field/field"
13
+ import {
14
+ FieldShell,
15
+ fieldA11yProps,
16
+ fieldInlineStack,
17
+ fieldLabel,
18
+ requiredMark,
19
+ } from "../field/field"
14
20
  import { CheckIcon } from "../popover/icons"
15
21
  import { type ControlIndicatorVariant, controlIndicator } from "./control"
16
22
 
@@ -22,8 +28,8 @@ import { type ControlIndicatorVariant, controlIndicator } from "./control"
22
28
  * layout footprint when it's visually hidden (e.g. `classNames.label:
23
29
  * "sr-only"`): an absolutely-positioned flex child isn't a flex item at all,
24
30
  * so it can't pick up the root's `gap-2`. `description` / `error` live below
25
- * it via the shared `Field` scaffold, so a `Checkbox` is accessible and
26
- * complete on its own. Implements the kit's `FormControlProps` contract: the
31
+ * the label via the shared `Field` scaffold, with the box centered on the
32
+ * label line, so a `Checkbox` is accessible and complete on its own. Implements the kit's `FormControlProps` contract: the
27
33
  * `ref` and `onBlur` land on the submittable hidden `<input>`, and `name`
28
34
  * wires it into native form submission.
29
35
  *
@@ -90,6 +96,7 @@ export type CheckboxProps = WithTestId & {
90
96
  root?: string
91
97
  control?: string
92
98
  label?: string
99
+ /** The description / error field, under the label. */
93
100
  field?: string
94
101
  }
95
102
  }
@@ -136,9 +143,10 @@ export const Checkbox = ({
136
143
  // library can flip it from `fieldState.invalid` (see FormControlProps).
137
144
  const isInvalid = invalid || error != null
138
145
 
139
- // A visible label above description/error needs the two grouped into one
140
- // flex-col item, or they'd land side by side in the root's row instead of
141
- // stacked. Label-only (incl. sr-only) never needs this extra wrapper.
146
+ // A visible label above description/error switches the root to a grid: the
147
+ // control centers on the label's row alone (not on the whole text stack),
148
+ // and the field hangs under the label in the second column. Label-only
149
+ // (incl. sr-only) stays a plain inline row.
142
150
  const hasStack = label != null && (description != null || error != null)
143
151
 
144
152
  const labelNode = label != null && (
@@ -171,7 +179,9 @@ export const Checkbox = ({
171
179
  // `relative` contains the absolutely positioned hidden input, which would
172
180
  // otherwise escape any scroller this control sits in.
173
181
  className={cn(
174
- "relative inline-flex items-center gap-2 select-none",
182
+ hasStack
183
+ ? fieldInlineStack({ size })
184
+ : "relative inline-flex items-center gap-2 select-none",
175
185
  className,
176
186
  classNames?.root,
177
187
  )}
@@ -181,26 +191,15 @@ export const Checkbox = ({
181
191
  <Ark.Indicator indeterminate>{icons.indeterminate}</Ark.Indicator>
182
192
  </Ark.Control>
183
193
 
184
- {hasStack ? (
185
- <div className={cn(fieldRoot({ size }), classNames?.field)}>
186
- {labelNode}
187
- <FieldShell description={description} error={error} size={size}>
188
- <CheckboxHiddenInput ref={ref} onBlur={onBlur} />
189
- </FieldShell>
190
- </div>
191
- ) : (
192
- <>
193
- {labelNode}
194
- <FieldShell
195
- description={description}
196
- error={error}
197
- size={size}
198
- className={classNames?.field}
199
- >
200
- <CheckboxHiddenInput ref={ref} onBlur={onBlur} />
201
- </FieldShell>
202
- </>
203
- )}
194
+ {labelNode}
195
+ <FieldShell
196
+ description={description}
197
+ error={error}
198
+ size={size}
199
+ className={cn(hasStack && "col-start-2", classNames?.field)}
200
+ >
201
+ <CheckboxHiddenInput ref={ref} onBlur={onBlur} />
202
+ </FieldShell>
204
203
  </Ark.Root>
205
204
  )
206
205
  }
@@ -177,8 +177,8 @@ export type ChoiceCardGroupProps<Data extends ChoiceCardGroupData = ChoiceCardIt
177
177
 
178
178
  /**
179
179
  * The card surface. Neutral at rest on the kit's translucent surface — the same
180
- * `bg-white/4` + `border-brand-900/20 dark:border-white/15` recipe as `Input`'s
181
- * `default` shell (also used by `Card` and `SegmentGroup`): a fixed opaque
180
+ * `bg-white/4` + `border-brand-900/20 dark:border-white/8` recipe as `Card`
181
+ * (Figma's `border-primary`, the card hairline): a fixed opaque
182
182
  * gray fill can vanish or over-assert depending on the host background, so the
183
183
  * fill carries no ground of its own. The selected treatment follows the
184
184
  * `variant`, mirroring `Checkbox` / `RadioGroup`:
@@ -198,7 +198,7 @@ const choiceCard = cva(
198
198
  "relative flex w-full cursor-pointer rounded-card border text-start select-none transition-[background-color,border-color,box-shadow]",
199
199
  "bg-white/4",
200
200
  TEXT_COLOR_CLASSES.primary,
201
- "border-brand-900/20 dark:border-white/15",
201
+ "border-brand-900/20 dark:border-white/8",
202
202
  "hover:border-brand-900/30 dark:hover:border-white/25",
203
203
  // Keyboard focus ring on the whole card — the kit's standard brand ring,
204
204
  // matching Checkbox / Radio regardless of palette.
@@ -13,6 +13,7 @@ import {
13
13
  } from "./chrome"
14
14
  import type { CodeBlockGutterColumn } from "./gutters"
15
15
  import { type CodeBlockTagStyle, highlightCode } from "./highlighter"
16
+ import type { CodeBlockLanguage } from "./languages"
16
17
  import { type ParsedNotation, parseNotation } from "./notation"
17
18
 
18
19
  export type {
@@ -60,8 +61,10 @@ export type { CodeBlockTagStyle } from "./highlighter"
60
61
  export type CodeBlockProps = WithTestId & {
61
62
  /** Source text to highlight. No `children` slot — content is Shiki-derived. */
62
63
  code: string
63
- /** Shiki-bundled language id (e.g. "tsx", "bash", "json"). Omit → plain "text" grammar, no async load. */
64
- language?: string
64
+ /** A bundled language id or alias (e.g. "tsx", "bash", "json"), or a name
65
+ * registered through `registerLanguage`. An unknown name renders as plain
66
+ * text, with a dev-only warning. Omit → plain "text" grammar, no async load. */
67
+ language?: CodeBlockLanguage
65
68
  /** Override the light/dark Shiki theme pair. @default { light: "github-light", dark: "github-dark-default" } */
66
69
  themes?: { light: string; dark: string }
67
70
  /** Notation-tag → styling lookup — a line carrying `// [!code removed]`
@@ -75,7 +78,7 @@ export type CodeBlockProps = WithTestId & {
75
78
  * run after the internal notation transformer — the escape hatch for
76
79
  * extending Shiki's own capabilities. See also `registerLanguage`/
77
80
  * `registerTheme` (exported from `@42/ui-react/code-block`) for
78
- * registering a custom language/theme the bundled set doesn't ship. */
81
+ * registering a language/theme the bundled set doesn't ship. */
79
82
  transformers?: ShikiTransformer[]
80
83
  /** Parse `// [!code tag]` markers. `false` renders them verbatim instead —
81
84
  * for a snippet that teaches the notation itself. @default true */
@@ -114,7 +117,7 @@ export type CodeBlockProps = WithTestId & {
114
117
 
115
118
  type HighlightedPreProps = {
116
119
  code: string
117
- lang?: string
120
+ lang?: CodeBlockLanguage
118
121
  themes?: { light: string; dark: string }
119
122
  tags?: Record<string, CodeBlockTagStyle>
120
123
  gutters?: CodeBlockGutterColumn[]
@@ -1,5 +1,6 @@
1
- import { describe, expect, it } from "vitest"
1
+ import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from "vitest"
2
2
  import { highlightCode, registerLanguage, registerTheme } from "./highlighter"
3
+ import { LANGUAGES } from "./languages"
3
4
  import { parseNotation } from "./notation"
4
5
 
5
6
  describe("highlightCode", () => {
@@ -259,3 +260,80 @@ describe("highlightCode", () => {
259
260
  expect(html).toContain("shiki")
260
261
  })
261
262
  })
263
+
264
+ /** One sample per bundled grammar. Running each through the real
265
+ * highlighter catches a grammar the JavaScript regex engine can't compile:
266
+ * it would throw, or fall back to unstyled tokens. */
267
+ const SAMPLES: Record<string, string> = {
268
+ c: "int main(void) { return 0; }",
269
+ cpp: "template <typename T> T id(T x) { return x; }",
270
+ python: "def f(x):\n return x + 1",
271
+ shellscript: 'for f in *.c; do echo "$f"; done',
272
+ javascript: "const x = () => 1",
273
+ typescript: "const x: number = 1",
274
+ jsx: 'const a = <div className="x">hi</div>',
275
+ tsx: "const a: JSX.Element = <div>hi</div>",
276
+ json: '{ "a": [1, true, null] }',
277
+ yaml: "key: value\nlist:\n - 1",
278
+ markdown: "# Title\n\n**bold** and `code`",
279
+ html: '<p class="x">hi</p><script>let a = 1</script>',
280
+ css: ".a { color: red; }",
281
+ sql: "SELECT id FROM users WHERE id = 1;",
282
+ go: "func main() { fmt.Println(1) }",
283
+ rust: "fn main() { let x: u8 = 1; }",
284
+ java: "class A { int x = 1; }",
285
+ make: "all: $(NAME)\n\tcc -o $@ $^",
286
+ docker: "FROM node:22\nRUN pnpm install",
287
+ diff: "--- a\n+++ b\n-old\n+new",
288
+ }
289
+
290
+ describe("bundled languages", () => {
291
+ let warn: MockInstance<typeof console.warn>
292
+ beforeEach(() => {
293
+ warn = vi.spyOn(console, "warn").mockImplementation(() => {})
294
+ })
295
+ afterEach(() => warn.mockRestore())
296
+
297
+ it.each(Object.keys(LANGUAGES))("%s highlights with colored tokens", async (lang) => {
298
+ const loaded = (await LANGUAGES[lang as keyof typeof LANGUAGES]()).default
299
+ const name = loaded[loaded.length - 1]?.name ?? lang
300
+ const html = await highlightCode(SAMPLES[name] ?? "x", { lang })
301
+ // more than one distinct token color → the grammar actually tokenized
302
+ const colors = new Set(html.match(/--shiki-light:#[0-9a-fA-F]+/g))
303
+ expect(colors.size).toBeGreaterThan(1)
304
+ expect(warn).not.toHaveBeenCalled()
305
+ })
306
+
307
+ it("renders an unknown language as plain text and warns once", async () => {
308
+ const a = await highlightCode("let x = 1", { lang: "not-a-language" })
309
+ await highlightCode("let y = 2", { lang: "not-a-language" })
310
+ expect(a).toContain("let x = 1")
311
+ expect(new Set(a.match(/--shiki-light:#[0-9a-fA-F]+/g)).size).toBeLessThanOrEqual(1)
312
+ expect(warn).toHaveBeenCalledTimes(1)
313
+ expect(warn.mock.calls[0]?.[0]).toContain('"not-a-language"')
314
+ expect(warn.mock.calls[0]?.[0]).toContain("registerLanguage")
315
+ })
316
+
317
+ it("does not load a Shiki grammar outside the map by name", async () => {
318
+ await highlightCode("main = print 1", { lang: "haskell" })
319
+ expect(warn).toHaveBeenCalledTimes(1)
320
+ })
321
+
322
+ it("falls back to the default theme for an unregistered theme name", async () => {
323
+ const fallback = await highlightCode("const x = 1", {
324
+ lang: "ts",
325
+ themes: { light: "nord", dark: "github-dark-default" },
326
+ })
327
+ const defaults = await highlightCode("const x = 1", { lang: "ts" })
328
+ expect(fallback).toBe(defaults)
329
+ expect(warn).toHaveBeenCalledTimes(1)
330
+ expect(warn.mock.calls[0]?.[0]).toContain('"nord"')
331
+ })
332
+
333
+ it("uses a registered Shiki grammar the map doesn't bundle", async () => {
334
+ await registerLanguage((await import("shiki/langs/haskell.mjs")).default)
335
+ const html = await highlightCode("main = print 1", { lang: "haskell" })
336
+ expect(new Set(html.match(/--shiki-light:#[0-9a-fA-F]+/g)).size).toBeGreaterThan(1)
337
+ expect(warn).not.toHaveBeenCalled()
338
+ })
339
+ })
@@ -1,12 +1,14 @@
1
1
  import type {
2
- Highlighter,
2
+ HighlighterCore,
3
3
  LanguageInput,
4
4
  ShikiTransformer,
5
5
  ShikiTransformerContext,
6
6
  ThemeInput,
7
7
  } from "shiki"
8
8
  import type { Color } from "../../lib/colors"
9
+ import { devWarnOnce } from "../../lib/dev-warn"
9
10
  import { type CodeBlockGutterColumn, resolveGutterColumns } from "./gutters"
11
+ import { type CodeBlockLanguage, languageLoader } from "./languages"
10
12
  import { type ParsedNotation, parseNotation } from "./notation"
11
13
 
12
14
  /** Structurally the same `Element` (hast) type `ShikiTransformer`'s own
@@ -20,33 +22,49 @@ type HastNode = LineHast["children"][number]
20
22
  /**
21
23
  * Module-level singleton — created lazily on first use, shared by every
22
24
  * `CodeBlock` on the page (a docs page can render dozens).
25
+ *
26
+ * Built from Shiki's fine-grained core, never the bare `shiki` entry: that
27
+ * one's registries carry ~300 grammar/theme imports and the Oniguruma WASM,
28
+ * which every consumer's bundler would have to emit. The JavaScript regex
29
+ * engine replaces the WASM, the two default themes are the only themes
30
+ * loaded by name, and grammars come from the finite `LANGUAGES` map.
23
31
  */
24
32
  const DEFAULT_THEMES = { light: "github-light", dark: "github-dark-default" } as const
25
33
 
26
- let highlighterPromise: Promise<Highlighter> | null = null
34
+ let highlighterPromise: Promise<HighlighterCore> | null = null
27
35
 
28
- function getHighlighter(): Promise<Highlighter> {
36
+ function getHighlighter(): Promise<HighlighterCore> {
29
37
  if (!highlighterPromise) {
30
- highlighterPromise = import("shiki").then(({ createHighlighter }) =>
31
- createHighlighter({ themes: [DEFAULT_THEMES.light, DEFAULT_THEMES.dark], langs: [] }),
38
+ highlighterPromise = Promise.all([
39
+ import("shiki/core"),
40
+ import("shiki/engine/javascript"),
41
+ import("shiki/themes/github-light.mjs"),
42
+ import("shiki/themes/github-dark-default.mjs"),
43
+ ]).then(([{ createHighlighterCore }, { createJavaScriptRegexEngine }, light, dark]) =>
44
+ createHighlighterCore({
45
+ themes: [light.default, dark.default],
46
+ langs: [],
47
+ engine: createJavaScriptRegexEngine(),
48
+ }),
32
49
  )
33
50
  }
34
51
  return highlighterPromise
35
52
  }
36
53
 
37
54
  /**
38
- * Register a custom TextMate grammar so `<CodeBlock language="...">` can
39
- * reference it by name, the same as a bundled language — Shiki's own
40
- * extension mechanism for a language it doesn't ship. Await this once
41
- * (e.g. at app startup) before rendering a `CodeBlock` that uses it.
55
+ * Register a TextMate grammar so `<CodeBlock language="...">` can reference
56
+ * it by name. Needed for any language outside the bundled `LANGUAGES` map,
57
+ * including Shiki's own: `registerLanguage((await import("shiki/langs/haskell.mjs")).default)`.
58
+ * Await this once (e.g. at app startup) before rendering a `CodeBlock` that
59
+ * uses it.
42
60
  */
43
61
  export async function registerLanguage(lang: LanguageInput): Promise<void> {
44
62
  const highlighter = await getHighlighter()
45
63
  await highlighter.loadLanguage(lang)
46
64
  }
47
65
 
48
- /** Register a custom VS Code-style theme, the same as a bundled theme —
49
- * Shiki's own extension mechanism for a theme it doesn't ship. */
66
+ /** Register a VS Code-style theme so `themes` can reference it by name.
67
+ * Only `github-light` and `github-dark-default` load without it. */
50
68
  export async function registerTheme(theme: ThemeInput): Promise<void> {
51
69
  const highlighter = await getHighlighter()
52
70
  await highlighter.loadTheme(theme)
@@ -80,7 +98,7 @@ type CodeBlockStyle = {
80
98
  export type CodeBlockTagStyle = CodeBlockStyle
81
99
 
82
100
  export type HighlightOptions = {
83
- lang?: string
101
+ lang?: CodeBlockLanguage
84
102
  themes?: { light: string; dark: string }
85
103
  /** Notation-tag → styling lookup — see `CodeBlockTagStyle`. */
86
104
  tags?: Record<string, CodeBlockTagStyle>
@@ -256,29 +274,57 @@ function buildCodeBlockTransformer(
256
274
  }
257
275
  }
258
276
 
259
- /** Highlights `code` as HTML via the shared Shiki singleton. Loads the
260
- * requested language/themes on demand — via the highlighter's own
261
- * `getLoadedLanguages`/`getLoadedThemes` (authoritative, so a name
262
- * registered through `registerLanguage`/`registerTheme` is recognized as
263
- * already loaded and never re-fetched as if it were a bundled id). `lang`
264
- * defaults to `"text"` (Shiki's built-in plaintext grammar — no dynamic
265
- * import needed). Called with `defaultColor: false` so neither theme is
266
- * inlined as a plain `color`/`background-color` — both live only in the
277
+ /** Shiki's built-in plain-text names: rendered without any grammar. */
278
+ const PLAIN_LANGUAGES = new Set(["text", "txt", "plain", "plaintext"])
279
+
280
+ /** Resolves `lang` to a name the highlighter can render: already loaded
281
+ * (bundled earlier, or registered), loadable from the `LANGUAGES` map, or
282
+ * else plain text, with a dev warning naming the fix. Unknown names used to
283
+ * reject inside `loadLanguage`, leaving the block unhighlighted for good. */
284
+ async function resolveLanguage(highlighter: HighlighterCore, lang: string): Promise<string> {
285
+ if (PLAIN_LANGUAGES.has(lang) || highlighter.getLoadedLanguages().includes(lang)) return lang
286
+ const loader = languageLoader(lang)
287
+ if (loader) {
288
+ await highlighter.loadLanguage((await loader()).default)
289
+ return lang
290
+ }
291
+ devWarnOnce(
292
+ `CodeBlock: unknown language "${lang}", rendering as plain text. Register its grammar with registerLanguage() first.`,
293
+ )
294
+ return "text"
295
+ }
296
+
297
+ /** Resolves one theme slot to a loaded theme name. Only the two defaults are
298
+ * loaded up front; any other name has to come through `registerTheme`, or
299
+ * that slot falls back to its default, with a dev warning. */
300
+ function resolveTheme(
301
+ highlighter: HighlighterCore,
302
+ name: string,
303
+ slot: keyof typeof DEFAULT_THEMES,
304
+ ): string {
305
+ if (highlighter.getLoadedThemes().includes(name)) return name
306
+ devWarnOnce(
307
+ `CodeBlock: unknown theme "${name}", using "${DEFAULT_THEMES[slot]}" instead. Register it with registerTheme() first.`,
308
+ )
309
+ return DEFAULT_THEMES[slot]
310
+ }
311
+
312
+ /** Highlights `code` as HTML via the shared Shiki singleton. The language
313
+ * loads on demand from the `LANGUAGES` map; a name registered through
314
+ * `registerLanguage`/`registerTheme` is recognized as already loaded via the
315
+ * highlighter's own `getLoadedLanguages`/`getLoadedThemes`. `lang` defaults
316
+ * to `"text"` (Shiki's built-in plaintext grammar — no dynamic import
317
+ * needed). Called with `defaultColor: false` so neither theme is inlined as
318
+ * a plain `color`/`background-color` — both live only in the
267
319
  * `--shiki-light`/`--shiki-dark` custom properties consumed by
268
320
  * `styles.css`, so the dark-mode CSS rule there needs no `!important`. */
269
321
  export async function highlightCode(code: string, opts: HighlightOptions = {}): Promise<string> {
270
- const lang = opts.lang ?? "text"
271
- const themes = opts.themes ?? DEFAULT_THEMES
272
322
  const highlighter = await getHighlighter()
273
323
  const notation = opts.notation ?? parseNotation(code)
274
-
275
- await Promise.all(
276
- [themes.light, themes.dark]
277
- .filter((t) => !highlighter.getLoadedThemes().includes(t))
278
- .map((t) => highlighter.loadTheme(t as never)),
279
- )
280
- if (!highlighter.getLoadedLanguages().includes(lang)) {
281
- await highlighter.loadLanguage(lang as never)
324
+ const lang = await resolveLanguage(highlighter, opts.lang ?? "text")
325
+ const themes = {
326
+ light: resolveTheme(highlighter, opts.themes?.light ?? DEFAULT_THEMES.light, "light"),
327
+ dark: resolveTheme(highlighter, opts.themes?.dark ?? DEFAULT_THEMES.dark, "dark"),
282
328
  }
283
329
 
284
330
  return highlighter.codeToHtml(code, {
@@ -13,6 +13,7 @@ import type {
13
13
  CodeBlockGutterColumn,
14
14
  } from "./gutters"
15
15
  import { type CodeBlockTagStyle, registerLanguage, registerTheme } from "./highlighter"
16
+ import type { CodeBlockLanguage } from "./languages"
16
17
  import { highlight, lineNumbers } from "./presets"
17
18
  // Extensionless, matching every other relative import in this package — the
18
19
  // compiled output needs a `.js` suffix here (Node ESM, "type": "module", is
@@ -46,6 +47,7 @@ export {
46
47
  type CodeBlockGutterColumn,
47
48
  type CodeBlockIconSlot,
48
49
  type CodeBlockIcons,
50
+ type CodeBlockLanguage,
49
51
  type CodeBlockProps,
50
52
  type CodeBlockStaticProps,
51
53
  type CodeBlockTagStyle,
@@ -0,0 +1,63 @@
1
+ import type { LanguageRegistration } from "shiki"
2
+
3
+ type LanguageLoader = () => Promise<{ default: LanguageRegistration[] }>
4
+
5
+ /**
6
+ * The grammars `CodeBlock` can load by name — a deliberately finite map.
7
+ *
8
+ * Each entry is a separate dynamic import, so a consumer's bundler emits one
9
+ * chunk per grammar here and nothing more. Shiki's full bundle registers
10
+ * ~300 of them (plus the Oniguruma WASM), and every app depending on the kit
11
+ * paid to emit and parse all of them even when it highlighted two languages.
12
+ *
13
+ * Aliases point to the same loader as their grammar: loading it registers
14
+ * Shiki's own aliases too, so `ts` and `typescript` resolve to one grammar.
15
+ * Anything not listed is added by the caller through `registerLanguage`.
16
+ */
17
+ export const LANGUAGES = {
18
+ c: () => import("shiki/langs/c.mjs"),
19
+ cpp: () => import("shiki/langs/cpp.mjs"),
20
+ "c++": () => import("shiki/langs/cpp.mjs"),
21
+ python: () => import("shiki/langs/python.mjs"),
22
+ py: () => import("shiki/langs/python.mjs"),
23
+ shellscript: () => import("shiki/langs/shellscript.mjs"),
24
+ bash: () => import("shiki/langs/shellscript.mjs"),
25
+ sh: () => import("shiki/langs/shellscript.mjs"),
26
+ shell: () => import("shiki/langs/shellscript.mjs"),
27
+ zsh: () => import("shiki/langs/shellscript.mjs"),
28
+ javascript: () => import("shiki/langs/javascript.mjs"),
29
+ js: () => import("shiki/langs/javascript.mjs"),
30
+ cjs: () => import("shiki/langs/javascript.mjs"),
31
+ mjs: () => import("shiki/langs/javascript.mjs"),
32
+ typescript: () => import("shiki/langs/typescript.mjs"),
33
+ ts: () => import("shiki/langs/typescript.mjs"),
34
+ cts: () => import("shiki/langs/typescript.mjs"),
35
+ mts: () => import("shiki/langs/typescript.mjs"),
36
+ jsx: () => import("shiki/langs/jsx.mjs"),
37
+ tsx: () => import("shiki/langs/tsx.mjs"),
38
+ json: () => import("shiki/langs/json.mjs"),
39
+ yaml: () => import("shiki/langs/yaml.mjs"),
40
+ yml: () => import("shiki/langs/yaml.mjs"),
41
+ markdown: () => import("shiki/langs/markdown.mjs"),
42
+ md: () => import("shiki/langs/markdown.mjs"),
43
+ html: () => import("shiki/langs/html.mjs"),
44
+ css: () => import("shiki/langs/css.mjs"),
45
+ sql: () => import("shiki/langs/sql.mjs"),
46
+ go: () => import("shiki/langs/go.mjs"),
47
+ rust: () => import("shiki/langs/rust.mjs"),
48
+ rs: () => import("shiki/langs/rust.mjs"),
49
+ java: () => import("shiki/langs/java.mjs"),
50
+ make: () => import("shiki/langs/make.mjs"),
51
+ makefile: () => import("shiki/langs/make.mjs"),
52
+ docker: () => import("shiki/langs/docker.mjs"),
53
+ dockerfile: () => import("shiki/langs/docker.mjs"),
54
+ diff: () => import("shiki/langs/diff.mjs"),
55
+ } satisfies Record<string, LanguageLoader>
56
+
57
+ /** A language `CodeBlock` resolves by name: a bundled id or alias, `"text"`,
58
+ * or any name registered through `registerLanguage`. */
59
+ export type CodeBlockLanguage = keyof typeof LANGUAGES | "text" | (string & {})
60
+
61
+ export function languageLoader(lang: string): LanguageLoader | undefined {
62
+ return Object.hasOwn(LANGUAGES, lang) ? LANGUAGES[lang as keyof typeof LANGUAGES] : undefined
63
+ }
@@ -14,11 +14,12 @@ import {
14
14
  } from "./chrome"
15
15
  import type { CodeBlockGutterColumn } from "./gutters"
16
16
  import { type CodeBlockTagStyle, highlightCode } from "./highlighter"
17
+ import type { CodeBlockLanguage } from "./languages"
17
18
  import { parseNotation } from "./notation"
18
19
 
19
20
  export type CodeBlockStaticProps = WithTestId & {
20
21
  code: string
21
- language?: string
22
+ language?: CodeBlockLanguage
22
23
  themes?: { light: string; dark: string }
23
24
  tags?: Record<string, CodeBlockTagStyle>
24
25
  gutters?: CodeBlockGutterColumn[]
@@ -135,17 +135,17 @@ export function DataTablePagination<TEntity extends RowData>({
135
135
  return (
136
136
  <div
137
137
  className={cn(
138
- // Same brand-tinted fill as thead/tfoot — this is Table's third
139
- // chrome band (it renders inside the same container), not a separate
140
- // opaque surface.
141
- "bg-brand-50/90 dark:bg-brand-950/85",
138
+ // Same fill as thead/tfoot — this is Table's third chrome band (it
139
+ // renders inside the same container): clear in the dark theme, where
140
+ // the frame carries the surface (Figma's pagination is the table's).
141
+ "bg-brand-50/90 dark:bg-transparent",
142
142
  // `flex-wrap`: both groups are intrinsically sized, and this band sits
143
143
  // *outside* Table's `overflow-auto` frame under an `overflow-hidden`
144
144
  // root — so in a container too narrow for both (a `max-w-xs` card, say)
145
145
  // a squeeze has nowhere to go and would silently clip the controls.
146
146
  // Dropping the page controls to a second row degrades instead.
147
147
  // `gap-2` already covers both axes.
148
- "flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-brand-900/20 px-4 py-3 dark:border-white/15",
148
+ "flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-brand-900/20 px-4 py-3 dark:border-white/8",
149
149
  className,
150
150
  )}
151
151
  >
@@ -295,7 +295,7 @@ export function DataTableStackOptions<TEntity extends RowData>({
295
295
  )}
296
296
  {sortableColumns.length > 0 && (
297
297
  <>
298
- <hr className="mt-6 mb-2 border-0 border-t border-brand-900/20 dark:border-white/15" />
298
+ <hr className="mt-6 mb-2 border-0 border-t border-brand-900/20 dark:border-white/8" />
299
299
  <div className="flex flex-col gap-3">
300
300
  <div className="flex items-center justify-between">
301
301
  <Text size="xs" c="muted" className="uppercase tracking-wide">
@@ -339,7 +339,7 @@ export function DataTableStackOptions<TEntity extends RowData>({
339
339
  {filterableColumns.length > 0 && (
340
340
  <>
341
341
  {(sortableColumns.length > 0 || enableColumnVisibility) && (
342
- <hr className="mt-6 mb-2 border-0 border-t border-brand-900/20 dark:border-white/15" />
342
+ <hr className="mt-6 mb-2 border-0 border-t border-brand-900/20 dark:border-white/8" />
343
343
  )}
344
344
  <div className="flex flex-col gap-4">
345
345
  <div className="flex items-center justify-between">
@@ -43,6 +43,20 @@ export const fieldRoot = cva("relative flex w-full flex-col", {
43
43
  defaultVariants: { size: "md" },
44
44
  })
45
45
 
46
+ // Root of an inline control (Switch, Checkbox) whose label carries a
47
+ // description or error: a two-column grid, so the control centers on the
48
+ // label's row alone instead of on the whole text stack, and the field (placed
49
+ // with `col-start-2`) hangs under the label. The row gap follows `fieldRoot`'s.
50
+ export const fieldInlineStack = cva(
51
+ "relative inline-grid grid-cols-[auto_1fr] items-center gap-x-2 select-none",
52
+ {
53
+ variants: {
54
+ size: { xs: "gap-y-1", sm: "gap-y-1", md: "gap-y-1.5", lg: "gap-y-1.5", xl: "gap-y-2" },
55
+ },
56
+ defaultVariants: { size: "md" },
57
+ },
58
+ )
59
+
46
60
  export const fieldLabel = cva(
47
61
  [
48
62
  "inline-flex items-center font-medium select-none text-trim",
@@ -76,7 +76,8 @@ const kbdVariants = cva(
76
76
  variant: {
77
77
  filled: "bg-(--c-solid) text-(--c-on-solid)",
78
78
  light: "bg-(--c-soft) text-(--c-text)",
79
- outline: "bg-transparent text-(--c-text) border-(--c-solid)",
79
+ // Button's outline edge: the colour at 35%.
80
+ outline: "bg-transparent text-(--c-text) border-(--c-solid)/35",
80
81
  subtle: "bg-transparent text-(--c-text)",
81
82
  // The key cap sits on the kit's translucent surface recipe — a 3%/4%
82
83
  // overlay plus the hairline `border-brand-900/20 dark:border-white/15`,
@@ -72,6 +72,21 @@ describe("Switch", () => {
72
72
  expect(screen.getByText("Select row").className).toContain("sr-only")
73
73
  })
74
74
 
75
+ it("aligns the control to the label line when a description sits below", () => {
76
+ const { container } = render(<Switch label="Airplane mode" description="Disables all radios" />)
77
+ const root = container.querySelector("label") as HTMLElement
78
+ // A grid root with control, label and field as direct cells: the control
79
+ // centers on the label row, and the field hangs under the label.
80
+ expect(root.className).toContain("inline-grid")
81
+ expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["SPAN", "SPAN", "DIV"])
82
+ expect(root.lastElementChild?.className).toContain("col-start-2")
83
+ })
84
+
85
+ it("keeps a label-only root as an inline row", () => {
86
+ const { container } = render(<Switch label="Airplane mode" />)
87
+ expect((container.querySelector("label") as HTMLElement).className).toContain("inline-flex")
88
+ })
89
+
75
90
  it("renders a sr-only label with no extra wrapper around it", () => {
76
91
  const { container } = render(<Switch label="Select row" classNames={{ label: "sr-only" }} />)
77
92
  const root = container.querySelector("label") as HTMLElement