@42-central/ui-react 0.23.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.
- package/dist/{chunk-FUNTJZX7.js → chunk-2CL3FKEY.js} +3 -3
- package/dist/{chunk-FUNTJZX7.js.map → chunk-2CL3FKEY.js.map} +1 -1
- package/dist/{chunk-OZMSXYBX.js → chunk-36NWC4GV.js} +3 -3
- package/dist/{chunk-OZMSXYBX.js.map → chunk-36NWC4GV.js.map} +1 -1
- package/dist/{chunk-4FEOMQYR.js → chunk-54W6VAI3.js} +5 -5
- package/dist/{chunk-4FEOMQYR.js.map → chunk-54W6VAI3.js.map} +1 -1
- package/dist/{chunk-SZEOTXRZ.js → chunk-6II2DVYR.js} +5 -5
- package/dist/{chunk-SZEOTXRZ.js.map → chunk-6II2DVYR.js.map} +1 -1
- package/dist/{chunk-DJLNGWMM.js → chunk-6IRMKF5T.js} +3 -3
- package/dist/{chunk-DJLNGWMM.js.map → chunk-6IRMKF5T.js.map} +1 -1
- package/dist/{chunk-YPFSRZ3T.js → chunk-6UIQJJNJ.js} +3 -3
- package/dist/{chunk-YPFSRZ3T.js.map → chunk-6UIQJJNJ.js.map} +1 -1
- package/dist/{chunk-DT6LKNZF.js → chunk-7247WBTV.js} +5 -4
- package/dist/chunk-7247WBTV.js.map +1 -0
- package/dist/{chunk-6VYGK3Q3.js → chunk-7E7JNWOC.js} +16 -21
- package/dist/chunk-7E7JNWOC.js.map +1 -0
- package/dist/{chunk-C4NFRSOR.js → chunk-7HZBD4YZ.js} +4 -4
- package/dist/{chunk-C4NFRSOR.js.map → chunk-7HZBD4YZ.js.map} +1 -1
- package/dist/{chunk-JVG5ISPT.js → chunk-AHKMN3YQ.js} +3 -3
- package/dist/{chunk-JVG5ISPT.js.map → chunk-AHKMN3YQ.js.map} +1 -1
- package/dist/{chunk-UAYENYS2.js → chunk-AKXALCUN.js} +3 -3
- package/dist/{chunk-UAYENYS2.js.map → chunk-AKXALCUN.js.map} +1 -1
- package/dist/{chunk-BE2LWUHY.js → chunk-BMEJBY6H.js} +5 -3
- package/dist/chunk-BMEJBY6H.js.map +1 -0
- package/dist/{chunk-MXAACRWE.js → chunk-E52Z2FKU.js} +5 -5
- package/dist/{chunk-MXAACRWE.js.map → chunk-E52Z2FKU.js.map} +1 -1
- package/dist/chunk-F374BNL4.js +129 -0
- package/dist/chunk-F374BNL4.js.map +1 -0
- package/dist/{chunk-MRAJ45IM.js → chunk-FZSLSUSX.js} +4 -4
- package/dist/{chunk-MRAJ45IM.js.map → chunk-FZSLSUSX.js.map} +1 -1
- package/dist/{chunk-3L5GLI67.js → chunk-I4B3N3UX.js} +3 -3
- package/dist/{chunk-3L5GLI67.js.map → chunk-I4B3N3UX.js.map} +1 -1
- package/dist/{chunk-IPYHTCFL.js → chunk-IUK7OJXZ.js} +3 -3
- package/dist/{chunk-IPYHTCFL.js.map → chunk-IUK7OJXZ.js.map} +1 -1
- package/dist/{chunk-2MXWEIMD.js → chunk-KKLCHLCZ.js} +12 -11
- package/dist/chunk-KKLCHLCZ.js.map +1 -0
- package/dist/{chunk-YWTOW7PZ.js → chunk-LHUWOA2U.js} +8 -8
- package/dist/{chunk-YWTOW7PZ.js.map → chunk-LHUWOA2U.js.map} +1 -1
- package/dist/{chunk-6N6J2DOE.js → chunk-LIZWCWED.js} +3 -3
- package/dist/{chunk-6N6J2DOE.js.map → chunk-LIZWCWED.js.map} +1 -1
- package/dist/{chunk-O7LS6OZR.js → chunk-LMCUGYHT.js} +3 -3
- package/dist/{chunk-O7LS6OZR.js.map → chunk-LMCUGYHT.js.map} +1 -1
- package/dist/{chunk-DHJB4UJD.js → chunk-N5M4PDBK.js} +4 -4
- package/dist/{chunk-DHJB4UJD.js.map → chunk-N5M4PDBK.js.map} +1 -1
- package/dist/{chunk-DA4QII2N.js → chunk-NLSJ6T7V.js} +4 -4
- package/dist/{chunk-DA4QII2N.js.map → chunk-NLSJ6T7V.js.map} +1 -1
- package/dist/{chunk-UT3TOV2Q.js → chunk-OVT2KZHY.js} +3 -3
- package/dist/{chunk-UT3TOV2Q.js.map → chunk-OVT2KZHY.js.map} +1 -1
- package/dist/{chunk-SVKN5ZHX.js → chunk-PEHFWGTT.js} +16 -13
- package/dist/chunk-PEHFWGTT.js.map +1 -0
- package/dist/{chunk-J44FJ7PH.js → chunk-PFZMB3US.js} +4 -4
- package/dist/{chunk-J44FJ7PH.js.map → chunk-PFZMB3US.js.map} +1 -1
- package/dist/{chunk-IRNF274I.js → chunk-PI7X5YFJ.js} +3 -3
- package/dist/{chunk-IRNF274I.js.map → chunk-PI7X5YFJ.js.map} +1 -1
- package/dist/{chunk-F2FSHVO5.js → chunk-QZ4N5LYG.js} +7 -7
- package/dist/{chunk-F2FSHVO5.js.map → chunk-QZ4N5LYG.js.map} +1 -1
- package/dist/{chunk-E5H3YWZV.js → chunk-SAXWCGWR.js} +3 -3
- package/dist/{chunk-E5H3YWZV.js.map → chunk-SAXWCGWR.js.map} +1 -1
- package/dist/{chunk-SWVUXEBT.js → chunk-SCXXJDKQ.js} +3 -3
- package/dist/{chunk-SWVUXEBT.js.map → chunk-SCXXJDKQ.js.map} +1 -1
- package/dist/{chunk-D3JYDAUZ.js → chunk-T44RW5DW.js} +4 -4
- package/dist/{chunk-D3JYDAUZ.js.map → chunk-T44RW5DW.js.map} +1 -1
- package/dist/{chunk-FB2G4LNH.js → chunk-UDCCOUWR.js} +5 -5
- package/dist/{chunk-FB2G4LNH.js.map → chunk-UDCCOUWR.js.map} +1 -1
- package/dist/{chunk-TCFB23JT.js → chunk-WERJ44ZN.js} +3 -3
- package/dist/{chunk-TCFB23JT.js.map → chunk-WERJ44ZN.js.map} +1 -1
- package/dist/{chunk-QNKD2SQM.js → chunk-X3YIHN2U.js} +5 -5
- package/dist/{chunk-QNKD2SQM.js.map → chunk-X3YIHN2U.js.map} +1 -1
- package/dist/{chunk-VD6PB3VA.js → chunk-X6DESK37.js} +12 -3
- package/dist/chunk-X6DESK37.js.map +1 -0
- package/dist/{chunk-7AQ4MN4M.js → chunk-XUFCI262.js} +4 -4
- package/dist/{chunk-7AQ4MN4M.js.map → chunk-XUFCI262.js.map} +1 -1
- package/dist/{chunk-47LEAR6G.js → chunk-Y2G47ARQ.js} +6 -6
- package/dist/{chunk-47LEAR6G.js.map → chunk-Y2G47ARQ.js.map} +1 -1
- package/dist/{chunk-F342ZT7O.js → chunk-ZVECQBGG.js} +13 -7
- package/dist/chunk-ZVECQBGG.js.map +1 -0
- package/dist/components/action-icon/action-icon.d.ts.map +1 -1
- package/dist/components/action-icon/index.js +1 -1
- package/dist/components/alert/index.js +1 -1
- package/dist/components/ambient-background/ambient-background.d.ts +14 -3
- package/dist/components/ambient-background/ambient-background.d.ts.map +1 -1
- package/dist/components/ambient-background/index.js +225 -2
- package/dist/components/ambient-background/index.js.map +1 -1
- package/dist/components/ambient-background/starfield.d.ts +13 -0
- package/dist/components/ambient-background/starfield.d.ts.map +1 -0
- package/dist/components/app-shell/index.js +4 -4
- package/dist/components/autocomplete/index.js +3 -3
- package/dist/components/avatar/index.js +2 -2
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/button-multi-select/index.js +3 -3
- package/dist/components/button-select/index.js +3 -3
- package/dist/components/calendar/index.js +4 -4
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +10 -10
- package/dist/components/card/card.d.ts.map +1 -1
- package/dist/components/card/index.js +1 -1
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/checkbox/checkbox.d.ts +3 -2
- package/dist/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/choice-card-group/index.js +2 -2
- package/dist/components/choice-card-group/index.js.map +1 -1
- package/dist/components/clipboard/index.js +3 -3
- package/dist/components/code-block/code-block.d.ts +6 -3
- package/dist/components/code-block/code-block.d.ts.map +1 -1
- package/dist/components/code-block/highlighter.d.ts +16 -15
- package/dist/components/code-block/highlighter.d.ts.map +1 -1
- package/dist/components/code-block/index.d.ts +2 -1
- package/dist/components/code-block/index.d.ts.map +1 -1
- package/dist/components/code-block/index.js +81 -10
- package/dist/components/code-block/index.js.map +1 -1
- package/dist/components/code-block/languages.d.ts +61 -0
- package/dist/components/code-block/languages.d.ts.map +1 -0
- package/dist/components/code-block/static.d.ts +2 -1
- package/dist/components/code-block/static.d.ts.map +1 -1
- package/dist/components/code-block/static.js +99 -10
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/combobox/index.js +3 -3
- package/dist/components/combobox-list/index.js +5 -5
- package/dist/components/compare/index.js +2 -2
- package/dist/components/data-table/index.js +30 -30
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +12 -12
- package/dist/components/download-button/index.js +2 -2
- package/dist/components/drawer/index.js +4 -4
- package/dist/components/field/field.d.ts +3 -0
- package/dist/components/field/field.d.ts.map +1 -1
- package/dist/components/field/index.js +1 -1
- package/dist/components/file-item/index.js +5 -5
- package/dist/components/file-preview/index.js +5 -5
- package/dist/components/file-trigger/index.js +2 -2
- package/dist/components/file-upload/index.js +6 -6
- package/dist/components/gallery/index.js +2 -2
- package/dist/components/geodesic/a11y.d.ts +3 -3
- package/dist/components/geodesic/a11y.d.ts.map +1 -1
- package/dist/components/image-cropper/index.js +7 -7
- package/dist/components/indicator/index.js +1 -1
- package/dist/components/input/index.js +2 -2
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/lightbox/index.js +7 -7
- package/dist/components/menu/index.js +2 -2
- package/dist/components/modal/index.js +4 -4
- package/dist/components/multi-combobox-list/index.js +5 -5
- package/dist/components/multi-select/index.js +6 -6
- package/dist/components/number-input/index.js +3 -3
- package/dist/components/overlays/index.js +6 -6
- package/dist/components/password-input/index.js +3 -3
- package/dist/components/photo-capture/index.js +14 -14
- package/dist/components/pills-input/index.js +5 -5
- package/dist/components/pin-input/index.js +2 -2
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/index.js +1 -1
- package/dist/components/schedule/index.js +5 -5
- package/dist/components/segment-group/index.js +4 -4
- package/dist/components/select/index.js +4 -4
- package/dist/components/slider/index.js +2 -2
- package/dist/components/spotlight/index.js +9 -9
- package/dist/components/switch/index.js +14 -19
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/switch.d.ts +1 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/tabs/index.js +3 -3
- package/dist/components/tags-input/index.js +5 -5
- package/dist/components/text-input/index.js +2 -2
- package/dist/components/textarea/index.js +2 -2
- package/dist/components/theme-icon/index.js +1 -1
- package/dist/components/theme-icon/theme-icon.d.ts.map +1 -1
- package/dist/components/time-input/index.js +7 -7
- package/dist/components/tree-multi-select/index.js +6 -6
- package/dist/components/tree-select/index.js +3 -3
- package/dist/index.js +4 -4
- package/dist/theme.css +103 -23
- package/package.json +1 -1
- package/src/components/action-icon/action-icon.tsx +3 -1
- package/src/components/ambient-background/ambient-background.test.tsx +59 -0
- package/src/components/ambient-background/ambient-background.tsx +15 -2
- package/src/components/ambient-background/starfield.tsx +333 -0
- package/src/components/badge/badge.tsx +11 -6
- package/src/components/button/button.tsx +1 -1
- package/src/components/card/card.tsx +10 -9
- package/src/components/checkbox/checkbox.test.tsx +17 -9
- package/src/components/checkbox/checkbox.tsx +26 -27
- package/src/components/choice-card-group/choice-card-group.tsx +3 -3
- package/src/components/code-block/code-block.tsx +7 -4
- package/src/components/code-block/highlighter.test.ts +79 -1
- package/src/components/code-block/highlighter.ts +76 -30
- package/src/components/code-block/index.ts +2 -0
- package/src/components/code-block/languages.ts +63 -0
- package/src/components/code-block/static.tsx +2 -1
- package/src/components/data-table/data-table-pagination.tsx +5 -5
- package/src/components/data-table/data-table-stack.tsx +2 -2
- package/src/components/field/field.tsx +14 -0
- package/src/components/kbd/kbd.tsx +2 -1
- package/src/components/switch/switch.test.tsx +15 -0
- package/src/components/switch/switch.tsx +27 -27
- package/src/components/table/table.test.tsx +1 -1
- package/src/components/table/table.tsx +14 -11
- package/src/components/theme-icon/theme-icon.tsx +46 -12
- package/src/icon-stroke.test.tsx +2 -0
- package/src/theme.css +103 -23
- package/src/theme.test.ts +10 -2
- package/dist/chunk-2MXWEIMD.js.map +0 -1
- package/dist/chunk-6VYGK3Q3.js.map +0 -1
- package/dist/chunk-7CNDZZZ6.js +0 -95
- package/dist/chunk-7CNDZZZ6.js.map +0 -1
- package/dist/chunk-BE2LWUHY.js.map +0 -1
- package/dist/chunk-DT6LKNZF.js.map +0 -1
- package/dist/chunk-F342ZT7O.js.map +0 -1
- package/dist/chunk-SVKN5ZHX.js.map +0 -1
- package/dist/chunk-VD6PB3VA.js.map +0 -1
|
@@ -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
|
-
/**
|
|
64
|
-
|
|
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
|
|
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?:
|
|
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
|
-
|
|
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<
|
|
34
|
+
let highlighterPromise: Promise<HighlighterCore> | null = null
|
|
27
35
|
|
|
28
|
-
function getHighlighter(): Promise<
|
|
36
|
+
function getHighlighter(): Promise<HighlighterCore> {
|
|
29
37
|
if (!highlighterPromise) {
|
|
30
|
-
highlighterPromise =
|
|
31
|
-
|
|
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
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* (e.g. at app startup) before rendering a `CodeBlock` that
|
|
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
|
|
49
|
-
*
|
|
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?:
|
|
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
|
-
/**
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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?:
|
|
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
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
"bg-brand-50/90 dark:bg-
|
|
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/
|
|
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/
|
|
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/
|
|
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:
|
|
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
|
|
@@ -10,7 +10,13 @@ import { focusStyles } from "../../lib/focus-styles"
|
|
|
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 {
|
|
13
|
+
import {
|
|
14
|
+
FieldShell,
|
|
15
|
+
fieldA11yProps,
|
|
16
|
+
fieldInlineStack,
|
|
17
|
+
fieldLabel,
|
|
18
|
+
requiredMark,
|
|
19
|
+
} from "../field/field"
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
22
|
* Switch — a single boolean toggle on Ark UI's Switch machine, styled as a
|
|
@@ -18,8 +24,9 @@ import { FieldShell, fieldA11yProps, fieldLabel, fieldRoot, requiredMark } from
|
|
|
18
24
|
* through the switch's own `Ark.Label` part (not `Field`'s) so it stays
|
|
19
25
|
* correctly wired to the hidden input's `aria-labelledby` and carries no
|
|
20
26
|
* layout footprint when visually hidden (e.g. `classNames.label: "sr-only"`).
|
|
21
|
-
* `description` / `error` / `required` live below
|
|
22
|
-
* scaffold,
|
|
27
|
+
* `description` / `error` / `required` live below the label via the shared
|
|
28
|
+
* `Field` scaffold, with the track centered on the label line, so a `Switch`
|
|
29
|
+
* is accessible and complete on its own. Implements
|
|
23
30
|
* the kit's `FormControlProps` contract: the `ref` and `onBlur` land on the
|
|
24
31
|
* submittable hidden `<input>`, and `name` wires it into native form
|
|
25
32
|
* submission.
|
|
@@ -127,6 +134,7 @@ export type SwitchProps = WithTestId & {
|
|
|
127
134
|
control?: string
|
|
128
135
|
thumb?: string
|
|
129
136
|
label?: string
|
|
137
|
+
/** The description / error field, under the label. */
|
|
130
138
|
field?: string
|
|
131
139
|
}
|
|
132
140
|
}
|
|
@@ -171,9 +179,10 @@ export const Switch = ({
|
|
|
171
179
|
// library can flip it from `fieldState.invalid` (see FormControlProps).
|
|
172
180
|
const isInvalid = invalid || error != null
|
|
173
181
|
|
|
174
|
-
// A visible label above description/error
|
|
175
|
-
//
|
|
176
|
-
//
|
|
182
|
+
// A visible label above description/error switches the root to a grid: the
|
|
183
|
+
// control centers on the label's row alone (not on the whole text stack),
|
|
184
|
+
// and the field hangs under the label in the second column. Label-only
|
|
185
|
+
// (incl. sr-only) stays a plain inline row.
|
|
177
186
|
const hasStack = label != null && (description != null || error != null)
|
|
178
187
|
|
|
179
188
|
const labelNode = label != null && (
|
|
@@ -206,7 +215,9 @@ export const Switch = ({
|
|
|
206
215
|
// `relative` contains the absolutely positioned hidden input, which would
|
|
207
216
|
// otherwise escape any scroller this control sits in.
|
|
208
217
|
className={cn(
|
|
209
|
-
|
|
218
|
+
hasStack
|
|
219
|
+
? fieldInlineStack({ size })
|
|
220
|
+
: "relative inline-flex items-center gap-2 select-none",
|
|
210
221
|
className,
|
|
211
222
|
classNames?.root,
|
|
212
223
|
)}
|
|
@@ -215,26 +226,15 @@ export const Switch = ({
|
|
|
215
226
|
<Ark.Thumb className={cn(switchThumb({ size }), classNames?.thumb)} />
|
|
216
227
|
</Ark.Control>
|
|
217
228
|
|
|
218
|
-
{
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
{labelNode}
|
|
228
|
-
<FieldShell
|
|
229
|
-
description={description}
|
|
230
|
-
error={error}
|
|
231
|
-
size={size}
|
|
232
|
-
className={classNames?.field}
|
|
233
|
-
>
|
|
234
|
-
<SwitchHiddenInput ref={ref} onBlur={onBlur} />
|
|
235
|
-
</FieldShell>
|
|
236
|
-
</>
|
|
237
|
-
)}
|
|
229
|
+
{labelNode}
|
|
230
|
+
<FieldShell
|
|
231
|
+
description={description}
|
|
232
|
+
error={error}
|
|
233
|
+
size={size}
|
|
234
|
+
className={cn(hasStack && "col-start-2", classNames?.field)}
|
|
235
|
+
>
|
|
236
|
+
<SwitchHiddenInput ref={ref} onBlur={onBlur} />
|
|
237
|
+
</FieldShell>
|
|
238
238
|
</Ark.Root>
|
|
239
239
|
)
|
|
240
240
|
}
|
|
@@ -73,7 +73,7 @@ describe("Table", () => {
|
|
|
73
73
|
const scroll = container.querySelector("table")?.parentElement as HTMLElement
|
|
74
74
|
// Root container: bordered, rounded, and clipped so the rounding survives a scrollbar.
|
|
75
75
|
expect(root.className).toContain("overflow-hidden")
|
|
76
|
-
expect(root.className).toContain("rounded-
|
|
76
|
+
expect(root.className).toContain("rounded-xl")
|
|
77
77
|
expect(root.className).toContain("border")
|
|
78
78
|
// The table sits inside the scrollable region.
|
|
79
79
|
expect(scroll.className).toContain("overflow-auto")
|