@slashsuite/ui-react 0.12.0 → 0.13.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/MIGRATING.md +386 -8
- package/README.md +101 -44
- package/agent-docs/components/app-shell.md +139 -0
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/avatar-stack.md +64 -0
- package/agent-docs/components/avatar.md +76 -0
- package/agent-docs/components/badge.md +62 -0
- package/agent-docs/components/body-text.md +169 -0
- package/agent-docs/components/bottom-sheet.md +105 -0
- package/agent-docs/components/breadcrumbs.md +66 -0
- package/agent-docs/components/bullet-list.md +54 -0
- package/agent-docs/components/button.md +135 -0
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +87 -0
- package/agent-docs/components/card-grid.md +116 -0
- package/agent-docs/components/card.md +128 -0
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/centered-layout.md +90 -0
- package/agent-docs/components/chat-composer.md +49 -0
- package/agent-docs/components/chat-message.md +61 -0
- package/agent-docs/components/chat-thread.md +49 -0
- package/agent-docs/components/checkbox.md +81 -0
- package/agent-docs/components/cluster.md +108 -0
- package/agent-docs/components/code-example.md +48 -0
- package/agent-docs/components/code.md +72 -0
- package/agent-docs/components/colour-scheme-toggle.md +98 -0
- 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 +51 -0
- package/agent-docs/components/copy-button.md +63 -0
- package/agent-docs/components/copy-line.md +55 -0
- package/agent-docs/components/date-field.md +106 -0
- package/agent-docs/components/date-range-picker.md +108 -0
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/detail-layout.md +147 -0
- package/agent-docs/components/dialog.md +132 -0
- package/agent-docs/components/disclosure.md +70 -0
- package/agent-docs/components/divider.md +62 -0
- package/agent-docs/components/docs-layout.md +164 -0
- package/agent-docs/components/drawer.md +137 -0
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +70 -0
- package/agent-docs/components/field-dialog.md +98 -0
- package/agent-docs/components/field.md +71 -0
- package/agent-docs/components/fieldset.md +82 -0
- package/agent-docs/components/file-drop.md +52 -0
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +144 -0
- package/agent-docs/components/form-row.md +93 -0
- package/agent-docs/components/full-bleed-layout.md +114 -0
- package/agent-docs/components/headings.md +107 -0
- package/agent-docs/components/hero.md +68 -0
- package/agent-docs/components/icon-button.md +90 -0
- package/agent-docs/components/icon.md +59 -0
- package/agent-docs/components/image.md +74 -0
- package/agent-docs/components/input.md +84 -0
- package/agent-docs/components/kbd.md +38 -0
- package/agent-docs/components/key-value-list.md +84 -0
- package/agent-docs/components/lightbox.md +97 -0
- package/agent-docs/components/list-layout.md +152 -0
- package/agent-docs/components/list-row.md +119 -0
- package/agent-docs/components/loading.md +69 -0
- package/agent-docs/components/markdown.md +51 -0
- package/agent-docs/components/media-tile.md +101 -0
- package/agent-docs/components/menu.md +110 -0
- package/agent-docs/components/meta-list.md +69 -0
- package/agent-docs/components/morph.md +134 -0
- package/agent-docs/components/navigation-progress.md +56 -0
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +74 -0
- package/agent-docs/components/page-fade.md +117 -0
- package/agent-docs/components/page-header.md +93 -0
- package/agent-docs/components/pagination.md +64 -0
- package/agent-docs/components/pill.md +105 -0
- 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/progress-bar.md +66 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +87 -0
- package/agent-docs/components/prose.md +41 -0
- package/agent-docs/components/radio-group.md +77 -0
- package/agent-docs/components/scroll-strip.md +48 -0
- package/agent-docs/components/segmented-control.md +135 -0
- package/agent-docs/components/select.md +70 -0
- package/agent-docs/components/show.md +120 -0
- package/agent-docs/components/side-column.md +74 -0
- package/agent-docs/components/sidebar-layout.md +134 -0
- package/agent-docs/components/site-footer.md +63 -0
- package/agent-docs/components/site-search.md +79 -0
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +112 -0
- package/agent-docs/components/split-bar.md +54 -0
- package/agent-docs/components/stack.md +197 -0
- package/agent-docs/components/stacked-bar.md +91 -0
- package/agent-docs/components/stat-tile.md +69 -0
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +112 -0
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/steps.md +74 -0
- package/agent-docs/components/sticky-bar.md +51 -0
- package/agent-docs/components/switch.md +79 -0
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +384 -0
- package/agent-docs/components/tabs.md +178 -0
- package/agent-docs/components/text-link.md +110 -0
- package/agent-docs/components/textarea.md +53 -0
- package/agent-docs/components/timeline.md +79 -0
- package/agent-docs/components/toast.md +91 -0
- package/agent-docs/components/trend-chart.md +61 -0
- package/agent-docs/components/video.md +49 -0
- package/agent-docs/llms.txt +174 -0
- 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 +1 -0
- package/dist/Button.js +4 -3
- 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 +113 -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/cx.d.ts +22 -3
- package/dist/cx.js +22 -3
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +15 -1
- package/dist/density.js +27 -8
- 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/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 +45 -0
- package/dist/stateMachineDots.js +162 -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 +27 -0
- package/dist/useFlowLayout.js +119 -0
- package/package.json +7 -3
- package/skills/uislash/SKILL.md +20 -0
package/dist/tableColumns.js
CHANGED
|
@@ -4,6 +4,9 @@ export const TableContext = createContext({
|
|
|
4
4
|
size: "sm",
|
|
5
5
|
numeric: [],
|
|
6
6
|
columns: undefined,
|
|
7
|
+
announce: () => undefined,
|
|
8
|
+
stack: false,
|
|
9
|
+
titles: [],
|
|
7
10
|
});
|
|
8
11
|
/** The column a cell starts at, set by its `TableRow`. */
|
|
9
12
|
const ColumnContext = createContext(undefined);
|
|
@@ -27,14 +30,28 @@ function first(children, type) {
|
|
|
27
30
|
* own component is not seen; its body cells then say `numeric` themselves.
|
|
28
31
|
*/
|
|
29
32
|
export function numericColumns(children, head, row) {
|
|
33
|
+
return headCells(children, head, row).flatMap((cell) => isValidElement(cell)
|
|
34
|
+
? Array.from({ length: span(cell.props) }, () => cell.props.numeric === true)
|
|
35
|
+
: []);
|
|
36
|
+
}
|
|
37
|
+
/** The cells of the table's first head row, read from their element props, or none. */
|
|
38
|
+
function headCells(children, head, row) {
|
|
30
39
|
const headElement = first(children, head);
|
|
31
40
|
if (!isValidElement(headElement))
|
|
32
41
|
return [];
|
|
33
42
|
const rowElement = first(headElement.props.children, row);
|
|
34
43
|
if (!isValidElement(rowElement))
|
|
35
44
|
return [];
|
|
36
|
-
return flat(rowElement.props.children)
|
|
37
|
-
|
|
45
|
+
return flat(rowElement.props.children);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Each column's visible title, read from the first head row like `numericColumns`: the head cell's
|
|
49
|
+
* children, or `undefined` for a column whose title is a hidden `label` (a row's actions) and for
|
|
50
|
+
* the later columns a spanning title covers.
|
|
51
|
+
*/
|
|
52
|
+
export function columnTitles(children, head, row) {
|
|
53
|
+
return headCells(children, head, row).flatMap((cell) => isValidElement(cell)
|
|
54
|
+
? Array.from({ length: span(cell.props) }, (_, i) => i === 0 && cell.props.label === undefined ? cell.props.children : undefined)
|
|
38
55
|
: []);
|
|
39
56
|
}
|
|
40
57
|
/**
|
|
@@ -70,3 +87,14 @@ export function useNumericColumn() {
|
|
|
70
87
|
const { numeric } = useContext(TableContext);
|
|
71
88
|
return at !== undefined && numeric[at] === true;
|
|
72
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* A stacked cell's label: its column's title from the head. None for the first column (the card's
|
|
92
|
+
* title), for a cell that spans columns, and outside a stacking table.
|
|
93
|
+
*/
|
|
94
|
+
export function useStackLabel(spans) {
|
|
95
|
+
const at = useContext(ColumnContext);
|
|
96
|
+
const { stack, titles } = useContext(TableContext);
|
|
97
|
+
if (!stack || spans || at === undefined || at === 0)
|
|
98
|
+
return undefined;
|
|
99
|
+
return titles[at];
|
|
100
|
+
}
|
package/dist/tableEmpty.js
CHANGED
|
@@ -3,15 +3,15 @@ import { useContext } from "react";
|
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { EmptySlot } from "./emptySlot.js";
|
|
5
5
|
import { TableContext } from "./tableColumns.js";
|
|
6
|
-
import { BODY_LINE, PAD } from "./tableRow.js";
|
|
6
|
+
import { BODY_LINE, PAD, STACK, stackRole } from "./tableRow.js";
|
|
7
7
|
import { Bone } from "./skeleton.js";
|
|
8
8
|
/**
|
|
9
9
|
* A table body's one row when it has no rows: a cell across every column the head declares, holding
|
|
10
10
|
* `empty` at the slot's small size. Internal to `TableBody`.
|
|
11
11
|
*/
|
|
12
12
|
export function EmptyRow({ children }) {
|
|
13
|
-
const { columns, size } = useContext(TableContext);
|
|
14
|
-
return (_jsx("tr", { className: BODY_LINE, children: _jsx("td", { colSpan: columns ?? 1, className: cx(PAD[size].cell, "text-center"), children: _jsx(EmptySlot, { size: "sm", children: children }) }) }));
|
|
13
|
+
const { columns, size, stack } = useContext(TableContext);
|
|
14
|
+
return (_jsx("tr", { ...stackRole(stack, "row"), className: cx(BODY_LINE, stack && STACK.row), children: _jsx("td", { ...stackRole(stack, "cell"), colSpan: columns ?? 1, className: cx(PAD[size].cell, "text-center", stack && STACK.block), children: _jsx(EmptySlot, { size: "sm", children: children }) }) }));
|
|
15
15
|
}
|
|
16
16
|
/** The bones of a body cell: one line of text not here yet. */
|
|
17
17
|
export const CELL_BONE = "block h-[0.6lh] w-3/4 rounded";
|
|
@@ -20,7 +20,7 @@ export const CELL_BONE = "block h-[0.6lh] w-3/4 rounded";
|
|
|
20
20
|
* head declares (one across the row with no head). Internal to `TableBody`.
|
|
21
21
|
*/
|
|
22
22
|
export function BoneRows() {
|
|
23
|
-
const { columns, size } = useContext(TableContext);
|
|
23
|
+
const { columns, size, stack } = useContext(TableContext);
|
|
24
24
|
const cells = Array.from({ length: columns ?? 1 }, (_, i) => i);
|
|
25
|
-
return (_jsx(_Fragment, { children: [0, 1, 2, 3, 4].map((row) => (_jsx("tr", { className: BODY_LINE, children: cells.map((cell) => (_jsx("td", { className: PAD[size].cell, children: _jsx(Bone, { shape: CELL_BONE }) }, cell))) }, row))) }));
|
|
25
|
+
return (_jsx(_Fragment, { children: [0, 1, 2, 3, 4].map((row) => (_jsx("tr", { ...stackRole(stack, "row"), className: cx(BODY_LINE, stack && STACK.row), children: cells.map((cell) => (_jsx("td", { ...stackRole(stack, "cell"), className: cx(PAD[size].cell, stack && STACK.block), children: _jsx(Bone, { shape: CELL_BONE }) }, cell))) }, row))) }));
|
|
26
26
|
}
|
package/dist/tableRow.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare const SELECTED = "bg-violet-50 hover:bg-violet-50";
|
|
|
9
9
|
* stripe takes the tone's text colour, which every theme already remaps, so no new palette entry.
|
|
10
10
|
*/
|
|
11
11
|
export type RowTone = "neutral" | "info" | "positive" | "warn" | "danger" | "muted";
|
|
12
|
+
/** A stripe on the leading edge in the current text colour. Shared with `ListRow`. */
|
|
13
|
+
export declare const STRIPE = "shadow-[inset_4px_0_0_0_currentColor]";
|
|
12
14
|
/** The row's mark: a `tone` (stripe and fill, or faded), a `stripe` alone or `emphasis`, only one of them. */
|
|
13
15
|
export type RowMark = {
|
|
14
16
|
/** The row's status: a stripe on the leading edge plus the tone's soft fill, or `muted` to fade the row. Give only one of `tone`, `stripe` and `emphasis`. */
|
|
@@ -56,8 +58,30 @@ export declare const PAD: Record<Size, {
|
|
|
56
58
|
cell: string;
|
|
57
59
|
group: string;
|
|
58
60
|
}>;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The look of a `Table` with `narrow="stack"` on a screen narrower than `sm` (a phone): the table,
|
|
63
|
+
* its sections and its rows become blocks, the head is hidden but still read, and each cell is a
|
|
64
|
+
* line of the row's card, its column's title at the start and its value at the end. The first
|
|
65
|
+
* column is the card's title. A viewport query, not a container query: a container has no width
|
|
66
|
+
* of its own, so a table in a box that sizes to its content would collapse to nothing.
|
|
67
|
+
*/
|
|
68
|
+
export declare const STACK: {
|
|
69
|
+
readonly table: "max-sm:block";
|
|
70
|
+
readonly head: "max-sm:sr-only";
|
|
71
|
+
readonly section: "max-sm:block";
|
|
72
|
+
readonly row: "max-sm:block max-sm:py-2";
|
|
73
|
+
readonly cell: "max-sm:flex max-sm:min-w-0 max-sm:items-baseline max-sm:justify-between max-sm:gap-4 max-sm:whitespace-normal max-sm:py-1";
|
|
74
|
+
readonly block: "max-sm:block max-sm:min-w-0 max-sm:whitespace-normal max-sm:py-1";
|
|
75
|
+
readonly label: "hidden shrink-0 text-xs font-medium uppercase tracking-wide text-slate-500 max-sm:block";
|
|
76
|
+
readonly value: "min-w-0 max-sm:text-right";
|
|
77
|
+
};
|
|
78
|
+
/** The ARIA role a stacking table puts on a part, since a part drawn as a block can lose its table role in some browsers. */
|
|
79
|
+
export declare function stackRole(stack: boolean, role: string): {
|
|
80
|
+
role?: string;
|
|
81
|
+
};
|
|
82
|
+
/** Where a table cell's content sits across it: `start`, `center` or `end` (numbers). */
|
|
83
|
+
export type CellAlign = "start" | "center" | "end";
|
|
84
|
+
export declare const ALIGN: Record<CellAlign, string>;
|
|
61
85
|
/**
|
|
62
86
|
* Whether a `TableRow` sits in the body (a line above, a hover fill), the foot (a firmer line above,
|
|
63
87
|
* strong cells) or the head or nowhere (neither).
|
package/dist/tableRow.js
CHANGED
|
@@ -13,7 +13,8 @@ const ROW_TONE = {
|
|
|
13
13
|
danger: "bg-red-50 text-red-700",
|
|
14
14
|
muted: "opacity-60",
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
/** A stripe on the leading edge in the current text colour. Shared with `ListRow`. */
|
|
17
|
+
export const STRIPE = "shadow-[inset_4px_0_0_0_currentColor]";
|
|
17
18
|
export const BODY_LINE = cx("relative border-t border-slate-200/70", liftInteractive);
|
|
18
19
|
/** The classes of a row: a line above in the body and the foot, the hover fill and the tone's or stripe's look in the body only. */
|
|
19
20
|
export function rowClass(section, plain, tone, stripe) {
|
|
@@ -37,6 +38,27 @@ export const PAD = {
|
|
|
37
38
|
md: { head: "px-5 py-3", cell: "px-5 py-4", group: "px-5 py-2.5" },
|
|
38
39
|
lg: { head: "px-6 py-3.5", cell: "px-6 py-5", group: "px-6 py-3" },
|
|
39
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The look of a `Table` with `narrow="stack"` on a screen narrower than `sm` (a phone): the table,
|
|
43
|
+
* its sections and its rows become blocks, the head is hidden but still read, and each cell is a
|
|
44
|
+
* line of the row's card, its column's title at the start and its value at the end. The first
|
|
45
|
+
* column is the card's title. A viewport query, not a container query: a container has no width
|
|
46
|
+
* of its own, so a table in a box that sizes to its content would collapse to nothing.
|
|
47
|
+
*/
|
|
48
|
+
export const STACK = {
|
|
49
|
+
table: "max-sm:block",
|
|
50
|
+
head: "max-sm:sr-only",
|
|
51
|
+
section: "max-sm:block",
|
|
52
|
+
row: "max-sm:block max-sm:py-2",
|
|
53
|
+
cell: "max-sm:flex max-sm:min-w-0 max-sm:items-baseline max-sm:justify-between max-sm:gap-4 max-sm:whitespace-normal max-sm:py-1",
|
|
54
|
+
block: "max-sm:block max-sm:min-w-0 max-sm:whitespace-normal max-sm:py-1",
|
|
55
|
+
label: "hidden shrink-0 text-xs font-medium uppercase tracking-wide text-slate-500 max-sm:block",
|
|
56
|
+
value: "min-w-0 max-sm:text-right",
|
|
57
|
+
};
|
|
58
|
+
/** The ARIA role a stacking table puts on a part, since a part drawn as a block can lose its table role in some browsers. */
|
|
59
|
+
export function stackRole(stack, role) {
|
|
60
|
+
return stack ? { role } : {};
|
|
61
|
+
}
|
|
40
62
|
export const ALIGN = {
|
|
41
63
|
start: "text-left",
|
|
42
64
|
center: "text-center",
|
package/dist/tableSort.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { CellAlign } from "./tableRow.js";
|
|
3
3
|
/** Where a sortable column stands: ARIA's own words. `none` is a column the table is not sorted by. */
|
|
4
4
|
export type TableSort = "ascending" | "descending" | "none";
|
|
5
5
|
/** The props of a sortable `TableHeaderCell`: the column's `sort` and what a click asks for. */
|
|
@@ -15,8 +15,13 @@ export type SortProps = {
|
|
|
15
15
|
/** Called with the next direction on a click: `none` goes to `ascending`, then each click flips it. */
|
|
16
16
|
onSort: (next: "ascending" | "descending") => void;
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A sortable column's title: a native button that fills the cell, padding and all, so the whole
|
|
20
|
+
* cell is its target (never under 24px tall), named by the title. A click asks for the next
|
|
21
|
+
* direction and has the table say the new sort aloud.
|
|
22
|
+
*/
|
|
23
|
+
export declare function SortButton({ sort, onSort, align, pad, children, }: SortProps & {
|
|
24
|
+
align: CellAlign;
|
|
25
|
+
pad: string;
|
|
21
26
|
children: ReactNode;
|
|
22
27
|
}): ReactElement;
|
package/dist/tableSort.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { cx, insetFocusRing } from "./cx.js";
|
|
4
|
+
import { TableContext } from "./tableColumns.js";
|
|
3
5
|
/** The direction a click asks for: `ascending` first, then it flips. */
|
|
4
6
|
function nextSort(sort) {
|
|
5
7
|
return sort === "ascending" ? "descending" : "ascending";
|
|
@@ -13,7 +15,16 @@ const JUSTIFY = {
|
|
|
13
15
|
function SortArrow({ sort }) {
|
|
14
16
|
return (_jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 12 12", className: cx("size-3 shrink-0", sort === "none" ? "text-slate-300" : "text-slate-600"), fill: "currentColor", children: [sort !== "descending" && _jsx("path", { d: "M6 1.5 9 5H3z" }), sort !== "ascending" && _jsx("path", { d: "M6 10.5 3 7h6z" })] }));
|
|
15
17
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A sortable column's title: a native button that fills the cell, padding and all, so the whole
|
|
20
|
+
* cell is its target (never under 24px tall), named by the title. A click asks for the next
|
|
21
|
+
* direction and has the table say the new sort aloud.
|
|
22
|
+
*/
|
|
23
|
+
export function SortButton({ sort, onSort, align, pad, children, }) {
|
|
24
|
+
const { announce } = useContext(TableContext);
|
|
25
|
+
return (_jsxs("button", { type: "button", onClick: (event) => {
|
|
26
|
+
const next = nextSort(sort);
|
|
27
|
+
onSort(next);
|
|
28
|
+
announce(event.currentTarget.textContent.trim(), next);
|
|
29
|
+
}, className: cx("flex min-h-6 w-full cursor-pointer items-center gap-1 uppercase tracking-wide hover:text-violet-700", pad, JUSTIFY[align], insetFocusRing), children: [children, _jsx(SortArrow, { sort: sort })] }));
|
|
19
30
|
}
|
package/dist/target.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hit areas bigger than what is drawn, made with an invisible `::before` centred on the element: it
|
|
3
|
+
* covers the element and grows to the minimum, so a click or tap on it lands on the element (a
|
|
4
|
+
* label's area toggles its input). Nothing moves: the pseudo-element is absolutely placed.
|
|
5
|
+
*/
|
|
6
|
+
/** At least 24px square for every pointer (WCAG 2.5.8), for a control drawn smaller (a `sm` Switch). */
|
|
7
|
+
export declare const MIN_TARGET = "relative before:absolute before:top-1/2 before:left-1/2 before:size-full before:min-h-6 before:min-w-6 before:-translate-x-1/2 before:-translate-y-1/2";
|
|
8
|
+
/**
|
|
9
|
+
* At least 44px square under a coarse pointer (a finger), for a small choice (a `Checkbox`, a
|
|
10
|
+
* `Radio`). A mouse keeps the drawn size, so stacked choices do not overlap.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TOUCH_TARGET = "relative pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2";
|
package/dist/target.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hit areas bigger than what is drawn, made with an invisible `::before` centred on the element: it
|
|
3
|
+
* covers the element and grows to the minimum, so a click or tap on it lands on the element (a
|
|
4
|
+
* label's area toggles its input). Nothing moves: the pseudo-element is absolutely placed.
|
|
5
|
+
*/
|
|
6
|
+
/** At least 24px square for every pointer (WCAG 2.5.8), for a control drawn smaller (a `sm` Switch). */
|
|
7
|
+
export const MIN_TARGET = "relative before:absolute before:top-1/2 before:left-1/2 before:size-full before:min-h-6 before:min-w-6 before:-translate-x-1/2 before:-translate-y-1/2";
|
|
8
|
+
/**
|
|
9
|
+
* At least 44px square under a coarse pointer (a finger), for a small choice (a `Checkbox`, a
|
|
10
|
+
* `Radio`). A mouse keeps the drawn size, so stacked choices do not overlap.
|
|
11
|
+
*/
|
|
12
|
+
export const TOUCH_TARGET = "relative pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2";
|
package/dist/textBox.js
CHANGED
|
@@ -17,7 +17,7 @@ const CLAMP = {
|
|
|
17
17
|
*/
|
|
18
18
|
export function layoutClass(align, lines) {
|
|
19
19
|
const box = lines === 1
|
|
20
|
-
? cx("min-w-0 truncate align-bottom", align ? "block" : "inline-block")
|
|
20
|
+
? cx("min-w-0 max-w-full truncate align-bottom", align ? "block" : "inline-block")
|
|
21
21
|
: (lines && CLAMP[lines]) || (align && "block");
|
|
22
22
|
return cx(align && ALIGN[align], box);
|
|
23
23
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, type RefObject } from "react";
|
|
2
|
+
type Cut = {
|
|
3
|
+
cut: boolean;
|
|
4
|
+
inner: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Whether the run in `ref` is cut by its box, and whether it holds its own focusable. Measured on
|
|
8
|
+
* each resize and when `text` changes. jsdom (a consumer's own tests) has no ResizeObserver, so
|
|
9
|
+
* there it reads never cut.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useCut(ref: RefObject<HTMLElement | null>, text: string | undefined): Cut;
|
|
12
|
+
/**
|
|
13
|
+
* A one-line truncated run (`truncate` plus the caller's width) that shows its whole `text` in a
|
|
14
|
+
* tooltip while it is cut. A run that holds a link takes the link's focus; a plain one becomes a
|
|
15
|
+
* focus stop only while it is cut and the tooltip is the library's own, so the keyboard can reach
|
|
16
|
+
* it. Internal.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Truncated({ text, as: Tag, attrs, className, children, }: {
|
|
19
|
+
/** The run's element: a block `div`, or inline `code`. */
|
|
20
|
+
as?: "div" | "code" | undefined;
|
|
21
|
+
/** The caller's own attributes for the run (`id`, `data-*`, `aria-*`). */
|
|
22
|
+
attrs?: {
|
|
23
|
+
"aria-describedby"?: string | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
/** The run's whole text; left out (the run is not plain text), it truncates with no tooltip. */
|
|
26
|
+
text: string | undefined;
|
|
27
|
+
/** The run's width and placement, added to `truncate`. */
|
|
28
|
+
className?: string | undefined;
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}): ReactElement;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, } from "react";
|
|
3
|
+
import { cx, focusRing } from "./cx.js";
|
|
4
|
+
import { useTooltip } from "./Tooltip.js";
|
|
5
|
+
// A one-line run cut with an ellipsis shows its whole text in the library's tooltip on hover,
|
|
6
|
+
// keyboard focus and a tap, not only in a native `title` (which the keyboard and touch never reach).
|
|
7
|
+
// The tooltip shows only while the text is cut: a ResizeObserver compares the run's scroll width
|
|
8
|
+
// with its box, so a run that fits says nothing twice. The tooltip repeats the run's own words, so it
|
|
9
|
+
// is hidden from assistive tech, which reads the whole text from the page already.
|
|
10
|
+
/** What can take focus inside a run: a link or a control. A run with none is made a stop itself. */
|
|
11
|
+
const FOCUSABLE = "a[href], button, input, select, textarea, [tabindex]";
|
|
12
|
+
/**
|
|
13
|
+
* Whether the run in `ref` is cut by its box, and whether it holds its own focusable. Measured on
|
|
14
|
+
* each resize and when `text` changes. jsdom (a consumer's own tests) has no ResizeObserver, so
|
|
15
|
+
* there it reads never cut.
|
|
16
|
+
*/
|
|
17
|
+
export function useCut(ref, text) {
|
|
18
|
+
const [state, setState] = useState({ cut: false, inner: false });
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const run = ref.current;
|
|
21
|
+
if (!run || text === undefined || typeof ResizeObserver === "undefined") {
|
|
22
|
+
setState((last) => (last.cut || last.inner ? { cut: false, inner: false } : last));
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const measure = () => {
|
|
26
|
+
const cut = run.scrollWidth > run.clientWidth;
|
|
27
|
+
const inner = run.querySelector(FOCUSABLE) !== null;
|
|
28
|
+
setState((last) => (last.cut === cut && last.inner === inner ? last : { cut, inner }));
|
|
29
|
+
};
|
|
30
|
+
const observer = new ResizeObserver(measure);
|
|
31
|
+
observer.observe(run);
|
|
32
|
+
return () => observer.disconnect();
|
|
33
|
+
}, [ref, text]);
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A one-line truncated run (`truncate` plus the caller's width) that shows its whole `text` in a
|
|
38
|
+
* tooltip while it is cut. A run that holds a link takes the link's focus; a plain one becomes a
|
|
39
|
+
* focus stop only while it is cut and the tooltip is the library's own, so the keyboard can reach
|
|
40
|
+
* it. Internal.
|
|
41
|
+
*/
|
|
42
|
+
export function Truncated({ text, as: Tag = "div", attrs, className, children, }) {
|
|
43
|
+
const ref = useRef(null);
|
|
44
|
+
const { cut, inner } = useCut(ref, text);
|
|
45
|
+
const { props, tooltip, enhanced } = useTooltip(cut ? text : undefined, { describes: false, tap: true }, { "aria-describedby": attrs?.["aria-describedby"] });
|
|
46
|
+
// A focus stop only where focus shows the tooltip: a native title never shows on focus.
|
|
47
|
+
const stop = cut && !inner && enhanced;
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tag, { ...attrs, ref: (run) => {
|
|
49
|
+
ref.current = run;
|
|
50
|
+
}, ...props, tabIndex: stop ? 0 : undefined, className: cx("truncate", className, stop && cx("rounded-sm", focusRing)), children: children }), tooltip] }));
|
|
51
|
+
}
|
package/dist/typography.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ElementType, type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { type TextAlign, type TextLines } from "./textBox.js";
|
|
3
3
|
import type { Passthrough } from "./props.js";
|
|
4
4
|
import { type LoadingProps } from "./skeleton.js";
|
|
@@ -52,21 +52,26 @@ type RunOwnProps = {
|
|
|
52
52
|
italic?: boolean | undefined;
|
|
53
53
|
/** Break a long unbroken string (a URL, a token) where the container ends, instead of overflowing. */
|
|
54
54
|
breakWords?: boolean | undefined;
|
|
55
|
+
/** The full text on hover, for a run that `lines` cuts and whose content is not plain text. */
|
|
56
|
+
title?: string | undefined;
|
|
55
57
|
};
|
|
56
58
|
type Own = OwnProps & InlineOwnProps;
|
|
57
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Own props + `as` + what every part takes through (`id`, `data-*`, `aria-*`). The element varies,
|
|
61
|
+
* its own attributes do not follow it: a role is text, so it takes no `role` or handler (`Text` and `Caption` take a `title` for `lines`).
|
|
62
|
+
*/
|
|
58
63
|
type TypographyProps<E extends ElementType> = OwnProps & {
|
|
59
|
-
/** The element to render
|
|
64
|
+
/** The element to render; each role has a semantic default. */
|
|
60
65
|
as?: E;
|
|
61
|
-
} &
|
|
66
|
+
} & Passthrough;
|
|
62
67
|
/**
|
|
63
68
|
* The props of an inline role: `TypographyProps` plus `tone`, `numeric`, `mono` and `align`.
|
|
64
|
-
* Spelled out like `TypographyProps`, not as an
|
|
69
|
+
* Spelled out like `TypographyProps`, not as an intersection with it, so the docs read its real types.
|
|
65
70
|
*/
|
|
66
71
|
export type InlineTypographyProps<E extends ElementType> = Own & {
|
|
67
|
-
/** The element to render
|
|
72
|
+
/** The element to render; each role has a semantic default. */
|
|
68
73
|
as?: E;
|
|
69
|
-
} &
|
|
74
|
+
} & Passthrough;
|
|
70
75
|
/**
|
|
71
76
|
* Marketing-scale headline: the one line at the top of a public page. `h1`,
|
|
72
77
|
* text-4xl/tight semibold, primary text, growing to text-6xl on wider screens.
|
|
@@ -133,18 +138,21 @@ export type SubsectionHeadingSize = Size;
|
|
|
133
138
|
* body size set apart by its weight) for a form-group caption or a dense card, or up to `lg`
|
|
134
139
|
* (text-xl) for a drawer title; `md` is the default. Under an `AppShell density="compact"` each is one step down. Inside a `Prose`
|
|
135
140
|
* `md` is text-xl/7 (the h3 of a doc), `sm` text-base/7 (the h4: body size, set apart by its weight)
|
|
136
|
-
* and `lg` text-2xl/8, the size of a `SectionHeading` there. `
|
|
141
|
+
* and `lg` text-2xl/8, the size of a `SectionHeading` there. `lines={1}` keeps it on
|
|
137
142
|
* one line and cuts it with an ellipsis where its container ends, the full text as the `title`.
|
|
138
143
|
*/
|
|
139
|
-
export declare function SubsectionHeading<E extends ElementType = "h3">({ size,
|
|
144
|
+
export declare function SubsectionHeading<E extends ElementType = "h3">({ size, ...props }: TypographyProps<E> & {
|
|
140
145
|
/**
|
|
141
146
|
* The heading's type size: `sm` is text-base/6, `md` text-lg/7 and `lg` text-xl/7 (one step down
|
|
142
147
|
* each under an `AppShell density="compact"`).
|
|
143
148
|
* @default md
|
|
144
149
|
*/
|
|
145
150
|
size?: SubsectionHeadingSize;
|
|
146
|
-
/**
|
|
147
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Show at most this many lines (1 to 4) and end in an ellipsis, as on `Text`: `1` cuts the
|
|
153
|
+
* heading where its container ends. With plain-text content the full text becomes the `title`.
|
|
154
|
+
*/
|
|
155
|
+
lines?: TextLines | undefined;
|
|
148
156
|
}): ReactElement;
|
|
149
157
|
/**
|
|
150
158
|
* Small all-caps label above a group. `span`, text-xs semibold uppercase, tertiary. `tone`,
|
package/dist/typography.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Children, createContext, useContext, } from "react";
|
|
3
|
-
import { cx } from "./cx.js";
|
|
3
|
+
import { balanced, cx, pretty } from "./cx.js";
|
|
4
4
|
import { useStackGap } from "./stackGap.js";
|
|
5
5
|
import { useTypeStep } from "./density.js";
|
|
6
6
|
import { layoutClass } from "./textBox.js";
|
|
@@ -69,14 +69,15 @@ function plainText(children) {
|
|
|
69
69
|
* `PageHeading` is the title of an ordinary page, a step below; a brochure hero needs a display
|
|
70
70
|
* scale, so it gets its own pinned role rather than callers overriding PageHeading's size.
|
|
71
71
|
*/
|
|
72
|
-
export const Display = typography("Display", "h1", "text-4xl/[1.1] font-semibold tracking-tight sm:text-5xl/[1.05] lg:text-6xl/[1.05]", "default");
|
|
72
|
+
export const Display = typography("Display", "h1", cx("text-4xl/[1.1] font-semibold tracking-tight sm:text-5xl/[1.05] lg:text-6xl/[1.05]", balanced), "default");
|
|
73
|
+
const LEAD = cx("text-lg/7 font-normal sm:text-xl/8", pretty);
|
|
73
74
|
/** The supporting sentence under a `Display`. `p`, text-lg/7 normal, secondary. */
|
|
74
|
-
export const Lead = typography("Lead", "p",
|
|
75
|
+
export const Lead = typography("Lead", "p", LEAD, "secondary");
|
|
75
76
|
/**
|
|
76
77
|
* Page title. `h1`, text-3xl/9 bold (text-4xl/10 from `sm`), tight, primary text: well above the
|
|
77
78
|
* `Lead` under it and the body text after it, so the page's title reads first.
|
|
78
79
|
*/
|
|
79
|
-
export const PageHeading = typography("PageHeading", "h1", "text-3xl/9 font-bold tracking-tight sm:text-4xl/10", "default");
|
|
80
|
+
export const PageHeading = typography("PageHeading", "h1", cx("text-3xl/9 font-bold tracking-tight sm:text-4xl/10", balanced), "default");
|
|
80
81
|
// --- Prose: the long-form scale ---------------------------------------------
|
|
81
82
|
/**
|
|
82
83
|
* Whether the text roles below are in a `Prose`. `Text`, `SectionHeading`, `SubsectionHeading` and
|
|
@@ -151,9 +152,9 @@ export function SectionHeading({ rule, description, ...props }) {
|
|
|
151
152
|
// An `id` makes the heading a link target, so an anchor jump leaves it clear of the sticky header.
|
|
152
153
|
const scroll = props.id === undefined ? undefined : SCROLL_TARGET;
|
|
153
154
|
if (!hasDescription) {
|
|
154
|
-
return pinned("h2", cx(rule && hairline, size, scroll), "default", props);
|
|
155
|
+
return pinned("h2", cx(rule && hairline, size, balanced, scroll), "default", props);
|
|
155
156
|
}
|
|
156
|
-
return (_jsxs("div", { className: cx("flex flex-col gap-1", rule && hairline), children: [pinned("h2", cx(size, scroll), "default", props), _jsx(Text, { tone: "muted", children: description })] }));
|
|
157
|
+
return (_jsxs("div", { className: cx("flex flex-col gap-1", rule && hairline), children: [pinned("h2", cx(size, balanced, scroll), "default", props), _jsx(Text, { tone: "muted", children: description })] }));
|
|
157
158
|
}
|
|
158
159
|
const SUBSECTION_SIZE = {
|
|
159
160
|
sm: {
|
|
@@ -177,14 +178,11 @@ const SUBSECTION_SIZE = {
|
|
|
177
178
|
* body size set apart by its weight) for a form-group caption or a dense card, or up to `lg`
|
|
178
179
|
* (text-xl) for a drawer title; `md` is the default. Under an `AppShell density="compact"` each is one step down. Inside a `Prose`
|
|
179
180
|
* `md` is text-xl/7 (the h3 of a doc), `sm` text-base/7 (the h4: body size, set apart by its weight)
|
|
180
|
-
* and `lg` text-2xl/8, the size of a `SectionHeading` there. `
|
|
181
|
+
* and `lg` text-2xl/8, the size of a `SectionHeading` there. `lines={1}` keeps it on
|
|
181
182
|
* one line and cuts it with an ellipsis where its container ends, the full text as the `title`.
|
|
182
183
|
*/
|
|
183
|
-
export function SubsectionHeading({ size = "md",
|
|
184
|
-
return pinned("h3", useScale(SUBSECTION_SIZE[size]), "default",
|
|
185
|
-
...props,
|
|
186
|
-
lines: truncate ? 1 : undefined,
|
|
187
|
-
});
|
|
184
|
+
export function SubsectionHeading({ size = "md", ...props }) {
|
|
185
|
+
return pinned("h3", cx(useScale(SUBSECTION_SIZE[size]), balanced), "default", props);
|
|
188
186
|
}
|
|
189
187
|
// --- Inline roles -------------------------------------------------------------
|
|
190
188
|
const OVERLINE = "text-xs font-semibold uppercase tracking-wide";
|
|
@@ -228,7 +226,7 @@ export function HeaderText({ children }) {
|
|
|
228
226
|
}
|
|
229
227
|
const TEXT = { app: "text-base/6", compact: "text-sm/5", prose: "text-base/7" };
|
|
230
228
|
function textVariant(strong, preserveNewlines, measure, size) {
|
|
231
|
-
return cx(preserveNewlines && "whitespace-pre-line", measure && "max-w-[72ch]", size, strong ? "font-medium" : "font-normal");
|
|
229
|
+
return cx(preserveNewlines && "whitespace-pre-line", measure && cx("max-w-[72ch]", pretty), size, strong ? "font-medium" : "font-normal");
|
|
232
230
|
}
|
|
233
231
|
/**
|
|
234
232
|
* Fine print / metadata. A paragraph (`p`; `as="span"` inline), text-sm/5 normal, tertiary
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { FlowEdge, FlowNode } from "./FlowDiagram.js";
|
|
3
|
+
import { type FlowDirection, type FlowLayout } from "./flowLayout.js";
|
|
4
|
+
/** What the layout reads from a node. */
|
|
5
|
+
type SizedNode = Pick<FlowNode, "id" | "label" | "group" | "content">;
|
|
6
|
+
export declare const nodeKey: (id: string) => string;
|
|
7
|
+
export declare const edgeKey: (index: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
* How far to shrink a diagram `width` wide so it fits the box `frame` refers to: 1 when it fits
|
|
10
|
+
* or the room is not known yet (the server render, a test's DOM), else the room over the width.
|
|
11
|
+
* The observer follows the room as it changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useFit(width: number): {
|
|
14
|
+
frame: RefObject<HTMLDivElement | null>;
|
|
15
|
+
scale: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Lays the diagram out, first at guessed sizes, then at the sizes the browser draws each box and
|
|
19
|
+
* arrow label at: every render measures them, and lays out again when one's size is not the one
|
|
20
|
+
* the layout used. A box's size never depends on where it is placed, so this settles after one
|
|
21
|
+
* pass; the observer catches a later change (a web font arriving).
|
|
22
|
+
*/
|
|
23
|
+
export declare function useFlowLayout(nodes: readonly SizedNode[], edges: readonly FlowEdge[], direction: FlowDirection): {
|
|
24
|
+
canvas: RefObject<HTMLDivElement | null>;
|
|
25
|
+
drawn: FlowLayout;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { layoutFlow, } from "./flowLayout.js";
|
|
3
|
+
/**
|
|
4
|
+
* The size a box or a label is drawn at before it can be measured (the server render, and a
|
|
5
|
+
* test's DOM, which has no layout): the label's characters at an average width, inside the
|
|
6
|
+
* padding and the border, wrapping at the 18rem cap. The browser then measures every box and lays
|
|
7
|
+
* the diagram out again at the real sizes.
|
|
8
|
+
*/
|
|
9
|
+
const NODE_MAX = 288;
|
|
10
|
+
const NODE_CHAR = 7.4;
|
|
11
|
+
const NODE_PAD_X = 26;
|
|
12
|
+
const NODE_PAD_Y = 18;
|
|
13
|
+
const NODE_LINE = 20;
|
|
14
|
+
const CONTENT_GUESS = 32;
|
|
15
|
+
const EDGE_CHAR = 6.6;
|
|
16
|
+
const EDGE_PAD = 8;
|
|
17
|
+
const EDGE_LINE = 16;
|
|
18
|
+
function guessNode(node) {
|
|
19
|
+
const text = Math.ceil(node.label.length * NODE_CHAR);
|
|
20
|
+
const lines = Math.max(1, Math.ceil(text / (NODE_MAX - NODE_PAD_X)));
|
|
21
|
+
return {
|
|
22
|
+
width: Math.min(NODE_MAX, text + NODE_PAD_X),
|
|
23
|
+
height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 : CONTENT_GUESS),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const guessLabel = (label) => ({
|
|
27
|
+
width: Math.ceil(label.length * EDGE_CHAR) + EDGE_PAD,
|
|
28
|
+
height: EDGE_LINE,
|
|
29
|
+
});
|
|
30
|
+
export const nodeKey = (id) => `n:${id}`;
|
|
31
|
+
export const edgeKey = (index) => `e:${index}`;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the drawn size of every box and arrow label under `root`, keyed by `data-measure`, in the
|
|
34
|
+
* diagram's own space: a canvas scaled to fit (`useFit`) is drawn smaller, so its sizes are read
|
|
35
|
+
* back at full scale. The small allowance keeps a rounding error from adding a pixel.
|
|
36
|
+
*/
|
|
37
|
+
function measure(root) {
|
|
38
|
+
const out = {};
|
|
39
|
+
const drawnWidth = root.getBoundingClientRect().width;
|
|
40
|
+
const scale = root.offsetWidth > 0 && drawnWidth > 0 ? drawnWidth / root.offsetWidth : 1;
|
|
41
|
+
const full = (n) => Math.ceil(scale === 1 ? n : n / scale - 0.01);
|
|
42
|
+
for (const el of root.querySelectorAll("[data-measure]")) {
|
|
43
|
+
const rect = el.getBoundingClientRect();
|
|
44
|
+
const key = el.dataset["measure"];
|
|
45
|
+
if (key && rect.width > 0 && rect.height > 0) {
|
|
46
|
+
out[key] = { width: full(rect.width), height: full(rect.height) };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* How far to shrink a diagram `width` wide so it fits the box `frame` refers to: 1 when it fits
|
|
53
|
+
* or the room is not known yet (the server render, a test's DOM), else the room over the width.
|
|
54
|
+
* The observer follows the room as it changes.
|
|
55
|
+
*/
|
|
56
|
+
export function useFit(width) {
|
|
57
|
+
const frame = useRef(null);
|
|
58
|
+
const [room, setRoom] = useState(0);
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
const box = frame.current;
|
|
61
|
+
if (!box)
|
|
62
|
+
return undefined;
|
|
63
|
+
const update = () => setRoom(box.clientWidth);
|
|
64
|
+
update();
|
|
65
|
+
if (typeof ResizeObserver === "undefined")
|
|
66
|
+
return undefined;
|
|
67
|
+
const observer = new ResizeObserver(update);
|
|
68
|
+
observer.observe(box);
|
|
69
|
+
return () => observer.disconnect();
|
|
70
|
+
}, []);
|
|
71
|
+
const scale = room > 0 && width > room ? room / width : 1;
|
|
72
|
+
return { frame, scale };
|
|
73
|
+
}
|
|
74
|
+
const sameSizes = (a, b) => {
|
|
75
|
+
const keys = Object.keys(a);
|
|
76
|
+
return (keys.length === Object.keys(b).length &&
|
|
77
|
+
keys.every((k) => a[k]?.width === b[k]?.width && a[k]?.height === b[k]?.height));
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Lays the diagram out, first at guessed sizes, then at the sizes the browser draws each box and
|
|
81
|
+
* arrow label at: every render measures them, and lays out again when one's size is not the one
|
|
82
|
+
* the layout used. A box's size never depends on where it is placed, so this settles after one
|
|
83
|
+
* pass; the observer catches a later change (a web font arriving).
|
|
84
|
+
*/
|
|
85
|
+
export function useFlowLayout(nodes, edges, direction) {
|
|
86
|
+
const canvas = useRef(null);
|
|
87
|
+
const [measured, setMeasured] = useState({});
|
|
88
|
+
const layoutNodes = nodes.map((n) => ({
|
|
89
|
+
id: n.id,
|
|
90
|
+
group: n.group,
|
|
91
|
+
...(measured[nodeKey(n.id)] ?? guessNode(n)),
|
|
92
|
+
}));
|
|
93
|
+
const layoutEdges = edges.map((e, index) => ({
|
|
94
|
+
from: e.from,
|
|
95
|
+
to: e.to,
|
|
96
|
+
label: e.label ? (measured[edgeKey(index)] ?? guessLabel(e.label)) : undefined,
|
|
97
|
+
}));
|
|
98
|
+
const key = JSON.stringify([direction, layoutNodes, layoutEdges]);
|
|
99
|
+
// The key holds every input the layout reads, so the layout reruns only when one changes.
|
|
100
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on the serialised input above
|
|
101
|
+
const drawn = useMemo(() => layoutFlow(layoutNodes, layoutEdges, direction), [key]);
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
const root = canvas.current;
|
|
104
|
+
if (!root)
|
|
105
|
+
return undefined;
|
|
106
|
+
const update = () => {
|
|
107
|
+
const next = measure(root);
|
|
108
|
+
setMeasured((prev) => (sameSizes(prev, next) ? prev : next));
|
|
109
|
+
};
|
|
110
|
+
update();
|
|
111
|
+
if (typeof ResizeObserver === "undefined")
|
|
112
|
+
return undefined;
|
|
113
|
+
const observer = new ResizeObserver(update);
|
|
114
|
+
for (const el of root.querySelectorAll("[data-measure]"))
|
|
115
|
+
observer.observe(el);
|
|
116
|
+
return () => observer.disconnect();
|
|
117
|
+
});
|
|
118
|
+
return { canvas, drawn };
|
|
119
|
+
}
|