mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
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.
74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import React from 'react';
|
|
import {Pagination as MPagination} from '@mantine/core';
|
|
|
|
/*
|
|
* Navigation: pagination and tab bars.
|
|
*
|
|
* Neither knows anything about routing — the app owns its links. The tab bar
|
|
* takes rendered children and supplies only the strip and its house style, so
|
|
* call sites keep using react-router's NavLink and its `isActive` render prop.
|
|
*/
|
|
|
|
// --------------------------------------------------------------- Pagination
|
|
|
|
export interface PaginationProps {
|
|
/** 1-based. */
|
|
activePage: number;
|
|
totalPages?: number;
|
|
onPageChange: (page: number) => void;
|
|
/** Pages shown either side of the active one. Fewer on a phone. */
|
|
siblingRange?: number;
|
|
/** Include jump-to-first and jump-to-last controls. */
|
|
showFirstAndLast?: boolean;
|
|
size?: string;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Page controls. Replaces Semantic's Pagination, keeping its prop names
|
|
* (`activePage`, `totalPages`, `onPageChange`) so call sites migrate as a
|
|
* rename — but `onPageChange` receives the page number directly rather than
|
|
* Semantic's `(event, data)` pair.
|
|
*/
|
|
export function Pagination({
|
|
activePage,
|
|
totalPages,
|
|
onPageChange,
|
|
siblingRange = 2,
|
|
showFirstAndLast = false,
|
|
size = 'sm',
|
|
disabled,
|
|
}: PaginationProps) {
|
|
return <MPagination
|
|
className='wrolpi-pagination'
|
|
value={activePage}
|
|
// A single empty page still renders, so the control never collapses to nothing
|
|
// and shift the layout when results arrive.
|
|
total={totalPages || 1}
|
|
onChange={onPageChange}
|
|
siblings={siblingRange}
|
|
withEdges={showFirstAndLast}
|
|
size={size}
|
|
disabled={disabled}
|
|
radius={0}
|
|
getItemProps={page => ({'aria-label': `Page ${page}`})}
|
|
/>
|
|
}
|
|
|
|
// ----------------------------------------------------------------- Tab bars
|
|
|
|
/** A row of tabs. Children are the links; routing stays with the caller. */
|
|
export function TabBar({children, right}: {children: React.ReactNode; right?: React.ReactNode}) {
|
|
return <nav className='wrolpi-tabs'>
|
|
<div className='wrolpi-tabs-links'>{children}</div>
|
|
{right && <div className='wrolpi-tabs-right'>{right}</div>}
|
|
</nav>
|
|
}
|
|
|
|
/**
|
|
* Class name for one tab. Exported rather than baked into a component so a
|
|
* caller can hand it straight to NavLink's `className` render prop, which is
|
|
* how the app decides what is active.
|
|
*/
|
|
export const tabClassName = (active: boolean): string =>
|
|
`wrolpi-tab${active ? ' wrolpi-tab-active' : ''}`;
|