oneslash-design-system 2.18.0 → 2.20.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 +54 -5
- package/dist/cases/app-shell/sidebar.d.ts +1 -0
- package/dist/cases/app-shell/sidebar.jsx +124 -0
- package/dist/cases/app-shell/top-tabs.d.ts +1 -0
- package/dist/cases/app-shell/top-tabs.jsx +106 -0
- package/dist/cases/app-shell.md +364 -0
- package/dist/cases/artifact-card/card.jsx +32 -6
- package/dist/cases/artifact-card.md +55 -7
- 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/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/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/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/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -21
- 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/load-failure/inline.jsx +2 -2
- package/dist/cases/load-failure.md +2 -2
- package/dist/cases/master-detail/list-then-page.d.ts +1 -0
- package/dist/cases/master-detail/list-then-page.jsx +65 -0
- package/dist/cases/master-detail/split.d.ts +1 -0
- package/dist/cases/master-detail/split.jsx +49 -0
- package/dist/cases/master-detail.md +213 -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/mobile-menu/links.d.ts +1 -0
- package/dist/cases/mobile-menu/links.jsx +24 -0
- package/dist/cases/mobile-menu/sections.d.ts +1 -0
- package/dist/cases/mobile-menu/sections.jsx +61 -0
- package/dist/cases/mobile-menu.md +170 -0
- package/dist/cases/not-found-page/in-shell.jsx +26 -17
- package/dist/cases/not-found-page.md +41 -20
- package/dist/cases/number-format.md +36 -0
- package/dist/cases/on-this-page/aside.d.ts +1 -0
- package/dist/cases/on-this-page/aside.jsx +39 -0
- package/dist/cases/on-this-page.md +80 -0
- package/dist/cases/page-header/actions.d.ts +1 -0
- package/dist/cases/page-header/actions.jsx +65 -0
- package/dist/cases/page-header/sub-page.d.ts +1 -0
- package/dist/cases/page-header/sub-page.jsx +37 -0
- package/dist/cases/page-header.md +195 -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/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/phone-navigation.md +32 -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/range-switch/segmented.jsx +11 -7
- package/dist/cases/range-switch.md +16 -11
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -21
- package/dist/cases/settings-page/top-tabs.jsx +4 -3
- package/dist/cases/settings-page.md +5 -4
- package/dist/cases/side-pane/beside.d.ts +1 -0
- package/dist/cases/side-pane/beside.jsx +79 -0
- package/dist/cases/side-pane/over.d.ts +1 -0
- package/dist/cases/side-pane/over.jsx +58 -0
- package/dist/cases/side-pane.md +238 -0
- package/dist/cases/sidebar-nav/flat.d.ts +1 -0
- package/dist/cases/sidebar-nav/flat.jsx +81 -0
- package/dist/cases/sidebar-nav/nested.d.ts +1 -0
- package/dist/cases/sidebar-nav/nested.jsx +122 -0
- package/dist/cases/sidebar-nav.md +261 -0
- package/dist/cases/site-footer/columns.d.ts +1 -0
- package/dist/cases/site-footer/columns.jsx +51 -0
- package/dist/cases/site-footer/simple.d.ts +1 -0
- package/dist/cases/site-footer/simple.jsx +24 -0
- package/dist/cases/site-footer.md +133 -0
- package/dist/cases/site-header/links.d.ts +1 -0
- package/dist/cases/site-header/links.jsx +26 -0
- package/dist/cases/site-header/sections.d.ts +1 -0
- package/dist/cases/site-header/sections.jsx +64 -0
- package/dist/cases/site-header.md +183 -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/theme-switcher/menu.d.ts +1 -0
- package/dist/cases/theme-switcher/menu.jsx +47 -0
- package/dist/cases/theme-switcher/segmented.d.ts +1 -0
- package/dist/cases/theme-switcher/segmented.jsx +26 -0
- package/dist/cases/theme-switcher.md +149 -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 +1756 -172
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.jsx +11 -5
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/formatNumber.d.ts +25 -0
- package/dist/components/formatNumber.js +125 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/iconButton.jsx +12 -7
- package/dist/components/link.d.ts +6 -1
- package/dist/components/link.jsx +11 -3
- package/dist/components/menuItem.d.ts +7 -1
- package/dist/components/menuItem.jsx +4 -3
- package/dist/components/modal.jsx +12 -23
- package/dist/components/onThisPage.d.ts +29 -0
- package/dist/components/onThisPage.jsx +151 -0
- package/dist/components/pageShell.d.ts +7 -1
- package/dist/components/pageShell.jsx +14 -1
- package/dist/components/pagination.d.ts +28 -0
- package/dist/components/pagination.jsx +89 -0
- package/dist/components/popover.jsx +4 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.jsx +50 -0
- package/dist/components/settingsSection.d.ts +6 -1
- package/dist/components/settingsSection.jsx +10 -3
- package/dist/components/sidePane.d.ts +32 -0
- package/dist/components/sidePane.jsx +128 -0
- package/dist/components/siteFooter.d.ts +24 -0
- package/dist/components/siteFooter.jsx +48 -0
- package/dist/components/siteHeader.d.ts +55 -0
- package/dist/components/siteHeader.jsx +125 -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/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/titleBar.d.ts +19 -0
- package/dist/components/titleBar.jsx +18 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/internal/overlayStack.d.ts +24 -0
- package/dist/internal/overlayStack.js +71 -0
- package/dist/internal/resize.d.ts +9 -0
- package/dist/internal/resize.js +31 -0
- package/dist/internal/scrollSpy.d.ts +24 -0
- package/dist/internal/scrollSpy.js +53 -0
- package/dist/internal/siteBrand.d.ts +6 -0
- package/dist/internal/siteBrand.jsx +11 -0
- package/dist/native-mapping.json +69 -3
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -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 +45 -0
- package/dist/stories/Cases.generated.stories.jsx +90 -0
- package/dist/stories/Drawer.stories.d.ts +10 -0
- package/dist/stories/Drawer.stories.jsx +123 -0
- package/dist/stories/Link.stories.d.ts +1 -0
- package/dist/stories/Link.stories.jsx +8 -0
- package/dist/stories/OnThisPage.stories.d.ts +10 -0
- package/dist/stories/OnThisPage.stories.jsx +105 -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/SettingsSection.stories.d.ts +1 -0
- package/dist/stories/SettingsSection.stories.jsx +27 -0
- package/dist/stories/SidePane.stories.d.ts +6 -0
- package/dist/stories/SidePane.stories.jsx +37 -0
- package/dist/stories/SiteFooter.stories.d.ts +7 -0
- package/dist/stories/SiteFooter.stories.jsx +63 -0
- package/dist/stories/SiteHeader.stories.d.ts +10 -0
- package/dist/stories/SiteHeader.stories.jsx +94 -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/Table.stories.d.ts +1 -0
- package/dist/stories/Table.stories.jsx +49 -1
- package/dist/stories/TitleBar.stories.d.ts +7 -0
- package/dist/stories/TitleBar.stories.jsx +41 -0
- package/package.json +5 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface AppShellProps {
|
|
3
|
+
/**
|
|
4
|
+
* The app's places, a `Navigation`. A column from md up; in a Drawer below md, and only one of the two is mounted.
|
|
5
|
+
* Keep a Modal's open state inside the sidebar's own components.
|
|
6
|
+
*/
|
|
7
|
+
sidebar: React.ReactNode;
|
|
8
|
+
/** The page, in `<main>` */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** A `SidePane`: beside main from lg up, in place of main below lg. Below lg the skip link goes to the pane. */
|
|
11
|
+
pane?: React.ReactNode;
|
|
12
|
+
/** Names the page in the top bar below md */
|
|
13
|
+
title: string;
|
|
14
|
+
/** Below md: whether the sidebar's Drawer is open */
|
|
15
|
+
navOpen: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Called with `true` from the Menu IconButton, `false` on Close, Escape, the scrim, a choice in the menu and on widening past md.
|
|
18
|
+
* A choice in a portaled menu inside the sidebar (an account menu) does not close the phone menu; close it in that item's onClick.
|
|
19
|
+
*/
|
|
20
|
+
onNavOpenChange: (open: boolean) => void;
|
|
21
|
+
/** The Menu IconButton's name, and the Drawer's. Default 'Menu'. */
|
|
22
|
+
menuLabel?: string;
|
|
23
|
+
/** Hides the sidebar column from md up, for a person who wants room. The phone menu still has it. */
|
|
24
|
+
sidebarHidden?: boolean;
|
|
25
|
+
/** The skip link's text. Default 'Skip to content'. */
|
|
26
|
+
skipLabel?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Gives the person the control to hide the sidebar, from md up only (the phone menu has no such control).
|
|
29
|
+
* With it, AppShell renders a hide IconButton at the top of the column and, while `sidebarHidden`, a show
|
|
30
|
+
* IconButton in a slim rail at the start; focus moves to the other control after a press. Keep the
|
|
31
|
+
* keyboard shortcut (`useHotkey('b', …)`) in the app, and have it call this too.
|
|
32
|
+
*/
|
|
33
|
+
onSidebarHiddenChange?: (hidden: boolean) => void;
|
|
34
|
+
/** The hide IconButton's name. Default 'Hide sidebar'. */
|
|
35
|
+
hideLabel?: string;
|
|
36
|
+
/** The show IconButton's name. Default 'Show sidebar'. */
|
|
37
|
+
showLabel?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* An app's frame: a skip link, the sidebar beside main from md up, and below md a top bar whose
|
|
41
|
+
* Menu IconButton opens the same sidebar in a start Drawer.
|
|
42
|
+
*/
|
|
43
|
+
export default function AppShell({ sidebar, children, pane, title, navOpen, onNavOpenChange, menuLabel, sidebarHidden, skipLabel, onSidebarHiddenChange, hideLabel, showLabel, }: AppShellProps): React.JSX.Element;
|
|
44
|
+
export { AppShell };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useId, useRef } from 'react';
|
|
3
|
+
import { Menu, PanelLeftClose, PanelLeftOpen } from 'lucide-react';
|
|
4
|
+
import Drawer from './drawer';
|
|
5
|
+
import IconButton from './iconButton';
|
|
6
|
+
import Tooltip from './tooltip';
|
|
7
|
+
import TitleBar from './titleBar';
|
|
8
|
+
import { focusRing } from './sharedStyles';
|
|
9
|
+
// Tailwind's md breakpoint: the sidebar is a column from here up
|
|
10
|
+
var WIDE = '(min-width: 768px)';
|
|
11
|
+
/**
|
|
12
|
+
* An app's frame: a skip link, the sidebar beside main from md up, and below md a top bar whose
|
|
13
|
+
* Menu IconButton opens the same sidebar in a start Drawer.
|
|
14
|
+
*/
|
|
15
|
+
export default function AppShell(_a) {
|
|
16
|
+
var sidebar = _a.sidebar, children = _a.children, pane = _a.pane, title = _a.title, navOpen = _a.navOpen, onNavOpenChange = _a.onNavOpenChange, _b = _a.menuLabel, menuLabel = _b === void 0 ? 'Menu' : _b, _c = _a.sidebarHidden, sidebarHidden = _c === void 0 ? false : _c, _d = _a.skipLabel, skipLabel = _d === void 0 ? 'Skip to content' : _d, onSidebarHiddenChange = _a.onSidebarHiddenChange, _e = _a.hideLabel, hideLabel = _e === void 0 ? 'Hide sidebar' : _e, _f = _a.showLabel, showLabel = _f === void 0 ? 'Show sidebar' : _f;
|
|
17
|
+
var mainId = useId();
|
|
18
|
+
var paneId = useId();
|
|
19
|
+
var drawerId = useId();
|
|
20
|
+
var onNavOpenChangeRef = useRef(onNavOpenChange);
|
|
21
|
+
onNavOpenChangeRef.current = onNavOpenChange;
|
|
22
|
+
var columnRef = useRef(null);
|
|
23
|
+
var mainRef = useRef(null);
|
|
24
|
+
// Set when widening closes the Drawer while focus was in it: the Menu IconButton it would go back to is hidden from md up
|
|
25
|
+
var refocusAfterWiden = useRef(false);
|
|
26
|
+
var hideRef = useRef(null);
|
|
27
|
+
var showRef = useRef(null);
|
|
28
|
+
// Set by a press on the hide or show control: the other control takes focus once it is on screen
|
|
29
|
+
var focusAfterToggle = useRef(null);
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
var _a;
|
|
32
|
+
var which = focusAfterToggle.current;
|
|
33
|
+
if (!which)
|
|
34
|
+
return;
|
|
35
|
+
focusAfterToggle.current = null;
|
|
36
|
+
(_a = (which === 'hide' ? hideRef : showRef).current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
37
|
+
}, [sidebarHidden]);
|
|
38
|
+
// The Drawer is for a phone: widening past md closes it, so the page is never left locked under it
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
if (!navOpen)
|
|
41
|
+
return;
|
|
42
|
+
var wide = window.matchMedia(WIDE);
|
|
43
|
+
var closeIfWide = function () {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!wide.matches)
|
|
46
|
+
return;
|
|
47
|
+
refocusAfterWiden.current = !!((_a = document.getElementById(drawerId)) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement));
|
|
48
|
+
onNavOpenChangeRef.current(false);
|
|
49
|
+
};
|
|
50
|
+
closeIfWide();
|
|
51
|
+
wide.addEventListener('change', closeIfWide);
|
|
52
|
+
return function () { return wide.removeEventListener('change', closeIfWide); };
|
|
53
|
+
}, [navOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
54
|
+
// After the close commits (the Drawer's cleanup has already sent focus to the hidden Menu IconButton),
|
|
55
|
+
// focus the current item in the column that is now on screen, or else main.
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
if (navOpen || !refocusAfterWiden.current)
|
|
59
|
+
return;
|
|
60
|
+
refocusAfterWiden.current = false;
|
|
61
|
+
(_c = ((_b = (_a = columnRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('[aria-current]')) !== null && _b !== void 0 ? _b : mainRef.current)) === null || _c === void 0 ? void 0 : _c.focus();
|
|
62
|
+
}, [navOpen]);
|
|
63
|
+
// A choice in the menu (a link or a menu item in the sidebar itself) closes it. A Button that opens
|
|
64
|
+
// its own menu (aria-haspopup) does not, and neither does an item in a Popover, which is not in the panel.
|
|
65
|
+
var closeOnChoice = function (e) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
var choice = (_b = (_a = e.target).closest) === null || _b === void 0 ? void 0 : _b.call(_a, 'a[href], [role="menuitem"]');
|
|
68
|
+
if (choice && e.currentTarget.contains(choice) && !choice.hasAttribute('aria-haspopup'))
|
|
69
|
+
onNavOpenChange(false);
|
|
70
|
+
};
|
|
71
|
+
var skipLink = function (target, shown) { return (<a href={"#".concat(target)} className={"sr-only focus:not-sr-only focus:fixed focus:left-2 focus:top-2 focus:z-[var(--os-z-tooltip)] focus:rounded-control focus:bg-background-elevated focus:px-3 focus:py-2 focus:text-body2 focus:text-fg-primary focus:shadow-overlay ".concat(focusRing).concat(shown)}>
|
|
72
|
+
{skipLabel}
|
|
73
|
+
</a>); };
|
|
74
|
+
return (<div className="min-h-[100dvh] bg-background-default md:flex">
|
|
75
|
+
{/* With a pane, below lg the pane takes main's place, so the skip link goes to the pane there */}
|
|
76
|
+
{skipLink(mainId, pane ? ' hidden lg:block' : '')}
|
|
77
|
+
{pane && skipLink(paneId, ' lg:hidden')}
|
|
78
|
+
{/* Menu sits beside the TitleBar, not in its back slot: TitleBar puts Back on its own line below md */}
|
|
79
|
+
<div className="sticky top-0 z-10 flex items-center gap-2 border-b border-misc-divider bg-background-default py-2 pl-2 pr-4 md:hidden">
|
|
80
|
+
<IconButton color="iconOnly" state="enabled" size="medium" icon={Menu} ariaLabel={menuLabel} aria-expanded={navOpen} aria-controls={drawerId} onClick={function () { return onNavOpenChange(true); }}/>
|
|
81
|
+
<div className="min-w-0 flex-1">
|
|
82
|
+
<TitleBar title={title} level={2}/>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
{/* Not while the phone menu is open, so the sidebar is mounted once. navOpen is true only below md. */}
|
|
86
|
+
{onSidebarHiddenChange && sidebarHidden && (<div className="hidden shrink-0 p-2 md:block">
|
|
87
|
+
<Tooltip title={showLabel}>
|
|
88
|
+
<IconButton ref={showRef} color="iconOnly" state="enabled" size="medium" icon={PanelLeftOpen} ariaLabel={showLabel} onClick={function () {
|
|
89
|
+
focusAfterToggle.current = 'hide';
|
|
90
|
+
onSidebarHiddenChange(false);
|
|
91
|
+
}}/>
|
|
92
|
+
</Tooltip>
|
|
93
|
+
</div>)}
|
|
94
|
+
{!sidebarHidden && !navOpen && (<div ref={columnRef} className="hidden md:flex md:sticky md:top-0 md:h-[100dvh] w-[16rem] shrink-0 flex-col overflow-y-auto [&>*]:flex-1">
|
|
95
|
+
{onSidebarHiddenChange ? (<>
|
|
96
|
+
<div className="!flex-none flex justify-end px-2 pt-2">
|
|
97
|
+
<Tooltip title={hideLabel}>
|
|
98
|
+
<IconButton ref={hideRef} color="iconOnly" state="enabled" size="medium" icon={PanelLeftClose} ariaLabel={hideLabel} onClick={function () {
|
|
99
|
+
focusAfterToggle.current = 'show';
|
|
100
|
+
onSidebarHiddenChange(true);
|
|
101
|
+
}}/>
|
|
102
|
+
</Tooltip>
|
|
103
|
+
</div>
|
|
104
|
+
{sidebar}
|
|
105
|
+
</>) : (sidebar)}
|
|
106
|
+
</div>)}
|
|
107
|
+
<main ref={mainRef} id={mainId} tabIndex={-1} className={"min-w-0 flex-1 p-xlarge outline-none md:p-xxlarge ".concat(pane ? 'hidden lg:block' : '')}>
|
|
108
|
+
{children}
|
|
109
|
+
</main>
|
|
110
|
+
{pane && (<div id={paneId} tabIndex={-1} className="flex min-w-0 flex-1 outline-none lg:sticky lg:top-0 lg:h-[100dvh] lg:flex-none">
|
|
111
|
+
{pane}
|
|
112
|
+
</div>)}
|
|
113
|
+
<Drawer id={drawerId} isOpen={navOpen} onClose={function () { return onNavOpenChange(false); }} aria-label={menuLabel} side="start" size="small">
|
|
114
|
+
{/* The panel already has its own background and padding: a Navigation drops its column's edge, fill and padding here */}
|
|
115
|
+
<div onClick={closeOnChoice} className="[&>nav]:border-r-0 [&>nav]:bg-transparent [&>nav]:p-0">
|
|
116
|
+
{sidebar}
|
|
117
|
+
</div>
|
|
118
|
+
</Drawer>
|
|
119
|
+
</div>);
|
|
120
|
+
}
|
|
121
|
+
export { AppShell };
|
|
@@ -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,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface DrawerProps {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
/** The visible heading; it names the dialog */
|
|
6
|
+
title?: string;
|
|
7
|
+
/** Names the dialog when there is no visible title */
|
|
8
|
+
'aria-label'?: string;
|
|
9
|
+
/** 'start' (default) for navigation; 'end' for a short task, a bottom sheet below md */
|
|
10
|
+
side?: 'start' | 'end';
|
|
11
|
+
/** 20rem, 24rem (default) or 32rem, never wider than 85vw */
|
|
12
|
+
size?: 'small' | 'medium' | 'large';
|
|
13
|
+
/** Buttons in the header, between the title and Close */
|
|
14
|
+
actions?: React.ReactNode;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
/** As in Modal: 'first' focuses the first focusable element in the panel, 'body' the first in the children */
|
|
17
|
+
initialFocus?: 'first' | 'body';
|
|
18
|
+
/** The Close button's name */
|
|
19
|
+
closeLabel?: string;
|
|
20
|
+
/** The panel's id, for an opener's `aria-controls` */
|
|
21
|
+
id?: string;
|
|
22
|
+
/** `'md'`: a Drawer for a phone. It closes (calls `onClose`) when the window is, or becomes, at least md wide, so the page is never left locked under it. */
|
|
23
|
+
closeFrom?: 'md';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A panel that slides in over a scrim. Focus moves in on open and back to the opener on close; Tab
|
|
27
|
+
* stays inside. Escape and a scrim click close it while it is the top overlay, so a Modal opened from
|
|
28
|
+
* inside it closes first.
|
|
29
|
+
*/
|
|
30
|
+
export default function Drawer({ isOpen, onClose, title, 'aria-label': ariaLabel, side, size, actions, children, initialFocus, closeLabel, id, closeFrom, }: DrawerProps): React.JSX.Element | null;
|
|
31
|
+
export { Drawer };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useId, useRef } from 'react';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
import IconButton from './iconButton';
|
|
5
|
+
import { useOverlayTransition } from './useOverlayTransition';
|
|
6
|
+
import { initialFocusCandidates } from '../internal/modal';
|
|
7
|
+
import { PICKABLE, claimEvent, isTopOverlay, lockScroll, popOverlay, pushOverlay, trapTab, unlockScroll } from '../internal/overlayStack';
|
|
8
|
+
// Class strings are written out whole so the app's Tailwind finds them
|
|
9
|
+
var widths = {
|
|
10
|
+
start: { small: 'w-[20rem]', medium: 'w-[24rem]', large: 'w-[32rem]' },
|
|
11
|
+
end: { small: 'md:w-[20rem]', medium: 'md:w-[24rem]', large: 'md:w-[32rem]' },
|
|
12
|
+
};
|
|
13
|
+
// A start Drawer is a full-height panel on the left at every width. An end Drawer is a bottom sheet
|
|
14
|
+
// below md, padded above a phone's home indicator, and a full-height panel on the right from md.
|
|
15
|
+
var placement = {
|
|
16
|
+
start: 'top-0 bottom-0 left-0 max-w-[85vw]',
|
|
17
|
+
end: 'bottom-0 left-0 right-0 max-h-[90dvh] rounded-t-container pb-[env(safe-area-inset-bottom)] md:pb-0 md:top-0 md:left-auto md:max-h-none md:max-w-[85vw] md:rounded-none',
|
|
18
|
+
};
|
|
19
|
+
// Hidden off its side. Open it has no transform at all, so a Modal inside the panel is fixed to the
|
|
20
|
+
// window and not to the panel.
|
|
21
|
+
var hidden = {
|
|
22
|
+
start: '[transform:translateX(-100%)]',
|
|
23
|
+
end: '[transform:translateY(100%)] md:[transform:translateX(100%)]',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A panel that slides in over a scrim. Focus moves in on open and back to the opener on close; Tab
|
|
27
|
+
* stays inside. Escape and a scrim click close it while it is the top overlay, so a Modal opened from
|
|
28
|
+
* inside it closes first.
|
|
29
|
+
*/
|
|
30
|
+
export default function Drawer(_a) {
|
|
31
|
+
var isOpen = _a.isOpen, onClose = _a.onClose, title = _a.title, ariaLabel = _a["aria-label"], _b = _a.side, side = _b === void 0 ? 'start' : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, actions = _a.actions, children = _a.children, _d = _a.initialFocus, initialFocus = _d === void 0 ? 'first' : _d, _e = _a.closeLabel, closeLabel = _e === void 0 ? 'Close' : _e, id = _a.id, closeFrom = _a.closeFrom;
|
|
32
|
+
var panelRef = useRef(null);
|
|
33
|
+
var bodyRef = useRef(null);
|
|
34
|
+
var titleId = useId();
|
|
35
|
+
var _f = useOverlayTransition(isOpen), mounted = _f.mounted, visible = _f.visible;
|
|
36
|
+
// Keep onClose in a ref so a new function each render doesn't re-run the focus effect
|
|
37
|
+
var onCloseRef = useRef(onClose);
|
|
38
|
+
onCloseRef.current = onClose;
|
|
39
|
+
// Tailwind's md breakpoint
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (!isOpen || !closeFrom)
|
|
42
|
+
return;
|
|
43
|
+
var wide = window.matchMedia('(min-width: 768px)');
|
|
44
|
+
var closeIfWide = function () {
|
|
45
|
+
if (wide.matches)
|
|
46
|
+
onCloseRef.current();
|
|
47
|
+
};
|
|
48
|
+
closeIfWide();
|
|
49
|
+
wide.addEventListener('change', closeIfWide);
|
|
50
|
+
return function () { return wide.removeEventListener('change', closeIfWide); };
|
|
51
|
+
}, [isOpen, closeFrom]);
|
|
52
|
+
useEffect(function () {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
if (!isOpen || !mounted)
|
|
55
|
+
return;
|
|
56
|
+
var previouslyFocused = document.activeElement;
|
|
57
|
+
var panel = panelRef.current;
|
|
58
|
+
var candidates = initialFocusCandidates(Array.from((_a = panel === null || panel === void 0 ? void 0 : panel.querySelectorAll(PICKABLE)) !== null && _a !== void 0 ? _a : []), Array.from((_c = (_b = bodyRef.current) === null || _b === void 0 ? void 0 : _b.querySelectorAll(PICKABLE)) !== null && _c !== void 0 ? _c : []), initialFocus);
|
|
59
|
+
for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
|
|
60
|
+
var candidate = candidates_1[_i];
|
|
61
|
+
candidate.focus();
|
|
62
|
+
if (panel === null || panel === void 0 ? void 0 : panel.contains(document.activeElement))
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (panel && !panel.contains(document.activeElement))
|
|
66
|
+
panel.focus();
|
|
67
|
+
pushOverlay(titleId, panel);
|
|
68
|
+
lockScroll();
|
|
69
|
+
var handleKeyDown = function (e) {
|
|
70
|
+
var _a;
|
|
71
|
+
if (!isTopOverlay(titleId))
|
|
72
|
+
return;
|
|
73
|
+
if (e.key === 'Escape') {
|
|
74
|
+
if (claimEvent(e))
|
|
75
|
+
onCloseRef.current();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (e.key !== 'Tab' || !panel)
|
|
79
|
+
return;
|
|
80
|
+
// Focus can fall to the page body, when a Modal in the panel gives it back to a menu item
|
|
81
|
+
// that is gone. Tab from there would leave the panel: start again at its first control.
|
|
82
|
+
if (document.activeElement === document.body) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
(_a = panel.querySelector(PICKABLE)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
trapTab(panel, e);
|
|
88
|
+
};
|
|
89
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
90
|
+
return function () {
|
|
91
|
+
var _a;
|
|
92
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
93
|
+
popOverlay(titleId);
|
|
94
|
+
unlockScroll();
|
|
95
|
+
(_a = previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocused);
|
|
96
|
+
};
|
|
97
|
+
}, [isOpen, mounted]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
98
|
+
if (!mounted)
|
|
99
|
+
return null;
|
|
100
|
+
var handleScrimClick = function () {
|
|
101
|
+
if (isTopOverlay(titleId))
|
|
102
|
+
onClose();
|
|
103
|
+
};
|
|
104
|
+
// dark-only edge: a ring only in dark mode, so it keeps a dark: variant (it follows whatever dark variant the app's preset/@theme defines, class-only or OS-aware)
|
|
105
|
+
return (<div className="fixed inset-0 z-[var(--os-z-overlay)]">
|
|
106
|
+
<div aria-hidden="true" onClick={handleScrimClick} className={"absolute inset-0 bg-misc-scrim/40 transition-opacity duration-[var(--os-duration-fast)] ease-out motion-reduce:transition-none ".concat(visible ? 'opacity-100' : 'opacity-0')}/>
|
|
107
|
+
<div ref={panelRef} id={id} role="dialog" aria-modal="true" aria-labelledby={title ? titleId : undefined} aria-label={title ? undefined : ariaLabel} tabIndex={-1} className={"absolute flex flex-col bg-background-elevated shadow-overlay dark:ring-1 dark:ring-misc-divider outline-none\n ".concat(placement[side], " ").concat(widths[side][size], "\n transition-[transform] duration-[var(--os-duration-fast)] ease-emphasized motion-reduce:transition-none\n ").concat(visible ? '[transform:none]' : hidden[side])}>
|
|
108
|
+
<div className="flex shrink-0 items-center gap-2 border-b border-misc-divider py-2 pl-4 pr-2">
|
|
109
|
+
{title ? (<h2 id={titleId} className="min-w-0 flex-1 text-h5 text-fg-primary">
|
|
110
|
+
{title}
|
|
111
|
+
</h2>) : (<div className="flex-1"/>)}
|
|
112
|
+
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
|
113
|
+
<IconButton color="iconOnly" state="enabled" size="medium" icon={X} ariaLabel={closeLabel} onClick={onClose}/>
|
|
114
|
+
</div>
|
|
115
|
+
<div ref={bodyRef} className="min-h-0 flex-1 overflow-y-auto px-4 py-4 text-body1 text-fg-primary" style={{ scrollbarWidth: 'thin' }}>
|
|
116
|
+
{children}
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>);
|
|
120
|
+
}
|
|
121
|
+
export { Drawer };
|
|
@@ -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
|
+
}
|
|
@@ -9,6 +9,8 @@ interface HeadingProps {
|
|
|
9
9
|
color?: 'default' | 'danger';
|
|
10
10
|
id?: string;
|
|
11
11
|
className?: string;
|
|
12
|
+
/** -1 lets a page move focus to the heading (a pane's title on open) without putting it in the tab order. */
|
|
13
|
+
tabIndex?: number;
|
|
12
14
|
}
|
|
13
|
-
export default function Heading({ children, level, size, color, id, className }: HeadingProps): React.JSX.Element;
|
|
15
|
+
export default function Heading({ children, level, size, color, id, className, tabIndex }: HeadingProps): React.JSX.Element;
|
|
14
16
|
export {};
|
|
@@ -6,9 +6,9 @@ var sizes = {
|
|
|
6
6
|
subtitle1: 'text-subtitle1',
|
|
7
7
|
};
|
|
8
8
|
export default function Heading(_a) {
|
|
9
|
-
var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, _d = _a.color, color = _d === void 0 ? 'default' : _d, id = _a.id, _e = _a.className, className = _e === void 0 ? '' : _e;
|
|
9
|
+
var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, _d = _a.color, color = _d === void 0 ? 'default' : _d, id = _a.id, _e = _a.className, className = _e === void 0 ? '' : _e, tabIndex = _a.tabIndex;
|
|
10
10
|
var Tag = "h".concat(level);
|
|
11
|
-
return (<Tag id={id} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
|
|
11
|
+
return (<Tag id={id} tabIndex={tabIndex} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
|
|
12
12
|
{children}
|
|
13
13
|
</Tag>);
|
|
14
14
|
}
|
|
@@ -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
|
});
|
|
@@ -5,7 +5,12 @@ interface LinkProps {
|
|
|
5
5
|
color?: 'info' | 'error' | 'warning' | 'success';
|
|
6
6
|
size?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'subtitle1' | 'subtitle2' | 'body1' | 'body2' | 'caption';
|
|
7
7
|
openInNewTab?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* When the link opens a new tab, add a small external icon and the hidden words '(opens in a new tab)',
|
|
10
|
+
* so a screen reader hears it too. Default false.
|
|
11
|
+
*/
|
|
12
|
+
announceNewTab?: boolean;
|
|
8
13
|
className?: string;
|
|
9
14
|
}
|
|
10
|
-
export default function Link({ href, children, color, size, openInNewTab, className, }: LinkProps): React.JSX.Element;
|
|
15
|
+
export default function Link({ href, children, color, size, openInNewTab, announceNewTab, className, }: LinkProps): React.JSX.Element;
|
|
11
16
|
export {};
|