oneslash-design-system 2.18.0 → 2.19.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 +26 -1
- 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/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -21
- 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/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/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/phone-navigation.md +32 -0
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -21
- 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/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.json +666 -19
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +2 -2
- 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/popover.jsx +4 -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/titleBar.d.ts +17 -0
- package/dist/components/titleBar.jsx +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -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 +43 -1
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -0
- package/dist/stories/Cases.generated.stories.d.ts +19 -0
- package/dist/stories/Cases.generated.stories.jsx +38 -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/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/TitleBar.stories.d.ts +6 -0
- package/dist/stories/TitleBar.stories.jsx +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useId, useRef, useState } from 'react';
|
|
3
|
+
import { Menu } from 'lucide-react';
|
|
4
|
+
import Drawer from './drawer';
|
|
5
|
+
import IconButton from './iconButton';
|
|
6
|
+
import { focusRing } from './sharedStyles';
|
|
7
|
+
import { SiteBrandLink } from '../internal/siteBrand';
|
|
8
|
+
// Tailwind's md breakpoint: the links are a row in the bar from here up
|
|
9
|
+
var WIDE = '(min-width: 768px)';
|
|
10
|
+
/**
|
|
11
|
+
* A site's bar, sticky at the top: a skip link, the brand, the main links and the actions. Below md the
|
|
12
|
+
* links and `actions` move into a start Drawer a Menu IconButton opens; the brand and the `phoneAction` stay.
|
|
13
|
+
* With no `links` and no `actions` there is no Main nav, no Menu IconButton and no Drawer.
|
|
14
|
+
* While mounted it sets `--os-header-offset` (its height) on `<html>`; `PageShell` with `aside` gives its level 2 and 3 headings
|
|
15
|
+
* `scroll-margin-top: var(--os-header-offset, 0px)`, so a `#hash` link lands below the bar. Other headings need the same.
|
|
16
|
+
* Use one SiteHeader per page: there is one `--os-header-offset`, and unmounting any header removes it.
|
|
17
|
+
*/
|
|
18
|
+
export default function SiteHeader(_a) {
|
|
19
|
+
var brand = _a.brand, links = _a.links, actions = _a.actions, phoneAction = _a.phoneAction, nav = _a.nav, _b = _a.menuLabel, menuLabel = _b === void 0 ? 'Menu' : _b, _c = _a.skipLabel, skipLabel = _c === void 0 ? 'Skip to content' : _c, _d = _a.mainId, mainId = _d === void 0 ? 'main' : _d;
|
|
20
|
+
var drawerId = useId();
|
|
21
|
+
// Without links or actions there is nothing for a Menu to hold
|
|
22
|
+
var hasMenu = links.length > 0 || !!actions;
|
|
23
|
+
var _e = useState(false), menuOpen = _e[0], setMenuOpen = _e[1];
|
|
24
|
+
var barRef = useRef(null);
|
|
25
|
+
// Set when widening closes the Drawer while focus was in it: the Menu IconButton it would go back to is hidden from md up
|
|
26
|
+
var refocusAfterWiden = useRef(false);
|
|
27
|
+
// Publish the bar's height for what sticks or scrolls below it (PageShell's aside, OnThisPage, heading scroll-margin)
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
var bar = barRef.current;
|
|
30
|
+
if (!bar)
|
|
31
|
+
return;
|
|
32
|
+
var root = document.documentElement;
|
|
33
|
+
var publish = function () { return root.style.setProperty('--os-header-offset', "".concat(bar.getBoundingClientRect().height, "px")); };
|
|
34
|
+
publish();
|
|
35
|
+
// On a server-rendered page the browser scrolled to the #hash before the offset existed, so the heading sits under
|
|
36
|
+
// the bar. Scroll to it once more, now with the scroll margin. Only on the first publish, never on a resize.
|
|
37
|
+
var target = null;
|
|
38
|
+
try {
|
|
39
|
+
target = location.hash.length > 1 ? document.getElementById(decodeURIComponent(location.hash.slice(1))) : null;
|
|
40
|
+
}
|
|
41
|
+
catch (_a) {
|
|
42
|
+
// a malformed hash names no heading
|
|
43
|
+
}
|
|
44
|
+
// Only a heading under the bar: one far above it means the person (or the browser's restore) scrolled on
|
|
45
|
+
var top = target === null || target === void 0 ? void 0 : target.getBoundingClientRect().top;
|
|
46
|
+
if (target && top !== undefined && top > -2 && top < bar.getBoundingClientRect().height) {
|
|
47
|
+
target.scrollIntoView({ block: 'start', behavior: 'instant' });
|
|
48
|
+
}
|
|
49
|
+
var observer = new ResizeObserver(publish);
|
|
50
|
+
observer.observe(bar);
|
|
51
|
+
return function () {
|
|
52
|
+
observer.disconnect();
|
|
53
|
+
root.style.removeProperty('--os-header-offset');
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
// The Drawer is for a phone: widening past md closes it, so the page is never left locked under it
|
|
57
|
+
useEffect(function () {
|
|
58
|
+
if (!menuOpen)
|
|
59
|
+
return;
|
|
60
|
+
var wide = window.matchMedia(WIDE);
|
|
61
|
+
var closeIfWide = function () {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!wide.matches)
|
|
64
|
+
return;
|
|
65
|
+
refocusAfterWiden.current = !!((_a = document.getElementById(drawerId)) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement));
|
|
66
|
+
setMenuOpen(false);
|
|
67
|
+
};
|
|
68
|
+
closeIfWide();
|
|
69
|
+
wide.addEventListener('change', closeIfWide);
|
|
70
|
+
return function () { return wide.removeEventListener('change', closeIfWide); };
|
|
71
|
+
}, [menuOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
72
|
+
// After the close commits (the Drawer's cleanup has already sent focus to the hidden Menu IconButton),
|
|
73
|
+
// focus the current link in the bar that is now on screen, or else the brand.
|
|
74
|
+
useEffect(function () {
|
|
75
|
+
var _a, _b, _c, _d;
|
|
76
|
+
if (menuOpen || !refocusAfterWiden.current)
|
|
77
|
+
return;
|
|
78
|
+
refocusAfterWiden.current = false;
|
|
79
|
+
(_d = ((_b = (_a = barRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('nav [aria-current]')) !== null && _b !== void 0 ? _b : (_c = barRef.current) === null || _c === void 0 ? void 0 : _c.querySelector('a[href]'))) === null || _d === void 0 ? void 0 : _d.focus();
|
|
80
|
+
}, [menuOpen]);
|
|
81
|
+
// A link or a Button in the menu closes it. A Button that opens its own menu (aria-haspopup) does not.
|
|
82
|
+
var closeOnChoice = function (e) {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
var choice = (_b = (_a = e.target).closest) === null || _b === void 0 ? void 0 : _b.call(_a, 'a[href], button');
|
|
85
|
+
if (choice && e.currentTarget.contains(choice) && !choice.hasAttribute('aria-haspopup'))
|
|
86
|
+
setMenuOpen(false);
|
|
87
|
+
};
|
|
88
|
+
var linkList = function (vertical) { return (<nav aria-label="Main" className={vertical ? '' : 'hidden min-w-0 flex-1 md:block'}>
|
|
89
|
+
<ul className={"m-0 flex list-none p-0 ".concat(vertical ? 'flex-col gap-0.5' : 'flex-wrap items-center gap-x-1 gap-y-0.5')}>
|
|
90
|
+
{links.map(function (link) { return (<li key={link.href + link.label}>
|
|
91
|
+
<a href={link.href} aria-current={link.current ? 'page' : undefined} className={"block whitespace-nowrap rounded-control no-underline hover:bg-background-accent200 ".concat(vertical ? 'px-3 py-2.5 text-body1' : 'px-2 py-1.5 text-body2', " ").concat(link.current ? 'bg-background-accent100 text-fg-primary' : 'text-fg-secondary hover:text-fg-primary', " ").concat(focusRing)}>
|
|
92
|
+
{link.label}
|
|
93
|
+
</a>
|
|
94
|
+
</li>); })}
|
|
95
|
+
</ul>
|
|
96
|
+
</nav>); };
|
|
97
|
+
// The Drawer is a sibling of the header: a sticky header is a stacking context, and the panel must sit above the page
|
|
98
|
+
return (<>
|
|
99
|
+
<header ref={barRef} className="sticky top-0 z-10 border-b border-misc-divider bg-background-default">
|
|
100
|
+
<a href={"#".concat(mainId)} 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)}>
|
|
101
|
+
{skipLabel}
|
|
102
|
+
</a>
|
|
103
|
+
<div className="mx-auto flex w-full max-w-page-wide items-center gap-2 py-2 pl-2 pr-4 md:gap-4 md:px-xxlarge">
|
|
104
|
+
{hasMenu && (<div className="shrink-0 md:hidden">
|
|
105
|
+
<IconButton color="iconOnly" state="enabled" size="medium" icon={Menu} ariaLabel={menuLabel} aria-expanded={menuOpen} aria-controls={drawerId} onClick={function () { return setMenuOpen(true); }}/>
|
|
106
|
+
</div>)}
|
|
107
|
+
<SiteBrandLink brand={brand}/>
|
|
108
|
+
{/* Not while the menu is open, so the links and actions are mounted once. menuOpen is true only below md. */}
|
|
109
|
+
{!menuOpen && links.length > 0 && linkList(false)}
|
|
110
|
+
<div className="ml-auto flex shrink-0 items-center gap-2">
|
|
111
|
+
{actions && !menuOpen && <div className="hidden items-center gap-2 md:flex">{actions}</div>}
|
|
112
|
+
{phoneAction}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
{nav && <div className="mx-auto w-full max-w-page-wide px-4 pb-2 md:px-xxlarge">{nav}</div>}
|
|
116
|
+
</header>
|
|
117
|
+
{hasMenu && (<Drawer id={drawerId} isOpen={menuOpen} onClose={function () { return setMenuOpen(false); }} aria-label={menuLabel} side="start" size="small">
|
|
118
|
+
<div onClick={closeOnChoice} className="flex flex-col gap-4">
|
|
119
|
+
{linkList(true)}
|
|
120
|
+
{actions && <div className="flex flex-col items-start gap-2">{actions}</div>}
|
|
121
|
+
</div>
|
|
122
|
+
</Drawer>)}
|
|
123
|
+
</>);
|
|
124
|
+
}
|
|
125
|
+
export { SiteHeader };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface TitleBarProps {
|
|
3
|
+
/** The page's or the pane's name */
|
|
4
|
+
title: string;
|
|
5
|
+
/** The heading's element. Default 1, for a page; a pane takes 2. */
|
|
6
|
+
level?: 1 | 2 | 3 | 4;
|
|
7
|
+
/** A Button before the title that goes one step up, e.g. 'Back to Inbox' */
|
|
8
|
+
back?: React.ReactNode;
|
|
9
|
+
/** Buttons at the end of the row. They never shrink; a long title wraps instead. */
|
|
10
|
+
actions?: React.ReactNode;
|
|
11
|
+
/** Below md these replace `actions`: the main action and a More menu holding the rest */
|
|
12
|
+
phoneActions?: React.ReactNode;
|
|
13
|
+
/** The heading's id */
|
|
14
|
+
id?: string;
|
|
15
|
+
}
|
|
16
|
+
export default function TitleBar({ title, level, back, actions, phoneActions, id }: TitleBarProps): React.JSX.Element;
|
|
17
|
+
export { TitleBar };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Heading from './heading';
|
|
3
|
+
// One row from md up: back, the title, then the actions. Below md Back takes its own line above the title.
|
|
4
|
+
// A row without Back is one row at every width. The heading takes tabIndex -1 so a page or a pane can
|
|
5
|
+
// move focus to it (a pane does on open) without adding it to the tab order.
|
|
6
|
+
export default function TitleBar(_a) {
|
|
7
|
+
var title = _a.title, _b = _a.level, level = _b === void 0 ? 1 : _b, back = _a.back, actions = _a.actions, phoneActions = _a.phoneActions, id = _a.id;
|
|
8
|
+
return (<div className={"flex min-w-0 items-center gap-2".concat(back ? ' flex-wrap md:flex-nowrap' : '')}>
|
|
9
|
+
{back && <div className="flex shrink-0 basis-full items-center md:basis-auto">{back}</div>}
|
|
10
|
+
<Heading level={level} size="h5" id={id} tabIndex={-1} className="min-w-0 flex-1 break-words outline-none">
|
|
11
|
+
{title}
|
|
12
|
+
</Heading>
|
|
13
|
+
{actions && <div className={"".concat(phoneActions ? 'hidden md:flex' : 'flex', " shrink-0 items-center gap-2")}>{actions}</div>}
|
|
14
|
+
{phoneActions && <div className="flex shrink-0 items-center gap-2 md:hidden">{phoneActions}</div>}
|
|
15
|
+
</div>);
|
|
16
|
+
}
|
|
17
|
+
export { TitleBar };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import './designTokens';
|
|
2
2
|
export * from './components/alert';
|
|
3
|
+
export * from './components/appShell';
|
|
3
4
|
export * from './components/button';
|
|
4
5
|
export * from './components/checkBox';
|
|
5
6
|
export * from './components/copyField';
|
|
7
|
+
export * from './components/drawer';
|
|
6
8
|
export * from './components/emptyBox';
|
|
7
9
|
export * from './components/formField';
|
|
8
10
|
export * from './components/iconButton';
|
|
@@ -12,12 +14,16 @@ export * from './components/menu';
|
|
|
12
14
|
export * from './components/menuItem';
|
|
13
15
|
export * from './components/modal';
|
|
14
16
|
export * from './components/navigation';
|
|
17
|
+
export * from './components/onThisPage';
|
|
15
18
|
export * from './components/popover';
|
|
16
19
|
export * from './components/radioGroup';
|
|
17
20
|
export * from './components/sectionIntro';
|
|
18
21
|
export * from './components/segmentedControl';
|
|
19
22
|
export * from './components/select';
|
|
20
23
|
export * from './components/settingsSection';
|
|
24
|
+
export * from './components/sidePane';
|
|
25
|
+
export * from './components/siteFooter';
|
|
26
|
+
export * from './components/siteHeader';
|
|
21
27
|
export * from './components/switch';
|
|
22
28
|
export * from './components/tab';
|
|
23
29
|
export * from './components/tableCell';
|
|
@@ -30,6 +36,7 @@ export * from './components/tag';
|
|
|
30
36
|
export * from './components/textarea';
|
|
31
37
|
export * from './components/textField';
|
|
32
38
|
export * from './components/timeStamp';
|
|
39
|
+
export * from './components/titleBar';
|
|
33
40
|
export * from './components/tooltip';
|
|
34
41
|
export * from './components/userImage';
|
|
35
42
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import './designTokens';
|
|
2
2
|
export * from './components/alert';
|
|
3
|
+
export * from './components/appShell';
|
|
3
4
|
export * from './components/button';
|
|
4
5
|
export * from './components/checkBox';
|
|
5
6
|
export * from './components/copyField';
|
|
7
|
+
export * from './components/drawer';
|
|
6
8
|
export * from './components/emptyBox';
|
|
7
9
|
export * from './components/formField';
|
|
8
10
|
export * from './components/iconButton';
|
|
@@ -12,12 +14,16 @@ export * from './components/menu';
|
|
|
12
14
|
export * from './components/menuItem';
|
|
13
15
|
export * from './components/modal';
|
|
14
16
|
export * from './components/navigation';
|
|
17
|
+
export * from './components/onThisPage';
|
|
15
18
|
export * from './components/popover';
|
|
16
19
|
export * from './components/radioGroup';
|
|
17
20
|
export * from './components/sectionIntro';
|
|
18
21
|
export * from './components/segmentedControl';
|
|
19
22
|
export * from './components/select';
|
|
20
23
|
export * from './components/settingsSection';
|
|
24
|
+
export * from './components/sidePane';
|
|
25
|
+
export * from './components/siteFooter';
|
|
26
|
+
export * from './components/siteHeader';
|
|
21
27
|
export * from './components/switch';
|
|
22
28
|
export * from './components/tab';
|
|
23
29
|
export * from './components/tableCell';
|
|
@@ -30,6 +36,7 @@ export * from './components/tag';
|
|
|
30
36
|
export * from './components/textarea';
|
|
31
37
|
export * from './components/textField';
|
|
32
38
|
export * from './components/timeStamp';
|
|
39
|
+
export * from './components/titleBar';
|
|
33
40
|
export * from './components/tooltip';
|
|
34
41
|
export * from './components/userImage';
|
|
35
42
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Overlay = {
|
|
2
|
+
id: string;
|
|
3
|
+
panel?: {
|
|
4
|
+
contains(node: unknown): boolean;
|
|
5
|
+
} | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function pushOverlay(id: string, panel?: Overlay['panel']): void;
|
|
8
|
+
export declare function popOverlay(id: string): void;
|
|
9
|
+
export declare function isTopOverlay(id: string): boolean;
|
|
10
|
+
export declare function isInTopOverlay(node: unknown): boolean;
|
|
11
|
+
export declare function claimEvent(event: object): boolean;
|
|
12
|
+
export declare function lockScroll(): void;
|
|
13
|
+
export declare function unlockScroll(): void;
|
|
14
|
+
export declare const PICKABLE: string;
|
|
15
|
+
type Focusable = {
|
|
16
|
+
focus(): void;
|
|
17
|
+
};
|
|
18
|
+
export declare function trapTab(panel: {
|
|
19
|
+
querySelectorAll(selector: string): ArrayLike<Focusable> | Iterable<Focusable>;
|
|
20
|
+
}, event: {
|
|
21
|
+
shiftKey: boolean;
|
|
22
|
+
preventDefault(): void;
|
|
23
|
+
}): void;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// One stack for the overlays that cover the page (Modal, Drawer), kept out of the public API.
|
|
2
|
+
// The newest open overlay is on top: only it acts on Escape, Tab and a scrim click, so a Modal
|
|
3
|
+
// opened from a Drawer closes alone. Nothing here touches the document until an effect calls it.
|
|
4
|
+
var stack = [];
|
|
5
|
+
// Puts an overlay on top. Pass its panel so a Popover can tell whether it sits in the top overlay.
|
|
6
|
+
export function pushOverlay(id, panel) {
|
|
7
|
+
popOverlay(id);
|
|
8
|
+
stack.push({ id: id, panel: panel });
|
|
9
|
+
}
|
|
10
|
+
// Takes an overlay off the stack wherever it is, so one below can close first
|
|
11
|
+
export function popOverlay(id) {
|
|
12
|
+
var index = stack.findIndex(function (o) { return o.id === id; });
|
|
13
|
+
if (index >= 0)
|
|
14
|
+
stack.splice(index, 1);
|
|
15
|
+
}
|
|
16
|
+
export function isTopOverlay(id) {
|
|
17
|
+
return stack.length > 0 && stack[stack.length - 1].id === id;
|
|
18
|
+
}
|
|
19
|
+
// True when no overlay is open or the top one holds `node`; false when a newer overlay covers it
|
|
20
|
+
export function isInTopOverlay(node) {
|
|
21
|
+
var top = stack[stack.length - 1];
|
|
22
|
+
return !(top === null || top === void 0 ? void 0 : top.panel) || top.panel.contains(node);
|
|
23
|
+
}
|
|
24
|
+
// Every overlay hears the same keydown on window. A browser runs React's update between two
|
|
25
|
+
// listeners, so the top overlay may already be gone when the next one asks: the first to claim
|
|
26
|
+
// an event acts on it, and the others leave it.
|
|
27
|
+
var claimed = new WeakSet();
|
|
28
|
+
export function claimEvent(event) {
|
|
29
|
+
if (claimed.has(event))
|
|
30
|
+
return false;
|
|
31
|
+
claimed.add(event);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// Counted, so stacked overlays lock the page once and give the page its own overflow back once
|
|
35
|
+
var locks = 0;
|
|
36
|
+
var savedOverflow = '';
|
|
37
|
+
export function lockScroll() {
|
|
38
|
+
if (locks++ === 0) {
|
|
39
|
+
savedOverflow = document.body.style.overflow;
|
|
40
|
+
document.body.style.overflow = 'hidden';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function unlockScroll() {
|
|
44
|
+
if (locks === 0)
|
|
45
|
+
return;
|
|
46
|
+
if (--locks === 0)
|
|
47
|
+
document.body.style.overflow = savedOverflow;
|
|
48
|
+
}
|
|
49
|
+
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
50
|
+
// For the first focus and the Tab trap: the same, minus a hidden input, which matches but cannot take focus
|
|
51
|
+
export var PICKABLE = FOCUSABLE.replace('input:not([disabled])', 'input:not([disabled]):not([type="hidden"])');
|
|
52
|
+
// Keeps Tab and Shift+Tab inside the panel: from the last element to the first and back.
|
|
53
|
+
// With nothing to focus, Tab does nothing.
|
|
54
|
+
export function trapTab(panel, event) {
|
|
55
|
+
var focusable = Array.from(panel.querySelectorAll(PICKABLE));
|
|
56
|
+
if (focusable.length === 0) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var first = focusable[0];
|
|
61
|
+
var last = focusable[focusable.length - 1];
|
|
62
|
+
var active = document.activeElement;
|
|
63
|
+
if (event.shiftKey && active === first) {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
last.focus();
|
|
66
|
+
}
|
|
67
|
+
else if (!event.shiftKey && active === last) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
first.focus();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** One arrow key press moves the edge this far */
|
|
2
|
+
export declare const KEY_STEP = 16;
|
|
3
|
+
export declare function clampWidth(width: number, min: number, max: number): number;
|
|
4
|
+
export declare function paneLimits(minWidth: number, maxWidth: number | undefined, windowWidth: number): {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function keyWidth(key: string, width: number, min: number, max: number): number | null;
|
|
9
|
+
export declare function dragWidth(startWidth: number, startX: number, x: number, min: number, max: number): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Width math for a pane resized from its start edge (SidePane). Pure, so it is tested without a page.
|
|
2
|
+
/** One arrow key press moves the edge this far */
|
|
3
|
+
export var KEY_STEP = 16;
|
|
4
|
+
export function clampWidth(width, min, max) {
|
|
5
|
+
return Math.min(max, Math.max(min, width));
|
|
6
|
+
}
|
|
7
|
+
// The default maximum is 60% of the window, and the maximum is never under the minimum
|
|
8
|
+
export function paneLimits(minWidth, maxWidth, windowWidth) {
|
|
9
|
+
var max = maxWidth !== null && maxWidth !== void 0 ? maxWidth : Math.round(windowWidth * 0.6);
|
|
10
|
+
return { min: minWidth, max: Math.max(minWidth, max) };
|
|
11
|
+
}
|
|
12
|
+
// The edge is on the pane's start side: Left widens the pane, Right narrows it, Home and End go to
|
|
13
|
+
// the smallest and largest width. Any other key gives null.
|
|
14
|
+
export function keyWidth(key, width, min, max) {
|
|
15
|
+
switch (key) {
|
|
16
|
+
case 'ArrowLeft':
|
|
17
|
+
return clampWidth(width + KEY_STEP, min, max);
|
|
18
|
+
case 'ArrowRight':
|
|
19
|
+
return clampWidth(width - KEY_STEP, min, max);
|
|
20
|
+
case 'Home':
|
|
21
|
+
return min;
|
|
22
|
+
case 'End':
|
|
23
|
+
return max;
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Dragging the edge left by some pixels widens the pane by as many
|
|
29
|
+
export function dragWidth(startWidth, startX, x, min, max) {
|
|
30
|
+
return clampWidth(startWidth + (startX - x), min, max);
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** How close to the end of the scroll counts as the end, in px */
|
|
2
|
+
export declare const BOTTOM_SLACK = 2;
|
|
3
|
+
/** The window to read from: its scroll position and sizes */
|
|
4
|
+
export interface ScrollMetrics {
|
|
5
|
+
scrollTop: number;
|
|
6
|
+
clientHeight: number;
|
|
7
|
+
scrollHeight: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether the scroll is at its end. A page that does not scroll is not at its end: its last
|
|
11
|
+
* section would otherwise be current on a short page.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isAtBottom({ scrollTop, clientHeight, scrollHeight }: ScrollMetrics): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The index of the current item. `tops` holds each heading's distance from the top of the scroll
|
|
16
|
+
* area (null for a heading that is not on the page yet).
|
|
17
|
+
* - At the end of the scroll, the last item: a last section shorter than the window never reaches the offset.
|
|
18
|
+
* - Otherwise the last heading at or above `offset`.
|
|
19
|
+
* - Above every heading, the first item.
|
|
20
|
+
* - -1 when no heading is on the page.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pickCurrent(tops: (number | null)[], offset: number, atBottom: boolean): number;
|
|
23
|
+
/** The id a `#hash` names, when it is one of the items; else null. Reads `#a%20b` as `a b`. */
|
|
24
|
+
export declare function hashId(hash: string, ids: string[]): string | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Which heading a long page is "at", for OnThisPage. Pure, so it is tested without a page.
|
|
2
|
+
/** How close to the end of the scroll counts as the end, in px */
|
|
3
|
+
export var BOTTOM_SLACK = 2;
|
|
4
|
+
/**
|
|
5
|
+
* Whether the scroll is at its end. A page that does not scroll is not at its end: its last
|
|
6
|
+
* section would otherwise be current on a short page.
|
|
7
|
+
*/
|
|
8
|
+
export function isAtBottom(_a) {
|
|
9
|
+
var scrollTop = _a.scrollTop, clientHeight = _a.clientHeight, scrollHeight = _a.scrollHeight;
|
|
10
|
+
if (scrollHeight <= clientHeight + BOTTOM_SLACK)
|
|
11
|
+
return false;
|
|
12
|
+
return scrollTop + clientHeight >= scrollHeight - BOTTOM_SLACK;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The index of the current item. `tops` holds each heading's distance from the top of the scroll
|
|
16
|
+
* area (null for a heading that is not on the page yet).
|
|
17
|
+
* - At the end of the scroll, the last item: a last section shorter than the window never reaches the offset.
|
|
18
|
+
* - Otherwise the last heading at or above `offset`.
|
|
19
|
+
* - Above every heading, the first item.
|
|
20
|
+
* - -1 when no heading is on the page.
|
|
21
|
+
*/
|
|
22
|
+
export function pickCurrent(tops, offset, atBottom) {
|
|
23
|
+
var first = -1;
|
|
24
|
+
var last = -1;
|
|
25
|
+
var passed = -1;
|
|
26
|
+
tops.forEach(function (top, i) {
|
|
27
|
+
if (top === null)
|
|
28
|
+
return;
|
|
29
|
+
if (first < 0)
|
|
30
|
+
first = i;
|
|
31
|
+
last = i;
|
|
32
|
+
if (top <= offset)
|
|
33
|
+
passed = i;
|
|
34
|
+
});
|
|
35
|
+
if (first < 0)
|
|
36
|
+
return -1;
|
|
37
|
+
if (atBottom)
|
|
38
|
+
return last;
|
|
39
|
+
return passed >= 0 ? passed : first;
|
|
40
|
+
}
|
|
41
|
+
/** The id a `#hash` names, when it is one of the items; else null. Reads `#a%20b` as `a b`. */
|
|
42
|
+
export function hashId(hash, ids) {
|
|
43
|
+
if (!hash || hash === '#')
|
|
44
|
+
return null;
|
|
45
|
+
var id = hash.startsWith('#') ? hash.slice(1) : hash;
|
|
46
|
+
try {
|
|
47
|
+
id = decodeURIComponent(id);
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
// keep the raw text
|
|
51
|
+
}
|
|
52
|
+
return ids.includes(id) ? id : null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SiteBrand } from '../components/siteHeader';
|
|
3
|
+
/** The brand as a link home: the logo named by the site, or the name as text. Shared by `SiteHeader` and `SiteFooter`, not public. */
|
|
4
|
+
export declare function SiteBrandLink({ brand }: {
|
|
5
|
+
brand: SiteBrand;
|
|
6
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Image from '../components/image';
|
|
3
|
+
import { focusRing } from '../components/sharedStyles';
|
|
4
|
+
/** The brand as a link home: the logo named by the site, or the name as text. Shared by `SiteHeader` and `SiteFooter`, not public. */
|
|
5
|
+
export function SiteBrandLink(_a) {
|
|
6
|
+
var _b;
|
|
7
|
+
var brand = _a.brand;
|
|
8
|
+
return (<a href={brand.href} className={"flex shrink-0 items-center rounded-control text-subtitle1 text-fg-primary no-underline ".concat(focusRing)}>
|
|
9
|
+
{brand.src ? <Image src={brand.src} alt={brand.name} width={brand.width} height={(_b = brand.height) !== null && _b !== void 0 ? _b : 28}/> : brand.name}
|
|
10
|
+
</a>);
|
|
11
|
+
}
|
package/dist/native-mapping.json
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
"compose": "`OdsBanner` for an inline message; `AlertDialog` for one that needs a decision",
|
|
7
7
|
"note": "ODS has no native toast: on Android use `Snackbar` in a `SnackbarHost`."
|
|
8
8
|
},
|
|
9
|
+
{
|
|
10
|
+
"ods": "appShell",
|
|
11
|
+
"swiftui": "`NavigationSplitView` with the sidebar, the content and an `.inspector`; on iPhone a `NavigationStack`, or a `TabView` of five places or fewer",
|
|
12
|
+
"compose": "`NavigationSuiteScaffold`; on a phone a `ModalNavigationDrawer` around a `Scaffold`",
|
|
13
|
+
"note": "The split view collapses to a stack on iPhone and shows and hides the sidebar itself. The skip link is web only."
|
|
14
|
+
},
|
|
9
15
|
{
|
|
10
16
|
"ods": "button",
|
|
11
17
|
"swiftui": "`Button` with `.odsProminentButton()` for accent (`.odsProminentButton(.glass)` for the glass style), `.bordered` for primary",
|
|
@@ -34,6 +40,12 @@
|
|
|
34
40
|
"compose": "An `OutlinedTextField` with `readOnly = true` and a `trailingIcon` `TextButton` that calls `LocalClipboard`",
|
|
35
41
|
"note": "Show \"Copied\" for 2 seconds only after the write succeeds. Announce it for VoiceOver / TalkBack. A secret shown once gets the line under it."
|
|
36
42
|
},
|
|
43
|
+
{
|
|
44
|
+
"ods": "drawer",
|
|
45
|
+
"swiftui": "`.sheet` with `.presentationDetents` on iPhone; `.inspector` on iPad and Mac",
|
|
46
|
+
"compose": "`ModalNavigationDrawer` for `side=\"start\"`; `ModalBottomSheet` for `side=\"end\"`",
|
|
47
|
+
"note": "The system sheet, inspector and drawer handle the scrim, swipe to close and focus. `ModalBottomSheet` needs `@OptIn(ExperimentalMaterial3Api::class)`."
|
|
48
|
+
},
|
|
37
49
|
{
|
|
38
50
|
"ods": "emptyBox",
|
|
39
51
|
"swiftui": "`ContentUnavailableView`",
|
|
@@ -157,6 +169,12 @@
|
|
|
157
169
|
"compose": "Not applicable: web page pattern",
|
|
158
170
|
"note": "In an app screen: rows of a `List` / `ListItem`s."
|
|
159
171
|
},
|
|
172
|
+
{
|
|
173
|
+
"ods": "onThisPage",
|
|
174
|
+
"swiftui": "Not applicable: web page pattern",
|
|
175
|
+
"compose": "Not applicable: web page pattern",
|
|
176
|
+
"note": "A site is web only. A long screen is a `List` in sections."
|
|
177
|
+
},
|
|
160
178
|
{
|
|
161
179
|
"ods": "pageHeader",
|
|
162
180
|
"swiftui": "Not applicable: web page pattern",
|
|
@@ -207,7 +225,25 @@
|
|
|
207
225
|
"ods": "settingsSection",
|
|
208
226
|
"swiftui": "A `Section` with a header `Text` and footer `Text` in a grouped `Form`",
|
|
209
227
|
"compose": "A `Column` with a title `Text`, a supporting `Text` and the controls under a `HorizontalDivider`",
|
|
210
|
-
"note": "A danger zone gets its own `Section` with the error color on the header. Settings Columns is a screen layout: one column on a phone. For Settings Layout, on a phone the nav is its own screen, pushed with `NavigationStack` / `NavHost`."
|
|
228
|
+
"note": "A danger zone gets its own `Section` with the error color on the header. Settings Columns is a screen layout: one column on a phone. For Settings Layout, on a phone the nav is its own screen, pushed with `NavigationStack` / `NavHost`. `navWidth=\"wide\"` (a list beside its detail) is a `NavigationSplitView` list column / `ListDetailPaneScaffold`."
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"ods": "sidePane",
|
|
232
|
+
"swiftui": "`.inspector(isPresented:)` with `.inspectorColumnWidth(min:ideal:max:)`",
|
|
233
|
+
"compose": "`SupportingPaneScaffold`",
|
|
234
|
+
"note": "The system resizes the inspector on iPad and Mac and shows it as a sheet on iPhone. `SupportingPaneScaffold` is in the Material 3 adaptive library and needs `@OptIn(ExperimentalMaterial3AdaptiveApi::class)`."
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"ods": "siteFooter",
|
|
238
|
+
"swiftui": "Not applicable: web page pattern",
|
|
239
|
+
"compose": "Not applicable: web page pattern",
|
|
240
|
+
"note": "A site is web only. An app has no footer: its links live in Settings, as rows."
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"ods": "siteHeader",
|
|
244
|
+
"swiftui": "Not applicable: web page pattern",
|
|
245
|
+
"compose": "Not applicable: web page pattern",
|
|
246
|
+
"note": "A site is web only. In an app: `NavigationStack` with a toolbar, and a `TabView` or `NavigationSuiteScaffold` for the places."
|
|
211
247
|
},
|
|
212
248
|
{
|
|
213
249
|
"ods": "sourceCard",
|
|
@@ -296,6 +332,12 @@
|
|
|
296
332
|
"swiftui": "`Text(_:style:)` (`.relative`) or `Text(_:format:)` (`.dateTime`)",
|
|
297
333
|
"compose": "`Text` with `DateUtils.getRelativeTimeSpanString` or `DateTimeFormatter.ofLocalizedDateTime`"
|
|
298
334
|
},
|
|
335
|
+
{
|
|
336
|
+
"ods": "titleBar",
|
|
337
|
+
"swiftui": "`.navigationTitle` with `.toolbar` items",
|
|
338
|
+
"compose": "`TopAppBar` with `navigationIcon` and `actions`",
|
|
339
|
+
"note": "The main action stays in the toolbar; the rest go in a `Menu` / an overflow `DropdownMenu`."
|
|
340
|
+
},
|
|
299
341
|
{
|
|
300
342
|
"ods": "toaster",
|
|
301
343
|
"swiftui": "`ODSBanner` for an inline message; a system banner (a local notification) when the app is not in front",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import AppShell from "../components/appShell";
|
|
4
|
+
declare const meta: Meta<typeof AppShell>;
|
|
5
|
+
export default meta;
|
|
6
|
+
declare function ShellBox({ initialNav, initialPane, resizable }: {
|
|
7
|
+
initialNav?: boolean;
|
|
8
|
+
initialPane?: boolean;
|
|
9
|
+
resizable?: boolean;
|
|
10
|
+
}): React.JSX.Element;
|
|
11
|
+
type Story = StoryObj<typeof ShellBox>;
|
|
12
|
+
export declare const Default: Story;
|
|
13
|
+
export declare const WithPane: Story;
|
|
14
|
+
export declare const Phone: Story;
|
|
15
|
+
export declare const Probe: Story;
|