@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
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The native theme generator: a theme's CSS (`themes/<id>.css`) as the style map a React Native
|
|
3
|
+
* renderer reads (`themes/<id>.native.json`). Pure: it takes the CSS text and the palette and
|
|
4
|
+
* returns the map, so the theme test can assert the committed file is current.
|
|
5
|
+
*
|
|
6
|
+
* Every palette utility lands in one place: a plain one (`bg-white`) in `utilities`, one behind a
|
|
7
|
+
* state variant in that state's slot (`hover:bg-violet-700` in `pressed`, `placeholder:text-slate-400`
|
|
8
|
+
* in `placeholderTextColor`, `backdrop:bg-slate-900/35` in `scrim`). A rule the map cannot hold as
|
|
9
|
+
* one utility (`.disabled\:opacity-50:disabled:is(…)`) is a compound. Anything else is listed in
|
|
10
|
+
* `unmapped`, so nothing is dropped silently, and the theme test requires that list to be empty.
|
|
11
|
+
*/
|
|
12
|
+
/** Which slot each Tailwind variant the palette uses lands in. */
|
|
13
|
+
export const STATE_OF_VARIANT = {
|
|
14
|
+
hover: "pressed",
|
|
15
|
+
"focus-visible": "focused",
|
|
16
|
+
"has-focus-visible": "focused",
|
|
17
|
+
placeholder: "placeholderTextColor",
|
|
18
|
+
backdrop: "scrim",
|
|
19
|
+
disabled: "disabled",
|
|
20
|
+
"aria-invalid": "invalid",
|
|
21
|
+
"has-aria-invalid": "invalid",
|
|
22
|
+
"user-invalid": "invalid",
|
|
23
|
+
"has-user-invalid": "invalid",
|
|
24
|
+
target: "target",
|
|
25
|
+
};
|
|
26
|
+
const CSS_TO_NATIVE = {
|
|
27
|
+
"background-color": "backgroundColor",
|
|
28
|
+
color: "color",
|
|
29
|
+
"border-color": "borderColor",
|
|
30
|
+
"outline-color": "outlineColor",
|
|
31
|
+
"accent-color": "accentColor",
|
|
32
|
+
opacity: "opacity",
|
|
33
|
+
"font-weight": "fontWeight",
|
|
34
|
+
};
|
|
35
|
+
/** Declarations a native map has no use for: web-only, or carried in `base`. Listed, so nothing else is dropped. */
|
|
36
|
+
const WEB_ONLY = new Set([
|
|
37
|
+
"transition",
|
|
38
|
+
"text-underline-offset",
|
|
39
|
+
"color-scheme",
|
|
40
|
+
"font-family",
|
|
41
|
+
"--font-mono",
|
|
42
|
+
"--font-sans",
|
|
43
|
+
"--font-heading",
|
|
44
|
+
]);
|
|
45
|
+
const COLOUR = /^(#[0-9a-f]{3,8}|rgba?\([^)]*\)|transparent)$/i;
|
|
46
|
+
/** One canonical form of a colour: lower-case hex, `rgba(r, g, b, a)`. */
|
|
47
|
+
function colourOf(value, where, unmapped) {
|
|
48
|
+
if (!COLOUR.test(value)) {
|
|
49
|
+
unmapped.push(`${where}: "${value}" is not a colour React Native parses`);
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return value
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/\(\s*/, "(")
|
|
55
|
+
.replace(/\s*\)/, ")")
|
|
56
|
+
.replace(/\s*,\s*/g, ", ");
|
|
57
|
+
}
|
|
58
|
+
function declarationsOf(body, where, unmapped) {
|
|
59
|
+
const style = {};
|
|
60
|
+
for (const declaration of body.split(";")) {
|
|
61
|
+
const colon = declaration.indexOf(":");
|
|
62
|
+
if (colon < 0)
|
|
63
|
+
continue;
|
|
64
|
+
const property = declaration.slice(0, colon).trim();
|
|
65
|
+
const value = declaration
|
|
66
|
+
.slice(colon + 1)
|
|
67
|
+
.replace(/\s+/g, " ")
|
|
68
|
+
.trim();
|
|
69
|
+
if (property === "" || WEB_ONLY.has(property) || property.startsWith("--hc-"))
|
|
70
|
+
continue;
|
|
71
|
+
const native = CSS_TO_NATIVE[property];
|
|
72
|
+
if (native === undefined) {
|
|
73
|
+
unmapped.push(`${where} { ${property} }`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (native === "opacity")
|
|
77
|
+
style[native] = Number(value);
|
|
78
|
+
else if (native === "fontWeight")
|
|
79
|
+
style[native] = value;
|
|
80
|
+
else {
|
|
81
|
+
const colour = colourOf(value, `${where} ${property}`, unmapped);
|
|
82
|
+
if (colour !== undefined)
|
|
83
|
+
style[native] = colour;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return style;
|
|
87
|
+
}
|
|
88
|
+
/** Split a selector list on the commas outside brackets. */
|
|
89
|
+
function selectorsOf(list) {
|
|
90
|
+
const parts = [];
|
|
91
|
+
let depth = 0;
|
|
92
|
+
let current = "";
|
|
93
|
+
for (const char of list) {
|
|
94
|
+
if (char === "(" || char === "[")
|
|
95
|
+
depth += 1;
|
|
96
|
+
if (char === ")" || char === "]")
|
|
97
|
+
depth -= 1;
|
|
98
|
+
if (char === "," && depth === 0) {
|
|
99
|
+
parts.push(current.trim());
|
|
100
|
+
current = "";
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
current += char;
|
|
104
|
+
}
|
|
105
|
+
return [...parts, current.trim()].filter(Boolean);
|
|
106
|
+
}
|
|
107
|
+
const unescapeClass = (name) => name.replace(/\\(.)/g, "$1");
|
|
108
|
+
const CLASS = String.raw `((?:\\.|[\w-])+)`;
|
|
109
|
+
/** `hover:bg-violet-700` as its variant and plain utility; no variant gives `undefined`. */
|
|
110
|
+
function splitVariant(utility) {
|
|
111
|
+
const colon = utility.lastIndexOf(":");
|
|
112
|
+
if (colon < 0)
|
|
113
|
+
return { variant: undefined, plain: utility };
|
|
114
|
+
return { variant: utility.slice(0, colon), plain: utility.slice(colon + 1) };
|
|
115
|
+
}
|
|
116
|
+
function merge(table, key, style) {
|
|
117
|
+
table[key] = { ...table[key], ...style };
|
|
118
|
+
}
|
|
119
|
+
function emptyParsed(scope) {
|
|
120
|
+
return {
|
|
121
|
+
scope,
|
|
122
|
+
base: { backgroundColor: "", color: "", fontFamily: null, headingFontFamily: null },
|
|
123
|
+
selection: {},
|
|
124
|
+
utilities: {},
|
|
125
|
+
states: {
|
|
126
|
+
pressed: {},
|
|
127
|
+
focused: {},
|
|
128
|
+
placeholderTextColor: {},
|
|
129
|
+
scrim: {},
|
|
130
|
+
disabled: {},
|
|
131
|
+
invalid: {},
|
|
132
|
+
target: {},
|
|
133
|
+
},
|
|
134
|
+
within: {},
|
|
135
|
+
headings: {},
|
|
136
|
+
compounds: [],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** The first family of a `--font-…` stack in the scope rule, unquoted; none gives `null`. */
|
|
140
|
+
function familyOf(body, variable) {
|
|
141
|
+
const family = new RegExp(`--font-${variable}:([^;]+);`)
|
|
142
|
+
.exec(body)?.[1]
|
|
143
|
+
?.split(",")[0]
|
|
144
|
+
?.trim()
|
|
145
|
+
.replace(/^["']|["']$/g, "");
|
|
146
|
+
return family === undefined || family === "" ? null : family;
|
|
147
|
+
}
|
|
148
|
+
/** The scope rule: the page's canvas, ink, sans family and heading family. */
|
|
149
|
+
function readScope(parsed, body, file, unmapped) {
|
|
150
|
+
const style = declarationsOf(body, `${file} .${parsed.scope}`, unmapped);
|
|
151
|
+
parsed.base.backgroundColor = String(style["backgroundColor"] ?? "");
|
|
152
|
+
parsed.base.color = String(style["color"] ?? "");
|
|
153
|
+
parsed.base.fontFamily = familyOf(body, "sans");
|
|
154
|
+
parsed.base.headingFontFamily = familyOf(body, "heading");
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A rule on the headings. The heading face is `base.headingFontFamily`, read from the scope rule, so
|
|
158
|
+
* a bare heading rule of font-family alone is taken; a utility on a heading
|
|
159
|
+
* (`:is(h1, h2, h3).text-slate-900`) lands in `headings`; anything else is unmapped.
|
|
160
|
+
*/
|
|
161
|
+
function readHeading(parsed, rest, style) {
|
|
162
|
+
if (rest === "")
|
|
163
|
+
return Object.keys(style).every((key) => key === "fontFamily");
|
|
164
|
+
const utility = new RegExp(`^\\.${CLASS}$`).exec(rest)?.[1];
|
|
165
|
+
if (utility === undefined)
|
|
166
|
+
return false;
|
|
167
|
+
merge(parsed.headings, unescapeClass(utility), style);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
/** A selector that is not one utility: the selection, the headings, a utility on a tint. */
|
|
171
|
+
function readSpecial(parsed, selector, style) {
|
|
172
|
+
const scope = parsed.scope;
|
|
173
|
+
if (new RegExp(`^\\.${scope}\\s*::selection$`).test(selector)) {
|
|
174
|
+
Object.assign(parsed.selection, style);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const heading = new RegExp(`^\\.${scope}\\s+:is\\(h1, h2, h3[^)]*\\)(.*)$`).exec(selector);
|
|
178
|
+
if (heading)
|
|
179
|
+
return readHeading(parsed, heading[1] ?? "", style);
|
|
180
|
+
const within = new RegExp(`^\\.${scope}\\s+\\.${CLASS}\\s+\\.${CLASS}$`).exec(selector);
|
|
181
|
+
if (!within)
|
|
182
|
+
return false;
|
|
183
|
+
const tint = unescapeClass(within[1] ?? "");
|
|
184
|
+
parsed.within[tint] = parsed.within[tint] ?? {};
|
|
185
|
+
merge(parsed.within[tint], unescapeClass(within[2] ?? ""), style);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
/** One utility, plain, behind a state variant, or held only alongside other classes. */
|
|
189
|
+
function readUtility(parsed, utility, rest, style) {
|
|
190
|
+
const requires = /:is\(([^)]*)\)/.exec(rest)?.[1];
|
|
191
|
+
if (requires !== undefined) {
|
|
192
|
+
const requiresAny = requires.split(",").map((name) => unescapeClass(name.trim().slice(1)));
|
|
193
|
+
parsed.compounds.push({ utility, requiresAny, style });
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
const { variant, plain } = splitVariant(utility);
|
|
197
|
+
if (variant === undefined) {
|
|
198
|
+
// A plain class with its own `:hover` (`.link:hover`) is that class pressed; any other
|
|
199
|
+
// pseudo-class on a plain class has no slot.
|
|
200
|
+
if (rest === ":hover")
|
|
201
|
+
merge(parsed.states.pressed, plain, style);
|
|
202
|
+
else if (rest === "")
|
|
203
|
+
merge(parsed.utilities, plain, style);
|
|
204
|
+
else
|
|
205
|
+
return false;
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const state = STATE_OF_VARIANT[variant];
|
|
209
|
+
if (state === undefined)
|
|
210
|
+
return false;
|
|
211
|
+
merge(parsed.states[state], plain, state === "placeholderTextColor" ? asPlaceholder(style) : style);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
/** One `.scope …` selector into its place in the map; false when it has none. */
|
|
215
|
+
function readSelector(parsed, selector, style) {
|
|
216
|
+
if (readSpecial(parsed, selector, style))
|
|
217
|
+
return true;
|
|
218
|
+
const plain = new RegExp(`^\\.${parsed.scope}\\s+\\.${CLASS}(.*)$`).exec(selector);
|
|
219
|
+
if (!plain)
|
|
220
|
+
return false;
|
|
221
|
+
return readUtility(parsed, unescapeClass(plain[1] ?? ""), plain[2] ?? "", style);
|
|
222
|
+
}
|
|
223
|
+
/** A placeholder's colour is a prop on a native text input, not a style. */
|
|
224
|
+
const asPlaceholder = (style) => style["color"] === undefined ? style : { placeholderTextColor: style["color"] };
|
|
225
|
+
/**
|
|
226
|
+
* The native map of one theme's CSS. `id` is the file name without `.css`. Returns the map and
|
|
227
|
+
* every rule or declaration it could not carry.
|
|
228
|
+
*/
|
|
229
|
+
export function nativeTheme(css, id) {
|
|
230
|
+
const file = `${id}.css`;
|
|
231
|
+
const uncommented = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
232
|
+
const scheme = /@custom-variant\s+dark\b/.test(uncommented) ? "dark" : "light";
|
|
233
|
+
const unmapped = [];
|
|
234
|
+
const { scope, base, selection, utilities, states, within, headings, compounds } = parse(uncommented.replace(/@[^;{}]*;/g, ""), file, unmapped);
|
|
235
|
+
return {
|
|
236
|
+
theme: {
|
|
237
|
+
id,
|
|
238
|
+
scope,
|
|
239
|
+
scheme,
|
|
240
|
+
statusBar: scheme === "dark" ? "light-content" : "dark-content",
|
|
241
|
+
base,
|
|
242
|
+
selection,
|
|
243
|
+
utilities,
|
|
244
|
+
states,
|
|
245
|
+
within,
|
|
246
|
+
headings,
|
|
247
|
+
compounds,
|
|
248
|
+
},
|
|
249
|
+
unmapped,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/** The scope rule's map, from the first rule: its selector must be the one scope class. */
|
|
253
|
+
function parseScope(list, body, file, unmapped) {
|
|
254
|
+
const scope = /^\.([\w-]+)$/.exec(selectorsOf(list)[0] ?? "")?.[1];
|
|
255
|
+
if (scope === undefined)
|
|
256
|
+
throw new Error(`${file}: the first rule is not the scope rule`);
|
|
257
|
+
const parsed = emptyParsed(scope);
|
|
258
|
+
readScope(parsed, body, file, unmapped);
|
|
259
|
+
return parsed;
|
|
260
|
+
}
|
|
261
|
+
/** The rules of one theme's CSS, comments and at-statements gone: the scope rule first. */
|
|
262
|
+
function parse(source, file, unmapped) {
|
|
263
|
+
let parsed;
|
|
264
|
+
for (const [, list = "", body = ""] of source.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
265
|
+
if (parsed === undefined) {
|
|
266
|
+
parsed = parseScope(list, body, file, unmapped);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for (const selector of selectorsOf(list)) {
|
|
270
|
+
const style = declarationsOf(body, `${file} ${selector}`, unmapped);
|
|
271
|
+
if (!readSelector(parsed, selector, style))
|
|
272
|
+
unmapped.push(`${file}: selector ${selector}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (parsed === undefined)
|
|
276
|
+
throw new Error(`${file}: no scope rule`);
|
|
277
|
+
return parsed;
|
|
278
|
+
}
|
|
279
|
+
/** The palette utilities a native map does not hold: each in `utilities`, or in its variant's slot. */
|
|
280
|
+
export function missingFromNative(theme, palette) {
|
|
281
|
+
return palette.filter((utility) => {
|
|
282
|
+
const { variant, plain } = splitVariant(utility);
|
|
283
|
+
if (variant === undefined)
|
|
284
|
+
return theme.utilities[plain] === undefined;
|
|
285
|
+
const state = STATE_OF_VARIANT[variant];
|
|
286
|
+
return state === undefined || theme.states[state][plain] === undefined;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/** The map as the file holds it: two-space JSON with a trailing newline. */
|
|
290
|
+
export const nativeThemeJson = (theme) => `${JSON.stringify(theme, null, 2)}\n`;
|
package/dist/cx.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
/** Join class names, dropping falsy parts. */
|
|
2
2
|
export declare function cx(...parts: Array<string | false | null | undefined>): string;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export { focusRing, insetFocusRing } from "./focus.js";
|
|
4
|
+
/**
|
|
5
|
+
* A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
|
|
6
|
+
* wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
|
|
7
|
+
* `lines` clamp (one line with an ellipsis) still wins; a browser that has neither wraps as before.
|
|
8
|
+
*/
|
|
9
|
+
export declare const balanced = "[text-wrap-style:balance]";
|
|
10
|
+
export declare const pretty = "[text-wrap-style:pretty]";
|
|
11
|
+
/**
|
|
12
|
+
* A fill that carries meaning (a bar's progress, the drop line, the current pill) in forced
|
|
13
|
+
* colours: there every background is painted the page's Canvas, so the fill would vanish. A system
|
|
14
|
+
* colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
|
|
15
|
+
*/
|
|
16
|
+
export declare const forcedFill = "forced-colors:bg-[color:Highlight]!";
|
|
5
17
|
/**
|
|
6
18
|
* On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
|
|
7
19
|
* above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
|
|
@@ -11,9 +23,9 @@ export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-
|
|
|
11
23
|
*/
|
|
12
24
|
export declare const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
|
|
13
25
|
/**
|
|
14
|
-
* A
|
|
15
|
-
* scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
26
|
+
* A scrollbar in the theme's muted ink instead of the native grey one, at the native width so it
|
|
27
|
+
* stays easy to grab, for a box that scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
16
28
|
* element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
|
|
17
29
|
* transparent. The element must not hold text of its own: put the readable colour on an inner box.
|
|
18
30
|
*/
|
|
19
|
-
export declare const themedScrollbar = "text-slate-400 [scrollbar-
|
|
31
|
+
export declare const themedScrollbar = "text-slate-400 [scrollbar-color:currentColor_transparent]";
|
package/dist/cx.js
CHANGED
|
@@ -2,8 +2,21 @@
|
|
|
2
2
|
export function cx(...parts) {
|
|
3
3
|
return parts.filter(Boolean).join(" ");
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
export
|
|
5
|
+
// The keyboard focus ring and its inset twin are core's, the one copy both renderers read.
|
|
6
|
+
export { focusRing, insetFocusRing } from "./focus.js";
|
|
7
|
+
/**
|
|
8
|
+
* A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
|
|
9
|
+
* wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
|
|
10
|
+
* `lines` clamp (one line with an ellipsis) still wins; a browser that has neither wraps as before.
|
|
11
|
+
*/
|
|
12
|
+
export const balanced = "[text-wrap-style:balance]";
|
|
13
|
+
export const pretty = "[text-wrap-style:pretty]";
|
|
14
|
+
/**
|
|
15
|
+
* A fill that carries meaning (a bar's progress, the drop line, the current pill) in forced
|
|
16
|
+
* colours: there every background is painted the page's Canvas, so the fill would vanish. A system
|
|
17
|
+
* colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
|
|
18
|
+
*/
|
|
19
|
+
export const forcedFill = "forced-colors:bg-[color:Highlight]!";
|
|
7
20
|
/**
|
|
8
21
|
* On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
|
|
9
22
|
* above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
|
|
@@ -13,9 +26,9 @@ export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2
|
|
|
13
26
|
*/
|
|
14
27
|
export const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
|
|
15
28
|
/**
|
|
16
|
-
* A
|
|
17
|
-
* scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
29
|
+
* A scrollbar in the theme's muted ink instead of the native grey one, at the native width so it
|
|
30
|
+
* stays easy to grab, for a box that scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
18
31
|
* element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
|
|
19
32
|
* transparent. The element must not hold text of its own: put the readable colour on an inner box.
|
|
20
33
|
*/
|
|
21
|
-
export const themedScrollbar = "text-slate-400 [scrollbar-
|
|
34
|
+
export const themedScrollbar = "text-slate-400 [scrollbar-color:currentColor_transparent]";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DateValue } from "@internationalized/date";
|
|
2
|
+
import type { ReactElement, ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The locale a date field shows its segments, month names and messages in: `locale` when it is
|
|
5
|
+
* given, else the app's own `I18nProvider`, else the browser's.
|
|
6
|
+
*/
|
|
7
|
+
export declare function DateLocale({ locale, children, }: {
|
|
8
|
+
locale: string | undefined;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): ReactElement;
|
|
11
|
+
/** The twelve month names in `locale`, January first. */
|
|
12
|
+
export declare function monthNames(locale: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
|
|
15
|
+
* en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
|
|
16
|
+
*/
|
|
17
|
+
export declare function shownIn(value: DateValue, locale: string, time: boolean): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DateFormatter, toCalendarDateTime } from "@internationalized/date";
|
|
3
|
+
import { I18nProvider } from "react-aria-components";
|
|
4
|
+
/**
|
|
5
|
+
* The locale a date field shows its segments, month names and messages in: `locale` when it is
|
|
6
|
+
* given, else the app's own `I18nProvider`, else the browser's.
|
|
7
|
+
*/
|
|
8
|
+
export function DateLocale({ locale, children, }) {
|
|
9
|
+
return locale ? _jsx(I18nProvider, { locale: locale, children: children }) : _jsx(_Fragment, { children: children });
|
|
10
|
+
}
|
|
11
|
+
/** The twelve month names in `locale`, January first. */
|
|
12
|
+
export function monthNames(locale) {
|
|
13
|
+
const months = new DateFormatter(locale, { month: "long", timeZone: "UTC" });
|
|
14
|
+
return Array.from({ length: 12 }, (_, i) => months.format(new Date(Date.UTC(2000, i, 1))));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
|
|
18
|
+
* en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
|
|
19
|
+
*/
|
|
20
|
+
export function shownIn(value, locale, time) {
|
|
21
|
+
const clock = time ? { hour: "2-digit", minute: "2-digit" } : {};
|
|
22
|
+
const format = new DateFormatter(locale, {
|
|
23
|
+
day: "2-digit",
|
|
24
|
+
month: "2-digit",
|
|
25
|
+
year: "numeric",
|
|
26
|
+
...clock,
|
|
27
|
+
timeZone: "UTC",
|
|
28
|
+
});
|
|
29
|
+
return format.format(toCalendarDateTime(value).toDate("UTC"));
|
|
30
|
+
}
|
package/dist/density.d.ts
CHANGED
|
@@ -26,13 +26,27 @@ export declare function useResponsiveDensity(size: Size | ResponsiveSize | undef
|
|
|
26
26
|
export declare function useTypeStep(): TypeStep | undefined;
|
|
27
27
|
/** The size twins, for the data test that each is its table with `md:` on every class. */
|
|
28
28
|
export declare const controlTextTables: {
|
|
29
|
-
text: Record<"
|
|
29
|
+
text: Record<import("./core/index.js").ControlTypeStep, Record<import("./core/index.js").ButtonSize, string>>;
|
|
30
30
|
textMd: Record<"compact" | "default", Record<Size, string>>;
|
|
31
|
-
leading: Record<
|
|
31
|
+
leading: Record<import("./core/index.js").ButtonSize, string>;
|
|
32
32
|
leadingMd: Record<Size, string>;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
|
|
36
|
-
* a person types in. A responsive size adds its `md` size from the breakpoint up
|
|
36
|
+
* a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
|
|
37
|
+
* holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
|
|
38
|
+
* wins over an `md:` size under 16px.
|
|
37
39
|
*/
|
|
38
40
|
export declare function controlText(size: Size | ResponsiveSize, step: TypeStep | undefined, entry: boolean): string;
|
|
41
|
+
/** The field type table, for the data test. */
|
|
42
|
+
export declare const fieldTypeTable: Record<"compact" | "default", {
|
|
43
|
+
label: string;
|
|
44
|
+
note: string;
|
|
45
|
+
line: string;
|
|
46
|
+
}>;
|
|
47
|
+
/** The type of a field's label and its notes at the step in force. */
|
|
48
|
+
export declare function useFieldType(): {
|
|
49
|
+
label: string;
|
|
50
|
+
note: string;
|
|
51
|
+
line: string;
|
|
52
|
+
};
|
package/dist/density.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createContext, createElement, useContext, useMemo, } from "react";
|
|
2
|
+
import { CONTROL_LEADING, CONTROL_TEXT } from "./core/index.js";
|
|
2
3
|
import { isResponsive } from "./size.js";
|
|
3
4
|
const DensityContext = createContext({ size: undefined, type: undefined });
|
|
4
5
|
/**
|
|
@@ -28,11 +29,6 @@ export function useResponsiveDensity(size) {
|
|
|
28
29
|
export function useTypeStep() {
|
|
29
30
|
return useContext(DensityContext).type;
|
|
30
31
|
}
|
|
31
|
-
/** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
|
|
32
|
-
const CONTROL_TEXT = {
|
|
33
|
-
default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
|
|
34
|
-
compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
|
|
35
|
-
};
|
|
36
32
|
/** `CONTROL_TEXT` from the `md` breakpoint up, for a responsive size. */
|
|
37
33
|
const CONTROL_TEXT_MD = {
|
|
38
34
|
default: { sm: "md:text-sm", md: "md:text-base", lg: "md:text-lg" },
|
|
@@ -43,12 +39,8 @@ const CONTROL_TEXT_MD = {
|
|
|
43
39
|
* not zoom the page when it takes the focus.
|
|
44
40
|
*/
|
|
45
41
|
const TOUCH_TEXT = "pointer-coarse:text-base";
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* every control is 26, 38 and 46px tall at both steps, and a `Select`, an `IconButton` and a
|
|
49
|
-
* `DateRangePicker`, whose heights are fixed, line up with it.
|
|
50
|
-
*/
|
|
51
|
-
const CONTROL_LEADING = { sm: "leading-4", md: "leading-5", lg: "leading-6" };
|
|
42
|
+
// `CONTROL_TEXT` and `CONTROL_LEADING` are core's, the one copy both renderers read; a `Select`, an
|
|
43
|
+
// `IconButton` and a `DateRangePicker`, whose heights are fixed, line up with them.
|
|
52
44
|
/** `CONTROL_LEADING` from the `md` breakpoint up, for a responsive size. */
|
|
53
45
|
const CONTROL_LEADING_MD = {
|
|
54
46
|
sm: "md:leading-4",
|
|
@@ -64,14 +56,33 @@ export const controlTextTables = {
|
|
|
64
56
|
};
|
|
65
57
|
/**
|
|
66
58
|
* The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
|
|
67
|
-
* a person types in. A responsive size adds its `md` size from the breakpoint up
|
|
59
|
+
* a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
|
|
60
|
+
* holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
|
|
61
|
+
* wins over an `md:` size under 16px.
|
|
68
62
|
*/
|
|
69
63
|
export function controlText(size, step, entry) {
|
|
70
|
-
|
|
71
|
-
const base = isResponsive(size) ? size.base : size;
|
|
72
|
-
const plain = `${
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
const table = CONTROL_TEXT[step ?? "default"];
|
|
65
|
+
const [base, wide] = isResponsive(size) ? [size.base, size.md] : [size, size];
|
|
66
|
+
const plain = `${table[base]} ${CONTROL_LEADING[base]}`;
|
|
67
|
+
const md = isResponsive(size)
|
|
68
|
+
? ` ${CONTROL_TEXT_MD[step ?? "default"][wide]} ${CONTROL_LEADING_MD[wide]}`
|
|
69
|
+
: "";
|
|
70
|
+
const small = [table[base], table[wide]].some((text) => !/text-(base|lg)/.test(text));
|
|
71
|
+
return `${plain}${md}${entry && small ? ` ${TOUCH_TEXT}` : ""}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The type of a field's words at each step: the label is the type of a `md` control (16px, 14px
|
|
75
|
+
* compact), so a label sits at the size of the text typed under it, and the notes under a control
|
|
76
|
+
* (the hint and the error) are one step below. `line` is the height of a note's first line, for the
|
|
77
|
+
* error's alert icon.
|
|
78
|
+
*/
|
|
79
|
+
const FIELD_TYPE = {
|
|
80
|
+
default: { label: "text-base", note: "text-sm", line: "h-5" },
|
|
81
|
+
compact: { label: "text-sm", note: "text-xs", line: "h-4" },
|
|
82
|
+
};
|
|
83
|
+
/** The field type table, for the data test. */
|
|
84
|
+
export const fieldTypeTable = FIELD_TYPE;
|
|
85
|
+
/** The type of a field's label and its notes at the step in force. */
|
|
86
|
+
export function useFieldType() {
|
|
87
|
+
return FIELD_TYPE[useTypeStep() ?? "default"];
|
|
77
88
|
}
|
package/dist/emptySlot.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** An `EmptyState`'s size: `md` a block with its heading, `sm` one muted line inside a card or a cell. */
|
|
2
3
|
export type EmptySize = "sm" | "md";
|
|
3
4
|
/** The size an `EmptyState` takes: its own, else its slot's, else `md`. */
|
|
4
5
|
export declare function useEmptySize(own: EmptySize | undefined): EmptySize;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode, type ReactPortal, type RefCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Announces a field's error through its page's (or dialog's) one polite live region, not a
|
|
4
|
+
* `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
|
|
5
|
+
* its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
|
|
6
|
+
* error in place and names it in the control's `aria-describedby`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useErrorAnnouncement(error: ReactNode): {
|
|
9
|
+
anchor: RefCallback<HTMLElement>;
|
|
10
|
+
announcement: ReactPortal | null;
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
/** The attribute that marks a field-error region. */
|
|
5
|
+
const REGION = "data-field-errors";
|
|
6
|
+
/**
|
|
7
|
+
* The polite live region for field errors under `host`, made on first use and shared by every field
|
|
8
|
+
* there: a hidden `<div aria-live="polite">` as the host's last child. The host is the open dialog the
|
|
9
|
+
* field sits in, or `body`: a modal dialog makes the rest of the page inert, and a screen reader
|
|
10
|
+
* does not announce a live region in inert content.
|
|
11
|
+
*/
|
|
12
|
+
function errorRegion(host) {
|
|
13
|
+
const found = host.querySelector(`:scope > [${REGION}]`);
|
|
14
|
+
if (found)
|
|
15
|
+
return found;
|
|
16
|
+
const region = document.createElement("div");
|
|
17
|
+
region.setAttribute(REGION, "");
|
|
18
|
+
region.setAttribute("aria-live", "polite");
|
|
19
|
+
region.className = "sr-only";
|
|
20
|
+
host.append(region);
|
|
21
|
+
return region;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Announces a field's error through its page's (or dialog's) one polite live region, not a
|
|
25
|
+
* `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
|
|
26
|
+
* its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
|
|
27
|
+
* error in place and names it in the control's `aria-describedby`.
|
|
28
|
+
*/
|
|
29
|
+
export function useErrorAnnouncement(error) {
|
|
30
|
+
const [region, setRegion] = useState(null);
|
|
31
|
+
const anchor = useCallback((node) => {
|
|
32
|
+
if (node)
|
|
33
|
+
setRegion(errorRegion(node.closest("dialog") ?? document.body));
|
|
34
|
+
}, []);
|
|
35
|
+
return { anchor, announcement: region ? createPortal(_jsx("p", { children: error }), region) : null };
|
|
36
|
+
}
|
package/dist/fieldControl.d.ts
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
export type FieldControlContext = {
|
|
3
3
|
/** The control's id, which the Field's label names. */
|
|
4
4
|
id: string;
|
|
5
|
-
/** The
|
|
5
|
+
/** The ids of the notes the Field draws (the hint, then the error), none when it draws neither. */
|
|
6
6
|
describedBy: string | undefined;
|
|
7
7
|
/** `true` when the Field shows an error. */
|
|
8
8
|
invalid: boolean;
|
|
9
|
+
/** `true` when the Field is `required`. */
|
|
10
|
+
required: boolean;
|
|
9
11
|
};
|
|
10
12
|
export declare const FieldContext: import("react").Context<FieldControlContext | undefined>;
|
|
11
13
|
type ControlA11y = {
|
|
12
14
|
id?: string | undefined;
|
|
13
15
|
"aria-describedby"?: string | undefined;
|
|
14
16
|
"aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling" | undefined;
|
|
17
|
+
required?: boolean | undefined;
|
|
15
18
|
};
|
|
16
19
|
/**
|
|
17
20
|
* Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
|
|
18
21
|
* `Field` the id is the Field's, so its label always names the control; the caller's
|
|
19
22
|
* `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
|
|
20
|
-
*
|
|
23
|
+
* With no error the control says `aria-invalid="false"` outright, so a browser does not read an
|
|
24
|
+
* empty required control as invalid before anyone has typed. A `required` Field makes the control
|
|
25
|
+
* `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
|
|
21
26
|
*/
|
|
22
27
|
export declare function useFieldControl(own: ControlA11y): ControlA11y;
|
|
23
28
|
export {};
|
package/dist/fieldControl.js
CHANGED
|
@@ -4,7 +4,9 @@ export const FieldContext = createContext(undefined);
|
|
|
4
4
|
* Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
|
|
5
5
|
* `Field` the id is the Field's, so its label always names the control; the caller's
|
|
6
6
|
* `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
|
|
7
|
-
*
|
|
7
|
+
* With no error the control says `aria-invalid="false"` outright, so a browser does not read an
|
|
8
|
+
* empty required control as invalid before anyone has typed. A `required` Field makes the control
|
|
9
|
+
* `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
|
|
8
10
|
*/
|
|
9
11
|
export function useFieldControl(own) {
|
|
10
12
|
const field = useContext(FieldContext);
|
|
@@ -13,12 +15,14 @@ export function useFieldControl(own) {
|
|
|
13
15
|
id: own.id,
|
|
14
16
|
"aria-describedby": own["aria-describedby"],
|
|
15
17
|
"aria-invalid": own["aria-invalid"],
|
|
18
|
+
required: own.required,
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
const describedBy = [own["aria-describedby"], field.describedBy].filter(Boolean).join(" ");
|
|
19
22
|
return {
|
|
20
23
|
id: field.id,
|
|
21
24
|
"aria-describedby": describedBy === "" ? undefined : describedBy,
|
|
22
|
-
"aria-invalid": own["aria-invalid"] ??
|
|
25
|
+
"aria-invalid": own["aria-invalid"] ?? field.invalid,
|
|
26
|
+
required: own.required ?? (field.required || undefined),
|
|
23
27
|
};
|
|
24
28
|
}
|
package/dist/fieldWait.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from "react";
|
|
2
|
-
import type { Size } from "./size.js";
|
|
2
|
+
import type { ResponsiveSize, Size } from "./size.js";
|
|
3
3
|
/** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
|
|
4
4
|
export declare function ControlBone({ size }: {
|
|
5
|
-
size?: Size | undefined;
|
|
5
|
+
size?: Size | ResponsiveSize | undefined;
|
|
6
6
|
}): ReactElement;
|
|
7
7
|
/**
|
|
8
8
|
* A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
|
|
@@ -25,6 +25,6 @@ export declare function WaitingField({ own, loadingLabel, label, look, size, att
|
|
|
25
25
|
loadingLabel: string | undefined;
|
|
26
26
|
label: ReactNode;
|
|
27
27
|
look: string;
|
|
28
|
-
size: Size | undefined;
|
|
28
|
+
size: Size | ResponsiveSize | undefined;
|
|
29
29
|
attrs: object;
|
|
30
30
|
}): ReactElement;
|