@metacensus/library-ui 0.17.1 → 0.18.0
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 +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/Dialog.d.ts +21 -0
- package/dist/tools/Dialog.js +52 -0
- package/dist/tools/Dialog.js.map +1 -0
- package/package.json +1 -1
- package/src/css/styles.css +38 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Components render on the server: no router, auth or API client, and no browser g
|
|
|
34
34
|
|
|
35
35
|
- Marks: `MetaCensusMark`, `MetaCensusLockup`, `MetaCensusWordmark` (the lockup's letters alone, in `WORDMARK_VIEWBOX`), `MetaCensusArrow`, `LogoArrowMorph`, and the shared geometry, including the lockup's spacing (`LOCKUP_VIEWBOX`, and `LOCKUP_MARK_BOX` for the mark's box within it).
|
|
36
36
|
- Chrome: `Header` (`nav` and `actions` slots, which wrap on a narrow screen; with no `nav`, the `actions` sit at the end of the row), `Footer` (`brand` replaces the linked lockup and its link is the consumer's; `tagline`; link columns as children), `Nav` (`links`).
|
|
37
|
-
- Tools: `cn`, `Button`, `Notice`, `Chip`, `CiteThisPage` with the formatters `formatRis`, `formatBibtex` and `formatCitationText`, the form kit (`Field`, `Label`, `Input`, `Textarea`, `Select`, `Checkbox`, `RadioGroup`, `FieldError`), `useTheme`, `useStill`, `DisplayControls`, `displayScript`.
|
|
37
|
+
- Tools: `cn`, `Button`, `Notice`, `Chip`, `Dialog`, `CiteThisPage` with the formatters `formatRis`, `formatBibtex` and `formatCitationText`, the form kit (`Field`, `Label`, `Input`, `Textarea`, `Select`, `Checkbox`, `RadioGroup`, `FieldError`), `useTheme`, `useStill`, `DisplayControls`, `displayScript`.
|
|
38
38
|
- People: `ContributorCard` (a person's photo, name, role, flavor chip and bio, whose bio floats open on hover or focus until Escape), `ContributorFlavorKey`, and `AudienceIcon` for each of `AUDIENCES`, labelled from `AUDIENCE_LABELS`. The floating card is portaled into `<body>`, so import `tokens.css` and set the theme on `:root`, not on a wrapper.
|
|
39
39
|
|
|
40
40
|
- Marks take `variant`: `auto` (the default: solid on every ground, over a Soft Lavender halo on dark that spills about one mark-height past its box, so its container must not clip it), `solid` or `reversed`. Mark usage is in [TRADEMARKS.md](TRADEMARKS.md).
|
|
@@ -42,6 +42,7 @@ Components render on the server: no router, auth or API client, and no browser g
|
|
|
42
42
|
- `Nav`'s mobile menu is a checkbox and CSS, so it works without JS.
|
|
43
43
|
- `Button` takes `variant`: `primary` (the default; one per view), `secondary`, `text`, `danger` or `inverse`. A solid Garnet fill marks only a risky action: one that destroys, discards, revokes or cannot be undone. A vote, a filter or a choice between options is not risky. `inverse` is a white fill for the call to action on a `--mc-fill-solid` or `--mc-night` ground, where `primary` is the ground's own colour or nearly so. Use it on those grounds only: it reads the same in light and dark, and `secondary` inside `.dark` is its quieter sibling.
|
|
44
44
|
- `Notice` takes `tone`: `alert` (the default, which reads the `--mc-alert-*` roles), `info` (the blue tint) or `success` (the purple tint fill with the accent ink, since the palette has no green). It renders `role="note"`; pass `role="alert"` for an error.
|
|
45
|
+
- `Dialog` is a native `<dialog>` opened with `showModal`: `open` is yours, `onClose` fires when Escape, the close control or a press on the backdrop closes it (not when `open` goes false), and focus returns to what opened it. Give it a `title`, its heading and name, or a `label`; `closeLabel` replaces "Close". Size it with `className`.
|
|
45
46
|
- `Button` and `Notice` follow the guidelines' illustrated Actions and Callout patterns. Those patterns do not bind yet: the guidelines have yet to state their shape.
|
|
46
47
|
- Display: inline `displayScript` in `<head>` so the stored choices are on `<html>` before first paint. `DisplayControls` is a round icon button fixed at the viewport's bottom-left corner; hover, focus or a tap opens a panel with the theme (`system`, the OS, `light` or `dark`) and a switch that stops animations. Render it once, from the layout; the panel may cover content on a phone. `useTheme` and `useStill` read and set the same choices. Stopped animations put `still` on `<html>`, whether the viewer chose it or the OS prefers reduced motion, so a page styles its own animations from `:root.still`, as the marks' halo does. With no stored choice the theme and `still` follow the system.
|
|
47
48
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { Nav, type NavLink } from './chrome/Nav.js';
|
|
|
6
6
|
export { Button } from './tools/Button.js';
|
|
7
7
|
export { Chip } from './tools/Chip.js';
|
|
8
8
|
export { cn } from './tools/cn.js';
|
|
9
|
+
export { Dialog } from './tools/Dialog.js';
|
|
9
10
|
export { formatBibtex, formatCitationText, formatRis, type Citation, } from './tools/cite.js';
|
|
10
11
|
export { CiteThisPage } from './tools/CiteThisPage.js';
|
|
11
12
|
export { Checkbox, Field, FieldError, Input, Label, RadioGroup, Select, Textarea, } from './tools/form.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { Nav } from './chrome/Nav.js';
|
|
|
6
6
|
export { Button } from './tools/Button.js';
|
|
7
7
|
export { Chip } from './tools/Chip.js';
|
|
8
8
|
export { cn } from './tools/cn.js';
|
|
9
|
+
export { Dialog } from './tools/Dialog.js';
|
|
9
10
|
export { formatBibtex, formatCitationText, formatRis, } from './tools/cite.js';
|
|
10
11
|
export { CiteThisPage } from './tools/CiteThisPage.js';
|
|
11
12
|
export { Checkbox, Field, FieldError, Input, Label, RadioGroup, Select, Textarea, } from './tools/form.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,kBAAkB,CAAA;AACzB,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,GAAG,EAAgB,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AA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,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EACL,QAAQ,EACR,KAAK,EACL,UAAU,EACV,KAAK,EACL,KAAK,EACL,UAAU,EACV,MAAM,EACN,QAAQ,GACT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,GAEb,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,eAAe,EACf,oBAAoB,GAErB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,eAAe,EACf,aAAa,EACb,QAAQ,EACR,QAAQ,GAET,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DialogHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
type Naming = {
|
|
3
|
+
title: ReactNode;
|
|
4
|
+
label?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
title?: undefined;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
type DialogProps = Naming & Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'title' | 'onClose'> & {
|
|
10
|
+
open: boolean;
|
|
11
|
+
/** Called when the dialog closes by Escape, the close control or a press
|
|
12
|
+
* on the backdrop; not when `open` goes false. */
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
closeLabel?: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
/** A modal on the native `<dialog>`: the browser gives the inert background,
|
|
17
|
+
* Escape and the top layer, and this returns focus to the opener. `open` is
|
|
18
|
+
* the parent's truth: set it false in `onClose`. A `title` is the visible heading and names the dialog;
|
|
19
|
+
* without one, `label` does. */
|
|
20
|
+
export declare function Dialog({ open, onClose, title, label, closeLabel, className, children, ...props }: DialogProps): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, } from 'react';
|
|
3
|
+
import { Button } from './Button.js';
|
|
4
|
+
import { cn } from './cn.js';
|
|
5
|
+
/** A modal on the native `<dialog>`: the browser gives the inert background,
|
|
6
|
+
* Escape and the top layer, and this returns focus to the opener. `open` is
|
|
7
|
+
* the parent's truth: set it false in `onClose`. A `title` is the visible heading and names the dialog;
|
|
8
|
+
* without one, `label` does. */
|
|
9
|
+
export function Dialog({ open, onClose, title, label, closeLabel = 'Close', className, children, ...props }) {
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
const opener = useRef(null);
|
|
12
|
+
const closing = useRef(false);
|
|
13
|
+
const pressedOutside = useRef(false);
|
|
14
|
+
const headingId = useId();
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const dialog = ref.current;
|
|
17
|
+
if (open && !dialog.open) {
|
|
18
|
+
opener.current = document.activeElement;
|
|
19
|
+
dialog.showModal();
|
|
20
|
+
}
|
|
21
|
+
else if (!open && dialog.open) {
|
|
22
|
+
// The close event this raises is the parent's own doing; `closed` skips it.
|
|
23
|
+
closing.current = true;
|
|
24
|
+
dialog.close();
|
|
25
|
+
}
|
|
26
|
+
}, [open]);
|
|
27
|
+
const closed = () => {
|
|
28
|
+
const back = opener.current;
|
|
29
|
+
opener.current = null;
|
|
30
|
+
if (back instanceof HTMLElement && back.isConnected)
|
|
31
|
+
back.focus({ preventScroll: true });
|
|
32
|
+
if (closing.current)
|
|
33
|
+
closing.current = false;
|
|
34
|
+
else
|
|
35
|
+
onClose();
|
|
36
|
+
};
|
|
37
|
+
// The backdrop is the dialog element itself, outside its box.
|
|
38
|
+
const outside = (event) => {
|
|
39
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
40
|
+
return (event.target === event.currentTarget &&
|
|
41
|
+
(event.clientX < box.left ||
|
|
42
|
+
event.clientX > box.right ||
|
|
43
|
+
event.clientY < box.top ||
|
|
44
|
+
event.clientY > box.bottom));
|
|
45
|
+
};
|
|
46
|
+
return (_jsxs("dialog", { ...props, ref: ref, className: cn('mc-dialog', className), "aria-labelledby": title !== undefined ? headingId : undefined, "aria-label": label, onClose: closed, onPointerDown: (e) => (pressedOutside.current = outside(e)), onClick: (e) => {
|
|
47
|
+
if (pressedOutside.current && outside(e))
|
|
48
|
+
ref.current.close();
|
|
49
|
+
pressedOutside.current = false;
|
|
50
|
+
}, children: [_jsxs("div", { className: "mc-dialog-header", children: [title !== undefined && (_jsx("h2", { id: headingId, className: "mc-dialog-title", children: title })), _jsx(Button, { variant: "secondary", onClick: () => ref.current.close(), children: closeLabel })] }), _jsx("div", { className: "mc-dialog-body", children: children })] }));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=Dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../src/tools/Dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,MAAM,GAIP,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAiB5B;;;iCAGiC;AACjC,MAAM,UAAU,MAAM,CAAC,EACrB,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,EACL,UAAU,GAAG,OAAO,EACpB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACI;IACZ,MAAM,GAAG,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAA;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7B,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACpC,MAAM,SAAS,GAAG,KAAK,EAAE,CAAA;IAEzB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,GAAG,CAAC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AE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,qBACpB,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,gBAChD,KAAK,EACjB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAC3D,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACb,IAAI,cAAc,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC;gBAAE,GAAG,CAAC,OAAQ,CAAC,KAAK,EAAE,CAAA;YAC9D,cAAc,CAAC,OAAO,GAAG,KAAK,CAAA;QAChC,CAAC,aAED,eAAK,SAAS,EAAC,kBAAkB,aAC9B,KAAK,KAAK,SAAS,IAAI,CACtB,aAAI,EAAE,EAAE,SAAS,EAAE,SAAS,EAAC,iBAAiB,YAC3C,KAAK,GACH,CACN,EACD,KAAC,MAAM,IAAC,OAAO,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAQ,CAAC,KAAK,EAAE,YAC5D,UAAU,GACJ,IACL,EACN,cAAK,SAAS,EAAC,gBAAgB,YAAE,QAAQ,GAAO,IACzC,CACV,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/css/styles.css
CHANGED
|
@@ -333,6 +333,44 @@
|
|
|
333
333
|
font-weight: 700;
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
/* Dialog: the native modal; the UA centres it. */
|
|
337
|
+
.mc-dialog {
|
|
338
|
+
display: flex;
|
|
339
|
+
flex-direction: column;
|
|
340
|
+
gap: 1rem;
|
|
341
|
+
box-sizing: border-box;
|
|
342
|
+
max-width: calc(100vw - 2rem);
|
|
343
|
+
max-height: calc(100dvh - 2rem);
|
|
344
|
+
padding: 1rem;
|
|
345
|
+
border: 1px solid var(--mc-hairline);
|
|
346
|
+
border-radius: var(--mc-radius);
|
|
347
|
+
background: var(--mc-card);
|
|
348
|
+
color: var(--mc-ink);
|
|
349
|
+
box-shadow: var(--mc-shadow);
|
|
350
|
+
}
|
|
351
|
+
/* A layered `display` beats the UA's hiding of a closed dialog. */
|
|
352
|
+
.mc-dialog:not([open]) {
|
|
353
|
+
display: none;
|
|
354
|
+
}
|
|
355
|
+
.mc-dialog::backdrop {
|
|
356
|
+
background: color-mix(in srgb, var(--mc-night) 60%, transparent);
|
|
357
|
+
}
|
|
358
|
+
.mc-dialog-header {
|
|
359
|
+
display: flex;
|
|
360
|
+
flex-wrap: wrap;
|
|
361
|
+
align-items: center;
|
|
362
|
+
justify-content: space-between;
|
|
363
|
+
gap: 0.75rem;
|
|
364
|
+
}
|
|
365
|
+
.mc-dialog-title {
|
|
366
|
+
margin: 0;
|
|
367
|
+
font-size: 1.25rem;
|
|
368
|
+
}
|
|
369
|
+
.mc-dialog-body {
|
|
370
|
+
min-height: 0;
|
|
371
|
+
overflow: auto;
|
|
372
|
+
}
|
|
373
|
+
|
|
336
374
|
/* Chip: the tint fill, with ink and border from the bold step. */
|
|
337
375
|
.mc-chip {
|
|
338
376
|
display: inline-block;
|