@slashsuite/ui-react 0.0.0-stage → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/MIGRATING.md +540 -0
- package/README.md +548 -2
- package/dist/AppShell.d.ts +127 -0
- package/dist/AppShell.js +119 -0
- package/dist/AppShellMenu.d.ts +26 -0
- package/dist/AppShellMenu.js +66 -0
- package/dist/Avatar.d.ts +75 -0
- package/dist/Avatar.js +95 -0
- package/dist/AvatarStack.d.ts +31 -0
- package/dist/AvatarStack.js +34 -0
- package/dist/Badge.d.ts +15 -0
- package/dist/Badge.js +15 -0
- package/dist/BottomSheet.d.ts +36 -0
- package/dist/BottomSheet.js +142 -0
- package/dist/Breadcrumbs.d.ts +27 -0
- package/dist/Breadcrumbs.js +29 -0
- package/dist/BulletList.d.ts +18 -0
- package/dist/BulletList.js +18 -0
- package/dist/Button.d.ts +121 -0
- package/dist/Button.js +182 -0
- package/dist/ButtonGroup.d.ts +15 -0
- package/dist/ButtonGroup.js +10 -0
- package/dist/Callout.d.ts +43 -0
- package/dist/Callout.js +45 -0
- package/dist/Card.d.ts +148 -0
- package/dist/Card.js +171 -0
- package/dist/CardBadge.d.ts +7 -0
- package/dist/CardBadge.js +12 -0
- package/dist/CardBody.d.ts +28 -0
- package/dist/CardBody.js +30 -0
- package/dist/CardGrid.d.ts +53 -0
- package/dist/CardGrid.js +52 -0
- package/dist/CardParts.d.ts +40 -0
- package/dist/CardParts.js +41 -0
- package/dist/ChatComposer.d.ts +35 -0
- package/dist/ChatComposer.js +50 -0
- package/dist/ChatMessage.d.ts +26 -0
- package/dist/ChatMessage.js +21 -0
- package/dist/ChatThread.d.ts +25 -0
- package/dist/ChatThread.js +60 -0
- package/dist/Checkbox.d.ts +42 -0
- package/dist/Checkbox.js +63 -0
- package/dist/Chevron.d.ts +5 -0
- package/dist/Chevron.js +6 -0
- package/dist/Cluster.d.ts +70 -0
- package/dist/Cluster.js +47 -0
- package/dist/Code.d.ts +6 -0
- package/dist/Code.js +5 -0
- package/dist/CodeBlock.d.ts +46 -0
- package/dist/CodeBlock.js +21 -0
- package/dist/CodeBody.d.ts +20 -0
- package/dist/CodeBody.js +38 -0
- package/dist/CodeExample.d.ts +25 -0
- package/dist/CodeExample.js +17 -0
- package/dist/CodeText.d.ts +11 -0
- package/dist/CodeText.js +64 -0
- package/dist/ColourSchemeToggle.d.ts +36 -0
- package/dist/ColourSchemeToggle.js +64 -0
- package/dist/Container.d.ts +22 -0
- package/dist/Container.js +26 -0
- package/dist/CopyButton.d.ts +17 -0
- package/dist/CopyButton.js +39 -0
- package/dist/CopyLine.d.ts +9 -0
- package/dist/CopyLine.js +7 -0
- package/dist/DateCalendar.d.ts +23 -0
- package/dist/DateCalendar.js +89 -0
- package/dist/DateField.d.ts +124 -0
- package/dist/DateField.js +111 -0
- package/dist/DateFieldCalendar.d.ts +24 -0
- package/dist/DateFieldCalendar.js +50 -0
- package/dist/DateRangePicker.d.ts +47 -0
- package/dist/DateRangePicker.js +44 -0
- package/dist/Dialog.d.ts +56 -0
- package/dist/Dialog.js +94 -0
- package/dist/Disclosure.d.ts +29 -0
- package/dist/Disclosure.js +23 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +5 -0
- package/dist/DocsLayout.d.ts +69 -0
- package/dist/DocsLayout.js +64 -0
- package/dist/Drawer.d.ts +30 -0
- package/dist/Drawer.js +24 -0
- package/dist/EmptyState.d.ts +47 -0
- package/dist/EmptyState.js +34 -0
- package/dist/Field.d.ts +44 -0
- package/dist/Field.js +51 -0
- package/dist/FieldDialog.d.ts +26 -0
- package/dist/FieldDialog.js +31 -0
- package/dist/Fieldset.d.ts +21 -0
- package/dist/Fieldset.js +22 -0
- package/dist/FileDrop.d.ts +17 -0
- package/dist/FileDrop.js +14 -0
- package/dist/FormRow.d.ts +46 -0
- package/dist/FormRow.js +39 -0
- package/dist/Hero.d.ts +23 -0
- package/dist/Hero.js +28 -0
- package/dist/Icon.d.ts +40 -0
- package/dist/Icon.js +30 -0
- package/dist/IconButton.d.ts +72 -0
- package/dist/IconButton.js +65 -0
- package/dist/Image.d.ts +58 -0
- package/dist/Image.js +69 -0
- package/dist/InlineEdit.d.ts +22 -0
- package/dist/InlineEdit.js +60 -0
- package/dist/Input.d.ts +40 -0
- package/dist/Input.js +42 -0
- package/dist/InputShell.d.ts +24 -0
- package/dist/InputShell.js +40 -0
- package/dist/Kbd.d.ts +6 -0
- package/dist/Kbd.js +5 -0
- package/dist/KeyValueList.d.ts +34 -0
- package/dist/KeyValueList.js +35 -0
- package/dist/Lightbox.d.ts +45 -0
- package/dist/Lightbox.js +46 -0
- package/dist/ListRow.d.ts +26 -0
- package/dist/ListRow.js +151 -0
- package/dist/Markdown.d.ts +11 -0
- package/dist/Markdown.js +49 -0
- package/dist/MediaTile.d.ts +66 -0
- package/dist/MediaTile.js +50 -0
- package/dist/Menu.d.ts +64 -0
- package/dist/Menu.js +86 -0
- package/dist/MetaList.d.ts +23 -0
- package/dist/MetaList.js +20 -0
- package/dist/Morph.d.ts +41 -0
- package/dist/Morph.js +107 -0
- package/dist/NavigationProgress.d.ts +20 -0
- package/dist/NavigationProgress.js +26 -0
- package/dist/OutlineRegion.d.ts +60 -0
- package/dist/OutlineRegion.js +51 -0
- package/dist/PageFade.d.ts +30 -0
- package/dist/PageFade.js +46 -0
- package/dist/PageHeader.d.ts +26 -0
- package/dist/PageHeader.js +18 -0
- package/dist/PageLayouts.d.ts +100 -0
- package/dist/PageLayouts.js +78 -0
- package/dist/Pagination.d.ts +38 -0
- package/dist/Pagination.js +65 -0
- package/dist/Pill.d.ts +79 -0
- package/dist/Pill.js +121 -0
- package/dist/ProgressBar.d.ts +47 -0
- package/dist/ProgressBar.js +47 -0
- package/dist/RadioGroup.d.ts +55 -0
- package/dist/RadioGroup.js +53 -0
- package/dist/ScrollStrip.d.ts +21 -0
- package/dist/ScrollStrip.js +12 -0
- package/dist/SearchInput.d.ts +9 -0
- package/dist/SearchInput.js +55 -0
- package/dist/Section.d.ts +93 -0
- package/dist/Section.js +55 -0
- package/dist/SegmentedControl.d.ts +47 -0
- package/dist/SegmentedControl.js +78 -0
- package/dist/Select.d.ts +28 -0
- package/dist/Select.js +19 -0
- package/dist/Show.d.ts +33 -0
- package/dist/Show.js +27 -0
- package/dist/SideColumn.d.ts +50 -0
- package/dist/SideColumn.js +45 -0
- package/dist/SidebarLayout.d.ts +32 -0
- package/dist/SidebarLayout.js +77 -0
- package/dist/SiteFooter.d.ts +31 -0
- package/dist/SiteFooter.js +24 -0
- package/dist/SiteSearch.d.ts +40 -0
- package/dist/SiteSearch.js +150 -0
- package/dist/SortableList.d.ts +86 -0
- package/dist/SortableList.js +191 -0
- package/dist/SplitBar.d.ts +29 -0
- package/dist/SplitBar.js +22 -0
- package/dist/Stack.d.ts +114 -0
- package/dist/Stack.js +76 -0
- package/dist/StackedBar.d.ts +64 -0
- package/dist/StackedBar.js +58 -0
- package/dist/StatTile.d.ts +33 -0
- package/dist/StatTile.js +44 -0
- package/dist/StatusPages.d.ts +49 -0
- package/dist/StatusPages.js +63 -0
- package/dist/Steps.d.ts +29 -0
- package/dist/Steps.js +43 -0
- package/dist/StickyBar.d.ts +12 -0
- package/dist/StickyBar.js +10 -0
- package/dist/Switch.d.ts +56 -0
- package/dist/Switch.js +91 -0
- package/dist/Table.d.ts +92 -0
- package/dist/Table.js +92 -0
- package/dist/TableCells.d.ts +97 -0
- package/dist/TableCells.js +104 -0
- package/dist/TableEditCell.d.ts +31 -0
- package/dist/TableEditCell.js +17 -0
- package/dist/TableExpandCell.d.ts +25 -0
- package/dist/TableExpandCell.js +15 -0
- package/dist/Tabs.d.ts +38 -0
- package/dist/Tabs.js +46 -0
- package/dist/TextLink.d.ts +51 -0
- package/dist/TextLink.js +38 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.js +11 -0
- package/dist/Timeline.d.ts +31 -0
- package/dist/Timeline.js +38 -0
- package/dist/ToastRegion.d.ts +44 -0
- package/dist/ToastRegion.js +37 -0
- package/dist/Tooltip.d.ts +46 -0
- package/dist/Tooltip.js +181 -0
- package/dist/TrendChart.d.ts +36 -0
- package/dist/TrendChart.js +58 -0
- package/dist/Video.d.ts +13 -0
- package/dist/Video.js +9 -0
- package/dist/blocked.d.ts +31 -0
- package/dist/blocked.js +31 -0
- package/dist/cardContext.d.ts +8 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardWait.d.ts +13 -0
- package/dist/cardWait.js +16 -0
- package/dist/colourScheme.d.ts +22 -0
- package/dist/colourScheme.js +53 -0
- package/dist/control.d.ts +29 -0
- package/dist/control.js +37 -0
- package/dist/copyScript.d.ts +13 -0
- package/dist/copyScript.js +13 -0
- package/dist/cx.d.ts +19 -0
- package/dist/cx.js +21 -0
- package/dist/density.d.ts +38 -0
- package/dist/density.js +77 -0
- package/dist/emptySlot.d.ts +11 -0
- package/dist/emptySlot.js +16 -0
- package/dist/fieldControl.d.ts +23 -0
- package/dist/fieldControl.js +24 -0
- package/dist/fieldWait.d.ts +30 -0
- package/dist/fieldWait.js +27 -0
- package/dist/foldedColumn.d.ts +18 -0
- package/dist/foldedColumn.js +51 -0
- package/dist/headingLevel.d.ts +10 -0
- package/dist/headingLevel.js +18 -0
- package/dist/highlight.d.ts +18 -0
- package/dist/highlight.js +306 -0
- package/dist/highlightConsole.d.ts +9 -0
- package/dist/highlightConsole.js +42 -0
- package/dist/highlightHtml.d.ts +7 -0
- package/dist/highlightHtml.js +132 -0
- package/dist/highlightKit.d.ts +16 -0
- package/dist/highlightKit.js +23 -0
- package/dist/highlightYaml.d.ts +3 -0
- package/dist/highlightYaml.js +143 -0
- package/dist/icons.d.ts +16 -0
- package/dist/icons.js +108 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +92 -0
- package/dist/isoDate.d.ts +5 -0
- package/dist/isoDate.js +16 -0
- package/dist/labelWords.d.ts +20 -0
- package/dist/labelWords.js +28 -0
- package/dist/layoutWait.d.ts +15 -0
- package/dist/layoutWait.js +18 -0
- package/dist/link.d.ts +82 -0
- package/dist/link.js +68 -0
- package/dist/listRowProps.d.ts +108 -0
- package/dist/listRowProps.js +1 -0
- package/dist/listRowWait.d.ts +6 -0
- package/dist/listRowWait.js +14 -0
- package/dist/modal.d.ts +25 -0
- package/dist/modal.js +61 -0
- package/dist/navFold.d.ts +15 -0
- package/dist/navFold.js +46 -0
- package/dist/pillTip.d.ts +8 -0
- package/dist/pillTip.js +25 -0
- package/dist/props.d.ts +26 -0
- package/dist/props.js +14 -0
- package/dist/scrollEdges.d.ts +12 -0
- package/dist/scrollEdges.js +40 -0
- package/dist/scrollStop.d.ts +32 -0
- package/dist/scrollStop.js +79 -0
- package/dist/sheetSnap.d.ts +27 -0
- package/dist/sheetSnap.js +45 -0
- package/dist/shownDate.d.ts +88 -0
- package/dist/shownDate.js +186 -0
- package/dist/size.d.ts +45 -0
- package/dist/size.js +12 -0
- package/dist/skeleton.d.ts +83 -0
- package/dist/skeleton.js +88 -0
- package/dist/stackGap.d.ts +9 -0
- package/dist/stackGap.js +16 -0
- package/dist/stickyColumn.d.ts +38 -0
- package/dist/stickyColumn.js +38 -0
- package/dist/switcher.d.ts +93 -0
- package/dist/switcher.js +78 -0
- package/dist/tableColumns.d.ts +31 -0
- package/dist/tableColumns.js +72 -0
- package/dist/tableEmpty.d.ts +15 -0
- package/dist/tableEmpty.js +26 -0
- package/dist/tableRow.d.ts +67 -0
- package/dist/tableRow.js +49 -0
- package/dist/tableSort.d.ts +22 -0
- package/dist/tableSort.js +19 -0
- package/dist/textBox.d.ts +10 -0
- package/dist/textBox.js +23 -0
- package/dist/tone.d.ts +11 -0
- package/dist/tone.js +1 -0
- package/dist/trend.d.ts +26 -0
- package/dist/trend.js +64 -0
- package/dist/typography.d.ts +203 -0
- package/dist/typography.js +242 -0
- package/dist/useImageFailed.d.ts +19 -0
- package/dist/useImageFailed.js +21 -0
- package/package.json +84 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Marks a box that scrolls with which of its edges still has content past it, so the layout can fade
|
|
4
|
+
* them: `data-more-start` (scrolled away from the start), `data-more-end` (more to scroll to) and
|
|
5
|
+
* `data-more` for either. `axis` is the way it scrolls: `x` (a row) or `y` (a column). A box that
|
|
6
|
+
* fits carries none. The attributes only carry state; a class turns them into a `mask-image`, so the
|
|
7
|
+
* fade follows any theme. `element` is the box once it is mounted (null before, and then nothing
|
|
8
|
+
* happens).
|
|
9
|
+
*
|
|
10
|
+
* The effect runs after every render on purpose: the box's children may have changed, and each one
|
|
11
|
+
* needs observing so a change in its size is noticed.
|
|
12
|
+
*/
|
|
13
|
+
export function useScrollEdges(element, axis) {
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!element)
|
|
16
|
+
return undefined;
|
|
17
|
+
const el = element;
|
|
18
|
+
const update = () => {
|
|
19
|
+
const [position, scrollSize, clientSize] = axis === "x"
|
|
20
|
+
? [el.scrollLeft, el.scrollWidth, el.clientWidth]
|
|
21
|
+
: [el.scrollTop, el.scrollHeight, el.clientHeight];
|
|
22
|
+
const start = position > 1;
|
|
23
|
+
const end = scrollSize - clientSize - position > 1;
|
|
24
|
+
el.toggleAttribute("data-more-start", start);
|
|
25
|
+
el.toggleAttribute("data-more-end", end);
|
|
26
|
+
el.toggleAttribute("data-more", start || end);
|
|
27
|
+
};
|
|
28
|
+
update();
|
|
29
|
+
el.addEventListener("scroll", update, { passive: true });
|
|
30
|
+
// jsdom (a consumer's own tests) has no ResizeObserver.
|
|
31
|
+
const resize = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(update);
|
|
32
|
+
resize?.observe(el);
|
|
33
|
+
for (const child of el.children)
|
|
34
|
+
resize?.observe(child);
|
|
35
|
+
return () => {
|
|
36
|
+
el.removeEventListener("scroll", update);
|
|
37
|
+
resize?.disconnect();
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type HTMLAttributes } from "react";
|
|
2
|
+
/** Anything the keyboard can reach on its own. */
|
|
3
|
+
export declare const TABBABLE = ":is(a[href], button, input:not([type=\"hidden\"]), select, textarea, summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable=\"false\"]), [tabindex]):not([disabled], [tabindex=\"-1\"])";
|
|
4
|
+
/**
|
|
5
|
+
* The keyboard side of a box that scrolls (a `Dialog`'s body, a sticky column, a code strip): a
|
|
6
|
+
* box that overflows along `axis` and holds nothing the keyboard can reach has no way to be
|
|
7
|
+
* scrolled from the keyboard, so it takes a tab stop (axe's `scrollable-region-focusable`). A box
|
|
8
|
+
* that holds a link, a field or a button needs none: the keyboard scrolls it by moving focus
|
|
9
|
+
* inside. `attach` is the box's `ref`; `element` is the box once it is mounted; `stop` is whether
|
|
10
|
+
* it takes the tab stop. Attach it to nothing and `stop` stays false. `axis` is the way the box
|
|
11
|
+
* scrolls: "y" (down, the default) or "x" (sideways); overflow the other way is not measured,
|
|
12
|
+
* since the box does not scroll that way. `measured` is false until the box has been measured once
|
|
13
|
+
* and true after: a page rendered to HTML and never hydrated is never measured, and neither is a
|
|
14
|
+
* box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub).
|
|
15
|
+
*/
|
|
16
|
+
export declare function useScrollStop(axis?: "x" | "y"): {
|
|
17
|
+
element: HTMLElement | null;
|
|
18
|
+
attach: (el: HTMLDivElement | null) => void;
|
|
19
|
+
stop: boolean;
|
|
20
|
+
measured: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The props a scroller takes while it holds the tab stop: focusable, ringed and, when the column
|
|
24
|
+
* has a name, a group of that name so a screen reader says what the stop is. Nothing otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export declare function scrollStopProps(stop: boolean, name?: {
|
|
27
|
+
label?: string | undefined;
|
|
28
|
+
labelledBy?: string | undefined;
|
|
29
|
+
}): {
|
|
30
|
+
props: HTMLAttributes<HTMLDivElement>;
|
|
31
|
+
ring: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { focusRing } from "./cx.js";
|
|
3
|
+
/** Anything the keyboard can reach on its own. */
|
|
4
|
+
export const TABBABLE = ':is(a[href], button, input:not([type="hidden"]), select, textarea, summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable="false"]), [tabindex]):not([disabled], [tabindex="-1"])';
|
|
5
|
+
/** Whether something in `scroller` is on screen and reachable by the keyboard. */
|
|
6
|
+
function holdsTabbable(scroller) {
|
|
7
|
+
for (const el of scroller.querySelectorAll(TABBABLE)) {
|
|
8
|
+
// A `display: none` summary (a folded column's, from its breakpoint up) is not a tab stop.
|
|
9
|
+
// jsdom (a consumer's own tests) has no `checkVisibility`; there everything counts.
|
|
10
|
+
if (typeof el.checkVisibility !== "function" || el.checkVisibility())
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The keyboard side of a box that scrolls (a `Dialog`'s body, a sticky column, a code strip): a
|
|
17
|
+
* box that overflows along `axis` and holds nothing the keyboard can reach has no way to be
|
|
18
|
+
* scrolled from the keyboard, so it takes a tab stop (axe's `scrollable-region-focusable`). A box
|
|
19
|
+
* that holds a link, a field or a button needs none: the keyboard scrolls it by moving focus
|
|
20
|
+
* inside. `attach` is the box's `ref`; `element` is the box once it is mounted; `stop` is whether
|
|
21
|
+
* it takes the tab stop. Attach it to nothing and `stop` stays false. `axis` is the way the box
|
|
22
|
+
* scrolls: "y" (down, the default) or "x" (sideways); overflow the other way is not measured,
|
|
23
|
+
* since the box does not scroll that way. `measured` is false until the box has been measured once
|
|
24
|
+
* and true after: a page rendered to HTML and never hydrated is never measured, and neither is a
|
|
25
|
+
* box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub).
|
|
26
|
+
*/
|
|
27
|
+
export function useScrollStop(axis = "y") {
|
|
28
|
+
const [element, setElement] = useState(null);
|
|
29
|
+
const [stop, setStop] = useState(false);
|
|
30
|
+
const [measured, setMeasured] = useState(false);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
// jsdom (a consumer's own tests) has no ResizeObserver.
|
|
33
|
+
if (!element || typeof ResizeObserver === "undefined")
|
|
34
|
+
return undefined;
|
|
35
|
+
const overflows = () => axis === "y"
|
|
36
|
+
? element.scrollHeight > element.clientHeight
|
|
37
|
+
: element.scrollWidth > element.clientWidth;
|
|
38
|
+
const measure = () => {
|
|
39
|
+
setStop(overflows() && !holdsTabbable(element));
|
|
40
|
+
setMeasured(true);
|
|
41
|
+
};
|
|
42
|
+
// Each observer reports once when it starts, and again when the box is resized, its content
|
|
43
|
+
// changes or something in it becomes (un)reachable by the keyboard.
|
|
44
|
+
const resize = new ResizeObserver(measure);
|
|
45
|
+
resize.observe(element);
|
|
46
|
+
for (const child of element.children)
|
|
47
|
+
resize.observe(child);
|
|
48
|
+
const change = new MutationObserver(measure);
|
|
49
|
+
change.observe(element, {
|
|
50
|
+
childList: true,
|
|
51
|
+
subtree: true,
|
|
52
|
+
characterData: true,
|
|
53
|
+
attributeFilter: ["disabled", "tabindex", "href", "type", "contenteditable", "open"],
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
resize.disconnect();
|
|
57
|
+
change.disconnect();
|
|
58
|
+
};
|
|
59
|
+
}, [element, axis]);
|
|
60
|
+
return { element, attach: setElement, stop: stop && element !== null, measured };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The props a scroller takes while it holds the tab stop: focusable, ringed and, when the column
|
|
64
|
+
* has a name, a group of that name so a screen reader says what the stop is. Nothing otherwise.
|
|
65
|
+
*/
|
|
66
|
+
export function scrollStopProps(stop, name = {}) {
|
|
67
|
+
if (!stop)
|
|
68
|
+
return { props: {}, ring: "" };
|
|
69
|
+
const named = name.label !== undefined || name.labelledBy !== undefined;
|
|
70
|
+
return {
|
|
71
|
+
props: {
|
|
72
|
+
tabIndex: 0,
|
|
73
|
+
...(named ? { role: "group" } : {}),
|
|
74
|
+
...(name.label !== undefined ? { "aria-label": name.label } : {}),
|
|
75
|
+
...(name.labelledBy !== undefined ? { "aria-labelledby": name.labelledBy } : {}),
|
|
76
|
+
},
|
|
77
|
+
ring: focusRing,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A snap height: a number from 0 to 1 is a share of the parent's height, a `"120px"` string is pixels. */
|
|
2
|
+
export type BottomSheetSnap = number | `${number}px`;
|
|
3
|
+
/** A release at this speed or faster (px per ms, by `PointerEvent.timeStamp`) is a fling. */
|
|
4
|
+
export declare const FLING = 0.5;
|
|
5
|
+
/** The snap's height in CSS, which the server render and a page without JavaScript show as is. */
|
|
6
|
+
export declare function snapCss(snap: BottomSheetSnap): string;
|
|
7
|
+
/**
|
|
8
|
+
* The snap's height in pixels against a parent `parent` px tall, held at the parent's height. A
|
|
9
|
+
* parent with no height (not laid out yet, or jsdom) holds nothing back, so a pixel snap reads as given.
|
|
10
|
+
*/
|
|
11
|
+
export declare function snapPx(snap: BottomSheetSnap, parent: number): number;
|
|
12
|
+
/** One pointer sample of a drag: the sheet's height and the event's `timeStamp`. */
|
|
13
|
+
export type SheetSample = {
|
|
14
|
+
height: number;
|
|
15
|
+
t: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The release velocity in px per ms, up positive: the last two samples' change in height over their
|
|
19
|
+
* change in time, or 0 when the last one is more than 100ms before the release (the pointer stopped).
|
|
20
|
+
*/
|
|
21
|
+
export declare function releaseVelocity(samples: readonly SheetSample[], releasedAt: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* The snap a released drag rests at. The nearest by distance (a tie goes to the lower); a fling
|
|
24
|
+
* moves it at least one snap from `startSnap` in its direction, held to the ends. A fling only adds
|
|
25
|
+
* a step, never takes one away, so a long drag lands on the same snap at any speed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function restingSnap(heights: readonly number[], height: number, velocity: number, startSnap: number): number;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** A release at this speed or faster (px per ms, by `PointerEvent.timeStamp`) is a fling. */
|
|
2
|
+
export const FLING = 0.5;
|
|
3
|
+
/** A last sample older than this (ms) before the release means the pointer stopped: no fling. */
|
|
4
|
+
const STALE = 100;
|
|
5
|
+
/** The snap's height in CSS, which the server render and a page without JavaScript show as is. */
|
|
6
|
+
export function snapCss(snap) {
|
|
7
|
+
return typeof snap === "number" ? `${snap * 100}%` : snap;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The snap's height in pixels against a parent `parent` px tall, held at the parent's height. A
|
|
11
|
+
* parent with no height (not laid out yet, or jsdom) holds nothing back, so a pixel snap reads as given.
|
|
12
|
+
*/
|
|
13
|
+
export function snapPx(snap, parent) {
|
|
14
|
+
const px = typeof snap === "number" ? snap * parent : Number.parseFloat(snap);
|
|
15
|
+
return parent > 0 ? Math.min(px, parent) : px;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The release velocity in px per ms, up positive: the last two samples' change in height over their
|
|
19
|
+
* change in time, or 0 when the last one is more than 100ms before the release (the pointer stopped).
|
|
20
|
+
*/
|
|
21
|
+
export function releaseVelocity(samples, releasedAt) {
|
|
22
|
+
const last = samples.at(-1);
|
|
23
|
+
const before = samples.at(-2);
|
|
24
|
+
if (!last || !before || last.t <= before.t || releasedAt - last.t > STALE)
|
|
25
|
+
return 0;
|
|
26
|
+
return (last.height - before.height) / (last.t - before.t);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The snap a released drag rests at. The nearest by distance (a tie goes to the lower); a fling
|
|
30
|
+
* moves it at least one snap from `startSnap` in its direction, held to the ends. A fling only adds
|
|
31
|
+
* a step, never takes one away, so a long drag lands on the same snap at any speed.
|
|
32
|
+
*/
|
|
33
|
+
export function restingSnap(heights, height, velocity, startSnap) {
|
|
34
|
+
let nearest = 0;
|
|
35
|
+
heights.forEach((h, i) => {
|
|
36
|
+
if (Math.abs(h - height) < Math.abs((heights[nearest] ?? 0) - height))
|
|
37
|
+
nearest = i;
|
|
38
|
+
});
|
|
39
|
+
const last = heights.length - 1;
|
|
40
|
+
if (velocity >= FLING)
|
|
41
|
+
return Math.min(last, Math.max(nearest, startSnap + 1));
|
|
42
|
+
if (velocity <= -FLING)
|
|
43
|
+
return Math.max(0, Math.min(nearest, startSnap - 1));
|
|
44
|
+
return nearest;
|
|
45
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { CalendarDate } from "@internationalized/date";
|
|
2
|
+
import { type FocusEvent, type ReactElement } from "react";
|
|
3
|
+
import type { FieldProps, Read } from "./DateField.js";
|
|
4
|
+
type ValueKeys = "value" | "defaultValue" | "onChange" | "minValue" | "maxValue" | "isRequired";
|
|
5
|
+
/** The value props, each of which may be passed as `undefined`. */
|
|
6
|
+
type ValueProps = {
|
|
7
|
+
[K in ValueKeys]?: (FieldProps & {
|
|
8
|
+
isRequired?: boolean;
|
|
9
|
+
})[K] | undefined;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The value the field reports is always what it shows: the typed date when it is complete, exists
|
|
13
|
+
* and is within min/max, else `null`. Two parts of React Aria disagree with that, so this owns both:
|
|
14
|
+
*
|
|
15
|
+
* - **The value.** React Aria keeps its last valid date behind an impossible or partly cleared
|
|
16
|
+
* display, and reports an out-of-range one. So the consumer's `onChange` is fired from what the
|
|
17
|
+
* segments read, once per change: a valid date turning invalid reports `null`. React Aria itself
|
|
18
|
+
* is controlled by `inner`, so a parent holding that `null` does not wipe the typed segments; a
|
|
19
|
+
* `value` the parent sets that differs from the last report is passed through, and not reported
|
|
20
|
+
* back. Because React Aria's own value goes stale, `validate` checks `isRequired` against the
|
|
21
|
+
* segments: a partly filled required field blocks the form.
|
|
22
|
+
* - **Keeping an impossible date.** When focus leaves a complete field, React Aria moves an
|
|
23
|
+
* impossible day to the month's last and reports that date (`confirmPlaceholder`); it skips this
|
|
24
|
+
* for a read-only field. So while the typed date is impossible, the field is read-only for exactly
|
|
25
|
+
* the blur that leaves it: `onBlurCapture` on a wrapper of the input turns it on before React
|
|
26
|
+
* Aria's blur handler runs, and the field's own `onBlur`, which runs after it, turns it off again.
|
|
27
|
+
*
|
|
28
|
+
* `shown` (`YYYY-MM-DD` or `""`) is what the hidden `name` input posts.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useShownDate(props: ValueProps): {
|
|
31
|
+
inner: CalendarDate | null;
|
|
32
|
+
setInner: import("react").Dispatch<import("react").SetStateAction<CalendarDate | null>>;
|
|
33
|
+
shown: string;
|
|
34
|
+
impossible: string | null;
|
|
35
|
+
onRead: (next: Read) => void;
|
|
36
|
+
validate: () => "Enter the whole date." | null;
|
|
37
|
+
leaving: boolean;
|
|
38
|
+
onBlurCapture: (event: FocusEvent<HTMLElement>) => void;
|
|
39
|
+
onLeft: () => void;
|
|
40
|
+
};
|
|
41
|
+
/** A from and to date, both days. */
|
|
42
|
+
export type ShownRange = {
|
|
43
|
+
start: CalendarDate;
|
|
44
|
+
end: CalendarDate;
|
|
45
|
+
};
|
|
46
|
+
type RangeProps = {
|
|
47
|
+
value?: ShownRange | null | undefined;
|
|
48
|
+
defaultValue?: ShownRange | null | undefined;
|
|
49
|
+
onChange?: ((range: ShownRange | null) => void) | undefined;
|
|
50
|
+
minValue?: FieldProps["minValue"] | undefined;
|
|
51
|
+
maxValue?: FieldProps["maxValue"] | undefined;
|
|
52
|
+
isRequired?: boolean | undefined;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* `useShownDate` for a range: each side's segments are read on their own, and the range reported is
|
|
56
|
+
* what both sides show, once both are complete, real dates within min/max and the start is on or
|
|
57
|
+
* before the end; otherwise `null`. Each side keeps an impossible day on blur with its own `leaving`
|
|
58
|
+
* state, so one side is read-only only for the blur that leaves it. `problem` is the message for an
|
|
59
|
+
* impossible day, naming its side, or for an end before the start. `startShown` and `endShown`, what
|
|
60
|
+
* the hidden inputs post, are `""` while there is no range.
|
|
61
|
+
*/
|
|
62
|
+
export declare function useShownRange(props: RangeProps): {
|
|
63
|
+
inner: ShownRange | null;
|
|
64
|
+
setInner: import("react").Dispatch<import("react").SetStateAction<ShownRange | null>>;
|
|
65
|
+
startShown: string;
|
|
66
|
+
endShown: string;
|
|
67
|
+
problem: string | null;
|
|
68
|
+
onReadStart: (next: Read) => void;
|
|
69
|
+
onReadEnd: (next: Read) => void;
|
|
70
|
+
validate: () => "Enter the whole date." | null;
|
|
71
|
+
start: {
|
|
72
|
+
leaving: boolean;
|
|
73
|
+
onBlurCapture: (event: FocusEvent<HTMLElement>) => void;
|
|
74
|
+
onLeft: () => void;
|
|
75
|
+
};
|
|
76
|
+
end: {
|
|
77
|
+
leaving: boolean;
|
|
78
|
+
onBlurCapture: (event: FocusEvent<HTMLElement>) => void;
|
|
79
|
+
onLeft: () => void;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
/** The hidden input a form posts under `name`: the shown date as `YYYY-MM-DD`, or `""`. */
|
|
83
|
+
export declare function ShownInput({ name, shown, isDisabled, }: {
|
|
84
|
+
name: string | undefined;
|
|
85
|
+
shown: string;
|
|
86
|
+
isDisabled: boolean | undefined;
|
|
87
|
+
}): ReactElement | null;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
3
|
+
import { flushSync } from "react-dom";
|
|
4
|
+
import { fromISODate, toISODate } from "./isoDate.js";
|
|
5
|
+
/** `iso` when it is a date within min/max, else `""`. */
|
|
6
|
+
function withinRange(iso, { minValue, maxValue }) {
|
|
7
|
+
const date = fromISODate(iso);
|
|
8
|
+
if (!date)
|
|
9
|
+
return "";
|
|
10
|
+
if (minValue && date.compare(minValue) < 0)
|
|
11
|
+
return "";
|
|
12
|
+
if (maxValue && date.compare(maxValue) > 0)
|
|
13
|
+
return "";
|
|
14
|
+
return iso;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The value the field reports is always what it shows: the typed date when it is complete, exists
|
|
18
|
+
* and is within min/max, else `null`. Two parts of React Aria disagree with that, so this owns both:
|
|
19
|
+
*
|
|
20
|
+
* - **The value.** React Aria keeps its last valid date behind an impossible or partly cleared
|
|
21
|
+
* display, and reports an out-of-range one. So the consumer's `onChange` is fired from what the
|
|
22
|
+
* segments read, once per change: a valid date turning invalid reports `null`. React Aria itself
|
|
23
|
+
* is controlled by `inner`, so a parent holding that `null` does not wipe the typed segments; a
|
|
24
|
+
* `value` the parent sets that differs from the last report is passed through, and not reported
|
|
25
|
+
* back. Because React Aria's own value goes stale, `validate` checks `isRequired` against the
|
|
26
|
+
* segments: a partly filled required field blocks the form.
|
|
27
|
+
* - **Keeping an impossible date.** When focus leaves a complete field, React Aria moves an
|
|
28
|
+
* impossible day to the month's last and reports that date (`confirmPlaceholder`); it skips this
|
|
29
|
+
* for a read-only field. So while the typed date is impossible, the field is read-only for exactly
|
|
30
|
+
* the blur that leaves it: `onBlurCapture` on a wrapper of the input turns it on before React
|
|
31
|
+
* Aria's blur handler runs, and the field's own `onBlur`, which runs after it, turns it off again.
|
|
32
|
+
*
|
|
33
|
+
* `shown` (`YYYY-MM-DD` or `""`) is what the hidden `name` input posts.
|
|
34
|
+
*/
|
|
35
|
+
export function useShownDate(props) {
|
|
36
|
+
const { value, defaultValue, onChange, isRequired } = props;
|
|
37
|
+
const [inner, setInner] = useState(value ?? defaultValue ?? null);
|
|
38
|
+
const [read, setRead] = useState({
|
|
39
|
+
typed: toISODate(inner),
|
|
40
|
+
impossible: null,
|
|
41
|
+
partial: false,
|
|
42
|
+
});
|
|
43
|
+
const side = useLeaving(read.impossible);
|
|
44
|
+
const shown = withinRange(read.typed, props);
|
|
45
|
+
const reported = useRef(shown);
|
|
46
|
+
const report = useRef(onChange);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
report.current = onChange;
|
|
49
|
+
});
|
|
50
|
+
const given = value === undefined ? undefined : toISODate(value);
|
|
51
|
+
const givenShown = withinRange(given ?? "", props);
|
|
52
|
+
const lastGiven = useRef(given);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (given === lastGiven.current)
|
|
55
|
+
return;
|
|
56
|
+
lastGiven.current = given;
|
|
57
|
+
if (given === undefined || given === reported.current)
|
|
58
|
+
return;
|
|
59
|
+
reported.current = givenShown;
|
|
60
|
+
setInner(fromISODate(given));
|
|
61
|
+
}, [given, givenShown]);
|
|
62
|
+
const onRead = useCallback((next) => setRead(next), []);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (shown === reported.current)
|
|
65
|
+
return;
|
|
66
|
+
reported.current = shown;
|
|
67
|
+
report.current?.(fromISODate(shown));
|
|
68
|
+
}, [shown]);
|
|
69
|
+
return {
|
|
70
|
+
inner,
|
|
71
|
+
setInner,
|
|
72
|
+
shown,
|
|
73
|
+
impossible: read.impossible,
|
|
74
|
+
onRead,
|
|
75
|
+
validate: () => (isRequired && read.partial ? "Enter the whole date." : null),
|
|
76
|
+
...side,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The `leaving` read-only trick for one group of segments (see `useShownDate`): `onBlurCapture` goes
|
|
81
|
+
* on a wrapper of the input and `onLeft` is the field's own `onBlur`.
|
|
82
|
+
*/
|
|
83
|
+
function useLeaving(impossible) {
|
|
84
|
+
const [leaving, setLeaving] = useState(false);
|
|
85
|
+
return {
|
|
86
|
+
leaving,
|
|
87
|
+
onBlurCapture: (event) => {
|
|
88
|
+
if (impossible && !event.currentTarget.contains(event.relatedTarget)) {
|
|
89
|
+
flushSync(() => setLeaving(true));
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
onLeft: () => setLeaving(false),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const blank = { typed: "", impossible: null, partial: false };
|
|
96
|
+
/** `"start/end"` when both are dates and start is on or before end, else `""`. */
|
|
97
|
+
function rangeKey(start, end) {
|
|
98
|
+
return start && end && start <= end ? `${start}/${end}` : "";
|
|
99
|
+
}
|
|
100
|
+
function fromKey(key) {
|
|
101
|
+
const [start, end] = key.split("/").map(fromISODate);
|
|
102
|
+
return start && end ? { start, end } : null;
|
|
103
|
+
}
|
|
104
|
+
/** The given range as `"start/end"`, each side kept only within `bounds` when they are passed. */
|
|
105
|
+
function givenKey(value, bounds) {
|
|
106
|
+
if (!value)
|
|
107
|
+
return "";
|
|
108
|
+
const [start, end] = [toISODate(value.start), toISODate(value.end)];
|
|
109
|
+
return bounds
|
|
110
|
+
? rangeKey(withinRange(start, bounds), withinRange(end, bounds))
|
|
111
|
+
: `${start}/${end}`;
|
|
112
|
+
}
|
|
113
|
+
/** An impossible day, naming its side, or else an end before the start; `null` for neither. */
|
|
114
|
+
function problemOf(start, end, startShown, endShown) {
|
|
115
|
+
const impossible = [
|
|
116
|
+
start.impossible && `Start date: ${start.impossible}`,
|
|
117
|
+
end.impossible && `End date: ${end.impossible}`,
|
|
118
|
+
].filter(Boolean);
|
|
119
|
+
if (impossible.length > 0)
|
|
120
|
+
return impossible.join(" ");
|
|
121
|
+
if (startShown && endShown && startShown > endShown) {
|
|
122
|
+
return "The end date is before the start date.";
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* `useShownDate` for a range: each side's segments are read on their own, and the range reported is
|
|
128
|
+
* what both sides show, once both are complete, real dates within min/max and the start is on or
|
|
129
|
+
* before the end; otherwise `null`. Each side keeps an impossible day on blur with its own `leaving`
|
|
130
|
+
* state, so one side is read-only only for the blur that leaves it. `problem` is the message for an
|
|
131
|
+
* impossible day, naming its side, or for an end before the start. `startShown` and `endShown`, what
|
|
132
|
+
* the hidden inputs post, are `""` while there is no range.
|
|
133
|
+
*/
|
|
134
|
+
export function useShownRange(props) {
|
|
135
|
+
const { value, defaultValue, onChange, isRequired } = props;
|
|
136
|
+
const [inner, setInner] = useState(value ?? defaultValue ?? null);
|
|
137
|
+
const [start, setStart] = useState({ ...blank, typed: toISODate(inner?.start) });
|
|
138
|
+
const [end, setEnd] = useState({ ...blank, typed: toISODate(inner?.end) });
|
|
139
|
+
const onReadStart = useCallback((next) => setStart(next), []);
|
|
140
|
+
const onReadEnd = useCallback((next) => setEnd(next), []);
|
|
141
|
+
const startSide = useLeaving(start.impossible);
|
|
142
|
+
const endSide = useLeaving(end.impossible);
|
|
143
|
+
const startShown = withinRange(start.typed, props);
|
|
144
|
+
const endShown = withinRange(end.typed, props);
|
|
145
|
+
const shown = rangeKey(startShown, endShown);
|
|
146
|
+
const problem = problemOf(start, end, startShown, endShown);
|
|
147
|
+
const reported = useRef(shown);
|
|
148
|
+
const report = useRef(onChange);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
report.current = onChange;
|
|
151
|
+
});
|
|
152
|
+
const given = value === undefined ? undefined : givenKey(value, null);
|
|
153
|
+
const givenShown = givenKey(value ?? null, props);
|
|
154
|
+
const lastGiven = useRef(given);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (given === lastGiven.current)
|
|
157
|
+
return;
|
|
158
|
+
lastGiven.current = given;
|
|
159
|
+
if (given === undefined || given === reported.current)
|
|
160
|
+
return;
|
|
161
|
+
reported.current = givenShown;
|
|
162
|
+
setInner(fromKey(given));
|
|
163
|
+
}, [given, givenShown]);
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (shown === reported.current)
|
|
166
|
+
return;
|
|
167
|
+
reported.current = shown;
|
|
168
|
+
report.current?.(fromKey(shown));
|
|
169
|
+
}, [shown]);
|
|
170
|
+
return {
|
|
171
|
+
inner,
|
|
172
|
+
setInner,
|
|
173
|
+
startShown: shown ? startShown : "",
|
|
174
|
+
endShown: shown ? endShown : "",
|
|
175
|
+
problem,
|
|
176
|
+
onReadStart,
|
|
177
|
+
onReadEnd,
|
|
178
|
+
validate: () => (isRequired && (start.partial || end.partial) ? "Enter the whole date." : null),
|
|
179
|
+
start: startSide,
|
|
180
|
+
end: endSide,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** The hidden input a form posts under `name`: the shown date as `YYYY-MM-DD`, or `""`. */
|
|
184
|
+
export function ShownInput({ name, shown, isDisabled, }) {
|
|
185
|
+
return name ? _jsx("input", { type: "hidden", name: name, value: shown, disabled: isDisabled }) : null;
|
|
186
|
+
}
|
package/dist/size.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one size scale of the library: `sm`, `md` and `lg`, with `md` the default. This is the one
|
|
3
|
+
* list of where it goes further and where the default is not `md`; the README and the docs point
|
|
4
|
+
* here rather than count them again.
|
|
5
|
+
*
|
|
6
|
+
* Past `sm`, `md` and `lg`, only where there is a real use, and no scale skips `md`:
|
|
7
|
+
* - `Avatar` and `AvatarStack` `size`: also `xs`, `xl`, `2xl` and `3xl`.
|
|
8
|
+
* - The gap scale (`Stack`, `Section` and `ProseLayout` `gap`): also `xs` and `xl`.
|
|
9
|
+
* - `Cluster` and `ScrollStrip` `gap`: `xs`, `sm` and `md`, the first steps of the gap scale.
|
|
10
|
+
* - `Icon` `size`: also `feature`, the mark of a feature card.
|
|
11
|
+
* - `Dialog` `width`: also `full`, the whole screen. `ChatThread` `height`: also `fill`, its parent's.
|
|
12
|
+
*
|
|
13
|
+
* Defaults that are not `md`:
|
|
14
|
+
* - `Table` `size` is `sm`, its row padding, and the buttons and pills in a table take that size;
|
|
15
|
+
* a field keeps `md`.
|
|
16
|
+
* - `Cluster` and `ScrollStrip` `gap` are `sm`: the items of a row sit closer than the blocks of a
|
|
17
|
+
* column.
|
|
18
|
+
* - `Stack` and `Section` `gap` are `xs` inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`,
|
|
19
|
+
* `Callout` or `ListRow`.
|
|
20
|
+
* - A `Pill`, `Button` or `IconButton` with no `size` takes the size of the `Card`, `ListRow` or
|
|
21
|
+
* `Table` it sits in; an `EmptyState` takes its slot's.
|
|
22
|
+
*
|
|
23
|
+
* A responsive size, `{ base, md }` (`ResponsiveSize`), changes at Tailwind's `md` breakpoint (48rem)
|
|
24
|
+
* in CSS, with no script: `Button`, `IconButton`, `SegmentedControl` and `Icon` take it.
|
|
25
|
+
*
|
|
26
|
+
* With no `size` at all, because they take the size of the text or the control they sit on:
|
|
27
|
+
* `Callout`, `CopyButton`, `Kbd`, `Badge` and `Breadcrumbs`.
|
|
28
|
+
*/
|
|
29
|
+
export type Size = "sm" | "md" | "lg";
|
|
30
|
+
/**
|
|
31
|
+
* A size that changes with the screen: `base` at every width, `md` from Tailwind's `md` breakpoint
|
|
32
|
+
* (48rem) up. Done in CSS, so a server-rendered page paints the right size on its first load.
|
|
33
|
+
*/
|
|
34
|
+
export type ResponsiveSize = {
|
|
35
|
+
base: Size;
|
|
36
|
+
md: Size;
|
|
37
|
+
};
|
|
38
|
+
/** Whether `size` is the responsive form. */
|
|
39
|
+
export declare function isResponsive(size: string | ResponsiveSize): size is ResponsiveSize;
|
|
40
|
+
/**
|
|
41
|
+
* The classes of `size` from a table and its twin, the same classes each prefixed `md:` and written
|
|
42
|
+
* out in full (a consumer's Tailwind scans the built package, so a class built at run time would
|
|
43
|
+
* never be generated). A plain size is its table entry, unchanged.
|
|
44
|
+
*/
|
|
45
|
+
export declare function sizeClass<K extends string>(table: Record<K, string> & Record<Size, string>, twin: Record<Size, string>, size: K | ResponsiveSize): string;
|
package/dist/size.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Whether `size` is the responsive form. */
|
|
2
|
+
export function isResponsive(size) {
|
|
3
|
+
return typeof size === "object";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The classes of `size` from a table and its twin, the same classes each prefixed `md:` and written
|
|
7
|
+
* out in full (a consumer's Tailwind scans the built package, so a class built at run time would
|
|
8
|
+
* never be generated). A plain size is its table entry, unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export function sizeClass(table, twin, size) {
|
|
11
|
+
return isResponsive(size) ? `${table[size.base]} ${twin[size.md]}` : table[size];
|
|
12
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type ElementType, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** The two props every part that can wait for its data takes. */
|
|
3
|
+
export type LoadingProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The data is not here yet: an empty slot draws a bone of its shape, a filled one draws as usual.
|
|
6
|
+
* Left out, the part takes the nearest loading layout's or part's; `false` opts it out inside one.
|
|
7
|
+
*/
|
|
8
|
+
loading?: boolean | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* What a screen reader hears while this part is loading, when its own `loading` is set.
|
|
11
|
+
* @default Loading
|
|
12
|
+
*/
|
|
13
|
+
loadingLabel?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
/** Whether a part is loading (its own prop, else its ancestors'), and whether it owns the wait. */
|
|
16
|
+
export declare function useLoading(own: boolean | undefined): {
|
|
17
|
+
loading: boolean;
|
|
18
|
+
owner: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** Passes `loading` down to every part inside. Renders no element. */
|
|
21
|
+
export declare function LoadingScope({ loading, children, }: {
|
|
22
|
+
loading: boolean;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}): ReactElement;
|
|
25
|
+
/**
|
|
26
|
+
* A slot with nothing in it: `null`, `undefined`, `false`, an empty string or an empty array. A
|
|
27
|
+
* number is a value, `0` included.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isEmptySlot(value: ReactNode): boolean;
|
|
30
|
+
/** The owner's root attribute: `aria-busy` while it waits, nothing otherwise. */
|
|
31
|
+
export declare function busy(owner: boolean, loading: boolean): {
|
|
32
|
+
"aria-busy"?: true;
|
|
33
|
+
};
|
|
34
|
+
/** The owner's one visually hidden announcement. Renders nothing for a part that inherits. */
|
|
35
|
+
export declare function BusyLabel({ owner, loading, label, }: {
|
|
36
|
+
owner: boolean;
|
|
37
|
+
loading: boolean;
|
|
38
|
+
label: string | undefined;
|
|
39
|
+
}): ReactElement | null;
|
|
40
|
+
/**
|
|
41
|
+
* One bone: the skeleton colour, pulsing unless the reader asked for less motion, hidden from
|
|
42
|
+
* assistive tech. `shape` is its size and corners, chosen by the part that draws it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function Bone({ shape }: {
|
|
45
|
+
shape: string;
|
|
46
|
+
}): ReactElement;
|
|
47
|
+
/** How wide a line of text bones is. */
|
|
48
|
+
type LineWidth = "full" | "3/4" | "3/5" | "1/2" | "1/3";
|
|
49
|
+
/**
|
|
50
|
+
* Lines of text bones, each a rounded bar inside its own line height, so they take the room the
|
|
51
|
+
* text would. The last of several is shorter, as a paragraph's last line is.
|
|
52
|
+
*/
|
|
53
|
+
export declare function BoneLines({ count, width, }: {
|
|
54
|
+
count?: number;
|
|
55
|
+
width?: LineWidth;
|
|
56
|
+
}): ReactElement;
|
|
57
|
+
/**
|
|
58
|
+
* A text role's wait: its root's `aria-busy`, and what it holds (its children, or bones of its
|
|
59
|
+
* element's shape when it has none yet, then the owner's label). `bones` says which.
|
|
60
|
+
*/
|
|
61
|
+
export declare function useTextWait(tag: ElementType, { loading: own, loadingLabel, children }: LoadingProps & {
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
}): {
|
|
64
|
+
attrs: {
|
|
65
|
+
"aria-busy"?: true;
|
|
66
|
+
};
|
|
67
|
+
body: ReactNode;
|
|
68
|
+
bones: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* A part that is all bone while it waits (a count, a pill with no text yet): a root carrying the
|
|
72
|
+
* part's passthrough props and the owner's `aria-busy`, the one bone, and the owner's label.
|
|
73
|
+
*/
|
|
74
|
+
export declare function WaitingBone({ own, label, shape, root, attrs, }: {
|
|
75
|
+
own: boolean | undefined;
|
|
76
|
+
label: string | undefined;
|
|
77
|
+
shape: string;
|
|
78
|
+
root: string;
|
|
79
|
+
attrs: object;
|
|
80
|
+
}): ReactElement;
|
|
81
|
+
/** The `id`, `data-*` and `aria-*` of a part's props: what its root takes through. */
|
|
82
|
+
export declare function passthroughOf(props: object): Record<string, unknown>;
|
|
83
|
+
export {};
|