@slashsuite/ui-react 0.0.0-stage → 0.12.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/LICENSE +21 -0
- package/MIGRATING.md +540 -0
- package/README.md +549 -2
- package/dist/AppShell.d.ts +127 -0
- package/dist/AppShell.js +119 -0
- package/dist/AppShellMenu.d.ts +26 -0
- package/dist/AppShellMenu.js +66 -0
- package/dist/Avatar.d.ts +75 -0
- package/dist/Avatar.js +95 -0
- package/dist/AvatarStack.d.ts +31 -0
- package/dist/AvatarStack.js +34 -0
- package/dist/Badge.d.ts +15 -0
- package/dist/Badge.js +15 -0
- package/dist/BottomSheet.d.ts +36 -0
- package/dist/BottomSheet.js +142 -0
- package/dist/Breadcrumbs.d.ts +27 -0
- package/dist/Breadcrumbs.js +29 -0
- package/dist/BulletList.d.ts +18 -0
- package/dist/BulletList.js +18 -0
- package/dist/Button.d.ts +121 -0
- package/dist/Button.js +182 -0
- package/dist/ButtonGroup.d.ts +15 -0
- package/dist/ButtonGroup.js +10 -0
- package/dist/Callout.d.ts +43 -0
- package/dist/Callout.js +45 -0
- package/dist/Card.d.ts +148 -0
- package/dist/Card.js +171 -0
- package/dist/CardBadge.d.ts +7 -0
- package/dist/CardBadge.js +12 -0
- package/dist/CardBody.d.ts +28 -0
- package/dist/CardBody.js +30 -0
- package/dist/CardGrid.d.ts +53 -0
- package/dist/CardGrid.js +52 -0
- package/dist/CardParts.d.ts +40 -0
- package/dist/CardParts.js +41 -0
- package/dist/ChatComposer.d.ts +35 -0
- package/dist/ChatComposer.js +50 -0
- package/dist/ChatMessage.d.ts +26 -0
- package/dist/ChatMessage.js +21 -0
- package/dist/ChatThread.d.ts +25 -0
- package/dist/ChatThread.js +60 -0
- package/dist/Checkbox.d.ts +42 -0
- package/dist/Checkbox.js +63 -0
- package/dist/Chevron.d.ts +5 -0
- package/dist/Chevron.js +6 -0
- package/dist/Cluster.d.ts +70 -0
- package/dist/Cluster.js +47 -0
- package/dist/Code.d.ts +6 -0
- package/dist/Code.js +5 -0
- package/dist/CodeBlock.d.ts +46 -0
- package/dist/CodeBlock.js +21 -0
- package/dist/CodeBody.d.ts +20 -0
- package/dist/CodeBody.js +38 -0
- package/dist/CodeExample.d.ts +25 -0
- package/dist/CodeExample.js +17 -0
- package/dist/CodeText.d.ts +11 -0
- package/dist/CodeText.js +64 -0
- package/dist/ColourSchemeToggle.d.ts +36 -0
- package/dist/ColourSchemeToggle.js +64 -0
- package/dist/Container.d.ts +22 -0
- package/dist/Container.js +26 -0
- package/dist/CopyButton.d.ts +17 -0
- package/dist/CopyButton.js +39 -0
- package/dist/CopyLine.d.ts +9 -0
- package/dist/CopyLine.js +7 -0
- package/dist/DateCalendar.d.ts +23 -0
- package/dist/DateCalendar.js +89 -0
- package/dist/DateField.d.ts +124 -0
- package/dist/DateField.js +111 -0
- package/dist/DateFieldCalendar.d.ts +24 -0
- package/dist/DateFieldCalendar.js +50 -0
- package/dist/DateRangePicker.d.ts +47 -0
- package/dist/DateRangePicker.js +44 -0
- package/dist/Dialog.d.ts +56 -0
- package/dist/Dialog.js +94 -0
- package/dist/Disclosure.d.ts +29 -0
- package/dist/Disclosure.js +23 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +5 -0
- package/dist/DocsLayout.d.ts +69 -0
- package/dist/DocsLayout.js +64 -0
- package/dist/Drawer.d.ts +30 -0
- package/dist/Drawer.js +24 -0
- package/dist/EmptyState.d.ts +47 -0
- package/dist/EmptyState.js +34 -0
- package/dist/Field.d.ts +44 -0
- package/dist/Field.js +51 -0
- package/dist/FieldDialog.d.ts +26 -0
- package/dist/FieldDialog.js +31 -0
- package/dist/Fieldset.d.ts +21 -0
- package/dist/Fieldset.js +22 -0
- package/dist/FileDrop.d.ts +17 -0
- package/dist/FileDrop.js +14 -0
- package/dist/FormRow.d.ts +46 -0
- package/dist/FormRow.js +39 -0
- package/dist/Hero.d.ts +23 -0
- package/dist/Hero.js +28 -0
- package/dist/Icon.d.ts +40 -0
- package/dist/Icon.js +30 -0
- package/dist/IconButton.d.ts +72 -0
- package/dist/IconButton.js +65 -0
- package/dist/Image.d.ts +58 -0
- package/dist/Image.js +69 -0
- package/dist/InlineEdit.d.ts +22 -0
- package/dist/InlineEdit.js +60 -0
- package/dist/Input.d.ts +40 -0
- package/dist/Input.js +42 -0
- package/dist/InputShell.d.ts +24 -0
- package/dist/InputShell.js +40 -0
- package/dist/Kbd.d.ts +6 -0
- package/dist/Kbd.js +5 -0
- package/dist/KeyValueList.d.ts +34 -0
- package/dist/KeyValueList.js +35 -0
- package/dist/Lightbox.d.ts +45 -0
- package/dist/Lightbox.js +46 -0
- package/dist/ListRow.d.ts +26 -0
- package/dist/ListRow.js +151 -0
- package/dist/Markdown.d.ts +11 -0
- package/dist/Markdown.js +49 -0
- package/dist/MediaTile.d.ts +66 -0
- package/dist/MediaTile.js +50 -0
- package/dist/Menu.d.ts +64 -0
- package/dist/Menu.js +86 -0
- package/dist/MetaList.d.ts +23 -0
- package/dist/MetaList.js +20 -0
- package/dist/Morph.d.ts +41 -0
- package/dist/Morph.js +107 -0
- package/dist/NavigationProgress.d.ts +20 -0
- package/dist/NavigationProgress.js +26 -0
- package/dist/OutlineRegion.d.ts +60 -0
- package/dist/OutlineRegion.js +51 -0
- package/dist/PageFade.d.ts +30 -0
- package/dist/PageFade.js +46 -0
- package/dist/PageHeader.d.ts +26 -0
- package/dist/PageHeader.js +18 -0
- package/dist/PageLayouts.d.ts +100 -0
- package/dist/PageLayouts.js +78 -0
- package/dist/Pagination.d.ts +38 -0
- package/dist/Pagination.js +65 -0
- package/dist/Pill.d.ts +79 -0
- package/dist/Pill.js +121 -0
- package/dist/ProgressBar.d.ts +47 -0
- package/dist/ProgressBar.js +47 -0
- package/dist/RadioGroup.d.ts +55 -0
- package/dist/RadioGroup.js +53 -0
- package/dist/ScrollStrip.d.ts +21 -0
- package/dist/ScrollStrip.js +12 -0
- package/dist/SearchInput.d.ts +9 -0
- package/dist/SearchInput.js +55 -0
- package/dist/Section.d.ts +93 -0
- package/dist/Section.js +55 -0
- package/dist/SegmentedControl.d.ts +47 -0
- package/dist/SegmentedControl.js +78 -0
- package/dist/Select.d.ts +28 -0
- package/dist/Select.js +19 -0
- package/dist/Show.d.ts +33 -0
- package/dist/Show.js +27 -0
- package/dist/SideColumn.d.ts +50 -0
- package/dist/SideColumn.js +45 -0
- package/dist/SidebarLayout.d.ts +32 -0
- package/dist/SidebarLayout.js +77 -0
- package/dist/SiteFooter.d.ts +31 -0
- package/dist/SiteFooter.js +24 -0
- package/dist/SiteSearch.d.ts +40 -0
- package/dist/SiteSearch.js +150 -0
- package/dist/SortableList.d.ts +86 -0
- package/dist/SortableList.js +191 -0
- package/dist/SplitBar.d.ts +29 -0
- package/dist/SplitBar.js +22 -0
- package/dist/Stack.d.ts +114 -0
- package/dist/Stack.js +76 -0
- package/dist/StackedBar.d.ts +64 -0
- package/dist/StackedBar.js +58 -0
- package/dist/StatTile.d.ts +33 -0
- package/dist/StatTile.js +44 -0
- package/dist/StatusPages.d.ts +49 -0
- package/dist/StatusPages.js +63 -0
- package/dist/Steps.d.ts +29 -0
- package/dist/Steps.js +43 -0
- package/dist/StickyBar.d.ts +12 -0
- package/dist/StickyBar.js +10 -0
- package/dist/Switch.d.ts +56 -0
- package/dist/Switch.js +91 -0
- package/dist/Table.d.ts +92 -0
- package/dist/Table.js +92 -0
- package/dist/TableCells.d.ts +97 -0
- package/dist/TableCells.js +104 -0
- package/dist/TableEditCell.d.ts +31 -0
- package/dist/TableEditCell.js +17 -0
- package/dist/TableExpandCell.d.ts +25 -0
- package/dist/TableExpandCell.js +15 -0
- package/dist/Tabs.d.ts +38 -0
- package/dist/Tabs.js +46 -0
- package/dist/TextLink.d.ts +51 -0
- package/dist/TextLink.js +38 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.js +11 -0
- package/dist/Timeline.d.ts +31 -0
- package/dist/Timeline.js +38 -0
- package/dist/ToastRegion.d.ts +44 -0
- package/dist/ToastRegion.js +37 -0
- package/dist/Tooltip.d.ts +46 -0
- package/dist/Tooltip.js +181 -0
- package/dist/TrendChart.d.ts +36 -0
- package/dist/TrendChart.js +58 -0
- package/dist/Video.d.ts +13 -0
- package/dist/Video.js +9 -0
- package/dist/blocked.d.ts +31 -0
- package/dist/blocked.js +31 -0
- package/dist/cardContext.d.ts +8 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardWait.d.ts +13 -0
- package/dist/cardWait.js +16 -0
- package/dist/colourScheme.d.ts +22 -0
- package/dist/colourScheme.js +53 -0
- package/dist/control.d.ts +29 -0
- package/dist/control.js +37 -0
- package/dist/copyScript.d.ts +13 -0
- package/dist/copyScript.js +13 -0
- package/dist/cx.d.ts +19 -0
- package/dist/cx.js +21 -0
- package/dist/density.d.ts +38 -0
- package/dist/density.js +77 -0
- package/dist/emptySlot.d.ts +11 -0
- package/dist/emptySlot.js +16 -0
- package/dist/fieldControl.d.ts +23 -0
- package/dist/fieldControl.js +24 -0
- package/dist/fieldWait.d.ts +30 -0
- package/dist/fieldWait.js +27 -0
- package/dist/foldedColumn.d.ts +18 -0
- package/dist/foldedColumn.js +51 -0
- package/dist/headingLevel.d.ts +10 -0
- package/dist/headingLevel.js +18 -0
- package/dist/highlight.d.ts +18 -0
- package/dist/highlight.js +306 -0
- package/dist/highlightConsole.d.ts +9 -0
- package/dist/highlightConsole.js +42 -0
- package/dist/highlightHtml.d.ts +7 -0
- package/dist/highlightHtml.js +132 -0
- package/dist/highlightKit.d.ts +16 -0
- package/dist/highlightKit.js +23 -0
- package/dist/highlightYaml.d.ts +3 -0
- package/dist/highlightYaml.js +143 -0
- package/dist/icons.d.ts +16 -0
- package/dist/icons.js +108 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +92 -0
- package/dist/isoDate.d.ts +5 -0
- package/dist/isoDate.js +16 -0
- package/dist/labelWords.d.ts +20 -0
- package/dist/labelWords.js +28 -0
- package/dist/layoutWait.d.ts +15 -0
- package/dist/layoutWait.js +18 -0
- package/dist/link.d.ts +82 -0
- package/dist/link.js +68 -0
- package/dist/listRowProps.d.ts +108 -0
- package/dist/listRowProps.js +1 -0
- package/dist/listRowWait.d.ts +6 -0
- package/dist/listRowWait.js +14 -0
- package/dist/modal.d.ts +25 -0
- package/dist/modal.js +61 -0
- package/dist/navFold.d.ts +15 -0
- package/dist/navFold.js +46 -0
- package/dist/pillTip.d.ts +8 -0
- package/dist/pillTip.js +25 -0
- package/dist/props.d.ts +26 -0
- package/dist/props.js +14 -0
- package/dist/scrollEdges.d.ts +12 -0
- package/dist/scrollEdges.js +40 -0
- package/dist/scrollStop.d.ts +32 -0
- package/dist/scrollStop.js +79 -0
- package/dist/sheetSnap.d.ts +27 -0
- package/dist/sheetSnap.js +45 -0
- package/dist/shownDate.d.ts +88 -0
- package/dist/shownDate.js +186 -0
- package/dist/size.d.ts +45 -0
- package/dist/size.js +12 -0
- package/dist/skeleton.d.ts +83 -0
- package/dist/skeleton.js +88 -0
- package/dist/stackGap.d.ts +9 -0
- package/dist/stackGap.js +16 -0
- package/dist/stickyColumn.d.ts +38 -0
- package/dist/stickyColumn.js +38 -0
- package/dist/switcher.d.ts +93 -0
- package/dist/switcher.js +78 -0
- package/dist/tableColumns.d.ts +31 -0
- package/dist/tableColumns.js +72 -0
- package/dist/tableEmpty.d.ts +15 -0
- package/dist/tableEmpty.js +26 -0
- package/dist/tableRow.d.ts +67 -0
- package/dist/tableRow.js +49 -0
- package/dist/tableSort.d.ts +22 -0
- package/dist/tableSort.js +19 -0
- package/dist/textBox.d.ts +10 -0
- package/dist/textBox.js +23 -0
- package/dist/tone.d.ts +11 -0
- package/dist/tone.js +1 -0
- package/dist/trend.d.ts +26 -0
- package/dist/trend.js +64 -0
- package/dist/typography.d.ts +203 -0
- package/dist/typography.js +242 -0
- package/dist/useImageFailed.d.ts +19 -0
- package/dist/useImageFailed.js +21 -0
- package/package.json +84 -4
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import { type ColourScheme, type ColourSchemeClasses } from "./colourScheme.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import type { Size } from "./size.js";
|
|
5
|
+
/**
|
|
6
|
+
* The class an app puts on its own `<html>`: it always reserves the scrollbar, so centred content
|
|
7
|
+
* does not shift between a short page and a long one. AppShell never touches `<html>` itself.
|
|
8
|
+
*/
|
|
9
|
+
export declare const appShellRootClass = "overflow-y-scroll";
|
|
10
|
+
/**
|
|
11
|
+
* Everything an app puts on its own `<html>` from the scheme the server knows: that scheme's class
|
|
12
|
+
* (`schemeClass`) and the shell's root class, joined: `<html className={appShellRootClassFor(scheme,
|
|
13
|
+
* schemes)}>`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function appShellRootClassFor(scheme: ColourScheme, schemes?: ColourSchemeClasses): string;
|
|
16
|
+
/**
|
|
17
|
+
* The `brand` slot as one link: a logo and a label inside the same `<a>`, so the whole brand is the
|
|
18
|
+
* way home. The label names the link; the logo is decoration and hidden from assistive tech.
|
|
19
|
+
* `collapse` shows only the logo below `sm`, the label staying in the accessible name. An in-app
|
|
20
|
+
* `href` is drawn by the app's router link through `LinkProvider`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function AppShellBrand({ logo, logoSize, label, collapse, href, ...rest }: Passthrough & {
|
|
23
|
+
/** The name beside the logo. It is the link's accessible name. */
|
|
24
|
+
label: ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Where the brand links, usually the app's home (`/`).
|
|
27
|
+
*
|
|
28
|
+
* With a router it goes through the app's `LinkProvider`, like every link.
|
|
29
|
+
*/
|
|
30
|
+
href: string;
|
|
31
|
+
/** The logo slot's box: sm 20px, md 24px (the default, an `Avatar size="sm"`), lg 32px. An `<img>` or `<svg>` logo fills it. */
|
|
32
|
+
logoSize?: Size;
|
|
33
|
+
} & ({
|
|
34
|
+
/** The mark before the label, e.g. an `Avatar` or an `<img>`. */
|
|
35
|
+
logo?: ReactNode;
|
|
36
|
+
collapse?: false | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
logo: ReactNode;
|
|
39
|
+
/** Below `sm` only the logo shows; the label is visually hidden and still names the link. Needs a `logo`. */
|
|
40
|
+
collapse: true;
|
|
41
|
+
})): ReactElement;
|
|
42
|
+
/** The type step an app sets once on its `AppShell`: `compact` is one step down for the whole app. */
|
|
43
|
+
export type AppShellDensity = "compact";
|
|
44
|
+
/**
|
|
45
|
+
* The page frame: it paints the page canvas and sets the type face, ink and font smoothing
|
|
46
|
+
* (`antialiased`), so an app writes no page-background or font rule of its own (a theme remaps
|
|
47
|
+
* the canvas and the font stacks). A sticky one-row header, an optional second `subnav` row, the main area and an
|
|
48
|
+
* optional footer. Header, main and footer each sit in a `Container`, so pages never set their own
|
|
49
|
+
* width or padding. `bleed` drops main's Container (the header keeps its own), for a layout that
|
|
50
|
+
* needs the whole width (`FullBleedLayout`). Main is a flex column. `SidebarLayout` needs no
|
|
51
|
+
* `bleed`: its rail and canvas share the header's Container.
|
|
52
|
+
*
|
|
53
|
+
* The header row is laid out by its slots, left to right: `brand`, `nav`, then `header` (anything
|
|
54
|
+
* the slots do not cover), then `controls`, pushed to the end. An app writes no wrapper or
|
|
55
|
+
* styling for any of them: an item that only fits a wide screen goes in a `Show from`. A bar
|
|
56
|
+
* that sticks under the header as the page scrolls is a `StickyBar`.
|
|
57
|
+
*
|
|
58
|
+
* On a phone (below `md`) the header is one 56px row at every page: `brand`, `header`, `controls`
|
|
59
|
+
* and a "Menu" button (`menuLabel`), and `nav` and `subnav` move into that menu, so every link is
|
|
60
|
+
* reachable and nothing scrolls sideways. The menu is a native `<details>`, so it works with the
|
|
61
|
+
* keyboard, with a screen reader and on a page that never hydrates. From `md` the header is the
|
|
62
|
+
* row, and the `subnav` row, as they are, except that a `nav` too wide for the row folds into the
|
|
63
|
+
* Menu and comes back when the screen is wide enough (measured, with script; a `subnav` never
|
|
64
|
+
* folds, it scrolls sideways with a fade).
|
|
65
|
+
*
|
|
66
|
+
* The edges need nothing from the app: with `viewport-fit=cover` every Container clears the
|
|
67
|
+
* safe-area insets at the sides, the header the top one and the shell the bottom one; and an
|
|
68
|
+
* element with an `id` anywhere inside lands below the sticky header when a link or focus scrolls
|
|
69
|
+
* to it.
|
|
70
|
+
*
|
|
71
|
+
* `controls` stay in the row at every width, so keep them few (a theme toggle, the viewer's avatar);
|
|
72
|
+
* on a phone a crowded `controls` clips, and the Menu button is never the part cut off. Pickers and
|
|
73
|
+
* actions that do not fit a phone row go in `menuControls`: rendered once, they sit in the row after
|
|
74
|
+
* `controls` from `md`, and below `md` at the top of the Menu, above `nav` and `subnav`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function AppShell({ brand, nav, controls, menuControls, header, subnav, menuLabel, footer, bleed, printChrome, density, children, ...rest }: {
|
|
77
|
+
/** The brand: a logo and a name, in the header's brand type, with the gap between them. `AppShellBrand` makes both one link. */
|
|
78
|
+
brand?: ReactNode;
|
|
79
|
+
/** The main navigation, e.g. a `Tabs` of links (it is already a `<nav>`). Below `md` it is in the menu. */
|
|
80
|
+
nav?: ReactNode;
|
|
81
|
+
/** The end of the row: a picker, a theme toggle. Gap-2, vertically centred; no child shrinks, and a full-width control (a `Select` at its default) sizes to its content. */
|
|
82
|
+
controls?: ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* Pickers and actions that do not fit a phone row, such as a project `Select` and a Sign out
|
|
85
|
+
* `Button`. From `md` they sit in the row after `controls`; below `md` they are at the top of the
|
|
86
|
+
* Menu, above `nav` and `subnav`. Rendered once, so a field keeps its state and ids stay unique.
|
|
87
|
+
* `controls` stay in the row at every width, so keep those few.
|
|
88
|
+
*/
|
|
89
|
+
menuControls?: ReactNode;
|
|
90
|
+
/**
|
|
91
|
+
* The escape hatch: a free node in the header row, after `brand` and `nav`.
|
|
92
|
+
*
|
|
93
|
+
* Only for a node no other slot covers: prefer `brand`, `nav` and `controls`.
|
|
94
|
+
*/
|
|
95
|
+
header?: ReactNode;
|
|
96
|
+
/** A second fixed-height row under the header from `md`, e.g. a `Tabs` of links. Below `md` it is in the menu with `nav`. */
|
|
97
|
+
subnav?: ReactNode;
|
|
98
|
+
/**
|
|
99
|
+
* The phone menu button's name, for an app in another language. Only drawn below `md`, and only
|
|
100
|
+
* when `nav`, `subnav` or `menuControls` is given.
|
|
101
|
+
* @default Menu
|
|
102
|
+
*/
|
|
103
|
+
menuLabel?: string;
|
|
104
|
+
/** The page footer: small muted text in a `Container`, under a hairline. Hidden in print with `printChrome={false}`. */
|
|
105
|
+
footer?: ReactNode;
|
|
106
|
+
/**
|
|
107
|
+
* Main without a Container, for a full-bleed layout.
|
|
108
|
+
*
|
|
109
|
+
* For a layout that needs the whole width, such as `FullBleedLayout`; `SidebarLayout` needs no
|
|
110
|
+
* `bleed`.
|
|
111
|
+
*/
|
|
112
|
+
bleed?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Whether a print shows the header and footer. `false` prints only the page: the header and
|
|
115
|
+
* footer are hidden, and main's Container drops its padding (the page margin is then `@page`'s).
|
|
116
|
+
*
|
|
117
|
+
* The screen is unchanged.
|
|
118
|
+
* @default true
|
|
119
|
+
*/
|
|
120
|
+
printChrome?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The app's type step, set once here and nowhere else: `compact` sets text, headings and controls
|
|
123
|
+
* one step down everywhere inside, for an app's dense chrome. Left out, text is 16px, as a site's.
|
|
124
|
+
*/
|
|
125
|
+
density?: AppShellDensity | undefined;
|
|
126
|
+
children: ReactNode;
|
|
127
|
+
} & Passthrough): ReactElement;
|
package/dist/AppShell.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { AppShellMenu } from "./AppShellMenu.js";
|
|
4
|
+
import { ContainerFrame } from "./Container.js";
|
|
5
|
+
import { schemeClass } from "./colourScheme.js";
|
|
6
|
+
import { cx, focusRing } from "./cx.js";
|
|
7
|
+
import { DensityProvider } from "./density.js";
|
|
8
|
+
import { renderLink } from "./link.js";
|
|
9
|
+
import { useNavFold } from "./navFold.js";
|
|
10
|
+
import { useScrollEdges } from "./scrollEdges.js";
|
|
11
|
+
/**
|
|
12
|
+
* The class an app puts on its own `<html>`: it always reserves the scrollbar, so centred content
|
|
13
|
+
* does not shift between a short page and a long one. AppShell never touches `<html>` itself.
|
|
14
|
+
*/
|
|
15
|
+
export const appShellRootClass = "overflow-y-scroll";
|
|
16
|
+
/**
|
|
17
|
+
* Everything an app puts on its own `<html>` from the scheme the server knows: that scheme's class
|
|
18
|
+
* (`schemeClass`) and the shell's root class, joined: `<html className={appShellRootClassFor(scheme,
|
|
19
|
+
* schemes)}>`.
|
|
20
|
+
*/
|
|
21
|
+
export function appShellRootClassFor(scheme, schemes) {
|
|
22
|
+
return cx(schemeClass(scheme, schemes), appShellRootClass);
|
|
23
|
+
}
|
|
24
|
+
const LOGO_BOX = { sm: "size-5", md: "size-6", lg: "size-8" };
|
|
25
|
+
/**
|
|
26
|
+
* The `brand` slot as one link: a logo and a label inside the same `<a>`, so the whole brand is the
|
|
27
|
+
* way home. The label names the link; the logo is decoration and hidden from assistive tech.
|
|
28
|
+
* `collapse` shows only the logo below `sm`, the label staying in the accessible name. An in-app
|
|
29
|
+
* `href` is drawn by the app's router link through `LinkProvider`.
|
|
30
|
+
*/
|
|
31
|
+
export function AppShellBrand({ logo, logoSize = "md", label, collapse = false, href, ...rest }) {
|
|
32
|
+
return renderLink({
|
|
33
|
+
...rest,
|
|
34
|
+
href,
|
|
35
|
+
className: cx("flex items-center gap-2 rounded", focusRing),
|
|
36
|
+
children: (_jsxs(_Fragment, { children: [logo && (_jsx("span", { "aria-hidden": "true", className: cx("flex shrink-0 items-center justify-center [&>img]:size-full [&>svg]:size-full", LOGO_BOX[logoSize]), children: logo })), _jsx("span", { className: collapse ? "sr-only sm:not-sr-only" : undefined, children: label })] })),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// One fixed-height row that never wraps; its children keep their width. From `md` it scrolls sideways
|
|
40
|
+
// if it must; below `md` nothing in the header scrolls (the nav is in the menu), so it only clips.
|
|
41
|
+
const ROW = "items-center gap-4 overflow-x-clip whitespace-nowrap md:overflow-x-auto *:shrink-0";
|
|
42
|
+
// From `md`, while a row has more to scroll to on a side, that edge fades out (a mask, so it follows
|
|
43
|
+
// any theme). `ScrollRow` sets `data-more-start` / `data-more-end` (and `data-more` for either); a
|
|
44
|
+
// row that fits has none and is untouched. Below `md` there is no mask, which would clip the menu.
|
|
45
|
+
const FADE = "md:data-more-start:[--fade-start:2rem] md:data-more-end:[--fade-end:2rem] md:data-more:[mask-image:linear-gradient(to_right,transparent,#000_var(--fade-start,0px),#000_calc(100%_-_var(--fade-end,0px)),transparent)]";
|
|
46
|
+
/** A row in a Container, with the fade on whichever side still has content to scroll to. `onRow` is also handed the row. */
|
|
47
|
+
function ScrollRow({ className, onRow, children, }) {
|
|
48
|
+
const [row, setRow] = useState(null);
|
|
49
|
+
useScrollEdges(row, "x");
|
|
50
|
+
const attach = useCallback((element) => {
|
|
51
|
+
setRow(element);
|
|
52
|
+
onRow?.(element);
|
|
53
|
+
}, [onRow]);
|
|
54
|
+
return (_jsx(ContainerFrame, { ref: attach, className: cx(ROW, FADE, className), children: children }));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The header row's slots in order: brand, nav (from `md`), the free `children`, then `controls` and
|
|
58
|
+
* the menu at the end. `controls` have a wrapper of their own that shrinks and clips, and the menu
|
|
59
|
+
* sits beside it, so a crowded `controls` never pushes the Menu off a phone screen. From `md` the
|
|
60
|
+
* menu is the inline row of `menuControls` after `controls`. `folded` hides the nav from `md` too:
|
|
61
|
+
* it is in the menu.
|
|
62
|
+
*/
|
|
63
|
+
function HeaderSlots({ brand, nav, controls, menu, menuInline, folded, children, }) {
|
|
64
|
+
return (_jsxs(_Fragment, { children: [brand && (_jsx("div", { className: "flex items-center gap-2 text-base font-bold tracking-tight text-slate-900", children: brand })), nav && (_jsx("div", { className: cx("hidden items-center gap-4 *:shrink-0", !folded && "md:flex"), children: nav })), children, (controls || menu) && (_jsxs("div", { className: cx(
|
|
65
|
+
// Below `md` this wrapper may shrink (the row's `*:shrink-0` is overridden), so a crowded
|
|
66
|
+
// `controls` clips inside its own box; from `md` it keeps its width and the row scrolls.
|
|
67
|
+
"ml-auto flex min-w-0 items-center gap-2 max-md:shrink!", !controls && !menuInline && !folded && "md:hidden"), children: [controls && (_jsx("div", { className: "flex min-w-0 items-center gap-2 *:shrink-0 max-md:-mx-1 max-md:overflow-x-clip max-md:px-1 [&>.w-full]:w-auto", children: controls })), menu] }))] }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The sticky header: the one-row slots, and from `md` the `subnav` row under them. It pads by the
|
|
71
|
+
* top safe-area inset. From `md` it measures its row: a nav that does not fit folds into the Menu
|
|
72
|
+
* (`data-nav-folded`) and comes back when the row is wide enough again (`useNavFold`).
|
|
73
|
+
*/
|
|
74
|
+
function AppShellHeader({ brand, nav, controls, menuControls, subnav, menuLabel, hideChromeInPrint, children, }) {
|
|
75
|
+
const [row, setRow] = useState(null);
|
|
76
|
+
const folded = useNavFold(row, !!nav);
|
|
77
|
+
return (_jsxs("header", { "data-nav-folded": folded ? "" : undefined, className: cx("sticky top-0 z-10 border-b border-slate-200 bg-white pt-[env(safe-area-inset-top)]", hideChromeInPrint && "print:hidden"), children: [_jsx(ScrollRow, { className: "flex h-14", onRow: setRow, children: _jsx(HeaderSlots, { brand: brand, nav: nav, controls: controls, menuInline: !!menuControls, folded: folded, menu: (nav || subnav || menuControls) && (_jsx(AppShellMenu, { label: menuLabel, controls: menuControls, nav: nav, subnav: subnav, folded: folded })), children: children }) }), subnav && _jsx(ScrollRow, { className: "hidden h-12 md:flex", children: subnav })] }));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The page frame: it paints the page canvas and sets the type face, ink and font smoothing
|
|
81
|
+
* (`antialiased`), so an app writes no page-background or font rule of its own (a theme remaps
|
|
82
|
+
* the canvas and the font stacks). A sticky one-row header, an optional second `subnav` row, the main area and an
|
|
83
|
+
* optional footer. Header, main and footer each sit in a `Container`, so pages never set their own
|
|
84
|
+
* width or padding. `bleed` drops main's Container (the header keeps its own), for a layout that
|
|
85
|
+
* needs the whole width (`FullBleedLayout`). Main is a flex column. `SidebarLayout` needs no
|
|
86
|
+
* `bleed`: its rail and canvas share the header's Container.
|
|
87
|
+
*
|
|
88
|
+
* The header row is laid out by its slots, left to right: `brand`, `nav`, then `header` (anything
|
|
89
|
+
* the slots do not cover), then `controls`, pushed to the end. An app writes no wrapper or
|
|
90
|
+
* styling for any of them: an item that only fits a wide screen goes in a `Show from`. A bar
|
|
91
|
+
* that sticks under the header as the page scrolls is a `StickyBar`.
|
|
92
|
+
*
|
|
93
|
+
* On a phone (below `md`) the header is one 56px row at every page: `brand`, `header`, `controls`
|
|
94
|
+
* and a "Menu" button (`menuLabel`), and `nav` and `subnav` move into that menu, so every link is
|
|
95
|
+
* reachable and nothing scrolls sideways. The menu is a native `<details>`, so it works with the
|
|
96
|
+
* keyboard, with a screen reader and on a page that never hydrates. From `md` the header is the
|
|
97
|
+
* row, and the `subnav` row, as they are, except that a `nav` too wide for the row folds into the
|
|
98
|
+
* Menu and comes back when the screen is wide enough (measured, with script; a `subnav` never
|
|
99
|
+
* folds, it scrolls sideways with a fade).
|
|
100
|
+
*
|
|
101
|
+
* The edges need nothing from the app: with `viewport-fit=cover` every Container clears the
|
|
102
|
+
* safe-area insets at the sides, the header the top one and the shell the bottom one; and an
|
|
103
|
+
* element with an `id` anywhere inside lands below the sticky header when a link or focus scrolls
|
|
104
|
+
* to it.
|
|
105
|
+
*
|
|
106
|
+
* `controls` stay in the row at every width, so keep them few (a theme toggle, the viewer's avatar);
|
|
107
|
+
* on a phone a crowded `controls` clips, and the Menu button is never the part cut off. Pickers and
|
|
108
|
+
* actions that do not fit a phone row go in `menuControls`: rendered once, they sit in the row after
|
|
109
|
+
* `controls` from `md`, and below `md` at the top of the Menu, above `nav` and `subnav`.
|
|
110
|
+
*/
|
|
111
|
+
export function AppShell({ brand, nav, controls, menuControls, header, subnav, menuLabel = "Menu", footer, bleed = false, printChrome = true, density, children, ...rest }) {
|
|
112
|
+
const hideChromeInPrint = !printChrome;
|
|
113
|
+
return (_jsx(DensityProvider, { type: density, children: _jsxs("div", { ...rest, className: cx("flex min-h-dvh flex-col bg-gray-50 pb-[env(safe-area-inset-bottom)] font-sans text-slate-900 antialiased",
|
|
114
|
+
// The sticky header's height (its rows, the top inset and the bottom border), for a bar
|
|
115
|
+
// that sticks under it. Below `md` it is one row whatever the slots are: the subnav is in the menu.
|
|
116
|
+
"[--app-header:calc(3.5rem+1px+env(safe-area-inset-top))]", subnav ? "md:[--app-header:calc(6.5rem+1px+env(safe-area-inset-top))]" : undefined,
|
|
117
|
+
// A link or focus that scrolls to any element with an id stops below the sticky header.
|
|
118
|
+
"[&_[id]]:scroll-mt-[calc(var(--app-header,0px)+1rem)]"), children: [_jsx(AppShellHeader, { brand: brand, nav: nav, controls: controls, menuControls: menuControls, subnav: subnav, menuLabel: menuLabel, hideChromeInPrint: hideChromeInPrint, children: header }), _jsx("main", { className: "flex flex-1 flex-col", children: bleed ? (children) : (_jsx(ContainerFrame, { className: cx("py-8", hideChromeInPrint && "print:p-0"), children: children })) }), footer && (_jsx("footer", { className: cx("border-t border-slate-200", hideChromeInPrint && "print:hidden"), children: _jsx(ContainerFrame, { className: "py-6 text-sm text-slate-500", children: footer }) }))] }) }));
|
|
119
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The header's phone menu (below `md`): a native `<details>` whose `<summary>` is the button, so it
|
|
4
|
+
* opens and closes by pointer, Enter and Space, and is announced as a disclosure with its expanded
|
|
5
|
+
* state, all with no script. That is why it also works on a page that is never hydrated. The panel
|
|
6
|
+
* is out of flow (it hangs under the header, `top-full`), so the header keeps its one height open
|
|
7
|
+
* or closed. With script it also closes on Escape (focus returns to the button) and when a link in
|
|
8
|
+
* it is followed, for a router that changes the page without a reload.
|
|
9
|
+
*
|
|
10
|
+
* `controls` (AppShell's `menuControls`) sit at the top of the panel, above the links. From `md`
|
|
11
|
+
* the `<details>` drops its own box and shows only them, inline at the row's end, whether it is
|
|
12
|
+
* open or not: the summary and the link copies are hidden (the links render in their own rows from
|
|
13
|
+
* `md`) and the panel is a plain row. They are rendered once, so a field keeps its state.
|
|
14
|
+
*
|
|
15
|
+
* `folded` (the nav did not fit the row from `md`) keeps the summary from `md` too, and its nav copy
|
|
16
|
+
* then hangs under the header as the panel does on a phone. The `subnav` copy stays phone only.
|
|
17
|
+
*/
|
|
18
|
+
export declare function AppShellMenu({ label, controls, nav, subnav, folded, }: {
|
|
19
|
+
label: string;
|
|
20
|
+
/** Rendered once: at the top of the panel below `md`, inline in the row from `md`. */
|
|
21
|
+
controls?: ReactNode;
|
|
22
|
+
nav: ReactNode;
|
|
23
|
+
subnav: ReactNode;
|
|
24
|
+
/** From `md` the nav is in the menu too: it did not fit the row. */
|
|
25
|
+
folded: boolean;
|
|
26
|
+
}): ReactElement;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { ContainerFrame } from "./Container.js";
|
|
4
|
+
import { cx, focusRing } from "./cx.js";
|
|
5
|
+
const ICON = {
|
|
6
|
+
viewBox: "0 0 20 20",
|
|
7
|
+
width: 16,
|
|
8
|
+
height: 16,
|
|
9
|
+
fill: "none",
|
|
10
|
+
stroke: "currentColor",
|
|
11
|
+
strokeWidth: 1.8,
|
|
12
|
+
strokeLinecap: "round",
|
|
13
|
+
strokeLinejoin: "round",
|
|
14
|
+
"aria-hidden": true,
|
|
15
|
+
className: "shrink-0 text-slate-500",
|
|
16
|
+
};
|
|
17
|
+
// A folded nav from `md`: the phone panel's dropdown, shown while the menu is open. The surface
|
|
18
|
+
// colours are unprefixed (below `md` the panel already draws them), so no palette utility takes a variant.
|
|
19
|
+
const FOLDED_NAV = "border-slate-200 bg-white md:absolute md:inset-x-0 md:top-full md:hidden md:max-h-[calc(100dvh-var(--app-header))] md:overflow-y-auto md:overscroll-contain md:border-y md:shadow-lg md:group-open:block";
|
|
20
|
+
/**
|
|
21
|
+
* The menu's copies of the links. From `md` the links render in their own rows, so these copies are
|
|
22
|
+
* hidden there, except a folded nav's, which hangs under the header while the menu is open.
|
|
23
|
+
*/
|
|
24
|
+
function MenuLinks({ nav, subnav, folded, }) {
|
|
25
|
+
return (_jsxs(_Fragment, { children: [nav && (_jsx("div", { className: folded ? FOLDED_NAV : "md:hidden", children: _jsx(ContainerFrame, { className: "flex flex-col gap-3 max-md:contents md:py-3", children: nav }) })), subnav && _jsx("div", { className: "flex flex-col gap-3 md:hidden", children: subnav })] }));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The header's phone menu (below `md`): a native `<details>` whose `<summary>` is the button, so it
|
|
29
|
+
* opens and closes by pointer, Enter and Space, and is announced as a disclosure with its expanded
|
|
30
|
+
* state, all with no script. That is why it also works on a page that is never hydrated. The panel
|
|
31
|
+
* is out of flow (it hangs under the header, `top-full`), so the header keeps its one height open
|
|
32
|
+
* or closed. With script it also closes on Escape (focus returns to the button) and when a link in
|
|
33
|
+
* it is followed, for a router that changes the page without a reload.
|
|
34
|
+
*
|
|
35
|
+
* `controls` (AppShell's `menuControls`) sit at the top of the panel, above the links. From `md`
|
|
36
|
+
* the `<details>` drops its own box and shows only them, inline at the row's end, whether it is
|
|
37
|
+
* open or not: the summary and the link copies are hidden (the links render in their own rows from
|
|
38
|
+
* `md`) and the panel is a plain row. They are rendered once, so a field keeps its state.
|
|
39
|
+
*
|
|
40
|
+
* `folded` (the nav did not fit the row from `md`) keeps the summary from `md` too, and its nav copy
|
|
41
|
+
* then hangs under the header as the panel does on a phone. The `subnav` copy stays phone only.
|
|
42
|
+
*/
|
|
43
|
+
export function AppShellMenu({ label, controls, nav, subnav, folded, }) {
|
|
44
|
+
const details = useRef(null);
|
|
45
|
+
const close = (focusButton) => {
|
|
46
|
+
const el = details.current;
|
|
47
|
+
if (!el?.open)
|
|
48
|
+
return;
|
|
49
|
+
el.open = false;
|
|
50
|
+
if (focusButton)
|
|
51
|
+
el.querySelector("summary")?.focus();
|
|
52
|
+
};
|
|
53
|
+
return (_jsxs("details", { ref: details, className: cx("group shrink-0", controls || folded
|
|
54
|
+
? "md:contents md:[&::details-content]:contents md:[&::details-content]:[content-visibility:visible]"
|
|
55
|
+
: "md:hidden"), onKeyDown: (event) => {
|
|
56
|
+
// A dialog opened from a control in the menu takes its own Escape; the menu stays open.
|
|
57
|
+
if (event.key === "Escape" &&
|
|
58
|
+
!(event.target instanceof Element && event.target.closest("dialog")))
|
|
59
|
+
close(true);
|
|
60
|
+
}, children: [_jsxs("summary", { className: cx("flex cursor-pointer list-none items-center gap-2 rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 select-none hover:bg-slate-50 [&::-webkit-details-marker]:hidden", focusRing, !folded && "md:hidden"), children: [_jsx("svg", { ...ICON, className: cx(ICON.className, "group-open:hidden"), children: _jsx("path", { d: "M3 5.5h14M3 10h14M3 14.5h14" }) }), _jsx("svg", { ...ICON, className: cx(ICON.className, "hidden group-open:block"), children: _jsx("path", { d: "M5 5l10 10M15 5L5 15" }) }), label] }), _jsx("div", {
|
|
61
|
+
// From `md` the panel draws no box (`contents`), so its dropdown look applies below `md` only.
|
|
62
|
+
className: "absolute inset-x-0 top-full max-h-[calc(100dvh-var(--app-header))] overflow-y-auto overscroll-contain border-y border-slate-200 bg-white shadow-lg md:contents", onClick: (event) => {
|
|
63
|
+
if (event.target instanceof Element && event.target.closest("a[href]"))
|
|
64
|
+
close(false);
|
|
65
|
+
}, children: _jsxs(ContainerFrame, { className: "flex flex-col gap-3 py-3 md:contents", children: [controls && (_jsx("div", { className: "flex flex-wrap items-center gap-2 md:flex-nowrap md:*:shrink-0 md:[&>.w-full]:w-auto", children: controls })), _jsx(MenuLinks, { nav: nav, subnav: subnav, folded: folded })] }) })] }));
|
|
66
|
+
}
|
package/dist/Avatar.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
|
+
declare const SIZE_CLASSES: {
|
|
5
|
+
readonly xs: "size-4 text-[0.5rem]";
|
|
6
|
+
readonly sm: "size-6 text-xs";
|
|
7
|
+
readonly md: "size-8 text-xs";
|
|
8
|
+
readonly lg: "size-10 text-base";
|
|
9
|
+
readonly xl: "size-14 text-xl";
|
|
10
|
+
readonly "2xl": "size-16 text-2xl";
|
|
11
|
+
readonly "3xl": "size-24 text-3xl";
|
|
12
|
+
};
|
|
13
|
+
/** An Avatar's size: `xs` 16px, `sm` 24px, `md` 32px, `lg` 40px, `xl` 56px, `2xl` 64px, `3xl` 96px. */
|
|
14
|
+
export type AvatarSize = keyof typeof SIZE_CLASSES;
|
|
15
|
+
/** `round` for a person, `square` (rounded corners that grow with the size) for an org or a team. */
|
|
16
|
+
export type AvatarShape = "round" | "square";
|
|
17
|
+
/** The corner classes for a shape at a size; `AvatarStack`'s "+N" chip uses the same. */
|
|
18
|
+
export declare function avatarShapeClass(shape: AvatarShape, size: AvatarSize): string;
|
|
19
|
+
/** The size classes of an Avatar, shared with `AvatarStack`'s "+N" chip. */
|
|
20
|
+
export declare function avatarSizeClass(size: AvatarSize): string;
|
|
21
|
+
/** The background class for a name: the same name gets the same colour everywhere. */
|
|
22
|
+
export declare function avatarColourClass(name: string): string;
|
|
23
|
+
/** Up to two letters or digits of a name, upper-cased; `?` when it has none. */
|
|
24
|
+
export declare function initialsOf(name: string): string;
|
|
25
|
+
type AvatarProps = {
|
|
26
|
+
/** Whose avatar: its initials, its colour (a hash of the name) and its title or `alt`. */
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* The person's photo, a local path. It replaces the initials and is announced as `name`. If it
|
|
30
|
+
* fails to load, the initials show instead.
|
|
31
|
+
*/
|
|
32
|
+
src?: string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* `xs` 16px, `sm` 24px, `md` 32px, `lg` 40px, `xl` 56px, `2xl` 64px or `3xl` 96px.
|
|
35
|
+
* @default md
|
|
36
|
+
*/
|
|
37
|
+
size?: AvatarSize;
|
|
38
|
+
/**
|
|
39
|
+
* `round` for a person; `square` (rounded corners) for an org or a team, so the two never read
|
|
40
|
+
* as each other.
|
|
41
|
+
* @default round
|
|
42
|
+
*/
|
|
43
|
+
shape?: AvatarShape;
|
|
44
|
+
} & LoadingProps & Passthrough & ({
|
|
45
|
+
onClick?: undefined;
|
|
46
|
+
href?: undefined;
|
|
47
|
+
external?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
/**
|
|
50
|
+
* Makes the Avatar one button, named by `name`: a person who opens their profile or a menu.
|
|
51
|
+
* Without it (or `href`) the Avatar is a plain mark.
|
|
52
|
+
*/
|
|
53
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
54
|
+
href?: undefined;
|
|
55
|
+
external?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
onClick?: undefined;
|
|
58
|
+
/** Makes the Avatar one link, named by `name`; an in-app path goes through `LinkProvider`. */
|
|
59
|
+
href: string;
|
|
60
|
+
/** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
|
|
61
|
+
external?: boolean | undefined;
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* A person as a round badge of initials, or as their photo when `src` is given; `shape="square"`
|
|
65
|
+
* marks an org or a team instead. It never loads a remote image on its own: that is a request to
|
|
66
|
+
* another server for decoration, and it makes a screenshot depend on the network. `src` is the
|
|
67
|
+
* app's own local path. With `onClick` the whole Avatar is one button, with `href` one link. A row of overlapping avatars
|
|
68
|
+
* is an `AvatarStack`. While `loading` with an empty `name` it is a bone of its size and shape.
|
|
69
|
+
*/
|
|
70
|
+
export declare function Avatar({ loading, loadingLabel, ...props }: AvatarProps): ReactElement;
|
|
71
|
+
/** Avatar plus the stack's ring: internal, so the ring only ever comes from `AvatarStack`. */
|
|
72
|
+
export declare function AvatarMark({ name, src, size, shape, ring, onClick, href, external, loading: _loading, loadingLabel: _loadingLabel, ...rest }: AvatarProps & {
|
|
73
|
+
ring?: string | false;
|
|
74
|
+
}): ReactElement;
|
|
75
|
+
export {};
|
package/dist/Avatar.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx, focusRing } from "./cx.js";
|
|
3
|
+
import { renderLink } from "./link.js";
|
|
4
|
+
import { passthroughOf, useLoading, WaitingBone } from "./skeleton.js";
|
|
5
|
+
import { useImageFailed } from "./useImageFailed.js";
|
|
6
|
+
/** The identity colours, in hash order. Each is a stock background utility; a theme remaps them. */
|
|
7
|
+
const COLOUR_CLASSES = [
|
|
8
|
+
"bg-violet-600",
|
|
9
|
+
"bg-orange-600",
|
|
10
|
+
"bg-cyan-600",
|
|
11
|
+
"bg-emerald-600",
|
|
12
|
+
"bg-sky-600",
|
|
13
|
+
"bg-pink-600",
|
|
14
|
+
"bg-amber-600",
|
|
15
|
+
];
|
|
16
|
+
const SIZE_CLASSES = {
|
|
17
|
+
xs: "size-4 text-[0.5rem]",
|
|
18
|
+
sm: "size-6 text-xs",
|
|
19
|
+
md: "size-8 text-xs",
|
|
20
|
+
lg: "size-10 text-base",
|
|
21
|
+
xl: "size-14 text-xl",
|
|
22
|
+
"2xl": "size-16 text-2xl",
|
|
23
|
+
"3xl": "size-24 text-3xl",
|
|
24
|
+
};
|
|
25
|
+
const SQUARE_CLASSES = {
|
|
26
|
+
xs: "rounded-sm",
|
|
27
|
+
sm: "rounded",
|
|
28
|
+
md: "rounded-md",
|
|
29
|
+
lg: "rounded-md",
|
|
30
|
+
xl: "rounded-lg",
|
|
31
|
+
"2xl": "rounded-lg",
|
|
32
|
+
"3xl": "rounded-xl",
|
|
33
|
+
};
|
|
34
|
+
/** The corner classes for a shape at a size; `AvatarStack`'s "+N" chip uses the same. */
|
|
35
|
+
export function avatarShapeClass(shape, size) {
|
|
36
|
+
return shape === "square" ? SQUARE_CLASSES[size] : "rounded-full";
|
|
37
|
+
}
|
|
38
|
+
/** The size classes of an Avatar, shared with `AvatarStack`'s "+N" chip. */
|
|
39
|
+
export function avatarSizeClass(size) {
|
|
40
|
+
return SIZE_CLASSES[size];
|
|
41
|
+
}
|
|
42
|
+
/** The background class for a name: the same name gets the same colour everywhere. */
|
|
43
|
+
export function avatarColourClass(name) {
|
|
44
|
+
let hash = 0;
|
|
45
|
+
for (const char of name)
|
|
46
|
+
hash = (hash * 31 + char.charCodeAt(0)) >>> 0;
|
|
47
|
+
return COLOUR_CLASSES[hash % COLOUR_CLASSES.length] ?? COLOUR_CLASSES[0];
|
|
48
|
+
}
|
|
49
|
+
/** Up to two letters or digits of a name, upper-cased; `?` when it has none. */
|
|
50
|
+
export function initialsOf(name) {
|
|
51
|
+
return (name
|
|
52
|
+
.replace(/[^a-z0-9]/gi, "")
|
|
53
|
+
.slice(0, 2)
|
|
54
|
+
.toUpperCase() || "?");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A person as a round badge of initials, or as their photo when `src` is given; `shape="square"`
|
|
58
|
+
* marks an org or a team instead. It never loads a remote image on its own: that is a request to
|
|
59
|
+
* another server for decoration, and it makes a screenshot depend on the network. `src` is the
|
|
60
|
+
* app's own local path. With `onClick` the whole Avatar is one button, with `href` one link. A row of overlapping avatars
|
|
61
|
+
* is an `AvatarStack`. While `loading` with an empty `name` it is a bone of its size and shape.
|
|
62
|
+
*/
|
|
63
|
+
export function Avatar({ loading, loadingLabel, ...props }) {
|
|
64
|
+
if (useLoading(loading).loading && props.name === "") {
|
|
65
|
+
const { size = "md", shape = "round" } = props;
|
|
66
|
+
return (_jsx(WaitingBone, { own: loading, label: loadingLabel, shape: cx("inline-block shrink-0", avatarShapeClass(shape, size), SIZE_CLASSES[size]), root: "inline-flex", attrs: passthroughOf(props) }));
|
|
67
|
+
}
|
|
68
|
+
return _jsx(AvatarMark, { ...props });
|
|
69
|
+
}
|
|
70
|
+
/** Avatar plus the stack's ring: internal, so the ring only ever comes from `AvatarStack`. */
|
|
71
|
+
export function AvatarMark({ name, src, size = "md", shape = "round", ring = false, onClick, href, external = false, loading: _loading, loadingLabel: _loadingLabel, ...rest }) {
|
|
72
|
+
const { ref, failed, markFailed } = useImageFailed(src);
|
|
73
|
+
const corners = avatarShapeClass(shape, size);
|
|
74
|
+
// As a button or a link, it takes the consumer's props and the mark inside keeps only its look.
|
|
75
|
+
const markProps = onClick || href !== undefined ? {} : rest;
|
|
76
|
+
const mark = src && !failed ? (_jsx("img", { ref: ref, src: src, alt: name, title: name, className: cx("shrink-0 object-cover", corners, SIZE_CLASSES[size], ring), onError: markFailed, ...markProps })) : (_jsx("span", { "aria-hidden": "true", title: name, className: cx("inline-grid shrink-0 place-items-center font-semibold text-violet-50", corners, SIZE_CLASSES[size], avatarColourClass(name), ring), ...markProps, children: initialsOf(name) }));
|
|
77
|
+
return framed({ name, href, external, onClick, rest, mark, corners });
|
|
78
|
+
}
|
|
79
|
+
/** The mark alone, or inside the one link or button the Avatar is, named by `name`. */
|
|
80
|
+
function framed({ name, href, external, onClick, rest, mark, corners, }) {
|
|
81
|
+
const frame = cx("inline-grid shrink-0", corners, focusRing);
|
|
82
|
+
if (href !== undefined) {
|
|
83
|
+
return renderLink({
|
|
84
|
+
"aria-label": name,
|
|
85
|
+
...rest,
|
|
86
|
+
href,
|
|
87
|
+
external,
|
|
88
|
+
className: frame,
|
|
89
|
+
children: mark,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!onClick)
|
|
93
|
+
return mark;
|
|
94
|
+
return (_jsx("button", { "aria-label": name, ...rest, type: "button", onClick: onClick, className: cx(frame, "cursor-pointer"), children: mark }));
|
|
95
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type AvatarShape, type AvatarSize } from "./Avatar.js";
|
|
3
|
+
import type { Passthrough } from "./props.js";
|
|
4
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
5
|
+
/** One member of an `AvatarStack`: the same `name` and optional local `src` an `Avatar` takes. */
|
|
6
|
+
export type AvatarStackPerson = {
|
|
7
|
+
name: string;
|
|
8
|
+
src?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Members as a row of overlapping avatars, each in a ring in the page colour that separates it from
|
|
12
|
+
* the next. With `max`, the first `max` show and a "+N" chip of the same size and shape stands for
|
|
13
|
+
* the rest. The row is one image to assistive tech, named by the people in it. While `loading`
|
|
14
|
+
* with no `items` yet it draws three avatar bones.
|
|
15
|
+
*/
|
|
16
|
+
export declare function AvatarStack({ items, max, size, shape, loading, loadingLabel, ...rest }: {
|
|
17
|
+
/** Who is in the stack, in order. Give each person's full name, as for `Avatar`. */
|
|
18
|
+
items: readonly AvatarStackPerson[];
|
|
19
|
+
/** How many avatars show before a "+N" chip takes the rest. Without it every person shows. */
|
|
20
|
+
max?: number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The size of every avatar and of the chip, as `Avatar`'s `size`.
|
|
23
|
+
* @default md
|
|
24
|
+
*/
|
|
25
|
+
size?: AvatarSize;
|
|
26
|
+
/**
|
|
27
|
+
* `square` for a stack of orgs or teams, as `Avatar`'s `shape`.
|
|
28
|
+
* @default round
|
|
29
|
+
*/
|
|
30
|
+
shape?: AvatarShape;
|
|
31
|
+
} & LoadingProps & Passthrough): ReactElement;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AvatarMark, avatarShapeClass, avatarSizeClass, } from "./Avatar.js";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
|
|
5
|
+
// Each avatar after the first overlaps the one before it by about a quarter of its width.
|
|
6
|
+
const OVERLAP = {
|
|
7
|
+
xs: "-ml-1",
|
|
8
|
+
sm: "-ml-1.5",
|
|
9
|
+
md: "-ml-2",
|
|
10
|
+
lg: "-ml-2.5",
|
|
11
|
+
xl: "-ml-3.5",
|
|
12
|
+
"2xl": "-ml-4",
|
|
13
|
+
"3xl": "-ml-6",
|
|
14
|
+
};
|
|
15
|
+
// The ring in the page colour that keeps two overlapping avatars apart.
|
|
16
|
+
const RING = "border-2 border-slate-50";
|
|
17
|
+
/**
|
|
18
|
+
* Members as a row of overlapping avatars, each in a ring in the page colour that separates it from
|
|
19
|
+
* the next. With `max`, the first `max` show and a "+N" chip of the same size and shape stands for
|
|
20
|
+
* the rest. The row is one image to assistive tech, named by the people in it. While `loading`
|
|
21
|
+
* with no `items` yet it draws three avatar bones.
|
|
22
|
+
*/
|
|
23
|
+
export function AvatarStack({ items, max, size = "md", shape = "round", loading, loadingLabel, ...rest }) {
|
|
24
|
+
const { loading: waiting, owner } = useLoading(loading);
|
|
25
|
+
if (waiting && items.length === 0) {
|
|
26
|
+
return (_jsxs("span", { ...rest, ...busy(owner, waiting), className: "inline-flex items-center", children: [[0, 1, 2].map((i) => (_jsx(Bone, { shape: cx("inline-block shrink-0", RING, avatarSizeClass(size), avatarShapeClass(shape, size), i > 0 && OVERLAP[size]) }, i))), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
27
|
+
}
|
|
28
|
+
const shown = max === undefined ? items : items.slice(0, Math.max(max, 0));
|
|
29
|
+
const hidden = items.slice(shown.length);
|
|
30
|
+
const overlap = OVERLAP[size];
|
|
31
|
+
const names = shown.map((person) => person.name);
|
|
32
|
+
const label = hidden.length > 0 ? `${names.join(", ")} and ${hidden.length} more` : names.join(", ");
|
|
33
|
+
return (_jsxs("span", { role: "img", "aria-label": label, className: "inline-flex items-center", ...rest, children: [shown.map((person, index) => (_jsx(AvatarMark, { name: person.name, src: person.src, size: size, shape: shape, ring: cx(RING, index > 0 && overlap) }, `${index}:${person.name}`))), hidden.length > 0 && (_jsxs("span", { "aria-hidden": "true", title: hidden.map((person) => person.name).join(", "), className: cx("inline-grid shrink-0 place-items-center bg-slate-100 font-semibold text-slate-700 tabular-nums", RING, avatarSizeClass(size), avatarShapeClass(shape, size), shown.length > 0 && overlap), children: ["+", hidden.length] }))] }));
|
|
34
|
+
}
|
package/dist/Badge.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
import { type LoadingProps } from "./skeleton.js";
|
|
4
|
+
/**
|
|
5
|
+
* A small red count, 10px, for sitting on an icon. An icon with a count is an `IconButton` with
|
|
6
|
+
* its `count`, which pins the Badge to its corner and puts the count in the button's name. A
|
|
7
|
+
* count above 99 reads `99+`. While `loading` it is
|
|
8
|
+
* a bone of its size: a count is a number, so 0 is a value and not a gap.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Badge({ count, corner, loading: ownLoading, loadingLabel, ...rest }: {
|
|
11
|
+
/** The number shown; above 99 it reads `99+`. */
|
|
12
|
+
count: number;
|
|
13
|
+
/** Pin it to the top corner at the end edge of its `relative` parent, over the icon. */
|
|
14
|
+
corner?: boolean;
|
|
15
|
+
} & LoadingProps & Passthrough): ReactElement;
|
package/dist/Badge.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
import { useLoading, WaitingBone } from "./skeleton.js";
|
|
4
|
+
/**
|
|
5
|
+
* A small red count, 10px, for sitting on an icon. An icon with a count is an `IconButton` with
|
|
6
|
+
* its `count`, which pins the Badge to its corner and puts the count in the button's name. A
|
|
7
|
+
* count above 99 reads `99+`. While `loading` it is
|
|
8
|
+
* a bone of its size: a count is a number, so 0 is a value and not a gap.
|
|
9
|
+
*/
|
|
10
|
+
export function Badge({ count, corner = false, loading: ownLoading, loadingLabel, ...rest }) {
|
|
11
|
+
if (useLoading(ownLoading).loading) {
|
|
12
|
+
return (_jsx(WaitingBone, { own: ownLoading, label: loadingLabel, attrs: rest, root: cx("inline-flex", corner && "absolute -end-1.5 -top-1.5"), shape: "inline-block h-4 w-5 rounded-full" }));
|
|
13
|
+
}
|
|
14
|
+
return (_jsx("span", { ...rest, className: cx("inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-red-600 px-1 text-[10px] font-semibold leading-none text-red-50", corner && "absolute -end-1.5 -top-1.5"), children: count > 99 ? "99+" : count }));
|
|
15
|
+
}
|