@slashsuite/ui-react 0.12.1 → 0.13.1
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/MIGRATING.md +386 -8
- package/README.md +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +4 -2
- package/dist/Button.js +9 -87
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +116 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/core/button.d.ts +33 -0
- package/dist/core/button.js +89 -0
- package/dist/core/control.d.ts +15 -0
- package/dist/core/control.js +14 -0
- package/dist/core/fixtures/button.d.ts +26 -0
- package/dist/core/fixtures/button.js +52 -0
- package/dist/core/fixtures/types.d.ts +13 -0
- package/dist/core/fixtures/types.js +10 -0
- package/dist/core/focus.d.ts +7 -0
- package/dist/core/focus.js +7 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/parity.d.ts +22 -0
- package/dist/core/parity.js +53 -0
- package/dist/core/themeNative.d.ts +62 -0
- package/dist/core/themeNative.js +290 -0
- package/dist/cx.d.ts +17 -5
- package/dist/cx.js +18 -5
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +17 -3
- package/dist/density.js +30 -19
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +9 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +77 -0
- package/dist/stateMachineDots.js +188 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +38 -0
- package/dist/useFlowLayout.js +122 -0
- package/package.json +5 -3
package/dist/Table.js
CHANGED
|
@@ -1,37 +1,64 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useContext } from "react";
|
|
2
|
+
import { useCallback, useContext, useState } from "react";
|
|
3
3
|
import { useInCard } from "./cardContext.js";
|
|
4
4
|
import { cx } from "./cx.js";
|
|
5
5
|
import { DensityProvider } from "./density.js";
|
|
6
6
|
import { hasNoChildren } from "./emptySlot.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { scrollStopProps, useScrollStop } from "./scrollStop.js";
|
|
8
|
+
import { columnCount, columnTitles, numericColumns, TableContext, withColumns, } from "./tableColumns.js";
|
|
9
|
+
import { rowClass, SectionContext, SELECTED, BODY_LINE, PAD, STACK, stackRole, } from "./tableRow.js";
|
|
9
10
|
export { TableCell, TableHeaderCell } from "./TableCells.js";
|
|
10
11
|
export { TableExpandCell } from "./TableExpandCell.js";
|
|
11
12
|
import { BoneRows, EmptyRow } from "./tableEmpty.js";
|
|
12
13
|
import { BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
|
|
13
14
|
/**
|
|
14
|
-
* A list of records in a rounded, bordered card
|
|
15
|
+
* A list of records in a rounded, bordered card. Compose it
|
|
15
16
|
* from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label`
|
|
16
17
|
* names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its
|
|
17
18
|
* own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A
|
|
18
19
|
* column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end
|
|
19
|
-
* alignment and tabular figures. `size` is the row padding, and the
|
|
20
|
-
* (`sm` by default)
|
|
20
|
+
* alignment and tabular figures. `size` is the row padding, and the buttons and pills in the rows follow it
|
|
21
|
+
* (`sm` by default); a field keeps its own `size`. Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
|
|
21
22
|
* body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the
|
|
22
|
-
* table keeps its role and its name.
|
|
23
|
+
* table keeps its role and its name. A table that fits its box keeps its head row in view (under
|
|
24
|
+
* the `AppShell` header) while the page scrolls past its rows; one wider than its box scrolls
|
|
25
|
+
* sideways instead, and takes a tab stop when nothing in it can take focus. `narrow="stack"` draws
|
|
26
|
+
* each row as a card on a screen narrower than `sm` (a phone), the cells as lines labelled by their column's
|
|
27
|
+
* title. A click on a sortable title has the table say the new sort aloud, in `sortedLabel`'s words.
|
|
23
28
|
*/
|
|
24
|
-
export function Table({ label, size = "sm", loading, loadingLabel, children, ...rest }) {
|
|
29
|
+
export function Table({ label, size = "sm", narrow = "scroll", sortedLabel = englishSorted, loading, loadingLabel, children, ...rest }) {
|
|
25
30
|
const plain = useInCard();
|
|
26
31
|
const { loading: waiting, owner } = useLoading(loading);
|
|
27
32
|
const numeric = numericColumns(children, TableHead, TableRow);
|
|
28
33
|
const columns = columnCount(children, TableHead, TableRow);
|
|
29
|
-
|
|
34
|
+
const stack = narrow === "stack";
|
|
35
|
+
const titles = stack ? columnTitles(children, TableHead, TableRow) : [];
|
|
36
|
+
const [said, setSaid] = useState("");
|
|
37
|
+
const announce = useCallback((column, sort) => setSaid(sortedLabel(column, sort)), [sortedLabel]);
|
|
38
|
+
const { attach, stop, measured, overflows } = useScrollStop("x", tableWider);
|
|
39
|
+
const { props: stopProps, ring } = scrollStopProps(stop, { label });
|
|
40
|
+
// Until measured (a page rendered on the server) and while too wide, the box scrolls sideways.
|
|
41
|
+
// Once it fits, it clips instead: a clipping box is no scroll container, so the head can stick.
|
|
42
|
+
const fits = measured && !overflows;
|
|
43
|
+
return (_jsx(TableContext.Provider, { value: { plain, size, numeric, columns, announce, stack, titles }, children: _jsx(DensityProvider, { size: size, children: _jsxs("div", { ref: attach, ...stopProps, className: cx(fits ? "overflow-clip" : "overflow-x-auto", ring, !plain && "rounded-xl border border-slate-200/70 bg-white shadow-sm"), children: [_jsxs("table", { ...rest, ...stackRole(stack, "table"), ...busy(owner, waiting), className: cx("w-full text-left text-sm", stack && STACK.table), children: [_jsx("caption", { className: "sr-only", children: label }), _jsx(LoadingScope, { loading: waiting, children: children })] }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel }), _jsx("div", { role: "status", className: "sr-only", children: said })] }) }) }));
|
|
30
44
|
}
|
|
31
|
-
/** The
|
|
45
|
+
/** The default `sortedLabel`. */
|
|
46
|
+
function englishSorted(column, sort) {
|
|
47
|
+
return `Sorted by ${column}, ${sort}`;
|
|
48
|
+
}
|
|
49
|
+
/** Whether the table is wider than its box: measured from the table, since a clipping box does not scroll. */
|
|
50
|
+
function tableWider(box) {
|
|
51
|
+
const table = box.querySelector(":scope > table");
|
|
52
|
+
return table instanceof HTMLElement && table.offsetWidth > box.clientWidth;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card.
|
|
56
|
+
* Holds one `TableRow` of `TableHeaderCell`s. Unless the table is in a card, it stays in view under
|
|
57
|
+
* the `AppShell` header while the page scrolls past the rows, as long as the table fits its box.
|
|
58
|
+
*/
|
|
32
59
|
export function TableHead({ children, ...rest }) {
|
|
33
|
-
const { plain } = useContext(TableContext);
|
|
34
|
-
return (_jsx("thead", { ...rest, className: cx("text-xs uppercase tracking-wide text-slate-500", !plain && "bg-slate-50"), children: _jsx(SectionContext.Provider, { value: "head", children: children }) }));
|
|
60
|
+
const { plain, stack } = useContext(TableContext);
|
|
61
|
+
return (_jsx("thead", { ...rest, ...stackRole(stack, "rowgroup"), className: cx("text-xs uppercase tracking-wide text-slate-500", !plain && "sticky top-[var(--app-header,0px)] z-1 bg-slate-50", stack && STACK.head), children: _jsx(SectionContext.Provider, { value: "head", children: children }) }));
|
|
35
62
|
}
|
|
36
63
|
/**
|
|
37
64
|
* The `<tbody>`: the rows, each with a line above it and, unless the table is in a card, a fill on
|
|
@@ -41,7 +68,8 @@ export function TableHead({ children, ...rest }) {
|
|
|
41
68
|
*/
|
|
42
69
|
export function TableBody({ empty, children, ...rest }) {
|
|
43
70
|
const waiting = useLoading(undefined).loading;
|
|
44
|
-
|
|
71
|
+
const { stack } = useContext(TableContext);
|
|
72
|
+
return (_jsx("tbody", { ...rest, ...stackRole(stack, "rowgroup"), className: stack ? STACK.section : undefined, children: _jsx(SectionContext.Provider, { value: "body", children: _jsx(BodyRows, { waiting: waiting, empty: empty, children: children }) }) }));
|
|
45
73
|
}
|
|
46
74
|
/** What a body holds: its rows; with none, bones while loading (loading beats empty), else `empty`. */
|
|
47
75
|
function BodyRows({ waiting, empty, children, }) {
|
|
@@ -57,7 +85,8 @@ function BodyRows({ waiting, empty, children, }) {
|
|
|
57
85
|
* no `tone`.
|
|
58
86
|
*/
|
|
59
87
|
export function TableFoot({ children, ...rest }) {
|
|
60
|
-
|
|
88
|
+
const { stack } = useContext(TableContext);
|
|
89
|
+
return (_jsx("tfoot", { ...rest, ...stackRole(stack, "rowgroup"), className: stack ? STACK.section : undefined, children: _jsx(SectionContext.Provider, { value: "foot", children: children }) }));
|
|
61
90
|
}
|
|
62
91
|
/**
|
|
63
92
|
* A `<tr>`, `relative`: the anchor a `TextLink stretch` (with `href`) stretches to. Any other link, button or
|
|
@@ -75,18 +104,19 @@ export function TableFoot({ children, ...rest }) {
|
|
|
75
104
|
*/
|
|
76
105
|
export function TableRow({ tone, stripe, emphasis = false, selected = false, children, ...rest }) {
|
|
77
106
|
const outer = useContext(SectionContext);
|
|
78
|
-
const { plain } = useContext(TableContext);
|
|
107
|
+
const { plain, stack } = useContext(TableContext);
|
|
79
108
|
const section = emphasis && outer === "body" ? "foot" : outer;
|
|
80
109
|
const current = selected && section === "body";
|
|
81
|
-
return (_jsx(SectionContext.Provider, { value: section, children: _jsx("tr", { ...rest, ...(current ? { "aria-current": true } : {}), className: current ? cx(BODY_LINE, SELECTED) : rowClass(section, plain, tone, stripe), children: withColumns(children) }) }));
|
|
110
|
+
return (_jsx(SectionContext.Provider, { value: section, children: _jsx("tr", { ...rest, ...stackRole(stack, "row"), ...(current ? { "aria-current": true } : {}), className: cx(current ? cx(BODY_LINE, SELECTED) : rowClass(section, plain, tone, stripe), stack && STACK.row), children: withColumns(children) }) }));
|
|
82
111
|
}
|
|
83
112
|
/**
|
|
84
113
|
* A full-width group header in the body: a tinted row with a `label` that spans every column the
|
|
85
|
-
* head declares (or `colSpan` columns), and optional `trailing`
|
|
86
|
-
* subtotal,
|
|
114
|
+
* head declares (or `colSpan` columns), and optional `trailing` text at the far end: the group's
|
|
115
|
+
* count or subtotal, muted. The group's rows follow it. The row is a `<th>`, a heading for the
|
|
116
|
+
* group, so an action on the group goes in its rows or above the table, not here. For a panel of other content across the
|
|
87
117
|
* whole row, use a `TableCell span="full"` instead.
|
|
88
118
|
*/
|
|
89
119
|
export function TableGroupRow({ label, trailing, colSpan, ...rest }) {
|
|
90
|
-
const { size, columns } = useContext(TableContext);
|
|
91
|
-
return (_jsx("tr", { ...rest, className: "relative border-t border-slate-200/70 bg-slate-50", children: _jsx("th", { scope: "rowgroup", colSpan: colSpan ?? columns, className: cx(PAD[size].group, "text-left text-sm"), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "font-medium text-slate-900", children: label }), trailing != null && trailing !== false && (_jsx("span", { className: "shrink-0 font-normal text-slate-500", children: trailing }))] }) }) }));
|
|
120
|
+
const { size, columns, stack } = useContext(TableContext);
|
|
121
|
+
return (_jsx("tr", { ...rest, ...stackRole(stack, "row"), className: cx("relative border-t border-slate-200/70 bg-slate-50", stack && STACK.section), children: _jsx("th", { scope: "rowgroup", ...stackRole(stack, "rowheader"), colSpan: colSpan ?? columns, className: cx(PAD[size].group, "text-left text-sm", stack && STACK.section), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "font-medium text-slate-900", children: label }), trailing != null && trailing !== false && (_jsx("span", { className: "shrink-0 font-normal text-slate-500", children: trailing }))] }) }) }));
|
|
92
122
|
}
|
package/dist/TableCells.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
-
import { type
|
|
2
|
+
import { type CellAlign, type Rest } from "./tableRow.js";
|
|
3
3
|
import { type SortProps } from "./tableSort.js";
|
|
4
4
|
import { type LoadingProps } from "./skeleton.js";
|
|
5
5
|
import type { Tone } from "./tone.js";
|
|
@@ -10,12 +10,15 @@ import type { Tone } from "./tone.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export type CellTone = "strong" | "muted" | Tone;
|
|
12
12
|
/**
|
|
13
|
-
* A column title, `<th scope="col">`. `numeric` declares a
|
|
14
|
-
* every cell under it take end alignment and tabular figures.
|
|
15
|
-
* head (a row's actions) takes `label` instead of `children`:
|
|
16
|
-
* ("Actions"), visually hidden so the head keeps its column. `sort`
|
|
17
|
-
* sortable: the title becomes a button that
|
|
18
|
-
* it stands with `aria-sort
|
|
13
|
+
* A header cell. In the `TableHead` it is a column title, `<th scope="col">`. `numeric` declares a
|
|
14
|
+
* column of figures, once: the title and every cell under it take end alignment and tabular figures.
|
|
15
|
+
* A column with nothing to show in its head (a row's actions) takes `label` instead of `children`:
|
|
16
|
+
* the name a screen reader hears ("Actions"), visually hidden so the head keeps its column. `sort`
|
|
17
|
+
* and `onSort` make the column sortable: the title becomes a button that fills the cell and asks for
|
|
18
|
+
* the next direction, the column says where it stands with `aria-sort`, and the table says the new
|
|
19
|
+
* sort aloud. The app sorts its rows; the table never does. In a body or foot row it is the row's
|
|
20
|
+
* header, `<th scope="row">`: the cell that names the row (a name, a date), drawn like a `strong`
|
|
21
|
+
* cell, so a screen reader reads it before each of the row's values.
|
|
19
22
|
*/
|
|
20
23
|
export declare function TableHeaderCell({ numeric, align, children, label, sort, onSort, ...rest }: {
|
|
21
24
|
/** A column of figures: this title and the cells under it are end aligned, the cells in tabular figures. */
|
|
@@ -24,7 +27,7 @@ export declare function TableHeaderCell({ numeric, align, children, label, sort,
|
|
|
24
27
|
* The title's horizontal alignment; `end` over a column of buttons, `center` over a centred column.
|
|
25
28
|
* @default end for a numeric column, else start
|
|
26
29
|
*/
|
|
27
|
-
align?:
|
|
30
|
+
align?: CellAlign | undefined;
|
|
28
31
|
} & ({
|
|
29
32
|
children?: ReactNode;
|
|
30
33
|
label?: undefined;
|
|
@@ -46,22 +49,22 @@ type Indent = 1 | 2 | 3;
|
|
|
46
49
|
* `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
|
|
47
50
|
* numeric already), `mono` a small mono face. `secondary` is a second,
|
|
48
51
|
* muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
|
|
49
|
-
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver)
|
|
50
|
-
*
|
|
51
|
-
* figure, a code, a type)
|
|
52
|
-
* an ellipsis on one line and
|
|
53
|
-
* numbers), since that is what the
|
|
52
|
+
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver); any
|
|
53
|
+
* other cell stays on one line at its content's width: one that holds a control or a link, and a
|
|
54
|
+
* `numeric` or `mono` cell (a figure, a code, a type). `lines={1}` caps a long value's width, cuts it with
|
|
55
|
+
* an ellipsis on one line and, while it is cut, shows the full text in a tooltip on hover, focus and a
|
|
56
|
+
* tap; the content is then plain text (strings and numbers), since that is what the tooltip shows. `colSpan` passes through: a cell that
|
|
54
57
|
* spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
|
|
55
58
|
* table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
|
|
56
59
|
* column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
|
|
57
60
|
* While `loading` an empty cell draws one bone, the width of a short value.
|
|
58
61
|
*/
|
|
59
|
-
export declare function TableCell({ span, colSpan, align, tone, numeric, mono,
|
|
62
|
+
export declare function TableCell({ span, colSpan, align, tone, numeric, mono, lines, indent, secondary, loading, loadingLabel, children, ...rest }: {
|
|
60
63
|
/**
|
|
61
64
|
* The cell's horizontal alignment; `center` for a full-width note.
|
|
62
65
|
* @default end for a numeric cell, else start
|
|
63
66
|
*/
|
|
64
|
-
align?:
|
|
67
|
+
align?: CellAlign | undefined;
|
|
65
68
|
/** Sets the cell in by this many levels (1 to 3), for a line under a parent row. Start-aligned cells only. */
|
|
66
69
|
indent?: Indent | undefined;
|
|
67
70
|
/** The text weight and colour (see `CellTone`). In a `TableFoot` it defaults to `strong`. */
|
|
@@ -74,14 +77,14 @@ export declare function TableCell({ span, colSpan, align, tone, numeric, mono, t
|
|
|
74
77
|
/** A small monospace face for a code or a type, and the cell never wraps. */
|
|
75
78
|
mono?: boolean | undefined;
|
|
76
79
|
/**
|
|
77
|
-
*
|
|
78
|
-
* Plain text content only.
|
|
80
|
+
* `1` caps the width and cuts a long value with an ellipsis on one line; while it is cut, the full
|
|
81
|
+
* text shows in a tooltip on hover, keyboard focus and a tap. Plain text content only.
|
|
79
82
|
*
|
|
80
|
-
* Without it, a prose cell wraps down to a floor so it never becomes a sliver,
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
+
* Without it, a prose cell wraps down to a floor so it never becomes a sliver, and any other cell
|
|
84
|
+
* (a `Pill`, a `Switch`, a `Button`, a `TextLink`, a `numeric` or `mono` value) stays on one line
|
|
85
|
+
* at its content's width.
|
|
83
86
|
*/
|
|
84
|
-
|
|
87
|
+
lines?: 1 | undefined;
|
|
85
88
|
/** A second, muted line under the content. */
|
|
86
89
|
secondary?: ReactNode;
|
|
87
90
|
children?: ReactNode;
|
package/dist/TableCells.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Children, useContext } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
|
-
import { TableContext, useNumericColumn } from "./tableColumns.js";
|
|
5
|
-
import { ALIGN, PAD, SectionContext } from "./tableRow.js";
|
|
4
|
+
import { TableContext, useNumericColumn, useStackLabel } from "./tableColumns.js";
|
|
5
|
+
import { ALIGN, PAD, SectionContext, STACK, stackRole, } from "./tableRow.js";
|
|
6
6
|
import { SortButton } from "./tableSort.js";
|
|
7
7
|
import { Bone, BusyLabel, busy, isEmptySlot, useLoading } from "./skeleton.js";
|
|
8
8
|
import { CELL_BONE } from "./tableEmpty.js";
|
|
9
|
+
import { Truncated } from "./truncated.js";
|
|
9
10
|
import { TEXT_TONE } from "./typography.js";
|
|
10
11
|
const TONE = {
|
|
11
12
|
strong: "font-medium text-slate-900",
|
|
@@ -17,30 +18,59 @@ function HeadTitle({ label, children }) {
|
|
|
17
18
|
return label === undefined ? children : _jsx("span", { className: "sr-only", children: label });
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
* A column title, `<th scope="col">`. `numeric` declares a
|
|
21
|
-
* every cell under it take end alignment and tabular figures.
|
|
22
|
-
* head (a row's actions) takes `label` instead of `children`:
|
|
23
|
-
* ("Actions"), visually hidden so the head keeps its column. `sort`
|
|
24
|
-
* sortable: the title becomes a button that
|
|
25
|
-
* it stands with `aria-sort
|
|
21
|
+
* A header cell. In the `TableHead` it is a column title, `<th scope="col">`. `numeric` declares a
|
|
22
|
+
* column of figures, once: the title and every cell under it take end alignment and tabular figures.
|
|
23
|
+
* A column with nothing to show in its head (a row's actions) takes `label` instead of `children`:
|
|
24
|
+
* the name a screen reader hears ("Actions"), visually hidden so the head keeps its column. `sort`
|
|
25
|
+
* and `onSort` make the column sortable: the title becomes a button that fills the cell and asks for
|
|
26
|
+
* the next direction, the column says where it stands with `aria-sort`, and the table says the new
|
|
27
|
+
* sort aloud. The app sorts its rows; the table never does. In a body or foot row it is the row's
|
|
28
|
+
* header, `<th scope="row">`: the cell that names the row (a name, a date), drawn like a `strong`
|
|
29
|
+
* cell, so a screen reader reads it before each of the row's values.
|
|
26
30
|
*/
|
|
27
31
|
export function TableHeaderCell({ numeric = false, align = numeric ? "end" : "start", children, label, sort, onSort, ...rest }) {
|
|
28
|
-
const { size } = useContext(TableContext);
|
|
29
|
-
const
|
|
30
|
-
|
|
32
|
+
const { size, stack } = useContext(TableContext);
|
|
33
|
+
const section = useContext(SectionContext);
|
|
34
|
+
const inHead = section !== "body" && section !== "foot";
|
|
35
|
+
const sortable = inHead && sort !== undefined && onSort !== undefined;
|
|
36
|
+
if (!inHead) {
|
|
37
|
+
return (_jsx(RowHeader, { ...rest, align: align, label: label, children: children }));
|
|
38
|
+
}
|
|
39
|
+
return (_jsx("th", { ...rest, scope: "col", ...stackRole(stack, "columnheader"), ...ariaSort(sort), className: cx("whitespace-nowrap font-medium", !sortable && PAD[size].head, ALIGN[align]), children: sortable ? (_jsx(SortButton, { sort: sort, onSort: onSort, align: align, pad: PAD[size].head, children: children })) : (_jsx(HeadTitle, { label: label, children: children })) }));
|
|
40
|
+
}
|
|
41
|
+
/** A sorted column's `aria-sort`; a column sorted by another one says nothing. */
|
|
42
|
+
function ariaSort(sort) {
|
|
43
|
+
return sort === "ascending" || sort === "descending" ? { "aria-sort": sort } : {};
|
|
44
|
+
}
|
|
45
|
+
/** A body or foot row's header cell, `<th scope="row">`, drawn like a `strong` cell. */
|
|
46
|
+
function RowHeader({ align, label, children, ...rest }) {
|
|
47
|
+
const { size, stack } = useContext(TableContext);
|
|
48
|
+
const stackLabel = useStackLabel(false);
|
|
49
|
+
return (_jsx("th", { ...rest, scope: "row", ...stackRole(stack, "rowheader"), className: cx(PAD[size].cell, ALIGN[align], TONE.strong, figureClass(false, false, isProse(children)), stackClass(stack, stackLabel)), children: _jsx(Stacked, { label: stackLabel, children: _jsx(HeadTitle, { label: label, children: children }) }) }));
|
|
50
|
+
}
|
|
51
|
+
/** A stacking table's cell: a labelled line, or a block when it has no column title. */
|
|
52
|
+
function stackClass(stack, label) {
|
|
53
|
+
return stack && (label === undefined ? STACK.block : STACK.cell);
|
|
54
|
+
}
|
|
55
|
+
/** Whether a cell spans more than one column (it then takes no column title when stacked). */
|
|
56
|
+
function spansColumns(span, colSpan) {
|
|
57
|
+
return span === "full" || (colSpan !== undefined && colSpan > 1);
|
|
31
58
|
}
|
|
32
59
|
/**
|
|
33
|
-
* The wrapping rule:
|
|
34
|
-
*
|
|
60
|
+
* The wrapping rule, one for every cell: prose (plain text and nothing else) wraps, down to
|
|
61
|
+
* `min-w-48`; everything else stays on one line at its content's width: a figure, a code, and a cell
|
|
62
|
+
* that holds an element (a link, a `Pill`, a `Switch`, a `Button`). So a column of short controls is
|
|
63
|
+
* only as wide as they are, and a link's words never break one per line on a phone: the table
|
|
64
|
+
* scrolls instead.
|
|
35
65
|
*/
|
|
36
66
|
function figureClass(numeric, mono, prose) {
|
|
37
67
|
if (!numeric && !mono)
|
|
38
|
-
return prose ? "min-w-48" : "";
|
|
68
|
+
return prose ? "min-w-48" : "whitespace-nowrap";
|
|
39
69
|
return cx("whitespace-nowrap", numeric && "tabular-nums", mono && "font-mono text-xs");
|
|
40
70
|
}
|
|
41
|
-
/** The widest a `
|
|
71
|
+
/** The widest a `lines={1}` cell grows. */
|
|
42
72
|
const TRUNCATE_WIDTH = "max-w-xs";
|
|
43
|
-
/** Where a `
|
|
73
|
+
/** Where a `lines={1}` cell's capped box sits, so it follows the cell's alignment. */
|
|
44
74
|
const TRUNCATE_ALIGN = {
|
|
45
75
|
start: undefined,
|
|
46
76
|
center: "mx-auto",
|
|
@@ -56,25 +86,26 @@ const INDENT = {
|
|
|
56
86
|
* `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
|
|
57
87
|
* numeric already), `mono` a small mono face. `secondary` is a second,
|
|
58
88
|
* muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
|
|
59
|
-
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver)
|
|
60
|
-
*
|
|
61
|
-
* figure, a code, a type)
|
|
62
|
-
* an ellipsis on one line and
|
|
63
|
-
* numbers), since that is what the
|
|
89
|
+
* lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver); any
|
|
90
|
+
* other cell stays on one line at its content's width: one that holds a control or a link, and a
|
|
91
|
+
* `numeric` or `mono` cell (a figure, a code, a type). `lines={1}` caps a long value's width, cuts it with
|
|
92
|
+
* an ellipsis on one line and, while it is cut, shows the full text in a tooltip on hover, focus and a
|
|
93
|
+
* tap; the content is then plain text (strings and numbers), since that is what the tooltip shows. `colSpan` passes through: a cell that
|
|
64
94
|
* spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
|
|
65
95
|
* table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
|
|
66
96
|
* column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
|
|
67
97
|
* While `loading` an empty cell draws one bone, the width of a short value.
|
|
68
98
|
*/
|
|
69
|
-
export function TableCell({ span, colSpan, align, tone, numeric, mono = false,
|
|
99
|
+
export function TableCell({ span, colSpan, align, tone, numeric, mono = false, lines, indent, secondary, loading, loadingLabel, children, ...rest }) {
|
|
70
100
|
const { loading: waiting, owner } = useLoading(loading);
|
|
71
101
|
const bone = waiting && isEmptySlot(children);
|
|
72
102
|
const foot = useContext(SectionContext) === "foot";
|
|
73
|
-
const { size, columns } = useContext(TableContext);
|
|
103
|
+
const { size, columns, stack } = useContext(TableContext);
|
|
104
|
+
const stackLabel = useStackLabel(spansColumns(span, colSpan));
|
|
74
105
|
const column = useNumericColumn();
|
|
75
106
|
const figure = numeric ?? column;
|
|
76
107
|
const side = align ?? (figure ? "end" : "start");
|
|
77
|
-
return (_jsxs("td", { ...rest, ...busy(owner, waiting), colSpan: span === "full" ? columns : colSpan, className: cellClass({
|
|
108
|
+
return (_jsxs("td", { ...rest, ...stackRole(stack, "cell"), ...busy(owner, waiting), colSpan: span === "full" ? columns : colSpan, className: cx(cellClass({
|
|
78
109
|
align: side,
|
|
79
110
|
size,
|
|
80
111
|
indent,
|
|
@@ -83,22 +114,32 @@ export function TableCell({ span, colSpan, align, tone, numeric, mono = false, t
|
|
|
83
114
|
numeric: figure,
|
|
84
115
|
mono,
|
|
85
116
|
prose: isProse(children),
|
|
86
|
-
}), children: [_jsx(CellBody, { align: side, truncate:
|
|
117
|
+
}), stackClass(stack, stackLabel)), children: [_jsx(Stacked, { label: stackLabel, children: _jsx(CellBody, { align: side, truncate: lines === 1, secondary: secondary, children: bone ? _jsx(Bone, { shape: CELL_BONE }) : children }) }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
|
|
87
118
|
}
|
|
88
119
|
/** The classes of a cell: the tone (`strong` by default in a foot, and a foot's cells are medium whatever the tone), then the wrapping rule. */
|
|
89
120
|
function cellClass({ align, size, indent, tone, foot, numeric, mono, prose, }) {
|
|
90
121
|
const resolved = tone ?? (foot ? "strong" : "neutral");
|
|
91
122
|
return cx(PAD[size].cell, align === "start" && indent !== undefined && INDENT[size][indent], ALIGN[align], TONE[resolved], foot && resolved !== "strong" && "font-medium", figureClass(numeric, mono, prose));
|
|
92
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* A cell's content in a stacking table: its column's title (hidden from assistive tech, which has
|
|
126
|
+
* the head) at the start of the line, shown only while stacked, and the value at the end. Outside
|
|
127
|
+
* a stacking table, or with no title, the content as it is.
|
|
128
|
+
*/
|
|
129
|
+
function Stacked({ label, children }) {
|
|
130
|
+
if (label === undefined || label === null)
|
|
131
|
+
return children;
|
|
132
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", className: STACK.label, children: label }), _jsx("div", { className: STACK.value, children: children })] }));
|
|
133
|
+
}
|
|
93
134
|
const isText = (node) => typeof node === "string" || typeof node === "number";
|
|
94
135
|
/** Prose: at least one part, every one text. An empty cell (a bone) is not prose and keeps no width. */
|
|
95
136
|
function isProse(children) {
|
|
96
137
|
const parts = Children.toArray(children);
|
|
97
138
|
return parts.length > 0 && parts.every(isText);
|
|
98
139
|
}
|
|
99
|
-
/** What a cell holds: the content, cut to one line
|
|
140
|
+
/** What a cell holds: the content, cut to one line when `truncate` (its full text in a tooltip while cut), then the `secondary` line. */
|
|
100
141
|
function CellBody({ align, truncate, secondary, children, }) {
|
|
101
142
|
const parts = Children.toArray(children);
|
|
102
143
|
const text = parts.every(isText) ? parts.join("") : undefined;
|
|
103
|
-
return (_jsxs(_Fragment, { children: [truncate ? (_jsx(
|
|
144
|
+
return (_jsxs(_Fragment, { children: [truncate ? (_jsx(Truncated, { text: text, className: cx(TRUNCATE_WIDTH, TRUNCATE_ALIGN[align]), children: children })) : (children), secondary != null && secondary !== false && (_jsx("div", { className: "text-xs font-normal text-slate-500", children: secondary }))] }));
|
|
104
145
|
}
|
package/dist/TableEditCell.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentProps, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { TableCell } from "./Table.js";
|
|
3
3
|
/** `TableCell`'s props without its content, kept a union so `span` and `colSpan` stay apart. */
|
|
4
|
-
type CellProps = ComponentProps<typeof TableCell> extends infer Props ? Props extends unknown ? Omit<Props, "children" | "
|
|
4
|
+
type CellProps = ComponentProps<typeof TableCell> extends infer Props ? Props extends unknown ? Omit<Props, "children" | "lines"> : never : never;
|
|
5
5
|
/**
|
|
6
6
|
* A `TableCell` whose value opens an editor in place: a cell that holds one `InlineEdit` and
|
|
7
7
|
* nothing else. It shows `children` as a button with a dotted underline; a click, Enter or Space
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Passthrough } from "./props.js";
|
|
3
|
+
/** One entry of a `TableOfContents`: the heading's `id` (its anchor), its words, and its level. */
|
|
4
|
+
export type TableOfContentsItem = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
level: 2 | 3;
|
|
8
|
+
};
|
|
9
|
+
/** The list of entries, each linking to its heading, the current one marked. Shared with `DocsLayout`'s own. Internal. */
|
|
10
|
+
export declare function ContentsList({ items, current, }: {
|
|
11
|
+
items: TableOfContentsItem[];
|
|
12
|
+
current: string | undefined;
|
|
13
|
+
}): ReactElement;
|
|
14
|
+
/**
|
|
15
|
+
* The headings of a long page, as links to their anchors: "On this page". `items` are the page's
|
|
16
|
+
* `h2`s and `h3`s in order, each `{ id, label, level }`; a level 3 entry is indented under the one
|
|
17
|
+
* before it. `current` is the id of the section being read, which the app tracks (from the scroll
|
|
18
|
+
* position or the URL hash): its link is marked in the accent and has `aria-current="location"`.
|
|
19
|
+
* The rest are small and quiet. `label` names the list and the `<nav>` landmark.
|
|
20
|
+
*
|
|
21
|
+
* It sets no width or position: put it in a `SideColumn`'s aside, sticky, beside the page.
|
|
22
|
+
* `DocsLayout` draws its own.
|
|
23
|
+
*/
|
|
24
|
+
export declare function TableOfContents({ items, current, label, ...rest }: {
|
|
25
|
+
/** The page's headings in order: `{ id, label, level }`, `level` 2 or 3. */
|
|
26
|
+
items: TableOfContentsItem[];
|
|
27
|
+
/** The id of the section being read; its link is marked as the current one. */
|
|
28
|
+
current?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The words over the list, and the name of the `<nav>` landmark.
|
|
31
|
+
* @default "On this page"
|
|
32
|
+
*/
|
|
33
|
+
label?: string | undefined;
|
|
34
|
+
} & Passthrough): ReactElement;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx, focusRing } from "./cx.js";
|
|
3
|
+
import { Overline } from "./typography.js";
|
|
4
|
+
const ENTRY = `rounded text-sm/6 transition ${focusRing}`;
|
|
5
|
+
const ENTRY_ON = "font-medium text-violet-700";
|
|
6
|
+
const ENTRY_OFF = "text-slate-600 hover:text-violet-700";
|
|
7
|
+
/** The list of entries, each linking to its heading, the current one marked. Shared with `DocsLayout`'s own. Internal. */
|
|
8
|
+
export function ContentsList({ items, current, }) {
|
|
9
|
+
return (_jsx("ul", { role: "list", className: "flex list-none flex-col gap-1", children: items.map((item) => (_jsx("li", { className: item.level === 3 ? "ps-3" : undefined, children: _jsx("a", { href: `#${item.id}`, "aria-current": item.id === current ? "location" : undefined, className: cx(ENTRY, item.id === current ? ENTRY_ON : ENTRY_OFF), children: item.label }) }, item.id))) }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The headings of a long page, as links to their anchors: "On this page". `items` are the page's
|
|
13
|
+
* `h2`s and `h3`s in order, each `{ id, label, level }`; a level 3 entry is indented under the one
|
|
14
|
+
* before it. `current` is the id of the section being read, which the app tracks (from the scroll
|
|
15
|
+
* position or the URL hash): its link is marked in the accent and has `aria-current="location"`.
|
|
16
|
+
* The rest are small and quiet. `label` names the list and the `<nav>` landmark.
|
|
17
|
+
*
|
|
18
|
+
* It sets no width or position: put it in a `SideColumn`'s aside, sticky, beside the page.
|
|
19
|
+
* `DocsLayout` draws its own.
|
|
20
|
+
*/
|
|
21
|
+
export function TableOfContents({ items, current, label = "On this page", ...rest }) {
|
|
22
|
+
return (_jsxs("nav", { ...rest, "aria-label": label, children: [_jsx("div", { className: "pb-2", children: _jsx(Overline, { children: label }) }), _jsx(ContentsList, { items: items, current: current })] }));
|
|
23
|
+
}
|
package/dist/Tabs.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { type TypeStep } from "./density.js";
|
|
3
3
|
import type { Size } from "./size.js";
|
|
4
|
-
import { type
|
|
4
|
+
import { type SwitchButton, type SwitchLink, type SwitchProps } from "./switcher.js";
|
|
5
|
+
/** A button tab; its `panel` is the view it shows, rendered by Tabs under (or beside) the row. */
|
|
6
|
+
export type TabButton = SwitchButton & {
|
|
7
|
+
/**
|
|
8
|
+
* The view this tab shows. Tabs renders it as the tab's `tabpanel`, labelled by the tab, and
|
|
9
|
+
* hides it while another tab is current; the browser's find in page still reaches a hidden one
|
|
10
|
+
* and switches to its tab.
|
|
11
|
+
*/
|
|
12
|
+
panel?: ReactNode;
|
|
13
|
+
};
|
|
5
14
|
/** One tab of a Tabs row: a button with a `value`, or a link with an `href`; never both kinds in one row. */
|
|
6
|
-
export type Tab =
|
|
7
|
-
/**
|
|
15
|
+
export type Tab = TabButton | SwitchLink;
|
|
16
|
+
/**
|
|
17
|
+
* The classes of one pill tab at the type `step` in force. Every pill is `font-medium`, so the
|
|
18
|
+
* current one is no wider than it was; it has a fill and an outline. A `disabled` one drops the
|
|
19
|
+
* hover fill.
|
|
20
|
+
*/
|
|
8
21
|
export declare function pillTabClass(active: boolean, disabled?: boolean, size?: Size, step?: TypeStep): string;
|
|
9
|
-
export type TabsProps = SwitchProps & ({
|
|
22
|
+
export type TabsProps = SwitchProps<TabButton> & ({
|
|
10
23
|
/**
|
|
11
|
-
* `horizontal` is a row of underline tabs over a bottom rule
|
|
12
|
-
*
|
|
13
|
-
* between button tabs.
|
|
24
|
+
* `horizontal` is a row of underline tabs over a bottom rule, one line that scrolls
|
|
25
|
+
* sideways when it is too wide; `vertical` is the pill rail, a column at the rail's width
|
|
26
|
+
* for a `SidebarLayout` aside, where the up and down arrows move between button tabs.
|
|
14
27
|
* @default horizontal
|
|
15
28
|
*/
|
|
16
29
|
orientation?: "horizontal";
|
|
@@ -26,13 +39,15 @@ export type TabsProps = SwitchProps & ({
|
|
|
26
39
|
});
|
|
27
40
|
/**
|
|
28
41
|
* Tabs for switching a view in place or between pages. Across (the default) they are underline
|
|
29
|
-
* tabs:
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `
|
|
35
|
-
*
|
|
36
|
-
*
|
|
42
|
+
* tabs: one line over a bottom rule, the current tab underlined in the accent, scrolling sideways
|
|
43
|
+
* with a fade when the row is too wide. `orientation="vertical"` is the pill rail instead, the
|
|
44
|
+
* current tab filled and outlined, for a `SidebarLayout` aside, and takes a `size`. `items` are
|
|
45
|
+
* `{ value, label, panel }` buttons (`value` and `onChange` are the caller's state; the arrow
|
|
46
|
+
* keys, Home and End move between tabs) or links (`href`, an in-app one through `LinkProvider`;
|
|
47
|
+
* `selected` on an item, or `value`, marks the current one, which gets `aria-current`). A button's
|
|
48
|
+
* `panel` is rendered as its `tabpanel`, wired to the tab and hidden while another is current. An
|
|
49
|
+
* item may carry a `count`, and a button one `disabledReason` (it stays reachable by the arrows and
|
|
50
|
+
* its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label`
|
|
51
|
+
* names the tab list.
|
|
37
52
|
*/
|
|
38
53
|
export declare function Tabs({ size, orientation, ...props }: TabsProps): ReactElement;
|