@42-central/ui-react 0.18.1 → 0.18.2
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/components/data-table/data-table-stack.d.ts +2 -2
- package/dist/components/data-table/data-table-stack.d.ts.map +1 -1
- package/dist/components/data-table/data-table.d.ts.map +1 -1
- package/dist/components/data-table/index.js +44 -5
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/kbd/index.js +29 -14
- package/dist/components/kbd/index.js.map +1 -1
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/schedule/index.js +2 -1
- package/dist/components/schedule/index.js.map +1 -1
- package/dist/components/schedule/now-cursor-line.d.ts.map +1 -1
- package/dist/components/switch/index.js +1 -1
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/switch.d.ts +2 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/data-table/data-table-stack.tsx +5 -3
- package/src/components/data-table/data-table.test.tsx +91 -0
- package/src/components/data-table/data-table.tsx +55 -6
- package/src/components/kbd/kbd.test.tsx +31 -0
- package/src/components/kbd/kbd.tsx +29 -14
- package/src/components/schedule/now-cursor-line.test.tsx +19 -0
- package/src/components/schedule/now-cursor-line.tsx +10 -1
- package/src/components/switch/switch.test.tsx +12 -0
- package/src/components/switch/switch.tsx +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"now-cursor-line.d.ts","sourceRoot":"","sources":["../../../src/components/schedule/now-cursor-line.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAiDhC,wBAAgB,aAAa,CAAC,EAC5B,GAAG,EACH,MAAM,EACN,SAAS,EACT,OAAO,EACP,OAAkB,EAClB,OAAe,EACf,SAAS,GACV,EAAE;IACD,iFAAiF;IACjF,GAAG,CAAC,EAAE,IAAI,CAAA;IACV;;;;;gCAK4B;IAC5B,MAAM,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;IAC5B,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAA;IACjB;;;;sEAIkE;IAClE,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IAC5B;;;;;;8BAM0B;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,sCA8BA;
|
|
1
|
+
{"version":3,"file":"now-cursor-line.d.ts","sourceRoot":"","sources":["../../../src/components/schedule/now-cursor-line.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAiDhC,wBAAgB,aAAa,CAAC,EAC5B,GAAG,EACH,MAAM,EACN,SAAS,EACT,OAAO,EACP,OAAkB,EAClB,OAAe,EACf,SAAS,GACV,EAAE;IACD,iFAAiF;IACjF,GAAG,CAAC,EAAE,IAAI,CAAA;IACV;;;;;gCAK4B;IAC5B,MAAM,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;IAC5B,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAA;IACjB;;;;sEAIkE;IAClE,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IAC5B;;;;;;8BAM0B;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,sCA8BA;AAKD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,GAAG,EACH,SAAS,EACT,OAAO,EACP,MAAM,EACN,SAAS,GACV,EAAE;IACD,iFAAiF;IACjF,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf;2BACuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS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C,cAAW,WAAA,EAA0B,KAAA,EAAc,MAClD,QAAA,kBAAA,GAAA,CAAC,iBAAA,EAAA,EAAkB,GAAA,EAAU,MAAA,EAAgB,CAAA,EAC/C;AAAA,SAAA,EACF,oBAEA,IAAA,CAAA,QAAA,EAAA,EACG,QAAA,EAAA;AAAA,UAAA,SAAA;AAAA,0BACD,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,WAAA;AAAA,cACA,KAAA;AAAA,cACA,IAAA;AAAA,cACA,WAAW,UAAA,EAAY,KAAA;AAAA,cAEvB,QAAA,kBAAA,GAAA,CAAC,iBAAA,EAAA,EAAkB,GAAA,EAAU,MAAA,EAAgB;AAAA;AAAA;AAC/C,SAAA,EACF;AAAA;AAAA;AAAA,GAEJ;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { Switch as Ark } from \"@ark-ui/react/switch\"\nimport { cva } from \"class-variance-authority\"\nimport type { FocusEvent, ReactNode, Ref } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { focusStyles } from \"../../lib/focus-styles\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { FieldShell, fieldA11yProps, fieldLabel, fieldRoot } from \"../field/field\"\n\n/**\n * Switch — a single boolean toggle on Ark UI's Switch machine, styled as a\n * sliding track + thumb. The label sits inline beside the track, rendered\n * through the switch's own `Ark.Label` part (not `Field`'s) so it stays\n * correctly wired to the hidden input's `aria-labelledby` and carries no\n * layout footprint when visually hidden (e.g. `classNames.label: \"sr-only\"`).\n * `description` / `error` / `required` live below it via the shared `Field`\n * scaffold, so a `Switch` is accessible and complete on its own. Implements\n * the kit's `FormControlProps` contract: the `ref` and `onBlur` land on the\n * submittable hidden `<input>`, and `name` wires it into native form\n * submission.\n *\n * - `onCheckedChange` hands you the next boolean directly (a value, not a DOM\n * event), matching the rest of the family.\n * - `invalid` is OR'd with `error != null`, so a form library can flip the\n * red state independently of the message.\n *\n * Unlike the selection controls, the Switch authors its own track / thumb\n * geometry rather than reusing `controlIndicator` (a pill, not a box), but\n * follows the same conventions: the track is palette-independent at rest and\n * only the checked fill / focus ring reference the active palette via the slot\n * vars (`--c-solid`), so it tints for free from whatever `data-color` sits on\n * the root.\n */\n\nconst switchTrack = cva(\n [\n \"inline-flex shrink-0 items-center rounded-sm transition-colors relative\",\n // Neutral resting track.\n \"bg-gray-light-300 dark:bg-gray-dark-700\",\n // Checked fill — palette solid, via the slot var.\n \"data-[state=checked]:bg-(--c-solid)\",\n // The kit's standard focus ring, keyed off the Control's own\n // `data-focus-visible` (zag mirrors the hidden input's focus-visible state\n // onto every switch part).\n focusStyles({ source: \"data-focus-visible\" }),\n // Invalid wins over the palette: red wash.\n \"data-invalid:bg-red-500/40\",\n // Disabled affordances.\n \"data-disabled:opacity-60 data-disabled:cursor-not-allowed\",\n ],\n {\n variants: {\n size: {\n xs: \"h-4 w-7 p-0.5\",\n sm: \"h-4.5 w-8 p-0.5\",\n md: \"h-5 w-9 p-0.5\",\n lg: \"h-6 w-11 p-0.5\",\n xl: \"h-7 w-13 p-0.5\",\n },\n },\n defaultVariants: { size: \"md\" },\n },\n)\n\nconst switchThumb = cva(\n [\n \"rounded-xs bg-white shadow-sm transition-[inset] absolute inset-s-0.5 data-[state=checked]:inset-s-1/2\",\n ],\n {\n variants: {\n size: {\n xs: \"size-3\",\n sm: \"size-3.5\",\n md: \"size-4\",\n lg: \"size-5\",\n xl: \"size-6\",\n },\n },\n defaultVariants: { size: \"md\" },\n },\n)\n\nexport type SwitchProps = WithTestId & {\n /** Controlled checked state. */\n checked?: boolean\n /** Uncontrolled initial checked state. */\n defaultChecked?: boolean\n /** Fires with the next checked state (a value, not a DOM event). */\n onCheckedChange?: (checked: boolean) => void\n /** Inline label beside the track. */\n label?: ReactNode\n /** Helper text above the control. */\n description?: ReactNode\n /** Error message below the control; its presence sets the invalid state. */\n error?: ReactNode\n /** Required flag (and, with a label, the red asterisk). */\n required?: boolean\n /** Red invalid state, OR'd with `error != null`. */\n invalid?: boolean\n /** Dims and blocks interaction. */\n disabled?: boolean\n /** Keeps full contrast but blocks edits. */\n readOnly?: boolean\n size?: Size\n color?: Color\n /** Field name for native form submission. */\n name?: string\n /** Submitted value when checked (defaults to `\"on\"`). */\n value?: string\n /** Explicit id for label association. */\n id?: string\n /** Lands on the hidden `<input>` for focus-on-error. */\n ref?: Ref<HTMLInputElement>\n /** Forwarded to the hidden `<input>`; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n className?: string\n classNames?: {\n root?: string\n control?: string\n thumb?: string\n label?: string\n field?: string\n }\n}\n\n/**\n * The real, submittable hidden `<input>`, split out so it reads the `Field`\n * context from *inside* the wrapping `FieldShell` — `Switch` itself renders\n * that shell, so calling `useFieldContext()` at its own top level would run\n * too early.\n */\nconst SwitchHiddenInput = ({ ref, onBlur }: Pick<SwitchProps, \"ref\" | \"onBlur\">) => {\n const field = useFieldContext()\n return <Ark.HiddenInput ref={ref} onBlur={onBlur} {...fieldA11yProps(field)} />\n}\n\nexport const Switch = ({\n checked,\n defaultChecked,\n onCheckedChange,\n label,\n description,\n error,\n required,\n invalid,\n disabled,\n readOnly,\n size = \"md\",\n color = \"green\",\n name,\n value,\n id,\n ref,\n onBlur,\n className,\n classNames,\n testId,\n}: SwitchProps) => {\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n // A visible label above description/error needs the two grouped into one\n // flex-col item, or they'd land side by side in the root's row instead of\n // stacked. Label-only (incl. sr-only) never needs this extra wrapper.\n const hasStack = label != null && (description != null || error != null)\n\n const labelNode = label != null && (\n <Ark.Label\n className={cn(fieldLabel({ size }), !hasStack && \"min-w-0 flex-1\", classNames?.label)}\n >\n {label}\n {required && (\n <span aria-hidden=\"true\" className=\"ms-0.5 text-red-500\">\n *\n </span>\n )}\n </Ark.Label>\n )\n\n return (\n <Ark.Root\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={onCheckedChange ? (d) => onCheckedChange(d.checked) : undefined}\n invalid={isInvalid}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n id={id}\n data-color={color}\n {...props({ \"data-testid\": testId })}\n // `relative` contains the absolutely positioned hidden input, which would\n // otherwise escape any scroller this control sits in.\n className={cn(\n \"relative inline-flex items-center gap-2 select-none\",\n className,\n classNames?.root,\n )}\n >\n <Ark.Control className={cn(switchTrack({ size }), classNames?.control)}>\n <Ark.Thumb className={cn(switchThumb({ size }), classNames?.thumb)} />\n </Ark.Control>\n\n {hasStack ? (\n <div className={cn(fieldRoot({ size }), classNames?.field)}>\n {labelNode}\n <FieldShell description={description} error={error} size={size}>\n <SwitchHiddenInput ref={ref} onBlur={onBlur} />\n </FieldShell>\n </div>\n ) : (\n <>\n {labelNode}\n <FieldShell\n description={description}\n error={error}\n size={size}\n className={classNames?.field}\n >\n <SwitchHiddenInput ref={ref} onBlur={onBlur} />\n </FieldShell>\n </>\n )}\n </Ark.Root>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/switch/switch.tsx"],"names":["Ark"],"mappings":";;;;;;;;;AAuCA,IAAM,WAAA,GAAc,GAAA;AAAA,EAClB;AAAA,IACE,yEAAA;AAAA;AAAA,IAEA,yCAAA;AAAA;AAAA,IAEA,qCAAA;AAAA;AAAA;AAAA;AAAA,IAIA,WAAA,CAAY,EAAE,MAAA,EAAQ,oBAAA,EAAsB,CAAA;AAAA;AAAA,IAE5C,4BAAA;AAAA;AAAA,IAEA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,IAAA,EAAM;AAAA,QACJ,EAAA,EAAI,eAAA;AAAA,QACJ,EAAA,EAAI,iBAAA;AAAA,QACJ,EAAA,EAAI,eAAA;AAAA,QACJ,EAAA,EAAI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AAA,CAAG,WAAA,CAAY,EAAE,IAAA,EAAM,CAAA,EAAG,UAAA,EAAY,KAAK,CAAA,EAAG,CAAA,EACtE,CAAA;AAAA,QAEC,QAAA,mBACC,IAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAW,EAAA,CAAG,SAAA,CAAU,EAAE,IAAA,EAAM,CAAA,EAAG,UAAA,EAAY,KAAK,CAAA,EACtD,QAAA,EAAA;AAAA,UAAA,SAAA;AAAA,0BACD,GAAA,CAAC,cAAW,WAAA,EAA0B,KAAA,EAAc,MAClD,QAAA,kBAAA,GAAA,CAAC,iBAAA,EAAA,EAAkB,GAAA,EAAU,MAAA,EAAgB,CAAA,EAC/C;AAAA,SAAA,EACF,oBAEA,IAAA,CAAA,QAAA,EAAA,EACG,QAAA,EAAA;AAAA,UAAA,SAAA;AAAA,0BACD,GAAA;AAAA,YAAC,UAAA;AAAA,YAAA;AAAA,cACC,WAAA;AAAA,cACA,KAAA;AAAA,cACA,IAAA;AAAA,cACA,WAAW,UAAA,EAAY,KAAA;AAAA,cAEvB,QAAA,kBAAA,GAAA,CAAC,iBAAA,EAAA,EAAkB,GAAA,EAAU,MAAA,EAAgB;AAAA;AAAA;AAC/C,SAAA,EACF;AAAA;AAAA;AAAA,GAEJ;AAEJ","file":"index.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { Switch as Ark } from \"@ark-ui/react/switch\"\nimport { cva } from \"class-variance-authority\"\nimport type { FocusEvent, ReactNode, Ref } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { focusStyles } from \"../../lib/focus-styles\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { FieldShell, fieldA11yProps, fieldLabel, fieldRoot } from \"../field/field\"\n\n/**\n * Switch — a single boolean toggle on Ark UI's Switch machine, styled as a\n * sliding track + thumb. The label sits inline beside the track, rendered\n * through the switch's own `Ark.Label` part (not `Field`'s) so it stays\n * correctly wired to the hidden input's `aria-labelledby` and carries no\n * layout footprint when visually hidden (e.g. `classNames.label: \"sr-only\"`).\n * `description` / `error` / `required` live below it via the shared `Field`\n * scaffold, so a `Switch` is accessible and complete on its own. Implements\n * the kit's `FormControlProps` contract: the `ref` and `onBlur` land on the\n * submittable hidden `<input>`, and `name` wires it into native form\n * submission.\n *\n * - `onCheckedChange` hands you the next boolean directly (a value, not a DOM\n * event), matching the rest of the family.\n * - `invalid` is OR'd with `error != null`, so a form library can flip the\n * red state independently of the message.\n *\n * Unlike the selection controls, the Switch authors its own track / thumb\n * geometry rather than reusing `controlIndicator` (a pill, not a box), but\n * follows the same conventions: the track is palette-independent at rest and\n * only the checked fill / focus ring reference the active palette via the slot\n * vars (`--c-solid`), so it tints for free from whatever `data-color` sits on\n * the root.\n */\n\nconst switchTrack = cva(\n [\n \"inline-flex shrink-0 items-center rounded-sm transition-colors relative\",\n // Neutral resting track.\n \"bg-gray-light-300 dark:bg-gray-dark-700\",\n // Checked fill — palette solid, via the slot var.\n \"data-[state=checked]:bg-(--c-solid)\",\n // The kit's standard focus ring, keyed off the Control's own\n // `data-focus-visible` (zag mirrors the hidden input's focus-visible state\n // onto every switch part).\n focusStyles({ source: \"data-focus-visible\" }),\n // Invalid wins over the palette: red wash.\n \"data-invalid:bg-red-500/40\",\n // Disabled affordances.\n \"data-disabled:opacity-60 data-disabled:cursor-not-allowed\",\n ],\n {\n variants: {\n size: {\n xs: \"h-4 w-7 p-0.5\",\n sm: \"h-4.5 w-8 p-0.5\",\n md: \"h-5 w-9 p-0.5\",\n lg: \"h-6 w-11 p-0.5\",\n xl: \"h-7 w-13 p-0.5\",\n },\n },\n defaultVariants: { size: \"md\" },\n },\n)\n\nconst switchThumb = cva(\n [\n \"rounded-xs bg-white shadow-sm transition-[inset] absolute inset-s-0.5 data-[state=checked]:inset-s-1/2\",\n ],\n {\n variants: {\n size: {\n xs: \"size-3\",\n sm: \"size-3.5\",\n md: \"size-4\",\n lg: \"size-5\",\n xl: \"size-6\",\n },\n },\n defaultVariants: { size: \"md\" },\n },\n)\n\nexport type SwitchProps = WithTestId & {\n /** Controlled checked state. */\n checked?: boolean\n /** Uncontrolled initial checked state. */\n defaultChecked?: boolean\n /** Fires with the next checked state (a value, not a DOM event). */\n onCheckedChange?: (checked: boolean) => void\n /** Inline label beside the track. */\n label?: ReactNode\n /** Helper text above the control. */\n description?: ReactNode\n /** Error message below the control; its presence sets the invalid state. */\n error?: ReactNode\n /** Required flag (and, with a label, the red asterisk). */\n required?: boolean\n /** Red invalid state, OR'd with `error != null`. */\n invalid?: boolean\n /** Dims and blocks interaction. */\n disabled?: boolean\n /** Keeps full contrast but blocks edits. */\n readOnly?: boolean\n size?: Size\n /** Checked fill. `neutral` is the one exception: it fills green, since\n * neutral's solid is the same white as the thumb on a dark page. */\n color?: Color\n /** Field name for native form submission. */\n name?: string\n /** Submitted value when checked (defaults to `\"on\"`). */\n value?: string\n /** Explicit id for label association. */\n id?: string\n /** Lands on the hidden `<input>` for focus-on-error. */\n ref?: Ref<HTMLInputElement>\n /** Forwarded to the hidden `<input>`; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void\n className?: string\n classNames?: {\n root?: string\n control?: string\n thumb?: string\n label?: string\n field?: string\n }\n}\n\n/**\n * The real, submittable hidden `<input>`, split out so it reads the `Field`\n * context from *inside* the wrapping `FieldShell` — `Switch` itself renders\n * that shell, so calling `useFieldContext()` at its own top level would run\n * too early.\n */\nconst SwitchHiddenInput = ({ ref, onBlur }: Pick<SwitchProps, \"ref\" | \"onBlur\">) => {\n const field = useFieldContext()\n return <Ark.HiddenInput ref={ref} onBlur={onBlur} {...fieldA11yProps(field)} />\n}\n\nexport const Switch = ({\n checked,\n defaultChecked,\n onCheckedChange,\n label,\n description,\n error,\n required,\n invalid,\n disabled,\n readOnly,\n size = \"md\",\n color = \"green\",\n name,\n value,\n id,\n ref,\n onBlur,\n className,\n classNames,\n testId,\n}: SwitchProps) => {\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n // A visible label above description/error needs the two grouped into one\n // flex-col item, or they'd land side by side in the root's row instead of\n // stacked. Label-only (incl. sr-only) never needs this extra wrapper.\n const hasStack = label != null && (description != null || error != null)\n\n const labelNode = label != null && (\n <Ark.Label\n className={cn(fieldLabel({ size }), !hasStack && \"min-w-0 flex-1\", classNames?.label)}\n >\n {label}\n {required && (\n <span aria-hidden=\"true\" className=\"ms-0.5 text-red-500\">\n *\n </span>\n )}\n </Ark.Label>\n )\n\n return (\n <Ark.Root\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={onCheckedChange ? (d) => onCheckedChange(d.checked) : undefined}\n invalid={isInvalid}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n id={id}\n data-color={color === \"neutral\" ? \"green\" : color}\n {...props({ \"data-testid\": testId })}\n // `relative` contains the absolutely positioned hidden input, which would\n // otherwise escape any scroller this control sits in.\n className={cn(\n \"relative inline-flex items-center gap-2 select-none\",\n className,\n classNames?.root,\n )}\n >\n <Ark.Control className={cn(switchTrack({ size }), classNames?.control)}>\n <Ark.Thumb className={cn(switchThumb({ size }), classNames?.thumb)} />\n </Ark.Control>\n\n {hasStack ? (\n <div className={cn(fieldRoot({ size }), classNames?.field)}>\n {labelNode}\n <FieldShell description={description} error={error} size={size}>\n <SwitchHiddenInput ref={ref} onBlur={onBlur} />\n </FieldShell>\n </div>\n ) : (\n <>\n {labelNode}\n <FieldShell\n description={description}\n error={error}\n size={size}\n className={classNames?.field}\n >\n <SwitchHiddenInput ref={ref} onBlur={onBlur} />\n </FieldShell>\n </>\n )}\n </Ark.Root>\n )\n}\n"]}
|
|
@@ -24,6 +24,8 @@ export type SwitchProps = WithTestId & {
|
|
|
24
24
|
/** Keeps full contrast but blocks edits. */
|
|
25
25
|
readOnly?: boolean;
|
|
26
26
|
size?: Size;
|
|
27
|
+
/** Checked fill. `neutral` is the one exception: it fills green, since
|
|
28
|
+
* neutral's solid is the same white as the thumb on a dark page. */
|
|
27
29
|
color?: Color;
|
|
28
30
|
/** Field name for native form submission. */
|
|
29
31
|
name?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../../src/components/switch/switch.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAG7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AA4EnD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC,gCAAgC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,oEAAoE;IACpE,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,qCAAqC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,qCAAqC;IACrC,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM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W,CAAC,EAAE,SAAS,CAAA;IACvB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;yEACqE;IACrE,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,wDAAwD;IACxD,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAC3B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAA;IACtD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF,CAAA;AAaD,eAAO,MAAM,MAAM,8LAqBhB,WAAW,gCAuEb,CAAA"}
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@ export function DataTableStackedRows<TEntity extends RowData>({
|
|
|
49
49
|
refetching,
|
|
50
50
|
empty,
|
|
51
51
|
onRowClick,
|
|
52
|
-
|
|
52
|
+
isRowClickIgnored,
|
|
53
53
|
onRetry,
|
|
54
54
|
table,
|
|
55
55
|
className,
|
|
@@ -63,7 +63,7 @@ export function DataTableStackedRows<TEntity extends RowData>({
|
|
|
63
63
|
empty?: DataTablePlaceholder
|
|
64
64
|
refetching: boolean
|
|
65
65
|
onRowClick?: (row: TEntity) => void
|
|
66
|
-
|
|
66
|
+
isRowClickIgnored: (target: EventTarget | null, row: Element) => boolean
|
|
67
67
|
onRetry?: () => void
|
|
68
68
|
table: ReactTableInstance<DataTableFeatures, TEntity>
|
|
69
69
|
className?: string
|
|
@@ -169,7 +169,9 @@ export function DataTableStackedRows<TEntity extends RowData>({
|
|
|
169
169
|
onClick={
|
|
170
170
|
onRowClick
|
|
171
171
|
? (event) => {
|
|
172
|
-
if (!
|
|
172
|
+
if (!isRowClickIgnored(event.target, event.currentTarget)) {
|
|
173
|
+
onRowClick(row.original)
|
|
174
|
+
}
|
|
173
175
|
}
|
|
174
176
|
: undefined
|
|
175
177
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react"
|
|
2
|
+
import { createPortal } from "react-dom"
|
|
2
3
|
import { describe, expect, it, vi } from "vitest"
|
|
3
4
|
import { DATA_TABLE_DEFAULT_EMPTY, DataTable } from "./data-table"
|
|
4
5
|
import { createColumnHelper } from "./data-table-features"
|
|
@@ -188,6 +189,96 @@ describe("DataTable", () => {
|
|
|
188
189
|
expect(onRowClick).not.toHaveBeenCalled()
|
|
189
190
|
})
|
|
190
191
|
|
|
192
|
+
it("fires onRowClick when an ancestor of the table carries a role (#304)", () => {
|
|
193
|
+
const onRowClick = vi.fn()
|
|
194
|
+
render(
|
|
195
|
+
<div role="tabpanel">
|
|
196
|
+
<DataTable columns={columns} data={USERS} onRowClick={onRowClick} />
|
|
197
|
+
</div>,
|
|
198
|
+
)
|
|
199
|
+
fireEvent.click(screen.getByText("Ada"))
|
|
200
|
+
expect(onRowClick).toHaveBeenCalledWith(USERS[0])
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it("fires onRowClick through a non-widget role inside the row", () => {
|
|
204
|
+
const onRowClick = vi.fn()
|
|
205
|
+
const c = createColumnHelper<User>()
|
|
206
|
+
const cols = [
|
|
207
|
+
c.accessor("name", { header: "Name" }),
|
|
208
|
+
c.display({ id: "status", cell: () => <span role="img">●</span> }),
|
|
209
|
+
]
|
|
210
|
+
render(<DataTable columns={cols} data={USERS} onRowClick={onRowClick} />)
|
|
211
|
+
fireEvent.click(screen.getAllByRole("img")[0] as HTMLElement)
|
|
212
|
+
expect(onRowClick).toHaveBeenCalledWith(USERS[0])
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("still ignores a nested button when an ancestor carries a role", () => {
|
|
216
|
+
const onRowClick = vi.fn()
|
|
217
|
+
const c = createColumnHelper<User>()
|
|
218
|
+
const cols = [
|
|
219
|
+
c.accessor("name", { header: "Name" }),
|
|
220
|
+
c.display({ id: "actions", cell: () => <button type="button">Edit</button> }),
|
|
221
|
+
]
|
|
222
|
+
render(
|
|
223
|
+
<div role="tabpanel">
|
|
224
|
+
<DataTable columns={cols} data={USERS} onRowClick={onRowClick} />
|
|
225
|
+
</div>,
|
|
226
|
+
)
|
|
227
|
+
fireEvent.click(screen.getAllByText("Edit")[0] as HTMLElement)
|
|
228
|
+
expect(onRowClick).not.toHaveBeenCalled()
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it("ignores clicks on content a cell portals out of the row", () => {
|
|
232
|
+
const onRowClick = vi.fn()
|
|
233
|
+
const c = createColumnHelper<User>()
|
|
234
|
+
const cols = [
|
|
235
|
+
c.accessor("name", { header: "Name" }),
|
|
236
|
+
c.display({
|
|
237
|
+
id: "menu",
|
|
238
|
+
cell: ({ row }) => createPortal(<p>Menu of {row.original.name}</p>, document.body),
|
|
239
|
+
}),
|
|
240
|
+
]
|
|
241
|
+
render(<DataTable columns={cols} data={USERS} onRowClick={onRowClick} />)
|
|
242
|
+
fireEvent.click(screen.getByText("Menu of Ada"))
|
|
243
|
+
expect(onRowClick).not.toHaveBeenCalled()
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it("fires onRowClick from a stacked card when an ancestor carries a role", () => {
|
|
247
|
+
const onRowClick = vi.fn()
|
|
248
|
+
render(
|
|
249
|
+
<div role="tabpanel">
|
|
250
|
+
<DataTable columns={columns} data={USERS} responsive="stack" onRowClick={onRowClick} />
|
|
251
|
+
</div>,
|
|
252
|
+
)
|
|
253
|
+
const cardCell = screen.getAllByText("Ada").find((el) => el.closest("tr") == null)
|
|
254
|
+
fireEvent.click(cardCell as HTMLElement)
|
|
255
|
+
expect(onRowClick).toHaveBeenCalledWith(USERS[0])
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it("ignores the click that ends a text selection inside the row", () => {
|
|
259
|
+
const onRowClick = vi.fn()
|
|
260
|
+
render(<DataTable columns={columns} data={USERS} onRowClick={onRowClick} />)
|
|
261
|
+
const cell = screen.getByText("Ada")
|
|
262
|
+
document.getSelection()?.selectAllChildren(cell)
|
|
263
|
+
fireEvent.click(cell)
|
|
264
|
+
document.getSelection()?.removeAllRanges()
|
|
265
|
+
expect(onRowClick).not.toHaveBeenCalled()
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it("still fires onRowClick while text outside the row is selected", () => {
|
|
269
|
+
const onRowClick = vi.fn()
|
|
270
|
+
render(
|
|
271
|
+
<>
|
|
272
|
+
<p>Elsewhere</p>
|
|
273
|
+
<DataTable columns={columns} data={USERS} onRowClick={onRowClick} />
|
|
274
|
+
</>,
|
|
275
|
+
)
|
|
276
|
+
document.getSelection()?.selectAllChildren(screen.getByText("Elsewhere"))
|
|
277
|
+
fireEvent.click(screen.getByText("Ada"))
|
|
278
|
+
document.getSelection()?.removeAllRanges()
|
|
279
|
+
expect(onRowClick).toHaveBeenCalledWith(USERS[0])
|
|
280
|
+
})
|
|
281
|
+
|
|
191
282
|
it("forwards size/striped/sticky to the underlying Table", () => {
|
|
192
283
|
const { container } = render(
|
|
193
284
|
<DataTable columns={columns} data={USERS} size="sm" striped stickyHeader />,
|
|
@@ -216,13 +216,62 @@ export type DataTableProps<TEntity extends RowData> = WithTestId & {
|
|
|
216
216
|
classNames?: DataTableClassNames
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/** Native controls plus the ARIA widget roles — not a bare `[role]`, which
|
|
220
|
+
* would also match a cell's `role="img"` spinner or `role="progressbar"`. */
|
|
221
|
+
const INTERACTIVE_SELECTOR = [
|
|
222
|
+
"a[href]",
|
|
223
|
+
"button",
|
|
224
|
+
"input",
|
|
225
|
+
"label",
|
|
226
|
+
"select",
|
|
227
|
+
"textarea",
|
|
228
|
+
"summary",
|
|
229
|
+
"[contenteditable]",
|
|
230
|
+
...[
|
|
231
|
+
"button",
|
|
232
|
+
"link",
|
|
233
|
+
"checkbox",
|
|
234
|
+
"radio",
|
|
235
|
+
"switch",
|
|
236
|
+
"menuitem",
|
|
237
|
+
"menuitemcheckbox",
|
|
238
|
+
"menuitemradio",
|
|
239
|
+
"tab",
|
|
240
|
+
"option",
|
|
241
|
+
"combobox",
|
|
242
|
+
"slider",
|
|
243
|
+
"spinbutton",
|
|
244
|
+
"textbox",
|
|
245
|
+
"searchbox",
|
|
246
|
+
].map((role) => `[role="${role}"]`),
|
|
247
|
+
].join(",")
|
|
248
|
+
|
|
219
249
|
/** A click landing on a nested interactive element shouldn't also fire
|
|
220
250
|
* `onRowClick` — a `<tr>` with a link / menu / checkbox can't itself be a
|
|
221
251
|
* button (nested interactives break keyboard + SR semantics), so the row
|
|
222
|
-
* handler only fires when the event target isn't one.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
252
|
+
* handler only fires when the event target isn't one.
|
|
253
|
+
*
|
|
254
|
+
* The search stops at `row`: an ancestor of the table (a `role="tabpanel"`,
|
|
255
|
+
* a dialog) must not count. A target outside the row's DOM is portaled
|
|
256
|
+
* content — a cell's Menu or Dialog, whose clicks still bubble through the
|
|
257
|
+
* React tree to the row — and never counts as a row click.
|
|
258
|
+
*
|
|
259
|
+
* A click that ends a drag-selection over the row is the user copying a
|
|
260
|
+
* value, not opening the row, so it is ignored too. */
|
|
261
|
+
const isRowClickIgnored = (target: EventTarget | null, row: Element): boolean => {
|
|
262
|
+
const selection = row.ownerDocument.getSelection()
|
|
263
|
+
const selectsRow =
|
|
264
|
+
selection != null &&
|
|
265
|
+
!selection.isCollapsed &&
|
|
266
|
+
Array.from({ length: selection.rangeCount }, (_, i) => selection.getRangeAt(i)).some((range) =>
|
|
267
|
+
range.intersectsNode(row),
|
|
268
|
+
)
|
|
269
|
+
if (selectsRow) return true
|
|
270
|
+
if (!(target instanceof Element)) return false
|
|
271
|
+
if (!row.contains(target)) return true
|
|
272
|
+
const hit = target.closest(INTERACTIVE_SELECTOR)
|
|
273
|
+
return hit != null && hit !== row && row.contains(hit)
|
|
274
|
+
}
|
|
226
275
|
|
|
227
276
|
/** Utility to resolve aria-sort from table state
|
|
228
277
|
*
|
|
@@ -527,7 +576,7 @@ function DataTableComponent<TEntity extends RowData>({
|
|
|
527
576
|
const skeletonRowCount = Math.min(Math.max(pagination.pageSize, 1), 100)
|
|
528
577
|
|
|
529
578
|
const handleRowClick = (row: TEntity) => (event: MouseEvent<HTMLTableRowElement>) => {
|
|
530
|
-
if (!onRowClick ||
|
|
579
|
+
if (!onRowClick || isRowClickIgnored(event.target, event.currentTarget)) return
|
|
531
580
|
onRowClick(row)
|
|
532
581
|
}
|
|
533
582
|
|
|
@@ -802,7 +851,7 @@ function DataTableComponent<TEntity extends RowData>({
|
|
|
802
851
|
refetching={isRefetching}
|
|
803
852
|
empty={empty}
|
|
804
853
|
onRowClick={onRowClick}
|
|
805
|
-
|
|
854
|
+
isRowClickIgnored={isRowClickIgnored}
|
|
806
855
|
onRetry={onRetry}
|
|
807
856
|
table={table}
|
|
808
857
|
skeletonRowCount={skeletonRowCount}
|
|
@@ -17,4 +17,35 @@ describe("Kbd", () => {
|
|
|
17
17
|
const trigger = screen.getByRole("button", { name: "⌘K" })
|
|
18
18
|
expect(trigger.className).toContain("focus-visible:ring-brand-500")
|
|
19
19
|
})
|
|
20
|
+
|
|
21
|
+
it("pairs the light-mode surface with a dark-mode one, so the cap never vanishes", () => {
|
|
22
|
+
render(<Kbd>K</Kbd>)
|
|
23
|
+
const cls = screen.getByText("K").className
|
|
24
|
+
// `bg-white/4` alone is invisible on a near-white page.
|
|
25
|
+
expect(cls).toContain("bg-black/3")
|
|
26
|
+
expect(cls).toContain("dark:bg-white/4")
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it("sets regular weight, so fallback symbol glyphs are not bolded", () => {
|
|
30
|
+
render(<Kbd>⌘</Kbd>)
|
|
31
|
+
const cls = screen.getByText("⌘").className
|
|
32
|
+
expect(cls).toContain("font-normal")
|
|
33
|
+
expect(cls).not.toContain("font-medium")
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it.each([
|
|
37
|
+
["sm", "text-xs"],
|
|
38
|
+
["md", "text-sm"],
|
|
39
|
+
["lg", "text-base"],
|
|
40
|
+
] as const)("uses a legible type step at size %s", (size, text) => {
|
|
41
|
+
render(<Kbd size={size}>Esc</Kbd>)
|
|
42
|
+
expect(screen.getByText("Esc").className).toContain(text)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it("draws a 1.5px non-scaling stroke on an inner svg at every size", () => {
|
|
46
|
+
render(<Kbd>K</Kbd>)
|
|
47
|
+
const cls = screen.getByText("K").className
|
|
48
|
+
expect(cls).toContain("[&_svg]:stroke-[1.5]")
|
|
49
|
+
expect(cls).toContain("[&_svg_*]:[vector-effect:non-scaling-stroke]")
|
|
50
|
+
})
|
|
20
51
|
})
|
|
@@ -36,9 +36,17 @@ const kbdVariants = cva(
|
|
|
36
36
|
[
|
|
37
37
|
"inline-flex items-center justify-center gap-1",
|
|
38
38
|
"whitespace-nowrap select-none",
|
|
39
|
-
|
|
39
|
+
// Regular weight, not medium: the mono face (Kode Mono) has no ⌘ ⇧ ⌥ ↵
|
|
40
|
+
// glyphs, so they fall back to a system font — and a 500 weight makes that
|
|
41
|
+
// fallback resolve to its *bold* face (Menlo Bold), a heavy blot next to
|
|
42
|
+
// the regular letters around it.
|
|
43
|
+
"font-mono font-normal leading-none",
|
|
40
44
|
"rounded-md border border-transparent",
|
|
41
45
|
"[&_svg]:shrink-0 [&_svg]:pointer-events-none",
|
|
46
|
+
// A 1.5px stroke at every size: the icon is sized by CSS, so a stroke in
|
|
47
|
+
// viewBox units would thin out at `size-3`. `non-scaling-stroke` keeps it in
|
|
48
|
+
// screen pixels (lucide's `absoluteStrokeWidth` ignores CSS sizing).
|
|
49
|
+
"[&_svg]:stroke-[1.5] [&_svg_*]:[vector-effect:non-scaling-stroke]",
|
|
42
50
|
// Inert on the default non-focusable <kbd>; applies once `asChild`
|
|
43
51
|
// renders Kbd onto a real <button>/<a>. See `focusStyles`.
|
|
44
52
|
focusStyles(),
|
|
@@ -50,23 +58,30 @@ const kbdVariants = cva(
|
|
|
50
58
|
light: "bg-(--c-soft) text-(--c-text)",
|
|
51
59
|
outline: "bg-transparent text-(--c-text) border-(--c-solid)",
|
|
52
60
|
subtle: "bg-transparent text-(--c-text)",
|
|
53
|
-
// The key cap sits on the kit's translucent surface recipe —
|
|
54
|
-
// plus the hairline `border-brand-900/20 dark:border-white/15`,
|
|
55
|
-
// pair `Input`'s default shell, `Card`, `Tabs
|
|
56
|
-
// `ChoiceCardGroup` use. An opaque gray step can only ever be right on
|
|
57
|
-
// one background it was picked against, and a `Kbd` is most often
|
|
58
|
-
// into a Button, a Menu row or a tinted panel
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
+
// The key cap sits on the kit's translucent surface recipe — a 3%/4%
|
|
62
|
+
// overlay plus the hairline `border-brand-900/20 dark:border-white/15`,
|
|
63
|
+
// the same pair `Input`'s default shell, `Card`, `Tabs` and
|
|
64
|
+
// `ChoiceCardGroup` use. An opaque gray step can only ever be right on
|
|
65
|
+
// the one background it was picked against, and a `Kbd` is most often
|
|
66
|
+
// inlined into a Button, a Menu row or a tinted panel. Light mode
|
|
67
|
+
// darkens (`bg-black/3`) because `bg-white/4` on a near-white page is
|
|
68
|
+
// invisible; dark mode lightens. A 1px inset shade along the bottom
|
|
69
|
+
// edge is the key-cap depth cue — the lip of a physical key — without
|
|
70
|
+
// adding height. The label is the kit's secondary text, not full
|
|
71
|
+
// contrast: a shortcut hint annotates the action, it is not the action.
|
|
61
72
|
default: [
|
|
62
|
-
"bg-
|
|
63
|
-
"
|
|
73
|
+
"bg-black/3 text-gray-light-700 border-brand-900/20",
|
|
74
|
+
"shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.08)]",
|
|
75
|
+
"dark:bg-white/4 dark:text-gray-dark-300 dark:border-white/15",
|
|
76
|
+
"dark:shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.35)]",
|
|
64
77
|
],
|
|
65
78
|
},
|
|
79
|
+
// Type is one Tailwind step per size (12 / 14 / 16px), the scale of
|
|
80
|
+
// the text a key sits beside — a 10px label left ⌘ and ↵ unreadable.
|
|
66
81
|
size: {
|
|
67
|
-
sm: "h-5 min-w-5 px-1.5 text-
|
|
68
|
-
md: "h-6 min-w-6 px-1.5 text-
|
|
69
|
-
lg: "h-7 min-w-7 px-2 text-
|
|
82
|
+
sm: "h-5 min-w-5 px-1.5 text-xs [&_svg]:size-3",
|
|
83
|
+
md: "h-6 min-w-6 px-1.5 text-sm [&_svg]:size-3.5",
|
|
84
|
+
lg: "h-7 min-w-7 px-2 text-base [&_svg]:size-4",
|
|
70
85
|
},
|
|
71
86
|
},
|
|
72
87
|
defaultVariants: {
|
|
@@ -183,6 +183,25 @@ describe("NowCursorLine — the painted window gates it", () => {
|
|
|
183
183
|
})
|
|
184
184
|
})
|
|
185
185
|
|
|
186
|
+
describe("NowCursorLabel — stays inside the band", () => {
|
|
187
|
+
// Centered on the line, a label at the very top or bottom used to stick
|
|
188
|
+
// half its height out of the grid, and the whole view scrolled a few px.
|
|
189
|
+
it("clamps its position to half its own height inside both edges", () => {
|
|
190
|
+
const { container } = render(
|
|
191
|
+
<NowCursorLabel now={new Date(2026, 0, 1, 17, 57)} startHour={8} endHour={18} />,
|
|
192
|
+
)
|
|
193
|
+
const label = container.querySelector('[data-schedule-part="now-indicator-label"]')
|
|
194
|
+
const top = (label as HTMLElement).style.top
|
|
195
|
+
// A clamp whose preferred value is still the line's exact position...
|
|
196
|
+
expect(top).toMatch(/^clamp\(/)
|
|
197
|
+
expect(top).toContain(`${((9 * 60 + 57) / 600) * 100}%`)
|
|
198
|
+
// ...bounded by the label's half-height, from 100% at the bottom edge.
|
|
199
|
+
// (jsdom normalizes the calc, so match its parts, not one spelling.)
|
|
200
|
+
expect(top).toContain("1em + 0.25rem")
|
|
201
|
+
expect(top).toContain("100%")
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
186
205
|
describe("NowCursorLabel — the painted window gates it too", () => {
|
|
187
206
|
it("renders its clock text inside the window", () => {
|
|
188
207
|
render(<NowCursorLabel now={INSIDE} {...WINDOW} />)
|
|
@@ -119,6 +119,9 @@ export function NowCursorLine({
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/** Half of `NowCursorLabel`'s own height: `leading-none` (1em) plus `py-0.5`. */
|
|
123
|
+
const HALF_LABEL = "calc((1em + 0.25rem) / 2)"
|
|
124
|
+
|
|
122
125
|
/**
|
|
123
126
|
* The now-cursor's presence in the hour gutter — a leaf on its own, same
|
|
124
127
|
* isolation reasoning as `NowCursorLine` above (a per-minute tick only
|
|
@@ -231,7 +234,13 @@ export function NowCursorLabel({
|
|
|
231
234
|
"[--sch-now-line-color:var(--color-red-500)]",
|
|
232
235
|
className,
|
|
233
236
|
)}
|
|
234
|
-
|
|
237
|
+
// Centered on the line, but never past the band's own edges: near the
|
|
238
|
+
// top or bottom it stops half its height inside, so it can't stick
|
|
239
|
+
// out of the grid (which made the whole view scroll by a few px for
|
|
240
|
+
// the minutes around `startHour`/`endHour`). Only the label nudges;
|
|
241
|
+
// the line stays exact. Half its height is derived from its own box:
|
|
242
|
+
// a 1em line (`leading-none`) plus `py-0.5` (0.125rem top and bottom).
|
|
243
|
+
style={{ top: `clamp(${HALF_LABEL}, ${top}%, calc(100% - ${HALF_LABEL}))` }}
|
|
235
244
|
>
|
|
236
245
|
{clockTimeLabel(current, locale)}
|
|
237
246
|
</span>
|
|
@@ -73,6 +73,18 @@ describe("Switch", () => {
|
|
|
73
73
|
expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["SPAN", "SPAN", "INPUT"])
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
// Neutral's solid is white in dark mode, the same white as the thumb, so a
|
|
77
|
+
// checked neutral switch would be white on white. It fills green instead.
|
|
78
|
+
it('fills green for `color="neutral"`', () => {
|
|
79
|
+
render(<Switch label="Airplane mode" color="neutral" testId="airplane-mode" />)
|
|
80
|
+
expect(screen.getByTestId("airplane-mode").getAttribute("data-color")).toBe("green")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("keeps every other color as given", () => {
|
|
84
|
+
render(<Switch label="Airplane mode" color="red" testId="airplane-mode" />)
|
|
85
|
+
expect(screen.getByTestId("airplane-mode").getAttribute("data-color")).toBe("red")
|
|
86
|
+
})
|
|
87
|
+
|
|
76
88
|
it("renders testId as data-testid on the root label, not the hidden input", () => {
|
|
77
89
|
render(<Switch label="Airplane mode" testId="airplane-mode" />)
|
|
78
90
|
const el = screen.getByTestId("airplane-mode")
|
|
@@ -107,6 +107,8 @@ export type SwitchProps = WithTestId & {
|
|
|
107
107
|
/** Keeps full contrast but blocks edits. */
|
|
108
108
|
readOnly?: boolean
|
|
109
109
|
size?: Size
|
|
110
|
+
/** Checked fill. `neutral` is the one exception: it fills green, since
|
|
111
|
+
* neutral's solid is the same white as the thumb on a dark page. */
|
|
110
112
|
color?: Color
|
|
111
113
|
/** Field name for native form submission. */
|
|
112
114
|
name?: string
|
|
@@ -195,7 +197,7 @@ export const Switch = ({
|
|
|
195
197
|
name={name}
|
|
196
198
|
value={value}
|
|
197
199
|
id={id}
|
|
198
|
-
data-color={color}
|
|
200
|
+
data-color={color === "neutral" ? "green" : color}
|
|
199
201
|
{...props({ "data-testid": testId })}
|
|
200
202
|
// `relative` contains the absolutely positioned hidden input, which would
|
|
201
203
|
// otherwise escape any scroller this control sits in.
|