strata-react 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/components/compare.d.ts +42 -0
- package/dist/components/fullscreen-frame.d.ts +16 -0
- package/dist/components/viewport.d.ts +41 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +563 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/viewport.d.ts +29 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ function KilnRoom() {
|
|
|
122
122
|
| Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup`, `Checkbox` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid`, and `action` puts a one-field form's button on the control's row with the hint and error under both; `Checkbox` requires `label` and is one target with it, and has a mixed state |
|
|
123
123
|
| Status and figures | `Status`, `Metric`, `MetricStrip`, `Meter`, `crossedThreshold`, `CompositionBar` | A status is always a word; figures have no icons or sparklines; `Meter` is a `meter` named for what it measures, with its reading in words ("72% used"), threshold notches, and a `Status` word once a threshold is crossed (each threshold must name its state); `CompositionBar` is a stacked bar over a table naming every part, its amount and share, and names the remainder (`total` needs `restLabel`); a part that is there reads "<1%" and keeps a sliver, never "0%"; `JobStatus` is a long-running server job: a required word per state beside the app's sentence, a progress bar when the total is known, each failure named with its reason, announced only when the item changes or the job ends |
|
|
124
124
|
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables and lists virtualise from 100 rows; a `DataTable` column with `value` sorts by type with missing values last both ways and draws a placeholder (`missing`, default an en dash); `InfiniteList` loads the next page on approach, with a skeleton for it, a Try again row when it fails and a Show more button for the keyboard, and `scroll="page"` draws a grid that scrolls with the page; `LoadMore` is that next-page row for any list or grid; charts label values directly |
|
|
125
|
+
| Compare | `Compare`, `ViewportFrame`, `useViewport`, `FullscreenFrame` | Two pictures judged together: side by side, swipe (a divider that moves from the keyboard), fade and blink (`x` flips), one zoom and pan for both sides (buttons, `+` `-` `0`, Ctrl-wheel or trackpad pinch, drag, arrow keys, double click, `1:1`), and full screen (the browser's Fullscreen API, a modal where there is none). `blind` is required: a blind comparison names pictures by `label` only and never writes the variant `id`, `note` or `alt`. A picture that fails shows the required `missing` words in its place; the keys come from one `Shortcut[]` shared with `KeysLegend`, and `keys={false}` leaves them to a surrounding screen. Pictures only so far: difference view, voting, text, audio and video are the next changes |
|
|
125
126
|
| Selection | `useSelection`, `BulkBar`, `SelectableGrid`, `DataTable`'s `selection` (`RowSelection<T>`) | Opt-in checkbox column with "Select all shown" that respects `isSelectable`; Shift-click or Shift+Space chooses or clears the run from the last row clicked, in the order shown; `initial` (keys or a test on the row) chooses a row the first time it appears, so it applies to data that loads later; the selection drops rows that are gone; `BulkBar` announces the count politely, and while it is up its one filled action is the view's only one (the screen's primary goes to `outline`); `SelectableGrid` is the same selection as a grid of pictures (`renderImage`), each tile one labelled target, virtualised from 100 tiles |
|
|
126
127
|
| Expansion | `Disclosure`, `useExpanded`, `DataTable`'s `expansion` (`RowExpansion<T>`) | Show more of one row in place. The toggle is a button with `aria-expanded`; the body is mounted only while open, so a request inside it runs on first open (unlike `<details>`, which mounts every closed body); `useExpanded({ param })` shares the open keys across a list or table and keeps them in the URL; a table's detail row spans the data columns and is measured when virtualised |
|
|
127
128
|
| Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `useInfiniteLoad`, `useJob`, `toLoad`, `staleOf`, `fetchJson`, `HttpError`, `readErrorBody`, `fieldErrorsOf` | TanStack Query in, `Load<T>` out; a refetch that fails after a good read stays `ready` with `stale` set, never an error panel; `useInfiniteLoad` works out the cursor itself (after the last item held), merges pages by key and can `dismiss` an item at once; `useJob` polls a job's status only while it runs and invalidates the queries it changes once, when it ends; `fetchJson` reads an error response's body onto the `HttpError` (`body`, `reason`, `fieldErrors`, read by `readErrorBody` or the API's own `readError`) |
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** A picture to compare. */
|
|
3
|
+
export type ImageMedia = {
|
|
4
|
+
kind: "image";
|
|
5
|
+
src: string;
|
|
6
|
+
/** What it shows. Ignored when the comparison is `blind`: the label names it then. */
|
|
7
|
+
alt: string;
|
|
8
|
+
/** Its natural size in pixels, if known, so the frame has its shape and "1:1" is exact before the picture loads. */
|
|
9
|
+
size?: readonly [number, number];
|
|
10
|
+
};
|
|
11
|
+
/** One side of a comparison. */
|
|
12
|
+
export type Candidate<M = ImageMedia> = {
|
|
13
|
+
/** Who it is: a variant name, a model. Never put on the page when `blind`, and never needed by it. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** What the person sees it called: "Original", or "A" when blind. */
|
|
16
|
+
label: string;
|
|
17
|
+
media: M;
|
|
18
|
+
/** A line under the label ("auto2, 14 s"). Not shown when `blind`. */
|
|
19
|
+
note?: string;
|
|
20
|
+
};
|
|
21
|
+
/** How two pictures are laid out. */
|
|
22
|
+
export type CompareMode = "side" | "swipe" | "fade" | "blink";
|
|
23
|
+
/** Props for `Compare`. */
|
|
24
|
+
export type CompareProps = {
|
|
25
|
+
/** Names the comparison for screen readers: "Photo 1 of 12, two versions". Required. */
|
|
26
|
+
label: string;
|
|
27
|
+
a: Candidate;
|
|
28
|
+
b: Candidate;
|
|
29
|
+
/** Whether the person must not learn which variant is which. Required, no default. */
|
|
30
|
+
blind: boolean;
|
|
31
|
+
/** The words shown where a picture could not be loaded: "Picture not found". Required. */
|
|
32
|
+
missing: string;
|
|
33
|
+
mode: CompareMode;
|
|
34
|
+
onModeChange: (mode: CompareMode) => void;
|
|
35
|
+
/** Which views are offered. Default all four. Must include `mode`. */
|
|
36
|
+
modes?: readonly CompareMode[];
|
|
37
|
+
/** Bind the view, zoom and full-screen keys on the window. Default true; turn off when a surrounding screen binds the same keys. */
|
|
38
|
+
keys?: boolean;
|
|
39
|
+
className?: string;
|
|
40
|
+
};
|
|
41
|
+
/** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
|
|
42
|
+
export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, keys, className }: CompareProps): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** Props for `FullscreenFrame`. */
|
|
3
|
+
export type FullscreenFrameProps = {
|
|
4
|
+
/** Names the full-screen view for screen readers: "Compare renderings". Required. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Whether the frame is full screen. The caller owns it so a button and a key can share it. */
|
|
7
|
+
active: boolean;
|
|
8
|
+
/** Called with `false` when the person leaves with Escape or the browser's own control. */
|
|
9
|
+
onActiveChange: (active: boolean) => void;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Whether this browser can show an element full screen. False in jsdom and on iPhone, where the modal fallback is used. */
|
|
14
|
+
export declare function canFullscreen(): boolean;
|
|
15
|
+
/** Shows its children full screen while `active`: the browser's Fullscreen API where there is one, a window-filling modal where there is not. */
|
|
16
|
+
export declare function FullscreenFrame({ label, active, onActiveChange, children, className }: FullscreenFrameProps): React.JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Viewport } from '../lib/viewport';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** The caller's zoom and pan, and how to change them. */
|
|
4
|
+
export type ViewportState = {
|
|
5
|
+
viewport: Viewport;
|
|
6
|
+
setViewport: (next: Viewport) => void;
|
|
7
|
+
};
|
|
8
|
+
/** Zoom and pan held in React state, to give to every `ViewportFrame` that should move together. */
|
|
9
|
+
export declare function useViewport(initial?: Viewport): ViewportState;
|
|
10
|
+
/** Props for `ViewportFrame`. */
|
|
11
|
+
export type ViewportFrameProps = ViewportState & {
|
|
12
|
+
/** Names the frame for screen readers: "Picture A". Required. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Width over height of the frame before anything inside it has loaded. */
|
|
15
|
+
aspect: number;
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
/** A second picture layer above `children`, zoomed and panned with them but cut at `shown` percent of the *frame's* width from the left, so a swipe divider in `overlay` stays where the cut is at any zoom. */
|
|
18
|
+
cover?: {
|
|
19
|
+
content: React.ReactNode;
|
|
20
|
+
shown: number;
|
|
21
|
+
};
|
|
22
|
+
/** Drawn over the frame, not zoomed with it: a divider to drag, a corner label. Its pointer, key and double-click events do not reach the frame, so using it never pans the picture. */
|
|
23
|
+
overlay?: React.ReactNode;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
/** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
|
|
27
|
+
export declare const ViewportFrame: React.ForwardRefExoticComponent<ViewportState & {
|
|
28
|
+
/** Names the frame for screen readers: "Picture A". Required. */
|
|
29
|
+
label: string;
|
|
30
|
+
/** Width over height of the frame before anything inside it has loaded. */
|
|
31
|
+
aspect: number;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
/** A second picture layer above `children`, zoomed and panned with them but cut at `shown` percent of the *frame's* width from the left, so a swipe divider in `overlay` stays where the cut is at any zoom. */
|
|
34
|
+
cover?: {
|
|
35
|
+
content: React.ReactNode;
|
|
36
|
+
shown: number;
|
|
37
|
+
};
|
|
38
|
+
/** Drawn over the frame, not zoomed with it: a divider to drag, a corner label. Its pointer, key and double-click events do not reach the frame, so using it never pans the picture. */
|
|
39
|
+
overlay?: React.ReactNode;
|
|
40
|
+
className?: string;
|
|
41
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,3 +50,7 @@ export { useActiveItem, ActiveList, type ActiveItem } from './components/active-
|
|
|
50
50
|
export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
|
|
51
51
|
export { StrataQueryProvider, createQueryClient, toLoad, staleOf, useLoad, useInfiniteLoad, useJob, fetchJson, HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody, type FetchJsonOptions, type InfiniteLoad, type InfiniteLoadOptions, type Job, type JobOptions, type More, } from './query';
|
|
52
52
|
export { describeActionError, fieldErrorsOf } from './lib/errors';
|
|
53
|
+
export { Compare, type CompareProps, type CompareMode, type Candidate, type ImageMedia } from './components/compare';
|
|
54
|
+
export { ViewportFrame, useViewport, type ViewportFrameProps, type ViewportState } from './components/viewport';
|
|
55
|
+
export { FullscreenFrame, canFullscreen, type FullscreenFrameProps } from './components/fullscreen-frame';
|
|
56
|
+
export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, type Viewport } from './lib/viewport';
|