feat(ui): the shared page frame and toolbar kit: Page, PageHeader, Toolbar, Dropdown (multi-select), SearchInput, FilterChip, Segmented, Tabs
Owner's UI review (2026-11-20): pages that don't scroll and sit on the left, native selects in toolbars, controls of different heights, labels too loud. Everything is global in @xenia/ui so no page rebuilds it: - Page: scrolls on its own, fills the area up to a 16:9 screen's width (--x-page-max = max(1280px, 100vh*16/9)), centred beyond (ultrawides); width="form" for settings; top= keeps a tab strip above the scroll - Dropdown: portal list, flips above, keyboard, search for long lists, multiple (array value, [] = all, allLabel), dots and hints; Input heights - SearchInput, FilterChip (tone + count), Segmented, Tabs (sideways scroll only, no 1px up/down scroll), Toolbar/ToolbarSpacer - InfoTip opens on hover too; Dialog size xl (920px) - tokens: --x-text-overline (11px), --x-pad-card(-y), muted ink-2 (contrast test still passes in every look); preset: text-overline, p-card, max-w-page, the special tone - component labels (search, clear, all, nothing found) in en/el Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { useLabels } from './labels.js'
|
||||
|
||||
const SearchIcon = () => (
|
||||
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="M20 20l-3.5-3.5" /></svg>
|
||||
)
|
||||
const ClearIcon = () => (
|
||||
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
||||
)
|
||||
|
||||
/**
|
||||
* A search box: icon, input, a clear button while there is text. Same heights as <Input>.
|
||||
* <SearchInput value={q} onChange={setQ} placeholder="Search contacts" />
|
||||
* onChange receives the text (not an event). Grows to fill a <Toolbar>.
|
||||
*/
|
||||
export function SearchInput({ value = '', onChange, placeholder, size = 'md', className, 'aria-label': ariaLabel, ...rest }) {
|
||||
const labels = useLabels()
|
||||
return (
|
||||
<div className={cx('x-search', className)}>
|
||||
<span className="x-search__icon"><SearchIcon /></span>
|
||||
<input type="search" className={cx('x-input', `x-input--${size}`, 'x-search__input')} value={value} placeholder={placeholder ?? labels.search}
|
||||
aria-label={ariaLabel ?? placeholder ?? labels.search} onChange={e => onChange?.(e.target.value)} {...rest} />
|
||||
{value && (
|
||||
<button type="button" className="x-search__clear" aria-label={labels.clear} onClick={() => onChange?.('')}><ClearIcon /></button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A toggle filter in a toolbar: a state, a status… with an optional coloured dot and a count.
|
||||
* tone: 'success' | 'info' | 'accent' | 'warning' | 'danger' | 'neutral' (the dot and the "on" look).
|
||||
*/
|
||||
export function FilterChip({ pressed = false, tone = 'neutral', count, size = 'md', className, children, ...rest }) {
|
||||
return (
|
||||
<button type="button" aria-pressed={pressed} className={cx('x-chip', `x-chip--${size}`, `x-chip--${tone}`, pressed && 'x-chip--on', className)} {...rest}>
|
||||
<span className="x-chip__dot" aria-hidden="true" />
|
||||
{children}
|
||||
{count != null && <span className="x-chip__count">{count}</span>}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A few mutually exclusive views (List / Map). options: [{ value, label, icon? }].
|
||||
* <Segmented value={view} onChange={setView} options={[…]} aria-label="View" />
|
||||
*/
|
||||
export function Segmented({ options = [], value, onChange, size = 'md', className, ...rest }) {
|
||||
return (
|
||||
<div role="group" className={cx('x-segmented', `x-segmented--${size}`, className)} {...rest}>
|
||||
{options.map(o => (
|
||||
<button key={o.value} type="button" aria-pressed={o.value === value} className={cx('x-segmented__item', o.value === value && 'x-segmented__item--on')}
|
||||
onClick={() => onChange?.(o.value)} data-testid={o.testId}>
|
||||
{o.icon}{o.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tabs with an underline: a page's or a dialog's sections. Scrolls sideways when they don't fit,
|
||||
* never up and down. tabs: [{ id, label, badge?, warn?, testId? }].
|
||||
* <Tabs tabs={tabs} value={tab} onChange={setTab} />
|
||||
* end: an element at the right end of the strip (a refresh button…).
|
||||
*/
|
||||
export function Tabs({ tabs = [], value, onChange, size = 'md', end, className, ...rest }) {
|
||||
return (
|
||||
<div className={cx('x-tabs', `x-tabs--${size}`, className)} {...rest}>
|
||||
<div className="x-tabs__list" role="tablist">
|
||||
{tabs.map(tb => (
|
||||
<button key={tb.id} type="button" role="tab" aria-selected={tb.id === value} data-testid={tb.testId}
|
||||
className={cx('x-tabs__tab', tb.id === value && 'x-tabs__tab--on')} onClick={() => onChange?.(tb.id)}>
|
||||
{tb.icon}{tb.label}
|
||||
{tb.badge != null && tb.badge !== false && <span className={cx('x-tabs__badge', tb.warn && 'x-tabs__badge--warn')}>{tb.badge}</span>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{end && <div className="x-tabs__end">{end}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user