mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 04:16:24 -05:00
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.
This commit is contained in:
parent
6ffc5b57c8
commit
00c52872fa
12 changed files with 621 additions and 202 deletions
|
|
@ -25,10 +25,14 @@ export interface MessageProps {
|
|||
kind?: MessageKind;
|
||||
title?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
/** Semantic icon name or a Tabler component, shown to the left of the text. */
|
||||
icon?: string | React.ComponentType<any>;
|
||||
/** Renders a dismiss button. Omit for messages the user cannot clear. */
|
||||
onDismiss?: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Message({kind = 'info', title, children, className}: MessageProps) {
|
||||
export function Message({kind = 'info', title, children, icon, onDismiss, className}: MessageProps) {
|
||||
return <div
|
||||
// Errors and warnings interrupt; info and success are announced politely.
|
||||
role={kind === 'error' ? 'alert' : 'status'}
|
||||
|
|
@ -36,8 +40,21 @@ export function Message({kind = 'info', title, children, className}: MessageProp
|
|||
.filter(Boolean).join(' ')}
|
||||
style={{['--message-color' as string]: messageColors[kind]}}
|
||||
>
|
||||
{title && <div className='wrolpi-message-title'>{title}</div>}
|
||||
{children && <div className='wrolpi-message-body'>{children}</div>}
|
||||
{icon && <div className='wrolpi-message-icon'>
|
||||
{typeof icon === 'string' ? <Icon name={icon} size={20}/> : <Icon component={icon} size={20}/>}
|
||||
</div>}
|
||||
<div className='wrolpi-message-content'>
|
||||
{title && <div className='wrolpi-message-title'>{title}</div>}
|
||||
{children && <div className='wrolpi-message-body'>{children}</div>}
|
||||
</div>
|
||||
{onDismiss && <button
|
||||
type='button'
|
||||
className='wrolpi-message-dismiss'
|
||||
aria-label='Dismiss'
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<Icon name='close' size={16}/>
|
||||
</button>}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
|
@ -137,6 +154,28 @@ export function Loader({size = 'sm', label}: LoaderProps) {
|
|||
return <MLoader size={size} color='var(--blue)' aria-label={label ?? 'Loading'}/>
|
||||
}
|
||||
|
||||
export interface LoadingProps {
|
||||
/** What is being waited on: "Loading backups…". Also the accessible name. */
|
||||
children?: React.ReactNode;
|
||||
size?: LoaderProps['size'];
|
||||
/** Vertical padding around the loader. */
|
||||
padding?: number | string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A centered loader with a caption, for a region that has nothing to show yet.
|
||||
* Replaces Semantic's `<Loader active inline='centered'>`, which 19 call sites
|
||||
* used with their own wrapper div.
|
||||
*/
|
||||
export function Loading({children, size = 'sm', padding = '2em'}: LoadingProps) {
|
||||
return <div style={{
|
||||
display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 10, padding,
|
||||
}}>
|
||||
<Loader size={size} label={typeof children === 'string' ? children : undefined}/>
|
||||
{children && <div style={{fontSize: 13, color: 'var(--muted)'}}>{children}</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
/** Placeholder for content that has not arrived. Replaces Semantic's Placeholder. */
|
||||
export function Placeholder({lines = 3, height = 12}: {lines?: number; height?: number}) {
|
||||
return <div style={{display: 'flex', flexDirection: 'column', gap: 8}}>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,27 @@ export function Toggle({style, className, ...props}: ToggleProps) {
|
|||
/>
|
||||
}
|
||||
|
||||
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>
|
||||
}
|
||||
|
||||
export {
|
||||
MTextInput as TextInput,
|
||||
MTextarea as Textarea,
|
||||
|
|
|
|||
|
|
@ -6,17 +6,76 @@ import {Button} from './Button';
|
|||
* Overlays: modals, confirmations, tooltips, menus.
|
||||
*/
|
||||
|
||||
export type ModalProps = React.ComponentProps<typeof MModal>;
|
||||
/*
|
||||
* Modals.
|
||||
*
|
||||
* Semantic's compound shape (`Modal.Header` / `Modal.Content` / `Modal.Actions`)
|
||||
* is kept because 34 call sites are written against it. The subcomponents are
|
||||
* markers: Modal reads them out of its children and places each in the right
|
||||
* slot, so the children stay in source order at the call site.
|
||||
*/
|
||||
|
||||
const ModalHeader = ({children}: {children?: React.ReactNode}) => <>{children}</>;
|
||||
ModalHeader.displayName = 'Modal.Header';
|
||||
|
||||
const ModalContent = ({children}: {children?: React.ReactNode; scrolling?: boolean}) => <>{children}</>;
|
||||
ModalContent.displayName = 'Modal.Content';
|
||||
|
||||
const ModalActions = ({children}: {children?: React.ReactNode}) => <>{children}</>;
|
||||
ModalActions.displayName = 'Modal.Actions';
|
||||
|
||||
// Semantic's size names, mapped onto Mantine's scale.
|
||||
const modalSizes: Record<string, string> = {
|
||||
mini: 'xs',
|
||||
tiny: 'sm',
|
||||
small: 'md',
|
||||
large: 'lg',
|
||||
fullscreen: '100%',
|
||||
};
|
||||
|
||||
export interface ModalProps extends Omit<React.ComponentProps<typeof MModal>, 'opened' | 'size'> {
|
||||
/** Semantic's name for `opened`. Either works. */
|
||||
open?: boolean;
|
||||
opened?: boolean;
|
||||
/** A title given directly, instead of a `Modal.Header` child. */
|
||||
title?: React.ReactNode;
|
||||
/** Semantic size name (mini/tiny/small/large/fullscreen) or a Mantine size. */
|
||||
size?: string | number;
|
||||
/** Accepted and ignored: the close button is always shown. */
|
||||
closeIcon?: boolean;
|
||||
}
|
||||
|
||||
function ModalBase({open, opened, size, closeIcon, title, children, ...props}: ModalProps) {
|
||||
const slots: Record<string, React.ReactNode[]> = {header: [], actions: [], body: []};
|
||||
React.Children.forEach(children, child => {
|
||||
const type = React.isValidElement(child) ? child.type : undefined;
|
||||
if (type === ModalHeader) slots.header.push((child as React.ReactElement).props.children);
|
||||
else if (type === ModalActions) slots.actions.push((child as React.ReactElement).props.children);
|
||||
else slots.body.push(child);
|
||||
});
|
||||
|
||||
export function Modal(props: ModalProps) {
|
||||
return <MModal
|
||||
opened={opened ?? open ?? false}
|
||||
centered
|
||||
size={typeof size === 'string' ? (modalSizes[size] ?? size) : size}
|
||||
title={slots.header.length ? slots.header : title}
|
||||
// Flat surfaces: the overlay separates the modal from the page, not a shadow.
|
||||
overlayProps={{backgroundOpacity: 0.55, blur: 0}}
|
||||
{...props}
|
||||
/>
|
||||
>
|
||||
{slots.body}
|
||||
{slots.actions.length > 0 && <div className='wrolpi-modal-actions'>{slots.actions}</div>}
|
||||
</MModal>
|
||||
}
|
||||
|
||||
export const Modal = Object.assign(ModalBase, {
|
||||
Header: ModalHeader,
|
||||
Content: ModalContent,
|
||||
Actions: ModalActions,
|
||||
// Mantine's own names, for new code.
|
||||
Body: ModalContent,
|
||||
});
|
||||
|
||||
export interface ConfirmProps {
|
||||
open: boolean;
|
||||
title?: React.ReactNode;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,49 @@
|
|||
import React from 'react';
|
||||
import {Card as MCard, Tabs as MTabs, Accordion as MAccordion, Breadcrumbs} from '@mantine/core';
|
||||
import {Icon} from './Icon';
|
||||
|
||||
/*
|
||||
* Surfaces and structure: panels, cards, statistics, tabs, accordions,
|
||||
* Surfaces and structure: headers, panels, cards, statistics, tabs, accordions,
|
||||
* breadcrumbs. Elevation is expressed with borders and background steps —
|
||||
* never a shadow (shadows are zeroed in the Mantine bridge).
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------- Headers
|
||||
|
||||
export type HeaderLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
||||
|
||||
export interface HeaderProps extends Omit<React.HTMLAttributes<HTMLHeadingElement>, 'color'> {
|
||||
/** Heading level. Also the visual size — pick it for the outline, not the look. */
|
||||
as?: HeaderLevel;
|
||||
/** Semantic icon name or a Tabler component, shown before the text. */
|
||||
icon?: string | React.ComponentType<any>;
|
||||
/** Secondary line below, in muted text. */
|
||||
subheader?: React.ReactNode;
|
||||
/** Hairline rule underneath, separating the section from what follows. */
|
||||
dividing?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A section heading. Named and shaped like Semantic's Header (`as`, `icon`,
|
||||
* `subheader`, `dividing`) so the app's 47 call sites migrate by import.
|
||||
*
|
||||
* Sizes come from ui.css, keyed on the level, rather than each call site
|
||||
* choosing — that is what keeps the type scale a scale.
|
||||
*/
|
||||
export function Header({as = 'h3', icon, subheader, dividing, className, children, ...props}: HeaderProps) {
|
||||
const Tag = as;
|
||||
return <div className={['wrolpi-header', dividing ? 'wrolpi-header-dividing' : '', className]
|
||||
.filter(Boolean).join(' ')}>
|
||||
<Tag className={`wrolpi-header-text wrolpi-header-${as}`} {...props}>
|
||||
{icon && (typeof icon === 'string'
|
||||
? <Icon name={icon} size='medium'/>
|
||||
: <Icon component={icon} size='medium'/>)}
|
||||
<span>{children}</span>
|
||||
</Tag>
|
||||
{subheader && <div className='wrolpi-header-sub'>{subheader}</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- Panels
|
||||
|
||||
export interface PanelProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,49 @@ html[data-theme="amber"] .wrolpi-theme-option-active {
|
|||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Modals */
|
||||
/*
|
||||
* Actions sit below the body, separated by a hairline rather than a raised bar.
|
||||
* Right-aligned, so the confirming action lands where the eye finishes reading.
|
||||
*/
|
||||
|
||||
.wrolpi-modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
/* Bleed back out through the modal body's own padding so the rule spans the
|
||||
full width; -1 * whatever Mantine padded the body with. */
|
||||
margin: 18px calc(var(--mantine-spacing-md) * -1) calc(var(--mantine-spacing-md) * -1);
|
||||
padding: 12px var(--mantine-spacing-md);
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- Action inputs */
|
||||
/*
|
||||
* Input and button share one outline: the input gives up its right border and
|
||||
* the button's left border becomes the seam between them.
|
||||
*/
|
||||
|
||||
.wrolpi-action-input {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.wrolpi-action-input > .mantine-TextInput-root {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.wrolpi-action-input .mantine-TextInput-input {
|
||||
border-right-width: 0;
|
||||
}
|
||||
|
||||
.wrolpi-action-input > :not(.mantine-TextInput-root) {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Switches */
|
||||
/*
|
||||
* Mantine's unchecked track is a gray from its own palette, which would put a
|
||||
|
|
@ -165,9 +208,69 @@ html[data-theme="night"] .wrolpi-label {
|
|||
border-color: var(--label-color);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Headers */
|
||||
|
||||
.wrolpi-header {
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.wrolpi-header-dividing {
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
.wrolpi-header-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
/*
|
||||
* Stated explicitly because semantic.min.css sets `h1,h2,h3,h4,h5 { font-family:
|
||||
* Lato }` and loads after Mantine's element rule, so headings would ignore the
|
||||
* theme's body face — visible in amber, where the body is mono and headings were
|
||||
* not. A class outranks the element selector. Can go once Semantic is gone.
|
||||
*/
|
||||
font-family: var(--font-body);
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
color: var(--text);
|
||||
text-wrap: balance;
|
||||
}
|
||||
|
||||
/* The scale lives here so no call site invents a size of its own. */
|
||||
.wrolpi-header-h1 {
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.wrolpi-header-h2 {
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.wrolpi-header-h3 {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.wrolpi-header-h4 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.wrolpi-header-h5 {
|
||||
font-size: 13px;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.wrolpi-header-sub {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Messages */
|
||||
|
||||
.wrolpi-message {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-left: 3px solid var(--message-color, var(--border));
|
||||
background: var(--panel);
|
||||
|
|
@ -175,6 +278,39 @@ html[data-theme="night"] .wrolpi-label {
|
|||
font-size: 13px;
|
||||
}
|
||||
|
||||
.wrolpi-message-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* The icon repeats what the border color already says, so it takes that color. */
|
||||
.wrolpi-message-icon {
|
||||
color: var(--message-color, var(--text));
|
||||
display: flex;
|
||||
padding-top: 1px;
|
||||
}
|
||||
|
||||
.wrolpi-message-dismiss {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
/* Widen the tap target past the glyph without moving it. */
|
||||
margin: -6px -6px -6px 0;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.wrolpi-message-dismiss:hover {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.wrolpi-message-dismiss:focus-visible {
|
||||
outline: 2px solid var(--blue);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.wrolpi-message-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import {ThemeContext} from '../../contexts/contexts';
|
|||
import {cssVariablesResolver, mantineTheme, semanticColorNames} from '../../themes/mantine';
|
||||
import {themeChoices} from '../../themes/names';
|
||||
import {
|
||||
ActionInput,
|
||||
Button,
|
||||
Confirm,
|
||||
Header,
|
||||
Icon,
|
||||
IconButton,
|
||||
Label,
|
||||
|
|
@ -129,6 +131,78 @@ describe('Message', () => {
|
|||
|
||||
expect(screen.getByRole('alert')).toHaveClass('wrolpi-message-error');
|
||||
});
|
||||
|
||||
it('dismisses when asked', async () => {
|
||||
const onDismiss = jest.fn();
|
||||
renderUI(<Message title='Install the extension' onDismiss={onDismiss}/>);
|
||||
|
||||
await userEvent.click(screen.getByRole('button', {name: 'Dismiss'}));
|
||||
|
||||
expect(onDismiss).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('offers no dismiss button when the message cannot be cleared', () => {
|
||||
renderUI(<Message title='Refresh running'/>);
|
||||
|
||||
expect(screen.queryByRole('button', {name: 'Dismiss'})).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders a leading icon when given one', () => {
|
||||
const {container} = renderUI(<Message icon='puzzle piece' title='Extension'/>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-message-icon svg')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Header', () => {
|
||||
it('renders the requested heading level', () => {
|
||||
renderUI(<Header as='h1'>Browser Extension</Header>);
|
||||
|
||||
expect(screen.getByRole('heading', {level: 1, name: 'Browser Extension'})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('defaults to h3 so a call site that omits the level still nests sanely', () => {
|
||||
renderUI(<Header>Firefox</Header>);
|
||||
|
||||
expect(screen.getByRole('heading', {level: 3, name: 'Firefox'})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('takes its size from the level, not from the call site', () => {
|
||||
// The class is what ui.css keys the type scale on; a call site passing its own
|
||||
// font-size is the thing this component exists to prevent.
|
||||
const {container} = renderUI(<Header as='h4'>Install steps</Header>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-header-h4')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders an icon and a subheader', () => {
|
||||
const {container} = renderUI(<Header icon='globe' subheader='Paste this into the extension'>
|
||||
This WROLPi's URL
|
||||
</Header>);
|
||||
|
||||
expect(container.querySelector('svg')).toBeInTheDocument();
|
||||
expect(screen.getByText('Paste this into the extension')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ActionInput', () => {
|
||||
it('joins the input and its action into one control', () => {
|
||||
const {container} = renderUI(
|
||||
<ActionInput label='URL' value='https://wrolpi.local' readOnly
|
||||
action={<Button role='cancel'>Copy</Button>}/>
|
||||
);
|
||||
|
||||
expect(container.querySelector('.wrolpi-action-input')).toBeInTheDocument();
|
||||
expect(screen.getByRole('textbox', {name: 'URL'})).toHaveValue('https://wrolpi.local');
|
||||
expect(screen.getByRole('button', {name: 'Copy'})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('is a plain input when no action is given', () => {
|
||||
const {container} = renderUI(<ActionInput label='URL'/>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-action-input')).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('textbox', {name: 'URL'})).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Progress', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue