mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 01:46:18 -05:00
ui: nine leaf files off Semantic, and the components they needed
Phase 2, part 2. Baseline 72 -> 63.
Migrated: Tables, SortableTable, DonatePage, Share, Headline, ErrorBoundary,
and the QR code, VIN decoder, and temperature calculators.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>`, keeping its grouped `results`
shape because four call sites already build it. A real
combobox: arrows move, Enter takes the highlighted suggestion
or submits the raw text, Escape closes without clearing.
Pagination Semantic's prop names, but onPageChange gets the page number
rather than an (event, data) pair.
TabBar the strip and its house style only; routing stays at the call
site, which is what decides what is active.
IconStack two glyphs composed into one symbol, named once for assistive
technology (Semantic's IconGroup).
Table.HeaderCell gains `sorted` and `onSort`.
That last one is a fix, not just a port. Semantic's `sorted` prop set
`aria-sort`; migrating a table by hand dropped it, leaving a clickable <th>
that no keyboard could reach and no screen reader could describe. Putting it
in the library means the next table gets it right without anyone remembering.
Night mode holes closed along the way: the QR codes on the donate, share, and
calculator pages are white by necessity — a scanner needs the contrast — and
they render as SVG, which the media filter does not target. In night mode that
was a lit panel. They now carry `.media`, so the filter remaps the block as a
unit and the contrast survives the mapping.
Also: `paypal` joins the icon map rather than being imported ad hoc in a page,
and FileBrowser stops passing Semantic-only table props into a DOM element.
This commit is contained in:
parent
2ee81fae14
commit
d359eea2d3
19 changed files with 1030 additions and 224 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import {Table as MTable, TableProps as MTableProps} from '@mantine/core';
|
||||
import {Icon} from './Icon';
|
||||
|
||||
/*
|
||||
* Tables.
|
||||
|
|
@ -54,19 +55,55 @@ function Cell({numeric, style, ...props}: CellProps) {
|
|||
/>
|
||||
}
|
||||
|
||||
export type SortDirection = 'ascending' | 'descending';
|
||||
|
||||
export interface HeaderCellProps extends React.ComponentPropsWithoutRef<'th'> {
|
||||
/** This column's current sort, or null/undefined when it is not the sorted one. */
|
||||
sorted?: SortDirection | null;
|
||||
/** Makes the header a sort control. Receives nothing; the caller knows its column. */
|
||||
onSort?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A header cell, optionally a sort control.
|
||||
*
|
||||
* When `onSort` is given the label becomes a real `<button>` — a click handler on
|
||||
* the `<th>` alone is unreachable by keyboard — and the cell carries `aria-sort`,
|
||||
* so the sort state is announced rather than left to the arrow glyph.
|
||||
*/
|
||||
function HeaderCell({sorted, onSort, children, ...props}: HeaderCellProps) {
|
||||
if (!onSort) return <MTable.Th {...props}>{children}</MTable.Th>
|
||||
|
||||
return <MTable.Th
|
||||
// `none` (not omitted) on the other columns tells assistive tech they are
|
||||
// sortable but not currently sorted.
|
||||
aria-sort={sorted ? sorted : 'none'}
|
||||
{...props}
|
||||
>
|
||||
<button type='button' className='wrolpi-th-sort' onClick={onSort}>
|
||||
{children}
|
||||
<Icon
|
||||
name={sorted === 'descending' ? 'arrow down' : 'arrow up'}
|
||||
size={14}
|
||||
className={sorted ? undefined : 'wrolpi-th-sort-idle'}
|
||||
/>
|
||||
</button>
|
||||
</MTable.Th>
|
||||
}
|
||||
|
||||
export const Table = Object.assign(TableBase, {
|
||||
Header: MTable.Thead,
|
||||
Body: MTable.Tbody,
|
||||
Footer: MTable.Tfoot,
|
||||
Row,
|
||||
Cell,
|
||||
HeaderCell: MTable.Th,
|
||||
HeaderCell,
|
||||
// Mantine's own names, for new code.
|
||||
Thead: MTable.Thead,
|
||||
Tbody: MTable.Tbody,
|
||||
Tfoot: MTable.Tfoot,
|
||||
Tr: Row,
|
||||
Td: Cell,
|
||||
Th: MTable.Th,
|
||||
Th: HeaderCell,
|
||||
ScrollContainer: MTable.ScrollContainer,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue