swarm-ui: shared form-field kit (TextField, SelectField, Button)
Closes #3448. New ui/ primitives: FormField (shared label+control wrapper), TextField, SelectField, Button — each with a min-height touch target (2.75em ~= 44px, WCAG 2.5.5) per mara's #3447 ask, and a max-width instead of a fixed width so the control caps on desktop without overflowing a narrow/touch viewport. CreateAgentPage's name field + submit button now come from the kit instead of page-scoped CSS; ComponentsPage gets a section for each new primitive with an editable sample.
This commit is contained in:
parent
3643eccf22
commit
ba873926fa
9 changed files with 288 additions and 57 deletions
26
frontend/packages/swarm-ui/src/ui/button/Button.css
Normal file
26
frontend/packages/swarm-ui/src/ui/button/Button.css
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* <Button> — same touch-target floor as `.ui-form-control`
|
||||
(../form-field/FormField.css: 2.75em ≈ 44px at the default root font,
|
||||
WCAG 2.5.5) so a button never reads as a smaller tap target than the
|
||||
input sitting next to it. Colours are the shared base16-derived vars
|
||||
(../../theme.css). */
|
||||
.ui-button {
|
||||
border-radius: 0.3em;
|
||||
padding: 0.5em 1.2em;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
min-height: 2.75em;
|
||||
}
|
||||
.ui-button-primary {
|
||||
background: var(--purple-dim);
|
||||
color: var(--fg);
|
||||
border: none;
|
||||
}
|
||||
.ui-button-default {
|
||||
background: var(--bg-elev);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.ui-button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: default;
|
||||
}
|
||||
35
frontend/packages/swarm-ui/src/ui/button/Button.tsx
Normal file
35
frontend/packages/swarm-ui/src/ui/button/Button.tsx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// <Button> — the shared clickable-action control (form submit today,
|
||||
// any future toolbar/dialog action later). `variant` is `'primary'`
|
||||
// (the one emphasised action on a page, e.g. a form's submit) or
|
||||
// `'default'` (everything else) — two is enough for every real caller
|
||||
// so far; a third reading gets added the day something needs it, not
|
||||
// speculatively.
|
||||
import type { ComponentChildren } from 'preact';
|
||||
import './Button.css';
|
||||
|
||||
export type ButtonVariant = 'primary' | 'default';
|
||||
|
||||
export function Button({
|
||||
variant = 'default',
|
||||
type = 'button',
|
||||
disabled,
|
||||
onClick,
|
||||
children,
|
||||
}: {
|
||||
variant?: ButtonVariant;
|
||||
type?: 'button' | 'submit';
|
||||
disabled?: boolean;
|
||||
onClick?: (e: Event) => void;
|
||||
children: ComponentChildren;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
class={'ui-button ui-button-' + variant}
|
||||
type={type}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue