oneslash-design-system 2.19.0 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/DESIGN.md +62 -5
- package/dist/cases/about-page/profile.d.ts +1 -0
- package/dist/cases/about-page/profile.jsx +64 -0
- package/dist/cases/about-page.md +114 -0
- package/dist/cases/admin-inbox/list.d.ts +1 -0
- package/dist/cases/admin-inbox/list.jsx +104 -0
- package/dist/cases/admin-inbox/split.d.ts +1 -0
- package/dist/cases/admin-inbox/split.jsx +68 -0
- package/dist/cases/admin-inbox.md +254 -0
- package/dist/cases/api-keys.md +1 -1
- package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
- package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
- package/dist/cases/billing-page/self-serve.d.ts +1 -0
- package/dist/cases/billing-page/self-serve.jsx +134 -0
- package/dist/cases/billing-page.md +247 -0
- package/dist/cases/blog-index/cards.d.ts +1 -0
- package/dist/cases/blog-index/cards.jsx +45 -0
- package/dist/cases/blog-index/list.d.ts +1 -0
- package/dist/cases/blog-index/list.jsx +46 -0
- package/dist/cases/blog-index.md +160 -0
- package/dist/cases/breakdown-list/bars.d.ts +1 -0
- package/dist/cases/breakdown-list/bars.jsx +47 -0
- package/dist/cases/breakdown-list/table.d.ts +1 -0
- package/dist/cases/breakdown-list/table.jsx +69 -0
- package/dist/cases/breakdown-list.md +158 -0
- package/dist/cases/changelog/by-month.d.ts +1 -0
- package/dist/cases/changelog/by-month.jsx +70 -0
- package/dist/cases/changelog/one-page.d.ts +1 -0
- package/dist/cases/changelog/one-page.jsx +70 -0
- package/dist/cases/changelog.md +200 -0
- package/dist/cases/code-sample/block.d.ts +1 -0
- package/dist/cases/code-sample/block.jsx +19 -0
- package/dist/cases/code-sample/command.d.ts +1 -0
- package/dist/cases/code-sample/command.jsx +17 -0
- package/dist/cases/code-sample.md +96 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
- package/dist/cases/composer-limit/notice.jsx +3 -3
- package/dist/cases/composer-limit.md +8 -8
- package/dist/cases/contact-page/form.d.ts +1 -0
- package/dist/cases/contact-page/form.jsx +83 -0
- package/dist/cases/contact-page/links.d.ts +1 -0
- package/dist/cases/contact-page/links.jsx +19 -0
- package/dist/cases/contact-page.md +142 -0
- package/dist/cases/dashboard/numbers-first.d.ts +1 -0
- package/dist/cases/dashboard/numbers-first.jsx +165 -0
- package/dist/cases/dashboard/work-first.d.ts +1 -0
- package/dist/cases/dashboard/work-first.jsx +165 -0
- package/dist/cases/dashboard.md +507 -0
- package/dist/cases/data-table-page/all-rows.d.ts +1 -0
- package/dist/cases/data-table-page/all-rows.jsx +226 -0
- package/dist/cases/data-table-page/paged.d.ts +1 -0
- package/dist/cases/data-table-page/paged.jsx +284 -0
- package/dist/cases/data-table-page.md +771 -0
- package/dist/cases/docs-component-page/reference.d.ts +1 -0
- package/dist/cases/docs-component-page/reference.jsx +93 -0
- package/dist/cases/docs-component-page.md +144 -0
- package/dist/cases/faq/accordion.d.ts +1 -0
- package/dist/cases/faq/accordion.jsx +25 -0
- package/dist/cases/faq/open-list.d.ts +1 -0
- package/dist/cases/faq/open-list.jsx +27 -0
- package/dist/cases/faq.md +110 -0
- package/dist/cases/feature-grid/cards.d.ts +1 -0
- package/dist/cases/feature-grid/cards.jsx +33 -0
- package/dist/cases/feature-grid/rows.d.ts +1 -0
- package/dist/cases/feature-grid/rows.jsx +30 -0
- package/dist/cases/feature-grid.md +132 -0
- package/dist/cases/image-viewer/gallery.d.ts +1 -0
- package/dist/cases/image-viewer/gallery.jsx +32 -0
- package/dist/cases/image-viewer/single.d.ts +1 -0
- package/dist/cases/image-viewer/single.jsx +25 -0
- package/dist/cases/image-viewer.md +123 -0
- package/dist/cases/invoice-list/table.d.ts +1 -0
- package/dist/cases/invoice-list/table.jsx +64 -0
- package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
- package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
- package/dist/cases/invoice-list.md +237 -0
- package/dist/cases/landing-hero/centered.d.ts +1 -0
- package/dist/cases/landing-hero/centered.jsx +22 -0
- package/dist/cases/landing-hero/split.d.ts +1 -0
- package/dist/cases/landing-hero/split.jsx +30 -0
- package/dist/cases/landing-hero.md +114 -0
- package/dist/cases/legal-page/sections.d.ts +1 -0
- package/dist/cases/legal-page/sections.jsx +61 -0
- package/dist/cases/legal-page.md +96 -0
- package/dist/cases/load-failure/inline.jsx +2 -2
- package/dist/cases/load-failure.md +2 -2
- package/dist/cases/long-form-page/article.d.ts +1 -0
- package/dist/cases/long-form-page/article.jsx +58 -0
- package/dist/cases/long-form-page/with-contents.d.ts +1 -0
- package/dist/cases/long-form-page/with-contents.jsx +41 -0
- package/dist/cases/long-form-page.md +170 -0
- package/dist/cases/members-list/rows.jsx +2 -1
- package/dist/cases/members-list/table.jsx +8 -9
- package/dist/cases/members-list.md +12 -13
- package/dist/cases/message-actions/hover-toolbar.jsx +11 -8
- package/dist/cases/message-actions/menu.jsx +10 -7
- package/dist/cases/message-actions.md +19 -13
- package/dist/cases/message-attachments/in-composer.jsx +2 -2
- package/dist/cases/message-attachments/in-message.jsx +16 -11
- package/dist/cases/message-attachments.md +29 -17
- package/dist/cases/number-format.md +36 -0
- package/dist/cases/one-main-action.md +33 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +9 -6
- package/dist/cases/overflow-menu/on-a-row.jsx +9 -6
- package/dist/cases/overflow-menu.md +16 -10
- package/dist/cases/page-end/cta-band.d.ts +1 -0
- package/dist/cases/page-end/cta-band.jsx +24 -0
- package/dist/cases/page-end/next-link.d.ts +1 -0
- package/dist/cases/page-end/next-link.jsx +18 -0
- package/dist/cases/page-end.md +88 -0
- package/dist/cases/paged-card/pager.d.ts +1 -0
- package/dist/cases/paged-card/pager.jsx +41 -0
- package/dist/cases/paged-card/see-all.d.ts +1 -0
- package/dist/cases/paged-card/see-all.jsx +34 -0
- package/dist/cases/paged-card.md +147 -0
- package/dist/cases/password-gate/inline.d.ts +1 -0
- package/dist/cases/password-gate/inline.jsx +94 -0
- package/dist/cases/password-gate/modal.d.ts +1 -0
- package/dist/cases/password-gate/modal.jsx +81 -0
- package/dist/cases/password-gate/page.d.ts +1 -0
- package/dist/cases/password-gate/page.jsx +82 -0
- package/dist/cases/password-gate.md +351 -0
- package/dist/cases/payment-method/none.d.ts +1 -0
- package/dist/cases/payment-method/none.jsx +17 -0
- package/dist/cases/payment-method/on-file.d.ts +1 -0
- package/dist/cases/payment-method/on-file.jsx +92 -0
- package/dist/cases/payment-method.md +182 -0
- package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
- package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
- package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
- package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
- package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
- package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
- package/dist/cases/plan-change-confirm.md +261 -0
- package/dist/cases/plan-picker/cards.d.ts +1 -0
- package/dist/cases/plan-picker/cards.jsx +97 -0
- package/dist/cases/plan-picker/list.d.ts +1 -0
- package/dist/cases/plan-picker/list.jsx +103 -0
- package/dist/cases/plan-picker.md +297 -0
- package/dist/cases/pricing-section/cards.d.ts +1 -0
- package/dist/cases/pricing-section/cards.jsx +40 -0
- package/dist/cases/pricing-section.md +85 -0
- package/dist/cases/product-cards/grid.d.ts +1 -0
- package/dist/cases/product-cards/grid.jsx +20 -0
- package/dist/cases/product-cards.md +71 -0
- package/dist/cases/range-switch/segmented.jsx +11 -7
- package/dist/cases/range-switch.md +16 -11
- package/dist/cases/reply-feedback/thumbs.jsx +11 -8
- package/dist/cases/reply-feedback/with-reason.jsx +11 -8
- package/dist/cases/reply-feedback.md +20 -14
- package/dist/cases/section-index/cards.d.ts +1 -0
- package/dist/cases/section-index/cards.jsx +25 -0
- package/dist/cases/section-index/list.d.ts +1 -0
- package/dist/cases/section-index/list.jsx +56 -0
- package/dist/cases/section-index.md +140 -0
- package/dist/cases/settings-page/top-tabs.jsx +4 -3
- package/dist/cases/settings-page.md +5 -4
- package/dist/cases/site-header.md +1 -1
- package/dist/cases/site-search/dialog.d.ts +1 -0
- package/dist/cases/site-search/dialog.jsx +131 -0
- package/dist/cases/site-search.md +176 -0
- package/dist/cases/stat-row/featured.d.ts +1 -0
- package/dist/cases/stat-row/featured.jsx +17 -0
- package/dist/cases/stat-row/tiles.d.ts +1 -0
- package/dist/cases/stat-row/tiles.jsx +34 -0
- package/dist/cases/stat-row.md +104 -0
- package/dist/cases/status-label/dot.d.ts +1 -0
- package/dist/cases/status-label/dot.jsx +39 -0
- package/dist/cases/status-label/text.d.ts +1 -0
- package/dist/cases/status-label/text.jsx +44 -0
- package/dist/cases/status-label.md +143 -0
- package/dist/cases/tabbed-panels/tabs.d.ts +1 -0
- package/dist/cases/tabbed-panels/tabs.jsx +40 -0
- package/dist/cases/tabbed-panels.md +81 -0
- package/dist/cases/upgrade-prompt/inline.jsx +4 -2
- package/dist/cases/upgrade-prompt/modal.jsx +2 -1
- package/dist/cases/upgrade-prompt.md +10 -6
- package/dist/cases/usage-meters/by-person.d.ts +1 -0
- package/dist/cases/usage-meters/by-person.jsx +72 -0
- package/dist/cases/usage-meters/meters.d.ts +1 -0
- package/dist/cases/usage-meters/meters.jsx +49 -0
- package/dist/cases/usage-meters/with-cap.d.ts +1 -0
- package/dist/cases/usage-meters/with-cap.jsx +73 -0
- package/dist/cases/usage-meters.md +303 -0
- package/dist/cases.json +2178 -97
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.jsx +103 -0
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.jsx +11 -5
- package/dist/components/codeBlock.d.ts +26 -0
- package/dist/components/codeBlock.jsx +101 -0
- package/dist/components/formatNumber.d.ts +25 -0
- package/dist/components/formatNumber.js +125 -0
- package/dist/components/iconButton.jsx +12 -7
- package/dist/components/lightbox.d.ts +31 -0
- package/dist/components/lightbox.jsx +161 -0
- package/dist/components/linkCard.d.ts +10 -1
- package/dist/components/linkCard.jsx +32 -6
- package/dist/components/modal.d.ts +10 -2
- package/dist/components/modal.jsx +17 -12
- package/dist/components/pageHeader.jsx +1 -1
- package/dist/components/pagination.d.ts +28 -0
- package/dist/components/pagination.jsx +89 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.jsx +50 -0
- package/dist/components/searchDialog.d.ts +44 -0
- package/dist/components/searchDialog.jsx +152 -0
- package/dist/components/skeleton.d.ts +21 -0
- package/dist/components/skeleton.jsx +41 -0
- package/dist/components/statTile.d.ts +32 -0
- package/dist/components/statTile.jsx +61 -0
- package/dist/components/tab.d.ts +5 -1
- package/dist/components/tab.jsx +2 -2
- package/dist/components/tabPanel.d.ts +16 -0
- package/dist/components/tabPanel.jsx +12 -0
- package/dist/components/tableContainer.d.ts +5 -1
- package/dist/components/tableContainer.jsx +9 -1
- package/dist/components/tableHeaderCell.d.ts +3 -1
- package/dist/components/tableHeaderCell.jsx +2 -2
- package/dist/components/tabsContainer.d.ts +5 -1
- package/dist/components/tabsContainer.jsx +2 -2
- package/dist/components/titleBar.d.ts +3 -1
- package/dist/components/titleBar.jsx +4 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/internal/accordion.d.ts +4 -0
- package/dist/internal/accordion.js +53 -0
- package/dist/internal/combobox.d.ts +20 -0
- package/dist/internal/combobox.js +28 -0
- package/dist/internal/highlight.d.ts +5 -0
- package/dist/internal/highlight.js +18 -0
- package/dist/native-mapping.json +57 -3
- package/dist/stories/Accordion.stories.d.ts +11 -0
- package/dist/stories/Accordion.stories.jsx +93 -0
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +19 -1
- package/dist/stories/Cases.generated.stories.d.ts +60 -0
- package/dist/stories/Cases.generated.stories.jsx +120 -0
- package/dist/stories/CodeBlock.stories.d.ts +12 -0
- package/dist/stories/CodeBlock.stories.jsx +65 -0
- package/dist/stories/Lightbox.stories.d.ts +8 -0
- package/dist/stories/Lightbox.stories.jsx +40 -0
- package/dist/stories/LinkCard.stories.d.ts +6 -0
- package/dist/stories/LinkCard.stories.jsx +17 -0
- package/dist/stories/PageHeader.stories.d.ts +2 -0
- package/dist/stories/PageHeader.stories.jsx +13 -0
- package/dist/stories/Pagination.stories.d.ts +9 -0
- package/dist/stories/Pagination.stories.jsx +75 -0
- package/dist/stories/Progress.stories.d.ts +9 -0
- package/dist/stories/Progress.stories.jsx +43 -0
- package/dist/stories/SearchDialog.stories.d.ts +17 -0
- package/dist/stories/SearchDialog.stories.jsx +111 -0
- package/dist/stories/Skeleton.stories.d.ts +7 -0
- package/dist/stories/Skeleton.stories.jsx +27 -0
- package/dist/stories/StatTile.stories.d.ts +10 -0
- package/dist/stories/StatTile.stories.jsx +55 -0
- package/dist/stories/TabPanel.stories.d.ts +7 -0
- package/dist/stories/TabPanel.stories.jsx +31 -0
- package/dist/stories/Table.stories.d.ts +1 -0
- package/dist/stories/Table.stories.jsx +49 -1
- package/dist/stories/TitleBar.stories.d.ts +1 -0
- package/dist/stories/TitleBar.stories.jsx +7 -0
- package/package.json +5 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface AccordionItem {
|
|
3
|
+
/** Names the item in `open` and in the address (`#<id>-<item.id>`) */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The words on the heading's button */
|
|
6
|
+
title: string;
|
|
7
|
+
content: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
interface AccordionProps {
|
|
10
|
+
items: AccordionItem[];
|
|
11
|
+
/** More than one item can be open. `false` keeps one open: opening an item closes the other. Default true. */
|
|
12
|
+
multiple?: boolean;
|
|
13
|
+
/** The item ids open at first, when `open` is not given */
|
|
14
|
+
defaultOpen?: string[];
|
|
15
|
+
/** The item ids open now. With it the accordion is controlled: say what changed in `onOpenChange`. */
|
|
16
|
+
open?: string[];
|
|
17
|
+
onOpenChange?: (open: string[]) => void;
|
|
18
|
+
/** The heading element of each item, 2 to 4. Pick the one that fits the page's outline. Default 3. */
|
|
19
|
+
headingLevel?: 2 | 3 | 4;
|
|
20
|
+
/** Opens the item named by the address `#<id>-<item.id>` on load and on change, and scrolls it under a `SiteHeader` */
|
|
21
|
+
linkable?: boolean;
|
|
22
|
+
/** Prefixes the ids of the items and their panels */
|
|
23
|
+
id: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Headings that each hold a full-width button opening a panel under it, with hairlines between and no box.
|
|
27
|
+
* Closed panels are in the server HTML, `hidden`. A panel is a `region` named by its heading when there are 6 items
|
|
28
|
+
* or fewer. Up, Down, Home and End move between the headings.
|
|
29
|
+
*/
|
|
30
|
+
export default function Accordion({ items, multiple, defaultOpen, open, onOpenChange, headingLevel, linkable, id, }: AccordionProps): React.JSX.Element;
|
|
31
|
+
export { Accordion };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { focusRing } from './sharedStyles';
|
|
5
|
+
import { hashItem, nextHeading, normalizeOpen, toggleOpen } from '../internal/accordion';
|
|
6
|
+
// More than this many open-able regions are noise for a screen reader's landmark list
|
|
7
|
+
var MAX_REGIONS = 6;
|
|
8
|
+
/**
|
|
9
|
+
* Headings that each hold a full-width button opening a panel under it, with hairlines between and no box.
|
|
10
|
+
* Closed panels are in the server HTML, `hidden`. A panel is a `region` named by its heading when there are 6 items
|
|
11
|
+
* or fewer. Up, Down, Home and End move between the headings.
|
|
12
|
+
*/
|
|
13
|
+
export default function Accordion(_a) {
|
|
14
|
+
var items = _a.items, _b = _a.multiple, multiple = _b === void 0 ? true : _b, _c = _a.defaultOpen, defaultOpen = _c === void 0 ? [] : _c, open = _a.open, onOpenChange = _a.onOpenChange, _d = _a.headingLevel, headingLevel = _d === void 0 ? 3 : _d, _e = _a.linkable, linkable = _e === void 0 ? false : _e, id = _a.id;
|
|
15
|
+
var ids = items.map(function (item) { return item.id; });
|
|
16
|
+
var _f = useState(function () { return normalizeOpen(defaultOpen, ids, multiple); }), inner = _f[0], setInner = _f[1];
|
|
17
|
+
var controlled = open !== undefined;
|
|
18
|
+
var current = normalizeOpen(controlled ? open : inner, ids, multiple);
|
|
19
|
+
var buttons = useRef([]);
|
|
20
|
+
// The effect below reads the latest values through here, so the hashchange listener is not re-bound on every render
|
|
21
|
+
var latest = useRef({ current: current, controlled: controlled, multiple: multiple, onOpenChange: onOpenChange });
|
|
22
|
+
latest.current = { current: current, controlled: controlled, multiple: multiple, onOpenChange: onOpenChange };
|
|
23
|
+
var change = function (next) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (!latest.current.controlled)
|
|
26
|
+
setInner(next);
|
|
27
|
+
(_b = (_a = latest.current).onOpenChange) === null || _b === void 0 ? void 0 : _b.call(_a, next);
|
|
28
|
+
};
|
|
29
|
+
var key = ids.join('\n');
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (!linkable)
|
|
32
|
+
return;
|
|
33
|
+
var frame = 0;
|
|
34
|
+
// On mount the browser has already jumped to a server-rendered #hash, so scroll again only when the heading sits
|
|
35
|
+
// under the header (where that jump put it). A reload or back that restored a scroll position far from it stays.
|
|
36
|
+
var first = true;
|
|
37
|
+
var apply = function () {
|
|
38
|
+
var item = hashItem(window.location.hash, id, ids);
|
|
39
|
+
if (!item)
|
|
40
|
+
return;
|
|
41
|
+
var heading = document.getElementById("".concat(id, "-").concat(item));
|
|
42
|
+
var scroll = true;
|
|
43
|
+
if (first && heading) {
|
|
44
|
+
var offset = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--os-header-offset')) || 0;
|
|
45
|
+
var top_1 = heading.getBoundingClientRect().top;
|
|
46
|
+
// A client-rendered page has no jump to rely on: at the top of the page, a heading far below needs the scroll
|
|
47
|
+
scroll = (top_1 > -2 && top_1 <= offset + 2) || (window.scrollY === 0 && top_1 > offset + 2);
|
|
48
|
+
}
|
|
49
|
+
first = false;
|
|
50
|
+
var _a = latest.current, now = _a.current, many = _a.multiple;
|
|
51
|
+
if (!now.includes(item))
|
|
52
|
+
change(toggleOpen(now, item, many));
|
|
53
|
+
if (!scroll)
|
|
54
|
+
return;
|
|
55
|
+
// After the panels that close have left the layout, bring the heading just under the header (scroll-margin-top)
|
|
56
|
+
cancelAnimationFrame(frame);
|
|
57
|
+
frame = requestAnimationFrame(function () {
|
|
58
|
+
var _a;
|
|
59
|
+
(_a = document.getElementById("".concat(id, "-").concat(item))) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'start', behavior: 'instant' });
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
apply();
|
|
63
|
+
window.addEventListener('hashchange', apply);
|
|
64
|
+
return function () {
|
|
65
|
+
cancelAnimationFrame(frame);
|
|
66
|
+
window.removeEventListener('hashchange', apply);
|
|
67
|
+
};
|
|
68
|
+
}, [linkable, id, key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
69
|
+
var onKeyDown = function (e, index) {
|
|
70
|
+
var _a;
|
|
71
|
+
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)
|
|
72
|
+
return;
|
|
73
|
+
var to = nextHeading(e.key, index, items.length);
|
|
74
|
+
if (to < 0)
|
|
75
|
+
return;
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
(_a = buttons.current[to]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
78
|
+
};
|
|
79
|
+
var Heading = "h".concat(headingLevel);
|
|
80
|
+
var regions = items.length <= MAX_REGIONS;
|
|
81
|
+
return (<div className="w-full border-y border-misc-divider divide-y divide-misc-divider">
|
|
82
|
+
{items.map(function (item, index) {
|
|
83
|
+
var isOpen = current.includes(item.id);
|
|
84
|
+
var headingId = "".concat(id, "-").concat(item.id);
|
|
85
|
+
var buttonId = "".concat(headingId, "-button");
|
|
86
|
+
var panelId = "".concat(headingId, "-panel");
|
|
87
|
+
return (<div key={item.id}>
|
|
88
|
+
<Heading id={headingId} className="m-0 scroll-mt-[var(--os-header-offset,0px)]">
|
|
89
|
+
<button ref={function (el) {
|
|
90
|
+
buttons.current[index] = el;
|
|
91
|
+
}} id={buttonId} type="button" aria-expanded={isOpen} aria-controls={panelId} onClick={function () { return change(toggleOpen(current, item.id, multiple)); }} onKeyDown={function (e) { return onKeyDown(e, index); }} className={"flex w-full items-center justify-between gap-3 rounded-control py-3 text-left text-subtitle1 text-fg-primary ".concat(focusRing)}>
|
|
92
|
+
<span className="min-w-0 break-words">{item.title}</span>
|
|
93
|
+
<ChevronDown aria-hidden strokeWidth={2} className={"h-6 w-6 shrink-0 text-fg-secondary transition-transform duration-[var(--os-duration-fast)] ease-out motion-reduce:transition-none ".concat(isOpen ? 'rotate-180' : '')}/>
|
|
94
|
+
</button>
|
|
95
|
+
</Heading>
|
|
96
|
+
<div id={panelId} hidden={!isOpen} role={regions ? 'region' : undefined} aria-labelledby={regions ? buttonId : undefined} className="pb-4 text-body1 text-fg-secondary">
|
|
97
|
+
{item.content}
|
|
98
|
+
</div>
|
|
99
|
+
</div>);
|
|
100
|
+
})}
|
|
101
|
+
</div>);
|
|
102
|
+
}
|
|
103
|
+
export { Accordion };
|
|
@@ -18,7 +18,7 @@ interface ButtonProps extends React.AriaAttributes {
|
|
|
18
18
|
onClickButton?: any;
|
|
19
19
|
onClickActionIcon?: () => void;
|
|
20
20
|
className?: string;
|
|
21
|
-
/** Shows a spinner in the icon slot
|
|
21
|
+
/** Shows a spinner in the icon slot and keeps the label. The button stays focusable (`aria-disabled`) and ignores presses, so a form cannot submit twice. */
|
|
22
22
|
loading?: boolean;
|
|
23
23
|
/** Renders a link that looks like the button. A path goes through `next/link`; an `http(s)://` URL is a plain `<a>`. */
|
|
24
24
|
href?: string;
|
|
@@ -94,11 +94,13 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
94
94
|
// gets the press feedback for non-buttons and a zero-specificity fit width that `w-full` overrides.
|
|
95
95
|
var linkClasses = state === 'disabled' || loading ? '[:where(&)]:w-fit' : "[:where(&)]:w-fit ".concat(pressFeedbackAny);
|
|
96
96
|
// Hover is pure CSS; `state="hovered"` and `state="focused"` only exist to show those states in docs
|
|
97
|
-
var buttonClasses = "\n flex flex-row items-center rounded-control ".concat(justify, " ").concat(stateTransition, " ").concat(isLink ? linkClasses : pressFeedback, "\n ").concat(color === 'danger' ? focusRingDanger : focusRing, "\n ").concat(sizeClasses, "\n ").concat(state === 'selected' ? stateClasses.selected : '', "\n ").concat(state === 'enabled' || state === 'hovered' ? "".concat(baseTypeClasses, " ").concat(loading ? 'cursor-wait' : "".concat(stateClasses.enabled, " ").concat(hoverTypeClasses)) : '', "\n ").concat(state === 'focused' ? "".concat(baseTypeClasses, " ").concat(hoverTypeClasses, " ").concat(stateClasses.focused) : '', "\n ").concat(state === 'disabled' ? stateClasses.disabled : '', "\n ").concat(className, "\n ");
|
|
97
|
+
var buttonClasses = "\n flex flex-row items-center rounded-control ".concat(justify, " ").concat(stateTransition, " ").concat(isLink ? linkClasses : loading ? '' : pressFeedback, "\n ").concat(color === 'danger' ? focusRingDanger : focusRing, "\n ").concat(sizeClasses, "\n ").concat(state === 'selected' ? stateClasses.selected : '', "\n ").concat(state === 'enabled' || state === 'hovered' ? "".concat(baseTypeClasses, " ").concat(loading ? 'cursor-wait' : "".concat(stateClasses.enabled, " ").concat(hoverTypeClasses)) : '', "\n ").concat(state === 'focused' ? "".concat(baseTypeClasses, " ").concat(hoverTypeClasses, " ").concat(stateClasses.focused) : '', "\n ").concat(state === 'disabled' ? stateClasses.disabled : '', "\n ").concat(className, "\n ");
|
|
98
98
|
var content = (<>
|
|
99
99
|
{/* Group IconLeft and label in a flex container for left alignment */}
|
|
100
100
|
<div className={"flex items-center ".concat(size === 'tiny' ? 'gap-0.5' : 'gap-1')}>
|
|
101
|
-
{loading ? (
|
|
101
|
+
{loading ? (
|
|
102
|
+
// The spinner's own "Loading" status is hidden: the button keeps its name and says it is busy
|
|
103
|
+
<div aria-hidden="true"><LoadingSmall size={spinnerSize}/></div>) : (<IconSlot icon={decoIcon} className={"".concat(sizeIcon, " flex-shrink-0")}/>)}
|
|
102
104
|
<div className={"flex flex-col text-center px-1"}>
|
|
103
105
|
<span className="whitespace-nowrap overflow-hidden truncate">{label}</span>
|
|
104
106
|
{secondLabel && (<span className={"whitespace-nowrap overflow-hidden truncate ".concat(size === 'tiny' ? 'text-caption' : 'text-body2', " opacity-70")}>{secondLabel}</span>)}
|
|
@@ -106,7 +108,7 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
106
108
|
</div>
|
|
107
109
|
{actionIcon && (<span onClick={function (e) {
|
|
108
110
|
// With no handler of its own, the icon is part of the button and the click goes through
|
|
109
|
-
if (!onClickActionIcon)
|
|
111
|
+
if (!onClickActionIcon || loading)
|
|
110
112
|
return;
|
|
111
113
|
// Don't also trigger the button's own click, or follow the link
|
|
112
114
|
e.stopPropagation();
|
|
@@ -120,7 +122,7 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
120
122
|
if (isLink) {
|
|
121
123
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
122
124
|
if (state === 'disabled' || loading) {
|
|
123
|
-
return (<a {...rest} ref={ref} role="link" aria-disabled="true" aria-busy
|
|
125
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" {...(loading ? { 'aria-busy': true } : {})} className={buttonClasses}>
|
|
124
126
|
{content}
|
|
125
127
|
</a>);
|
|
126
128
|
}
|
|
@@ -131,7 +133,11 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
131
133
|
}
|
|
132
134
|
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
133
135
|
}
|
|
134
|
-
return (<button {...rest} ref={ref} type={htmlType} className={buttonClasses} disabled={state === 'disabled'
|
|
136
|
+
return (<button {...rest} ref={ref} type={htmlType} className={buttonClasses} disabled={state === 'disabled'}
|
|
137
|
+
// Spread, so a consumer's own aria-disabled and aria-busy survive when it is not loading
|
|
138
|
+
{...(loading ? { 'aria-disabled': true, 'aria-busy': true } : {})}
|
|
139
|
+
// While loading the button stays focusable but ignores presses; preventDefault also stops a form submit
|
|
140
|
+
onClick={loading ? function (e) { return e.preventDefault(); } : onClickButton}>
|
|
135
141
|
{content}
|
|
136
142
|
</button>);
|
|
137
143
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface CodeBlockProps {
|
|
3
|
+
/** The text, exactly as it is copied. Line breaks stay. */
|
|
4
|
+
code: string;
|
|
5
|
+
/** Visible above the code ('Install command', 'button.tsx'); it names the scroll region and the Copy button */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Shown beside the label for the reader ('tsx', 'bash'). It does not color the code. */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Wrap long lines instead of scrolling them sideways. Default false. */
|
|
10
|
+
wrap?: boolean;
|
|
11
|
+
/** The button's words. Defaults to "Copy". */
|
|
12
|
+
copyLabel?: string;
|
|
13
|
+
/** The button's words for 2 seconds after the text is on the clipboard. Defaults to "Copied". */
|
|
14
|
+
copiedLabel?: string;
|
|
15
|
+
/** Prefixes the ids of the code and the line shown when copying is blocked */
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Code in a figure: a visible label, a Copy button at the end of the label row, and the code on the panel
|
|
20
|
+
* surface. A long line scrolls inside the code, a named region a keyboard can focus and scroll; the page never
|
|
21
|
+
* does. "Copied" shows only after the browser accepted the text; otherwise a line says to copy by hand.
|
|
22
|
+
* With `wrap` the block is still a Tab stop, so use `wrap` only for short blocks.
|
|
23
|
+
* No highlighting and no line numbers. One line to paste is a `CopyField`.
|
|
24
|
+
*/
|
|
25
|
+
export default function CodeBlock({ code, label, language, wrap, copyLabel, copiedLabel, id, }: CodeBlockProps): React.JSX.Element;
|
|
26
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
39
|
+
import { copyText } from '../internal/copyField';
|
|
40
|
+
import Button from './button';
|
|
41
|
+
import { focusRing } from './sharedStyles';
|
|
42
|
+
/**
|
|
43
|
+
* Code in a figure: a visible label, a Copy button at the end of the label row, and the code on the panel
|
|
44
|
+
* surface. A long line scrolls inside the code, a named region a keyboard can focus and scroll; the page never
|
|
45
|
+
* does. "Copied" shows only after the browser accepted the text; otherwise a line says to copy by hand.
|
|
46
|
+
* With `wrap` the block is still a Tab stop, so use `wrap` only for short blocks.
|
|
47
|
+
* No highlighting and no line numbers. One line to paste is a `CopyField`.
|
|
48
|
+
*/
|
|
49
|
+
export default function CodeBlock(_a) {
|
|
50
|
+
var _this = this;
|
|
51
|
+
var code = _a.code, label = _a.label, language = _a.language, _b = _a.wrap, wrap = _b === void 0 ? false : _b, _c = _a.copyLabel, copyLabel = _c === void 0 ? 'Copy' : _c, _d = _a.copiedLabel, copiedLabel = _d === void 0 ? 'Copied' : _d, id = _a.id;
|
|
52
|
+
var _e = useState(false), copied = _e[0], setCopied = _e[1];
|
|
53
|
+
var _f = useState(false), blocked = _f[0], setBlocked = _f[1];
|
|
54
|
+
var timer = useRef(undefined);
|
|
55
|
+
var mounted = useRef(false);
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
mounted.current = true;
|
|
58
|
+
return function () {
|
|
59
|
+
mounted.current = false;
|
|
60
|
+
clearTimeout(timer.current);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
var handleCopy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
64
|
+
var ok;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0: return [4 /*yield*/, copyText(typeof navigator === 'undefined' ? undefined : navigator.clipboard, code)];
|
|
68
|
+
case 1:
|
|
69
|
+
ok = _a.sent();
|
|
70
|
+
if (!mounted.current)
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
clearTimeout(timer.current);
|
|
73
|
+
setBlocked(!ok);
|
|
74
|
+
setCopied(ok);
|
|
75
|
+
if (ok)
|
|
76
|
+
timer.current = setTimeout(function () { return setCopied(false); }, 2000);
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}); };
|
|
81
|
+
var blockedId = "".concat(id, "-blocked");
|
|
82
|
+
return (<figure className="m-0 grid w-full min-w-0 max-w-full grid-cols-[minmax(0,1fr)_auto] items-center gap-x-2 gap-y-1">
|
|
83
|
+
<figcaption className="min-w-0 break-words text-caption text-fg-secondary">
|
|
84
|
+
{label}
|
|
85
|
+
{language && <span className="ml-2 text-caption text-fg-secondary">{language}</span>}
|
|
86
|
+
</figcaption>
|
|
87
|
+
<div className="flex-shrink-0">
|
|
88
|
+
<Button size="small" type="tertiary" state="enabled" label={copied ? copiedLabel : copyLabel} aria-label={"".concat(copied ? copiedLabel : copyLabel, " ").concat(label)} aria-describedby={blocked ? blockedId : undefined} onClickButton={handleCopy}/>
|
|
89
|
+
</div>
|
|
90
|
+
<pre id={"".concat(id, "-code")} tabIndex={0} role="region" aria-label={label} className={"col-span-2 m-0 max-w-full overflow-x-auto rounded-control bg-background-panel p-medium font-mono text-body2 text-fg-primary ".concat(wrap ? 'whitespace-pre-wrap break-words' : '', " ").concat(focusRing)}>
|
|
91
|
+
<code>{code}</code>
|
|
92
|
+
</pre>
|
|
93
|
+
{blocked && (<p id={blockedId} role="alert" className="col-span-2 text-error-text text-body2">
|
|
94
|
+
Copying is blocked here. Select the text and copy it.
|
|
95
|
+
</p>)}
|
|
96
|
+
<span role="status" className="sr-only col-span-2">
|
|
97
|
+
{copied ? copiedLabel : ''}
|
|
98
|
+
</span>
|
|
99
|
+
</figure>);
|
|
100
|
+
}
|
|
101
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** '1,240'. With `compact`, from 10,000 up: '12.4K', '1.2M', '10B', '3.5T'. Below 10,000 it stays exact. */
|
|
2
|
+
export declare function formatCount(n: number, { compact }?: {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
}): string;
|
|
5
|
+
/** '$1,240.00' (two decimals). A non-zero amount under a cent is '< $0.01'. With `compact`, from 10,000 up: '$12.4K'. */
|
|
6
|
+
export declare function formatMoney(n: number, { currency, compact }?: {
|
|
7
|
+
currency?: string;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}): string;
|
|
10
|
+
/** A fraction as a whole percent: 0.124 is '12%'. A small non-zero share is '< 1%'. */
|
|
11
|
+
export declare function formatPercent(fraction: number): string;
|
|
12
|
+
/** Base 1024. 'B' as is; KB and MB keep one decimal under 10 ('1.5 KB') and are whole from 10; GB and TB have one decimal. */
|
|
13
|
+
export declare function formatBytes(n: number): string;
|
|
14
|
+
/** '340 ms', '1.2 s', '4 min 10 s', '1 h 5 min'. */
|
|
15
|
+
export declare function formatDuration(ms: number): string;
|
|
16
|
+
export type ChangePeriod = 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
17
|
+
export type Change = {
|
|
18
|
+
direction: 'up' | 'down' | 'same' | 'new' | null;
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
23
|
+
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatChange(value: number | null | undefined, previous: number | null | undefined, period?: ChangePeriod): Change;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
// Number formatting for counts, money, shares, sizes, durations and change lines.
|
|
13
|
+
// One fixed locale ('en-US') so a server and a browser print the same string and nothing mismatches on hydration.
|
|
14
|
+
var LOCALE = 'en-US';
|
|
15
|
+
var COMPACT_FROM = 10000;
|
|
16
|
+
var DASH = '–';
|
|
17
|
+
var finite = function (n) { return typeof n === 'number' && Number.isFinite(n); };
|
|
18
|
+
var exact = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 20 });
|
|
19
|
+
var whole = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 0 });
|
|
20
|
+
var oneDecimal = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 1 });
|
|
21
|
+
var compactCount = new Intl.NumberFormat(LOCALE, { notation: 'compact', maximumFractionDigits: 1 });
|
|
22
|
+
var percent = new Intl.NumberFormat(LOCALE, { style: 'percent', maximumFractionDigits: 0 });
|
|
23
|
+
var money = function (currency, compact) {
|
|
24
|
+
return new Intl.NumberFormat(LOCALE, __assign({ style: 'currency', currency: currency }, (compact
|
|
25
|
+
? { notation: 'compact', minimumFractionDigits: 0, maximumFractionDigits: 1 }
|
|
26
|
+
: { minimumFractionDigits: 2, maximumFractionDigits: 2 })));
|
|
27
|
+
};
|
|
28
|
+
/** '1,240'. With `compact`, from 10,000 up: '12.4K', '1.2M', '10B', '3.5T'. Below 10,000 it stays exact. */
|
|
29
|
+
export function formatCount(n, _a) {
|
|
30
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.compact, compact = _c === void 0 ? false : _c;
|
|
31
|
+
if (!finite(n))
|
|
32
|
+
return DASH;
|
|
33
|
+
// -0 would print '-0'
|
|
34
|
+
if (n === 0)
|
|
35
|
+
n = 0;
|
|
36
|
+
if (compact && Math.abs(n) >= COMPACT_FROM)
|
|
37
|
+
return compactCount.format(n);
|
|
38
|
+
return exact.format(n);
|
|
39
|
+
}
|
|
40
|
+
/** '$1,240.00' (two decimals). A non-zero amount under a cent is '< $0.01'. With `compact`, from 10,000 up: '$12.4K'. */
|
|
41
|
+
export function formatMoney(n, _a) {
|
|
42
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.currency, currency = _c === void 0 ? 'USD' : _c, _d = _b.compact, compact = _d === void 0 ? false : _d;
|
|
43
|
+
if (!finite(n))
|
|
44
|
+
return DASH;
|
|
45
|
+
// -0 would print '-$0.00'
|
|
46
|
+
if (n === 0)
|
|
47
|
+
n = 0;
|
|
48
|
+
if (n !== 0 && Math.abs(n) < 0.005) {
|
|
49
|
+
var cent = money(currency, false).format(0.01);
|
|
50
|
+
return n > 0 ? "< ".concat(cent) : "> -".concat(cent);
|
|
51
|
+
}
|
|
52
|
+
return money(currency, compact && Math.abs(n) >= COMPACT_FROM).format(n);
|
|
53
|
+
}
|
|
54
|
+
/** A fraction as a whole percent: 0.124 is '12%'. A small non-zero share is '< 1%'. */
|
|
55
|
+
export function formatPercent(fraction) {
|
|
56
|
+
if (!finite(fraction))
|
|
57
|
+
return DASH;
|
|
58
|
+
// -0 would print '-0%'
|
|
59
|
+
if (fraction === 0)
|
|
60
|
+
fraction = 0;
|
|
61
|
+
var whole100 = Math.round(Math.abs(fraction) * 100);
|
|
62
|
+
if (fraction !== 0 && whole100 === 0)
|
|
63
|
+
return fraction > 0 ? '< 1%' : '> -1%';
|
|
64
|
+
// A share that is not full never reads 100%
|
|
65
|
+
if (Math.abs(fraction) < 1 && whole100 >= 100)
|
|
66
|
+
return fraction > 0 ? '99%' : '-99%';
|
|
67
|
+
return percent.format(fraction);
|
|
68
|
+
}
|
|
69
|
+
/** Base 1024. 'B' as is; KB and MB keep one decimal under 10 ('1.5 KB') and are whole from 10; GB and TB have one decimal. */
|
|
70
|
+
export function formatBytes(n) {
|
|
71
|
+
if (!finite(n))
|
|
72
|
+
return DASH;
|
|
73
|
+
var sign = n < 0 ? '-' : '';
|
|
74
|
+
var v = Math.abs(n);
|
|
75
|
+
if (v < 1024)
|
|
76
|
+
return "".concat(sign).concat(whole.format(v), " B");
|
|
77
|
+
var units = ['KB', 'MB', 'GB', 'TB'];
|
|
78
|
+
var i = 0;
|
|
79
|
+
v /= 1024;
|
|
80
|
+
// Rounding can carry into the next unit ('1,023.99 KB' is '1 MB')
|
|
81
|
+
while (i < units.length - 1 && (v >= 1024 || Math.round(v) >= 1024)) {
|
|
82
|
+
v /= 1024;
|
|
83
|
+
i += 1;
|
|
84
|
+
}
|
|
85
|
+
var unit = units[i];
|
|
86
|
+
var text = unit === 'KB' || unit === 'MB' ? (v < 10 ? oneDecimal.format(v) : whole.format(v)) : oneDecimal.format(v);
|
|
87
|
+
return "".concat(sign).concat(text, " ").concat(unit);
|
|
88
|
+
}
|
|
89
|
+
/** '340 ms', '1.2 s', '4 min 10 s', '1 h 5 min'. */
|
|
90
|
+
export function formatDuration(ms) {
|
|
91
|
+
if (!finite(ms))
|
|
92
|
+
return DASH;
|
|
93
|
+
var t = Math.max(0, ms);
|
|
94
|
+
if (t < 999.5)
|
|
95
|
+
return "".concat(whole.format(t), " ms");
|
|
96
|
+
if (t < 59950)
|
|
97
|
+
return "".concat(oneDecimal.format(t / 1000), " s");
|
|
98
|
+
var total = Math.round(t / 1000);
|
|
99
|
+
var h = Math.floor(total / 3600);
|
|
100
|
+
var m = Math.floor((total % 3600) / 60);
|
|
101
|
+
var s = total % 60;
|
|
102
|
+
if (h > 0)
|
|
103
|
+
return m > 0 ? "".concat(h, " h ").concat(m, " min") : "".concat(h, " h");
|
|
104
|
+
return s > 0 ? "".concat(m, " min ").concat(s, " s") : "".concat(m, " min");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
108
|
+
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
109
|
+
*/
|
|
110
|
+
export function formatChange(value, previous, period) {
|
|
111
|
+
if (period === void 0) { period = 'week'; }
|
|
112
|
+
if (!finite(value) || !finite(previous))
|
|
113
|
+
return { direction: null, text: '' };
|
|
114
|
+
// 'last day' and 'this day' are not English
|
|
115
|
+
var from = period === 'day' ? 'yesterday' : "last ".concat(period);
|
|
116
|
+
var now = period === 'day' ? 'today' : "this ".concat(period);
|
|
117
|
+
if (value === previous)
|
|
118
|
+
return { direction: 'same', text: "No change from ".concat(from) };
|
|
119
|
+
if (previous === 0)
|
|
120
|
+
return { direction: 'new', text: "New ".concat(now) };
|
|
121
|
+
var share = formatPercent(Math.abs(value - previous) / Math.abs(previous));
|
|
122
|
+
return value > previous
|
|
123
|
+
? { direction: 'up', text: "Up ".concat(share, " from ").concat(from) }
|
|
124
|
+
: { direction: 'down', text: "Down ".concat(share, " from ").concat(from) };
|
|
125
|
+
}
|
|
@@ -69,10 +69,10 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
69
69
|
: color === 'secondary'
|
|
70
70
|
? 'hover:bg-secondary-dark/75' // Secondary
|
|
71
71
|
: 'hover:bg-background-accent200/75'; // Tertiary and iconOnly
|
|
72
|
-
// Background hover color; `enabled:` skips it while disabled
|
|
72
|
+
// Background hover color; `enabled:` skips it while disabled, and a loading button gets none
|
|
73
73
|
var bgColorHover = isLink
|
|
74
74
|
? bgColorHoverLink
|
|
75
|
-
: state === 'selected'
|
|
75
|
+
: state === 'selected' || loading
|
|
76
76
|
? '' // No hover effect when selected
|
|
77
77
|
: color === 'primary'
|
|
78
78
|
? 'enabled:hover:bg-accent-dark/75' // Primary
|
|
@@ -103,13 +103,15 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
103
103
|
: 'cursor-pointer';
|
|
104
104
|
// A <button> shrinks to its content and `enabled:` matches it. An <a> does neither, so a link
|
|
105
105
|
// gets the press feedback for non-buttons and a zero-specificity fit width a width class overrides.
|
|
106
|
-
var press = isLink ? "[:where(&)]:w-fit ".concat(isDisabled || loading ? '' : pressFeedbackAny) : pressFeedback;
|
|
106
|
+
var press = isLink ? "[:where(&)]:w-fit ".concat(isDisabled || loading ? '' : pressFeedbackAny) : loading ? '' : pressFeedback;
|
|
107
107
|
var className = "".concat(baseClasses, " ").concat(bgColor, " ").concat(iconColor, " ").concat(bgColorHover, " ").concat(stateClasses, " ").concat(stateTransition, " ").concat(press, " ").concat(focusRing, " flex items-center justify-center");
|
|
108
|
-
var content = loading ? (
|
|
108
|
+
var content = loading ? (
|
|
109
|
+
// The spinner's own "Loading" status is hidden: the button keeps its name and says it is busy
|
|
110
|
+
<div aria-hidden="true"><LoadingSmall size={size}/></div>) : (<IconSlot icon={icon !== null && icon !== void 0 ? icon : iconName} className={iconSizeClasses[size]}/>);
|
|
109
111
|
if (isLink) {
|
|
110
112
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
111
113
|
if (isDisabled || loading) {
|
|
112
|
-
return (<a {...rest} ref={ref} role="link" aria-disabled="true" className={className} aria-label={
|
|
114
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" {...(loading ? { 'aria-busy': true } : {})} className={className} aria-label={label}>
|
|
113
115
|
{content}
|
|
114
116
|
</a>);
|
|
115
117
|
}
|
|
@@ -120,8 +122,11 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
120
122
|
}
|
|
121
123
|
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
122
124
|
}
|
|
123
|
-
return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled
|
|
124
|
-
|
|
125
|
+
return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled}
|
|
126
|
+
// Spread, so a consumer's own aria-disabled and aria-busy survive when it is not loading
|
|
127
|
+
{...(loading ? { 'aria-disabled': true, 'aria-busy': true } : {})}
|
|
128
|
+
// While loading the button stays focusable but ignores presses
|
|
129
|
+
onClick={loading ? function (e) { return e.preventDefault(); } : onClick} aria-label={label}>
|
|
125
130
|
{content}
|
|
126
131
|
</button>);
|
|
127
132
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface LightboxImage {
|
|
3
|
+
src: string;
|
|
4
|
+
/** Required: it names the thumbnail, titles the viewer when there is no caption, and stands in for an image that fails. */
|
|
5
|
+
alt: string;
|
|
6
|
+
/** Shown under the image, and as the viewer's title. */
|
|
7
|
+
caption?: string;
|
|
8
|
+
}
|
|
9
|
+
interface LightboxProps {
|
|
10
|
+
images: LightboxImage[];
|
|
11
|
+
/** The image shown, counted from 0. */
|
|
12
|
+
index: number;
|
|
13
|
+
onIndexChange: (index: number) => void;
|
|
14
|
+
isOpen: boolean;
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
/** Names the dialog. Defaults to 'Image viewer'. The visible title is the image's caption or alt text. */
|
|
17
|
+
'aria-label'?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Images in a full-size Modal: the image fits the viewport, its caption under it, and '2 of 5' after the title.
|
|
21
|
+
* 'Previous image' and 'Next image', ArrowLeft and ArrowRight, and a 40px swipe on touch step one image and stop at
|
|
22
|
+
* the ends; the Button at an end is disabled and focus moves to the other one, as Pagination does. Escape, the
|
|
23
|
+
* backdrop and Close close it, and the Modal gives focus back to what opened it. Images only: no video.
|
|
24
|
+
*/
|
|
25
|
+
export default function Lightbox({ images, index, onIndexChange, isOpen, onClose, 'aria-label': ariaLabel, }: LightboxProps): React.JSX.Element | null;
|
|
26
|
+
/** A thumbnail that opens the Lightbox: a button named 'Open image: <alt>' around a cropped Figure. */
|
|
27
|
+
export declare function LightboxThumbnail({ image, onOpen }: {
|
|
28
|
+
image: LightboxImage;
|
|
29
|
+
onOpen: () => void;
|
|
30
|
+
}): React.JSX.Element;
|
|
31
|
+
export { Lightbox };
|