wrolpi/app/src/components/ui/Inputs.tsx

90 lines
2.9 KiB
TypeScript
Raw Normal View History

ui: token-driven component library on Mantine Adds src/components/ui: buttons, messages, labels, progress, status, tables, form controls, panels, cards, statistics, modals, tooltips, tabs, and icons. Everything resolves its colors through theme tokens, so no component branches on the current theme, and Semantic UI keeps rendering the app meanwhile. Mantine is bridged rather than restyled: its own CSS variables are pointed at our tokens. Four details were not obvious, and each caused a visible defect in night mode before being fixed: - Structural colors must go in the resolver's light/dark blocks. Mantine emits its values under [data-mantine-color-scheme], which outranks the :root block that `variables` becomes, so its grays were winning. - The dark and gray palettes are mapped shade by shade to tokens. Mantine reads them directly for table borders, zebra stripes and input chrome; they can be neither flattened nor left alone. - Mantine writes --button-* as inline styles, which no stylesheet can outrank, so the dashed danger treatment sets real properties instead. - Switch colors are written onto inner elements, so they need scoped CSS rather than a variable on the root. Adds a --knob token for control handles, because Mantine's default thumb follows theme.white, which is near-black in the dark-based themes. An audit of every painted pixel in the /theme-sample gallery now finds no non-red channel in night mode. Icons come from @tabler/icons-react with the 102 Semantic names the app uses mapped to components; they stroke with currentColor, so they follow the theme without any rule of their own. Toasts keep the react-semantic-toasts-2 signature so those call sites migrate by changing an import. TypeScript 5 is required: Mantine's declarations use `const` type parameters, which 4.9 cannot parse (Mantine 7 is the same, so downgrading is no escape). That needs two npm overrides to keep clean installs working, both verified against a Docker build: react-scripts declares peerOptional typescript ^3||^4, and fork-ts-checker 6.5.2 assigns typescript.performance.mark, which TS 5 made getter-only - crashing the dev server's type checker on every rebuild. semantic-baseline.test.js ratchets the removal: it fails if a file not already listed imports Semantic UI. An ESLint rule would have printed 75 warnings per rebuild, and CI unsets CI= for its build step, so it would guard nothing there. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 19:22:03 -06:00
import React from 'react';
import {
Checkbox as MCheckbox,
MultiSelect,
NumberInput,
Radio,
Select as MSelect,
Switch as MSwitch,
Textarea as MTextarea,
TextInput as MTextInput,
} from '@mantine/core';
/*
* Form controls.
*
* All of these are Mantine components, deliberately: every one renders its own
* markup rather than a native control. Native checkboxes, radios, and select
* arrows are drawn by the browser in white, which cannot be restyled and would
* put white pixels on screen in night mode. Mantine draws SVG we can color
* from tokens.
*/
// Mantine reads these per-component variables; pointing them at tokens keeps the
// controls correct in all four themes without any per-theme branching.
const checkboxStyles = {
'--checkbox-color': 'var(--blue)',
'--checkbox-icon-color': 'var(--btn-text)',
} as React.CSSProperties;
/*
* `--switch-color` is the *checked* track and comes from the `color` prop, so it is
* deliberately not set here. The thumb must be a token: Mantine's default follows
* `theme.white`, which is our `--btn-text` — near-black on the dark-based themes.
*
* The unchecked track is set in ui.css instead of here. Mantine writes `--switch-bg`
* onto the track element itself, so a variable on this root would never reach it.
*/
const switchStyles = {
'--switch-thumb-bg': 'var(--knob)',
'--switch-disabled-color': 'var(--head)',
} as React.CSSProperties;
export type CheckboxProps = React.ComponentProps<typeof MCheckbox>;
export function Checkbox({style, ...props}: CheckboxProps) {
return <MCheckbox style={{...checkboxStyles, ...style}} {...props}/>
}
export type ToggleProps = React.ComponentProps<typeof MSwitch>;
/** An on/off switch. Replaces Semantic's `Radio toggle`. */
export function Toggle({style, className, ...props}: ToggleProps) {
return <MSwitch
className={['wrolpi-switch', className].filter(Boolean).join(' ')}
style={{...switchStyles, ...style}}
color='blue'
{...props}
/>
}
ui: migrate the extension pages and Configs; five components they needed Phase 2, part 1. Three files leave Semantic UI (baseline 75 -> 72), and the components they needed join the library and the gallery: Header Semantic's shape (as/icon/subheader/dividing). 47 files use <Header>, and the level now picks the size, so the type scale stays a scale instead of each call site choosing a font size. Message gains an icon and a dismiss button. ActionInput input and button sharing one outline, for <Input action={...}/>. Loading centered loader with a caption, replacing the <Loader active inline='centered'> + wrapper div in 19 places. Modal becomes compound - Modal.Header/.Content/.Actions, plus Semantic's open, closeIcon, and size names - because 34 files are written against that shape. test-utils mounts MantineProvider with ThemeProvider's exact configuration: migrated components render Mantine internals and every one of their test files would otherwise need its own provider. One Semantic bleed found and fixed: semantic.min.css sets `h1,h2,h3,h4,h5 { font-family: Lato }` and loads after Mantine's element rule, so headings ignored the theme's body face. Only visible in amber, where the body is mono and the headings were not. A class-level restatement outranks it; the rule comes out when Semantic does. Verified: 925 jest tests, clean production build, and a night-mode audit of every painted pixel in the gallery (red-only, one known false positive). The Configs backup and restore flow was exercised against the real API.
2026-07-29 20:25:34 -06:00
export interface ActionInputProps extends React.ComponentProps<typeof MTextInput> {
/** Button (or buttons) attached to the input's trailing edge. */
action?: React.ReactNode;
}
/**
* A text input with a button joined to its right edge. Replaces Semantic's
* `<Input action={...}/>`.
*
* The two share one outline rather than sitting side by side, so the pair reads
* as a single control — the input's own right border is dropped and the button
* supplies the edge.
*/
export function ActionInput({action, className, ...props}: ActionInputProps) {
if (!action) return <MTextInput className={className} {...props}/>
return <div className={['wrolpi-action-input', className].filter(Boolean).join(' ')}>
<MTextInput {...props}/>
{action}
</div>
}
ui: token-driven component library on Mantine Adds src/components/ui: buttons, messages, labels, progress, status, tables, form controls, panels, cards, statistics, modals, tooltips, tabs, and icons. Everything resolves its colors through theme tokens, so no component branches on the current theme, and Semantic UI keeps rendering the app meanwhile. Mantine is bridged rather than restyled: its own CSS variables are pointed at our tokens. Four details were not obvious, and each caused a visible defect in night mode before being fixed: - Structural colors must go in the resolver's light/dark blocks. Mantine emits its values under [data-mantine-color-scheme], which outranks the :root block that `variables` becomes, so its grays were winning. - The dark and gray palettes are mapped shade by shade to tokens. Mantine reads them directly for table borders, zebra stripes and input chrome; they can be neither flattened nor left alone. - Mantine writes --button-* as inline styles, which no stylesheet can outrank, so the dashed danger treatment sets real properties instead. - Switch colors are written onto inner elements, so they need scoped CSS rather than a variable on the root. Adds a --knob token for control handles, because Mantine's default thumb follows theme.white, which is near-black in the dark-based themes. An audit of every painted pixel in the /theme-sample gallery now finds no non-red channel in night mode. Icons come from @tabler/icons-react with the 102 Semantic names the app uses mapped to components; they stroke with currentColor, so they follow the theme without any rule of their own. Toasts keep the react-semantic-toasts-2 signature so those call sites migrate by changing an import. TypeScript 5 is required: Mantine's declarations use `const` type parameters, which 4.9 cannot parse (Mantine 7 is the same, so downgrading is no escape). That needs two npm overrides to keep clean installs working, both verified against a Docker build: react-scripts declares peerOptional typescript ^3||^4, and fork-ts-checker 6.5.2 assigns typescript.performance.mark, which TS 5 made getter-only - crashing the dev server's type checker on every rebuild. semantic-baseline.test.js ratchets the removal: it fails if a file not already listed imports Semantic UI. An ESLint rule would have printed 75 warnings per rebuild, and CI unsets CI= for its build step, so it would guard nothing there. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 19:22:03 -06:00
export {
MTextInput as TextInput,
MTextarea as Textarea,
MSelect as Select,
MultiSelect,
NumberInput,
Radio,
};