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,151 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useSlidingIndicator } from './slidingIndicator';
|
|
4
|
+
import { focusRing } from './sharedStyles';
|
|
5
|
+
import { hashId, isAtBottom, pickCurrent } from '../internal/scrollSpy';
|
|
6
|
+
// A click or a #hash pins its item as current while the page scrolls there, so the items in between don't flash past
|
|
7
|
+
var PIN_LIMIT = 1000;
|
|
8
|
+
var headerOffset = function () { return parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--os-header-offset')) || 0; };
|
|
9
|
+
var INPUT_EVENTS = ['wheel', 'touchstart', 'keydown', 'pointerdown'];
|
|
10
|
+
/**
|
|
11
|
+
* Links to a long page's headings, with the one the reader is at marked. The current heading is the last one
|
|
12
|
+
* above `offset`; the last item at the end of the scroll; the one in the `#hash` on load. A click keeps its item
|
|
13
|
+
* current until the scroll ends. Reduced motion jumps instead of scrolling.
|
|
14
|
+
*/
|
|
15
|
+
export default function OnThisPage(_a) {
|
|
16
|
+
var _b, _c;
|
|
17
|
+
var items = _a.items, _d = _a["aria-label"], ariaLabel = _d === void 0 ? 'On this page' : _d, root = _a.root, offset = _a.offset;
|
|
18
|
+
var ids = items.map(function (item) { return item.id; });
|
|
19
|
+
var key = ids.join('\n');
|
|
20
|
+
var _e = useState((_c = (_b = items[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null), current = _e[0], setCurrent = _e[1];
|
|
21
|
+
var _f = useSlidingIndicator("".concat(key, "|").concat(current)), containerRef = _f.containerRef, indicator = _f.indicator;
|
|
22
|
+
var pin = useRef(null);
|
|
23
|
+
var pinTimer = useRef(undefined);
|
|
24
|
+
// The effect below puts its recompute here, for the click handler
|
|
25
|
+
var refresh = useRef(function () { });
|
|
26
|
+
var setPin = function (id, until) {
|
|
27
|
+
clearTimeout(pinTimer.current);
|
|
28
|
+
pin.current = { id: id, until: until };
|
|
29
|
+
setCurrent(id);
|
|
30
|
+
// Where scrollend exists it ends the pin; the timer is for a browser without it
|
|
31
|
+
if (until === 'scrollend' && !('onscrollend' in window)) {
|
|
32
|
+
pinTimer.current = setTimeout(function () {
|
|
33
|
+
pin.current = null;
|
|
34
|
+
refresh.current();
|
|
35
|
+
}, PIN_LIMIT);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
if (ids.length < 2)
|
|
40
|
+
return;
|
|
41
|
+
var rootEl = root ? document.getElementById(root) : null;
|
|
42
|
+
var target = rootEl !== null && rootEl !== void 0 ? rootEl : window;
|
|
43
|
+
var frame = 0;
|
|
44
|
+
var compute = function () {
|
|
45
|
+
frame = 0;
|
|
46
|
+
if (pin.current)
|
|
47
|
+
return;
|
|
48
|
+
var base = rootEl ? rootEl.getBoundingClientRect().top : 0;
|
|
49
|
+
var tops = ids.map(function (id) {
|
|
50
|
+
var el = document.getElementById(id);
|
|
51
|
+
return el ? el.getBoundingClientRect().top - base : null;
|
|
52
|
+
});
|
|
53
|
+
var metrics = rootEl
|
|
54
|
+
? { scrollTop: rootEl.scrollTop, clientHeight: rootEl.clientHeight, scrollHeight: rootEl.scrollHeight }
|
|
55
|
+
: {
|
|
56
|
+
scrollTop: window.scrollY,
|
|
57
|
+
clientHeight: window.innerHeight,
|
|
58
|
+
scrollHeight: document.documentElement.scrollHeight,
|
|
59
|
+
};
|
|
60
|
+
var i = pickCurrent(tops, offset !== null && offset !== void 0 ? offset : 40 + (rootEl ? 0 : headerOffset()), isAtBottom(metrics));
|
|
61
|
+
if (i >= 0)
|
|
62
|
+
setCurrent(ids[i]);
|
|
63
|
+
};
|
|
64
|
+
var schedule = function () {
|
|
65
|
+
if (!frame)
|
|
66
|
+
frame = requestAnimationFrame(compute);
|
|
67
|
+
};
|
|
68
|
+
refresh.current = compute;
|
|
69
|
+
var release = function (only) {
|
|
70
|
+
if (!pin.current || (only && pin.current.until !== only))
|
|
71
|
+
return;
|
|
72
|
+
clearTimeout(pinTimer.current);
|
|
73
|
+
pin.current = null;
|
|
74
|
+
schedule();
|
|
75
|
+
};
|
|
76
|
+
var onInput = function () { return release(); };
|
|
77
|
+
var onScrollEnd = function () { return release('scrollend'); };
|
|
78
|
+
var onHashChange = function () {
|
|
79
|
+
var id = hashId(window.location.hash, ids);
|
|
80
|
+
if (id)
|
|
81
|
+
setPin(id, 'scrollend');
|
|
82
|
+
};
|
|
83
|
+
// Opened with a #hash: that item is current until the reader scrolls
|
|
84
|
+
var initial = hashId(window.location.hash, ids);
|
|
85
|
+
if (initial)
|
|
86
|
+
setPin(initial, 'input');
|
|
87
|
+
else
|
|
88
|
+
compute();
|
|
89
|
+
target.addEventListener('scroll', schedule, { passive: true });
|
|
90
|
+
target.addEventListener('scrollend', onScrollEnd);
|
|
91
|
+
window.addEventListener('resize', schedule);
|
|
92
|
+
window.addEventListener('hashchange', onHashChange);
|
|
93
|
+
INPUT_EVENTS.forEach(function (type) { return target.addEventListener(type, onInput, { passive: true }); });
|
|
94
|
+
return function () {
|
|
95
|
+
cancelAnimationFrame(frame);
|
|
96
|
+
clearTimeout(pinTimer.current);
|
|
97
|
+
pin.current = null;
|
|
98
|
+
refresh.current = function () { };
|
|
99
|
+
target.removeEventListener('scroll', schedule);
|
|
100
|
+
target.removeEventListener('scrollend', onScrollEnd);
|
|
101
|
+
window.removeEventListener('resize', schedule);
|
|
102
|
+
window.removeEventListener('hashchange', onHashChange);
|
|
103
|
+
INPUT_EVENTS.forEach(function (type) { return target.removeEventListener(type, onInput); });
|
|
104
|
+
};
|
|
105
|
+
}, [key, root, offset]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
106
|
+
var onLinkClick = function (e, id) {
|
|
107
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
|
|
108
|
+
return;
|
|
109
|
+
var heading = document.getElementById(id);
|
|
110
|
+
if (!heading)
|
|
111
|
+
return;
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
var rootEl = root ? document.getElementById(root) : null;
|
|
114
|
+
var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
115
|
+
// The heading ends just under a header above the page; 'instant' ignores a page's own `scroll-behavior: smooth`
|
|
116
|
+
var behavior = reduced ? 'instant' : 'smooth';
|
|
117
|
+
var gap = rootEl ? 0 : headerOffset();
|
|
118
|
+
var delta = heading.getBoundingClientRect().top - (rootEl ? rootEl.getBoundingClientRect().top : 0) - gap;
|
|
119
|
+
window.history.pushState(window.history.state, '', "#".concat(encodeURIComponent(id)));
|
|
120
|
+
var top = rootEl ? rootEl.scrollTop : window.scrollY;
|
|
121
|
+
var room = rootEl
|
|
122
|
+
? rootEl.scrollHeight - rootEl.clientHeight - top
|
|
123
|
+
: document.documentElement.scrollHeight - window.innerHeight - top;
|
|
124
|
+
if (Math.abs(delta > 0 ? Math.min(delta, room) : Math.max(delta, -top)) < 1) {
|
|
125
|
+
// Nowhere to scroll (already there, or at an end): no scrollend to wait for
|
|
126
|
+
setCurrent(id);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
setPin(id, 'scrollend');
|
|
130
|
+
if (rootEl)
|
|
131
|
+
rootEl.scrollBy({ top: delta, behavior: behavior });
|
|
132
|
+
else
|
|
133
|
+
window.scrollBy({ top: delta, behavior: behavior });
|
|
134
|
+
};
|
|
135
|
+
if (items.length < 2)
|
|
136
|
+
return null;
|
|
137
|
+
return (<nav ref={containerRef} aria-label={ariaLabel} className="relative border-l border-misc-divider">
|
|
138
|
+
{indicator && (<span aria-hidden className={"pointer-events-none absolute -left-px top-0 w-0.5 rounded-full bg-primary-dark ".concat(indicator.animate ? 'transition-[transform,height] duration-[var(--os-duration-slide)] ease-emphasized motion-reduce:transition-none' : '')} style={{ transform: "translateY(".concat(indicator.y, "px)"), height: indicator.height }}/>)}
|
|
139
|
+
<ul className="m-0 flex list-none flex-col p-0">
|
|
140
|
+
{items.map(function (item) {
|
|
141
|
+
var isCurrent = item.id === current;
|
|
142
|
+
return (<li key={item.id}>
|
|
143
|
+
<a href={"#".concat(item.id)} aria-current={isCurrent ? 'location' : undefined} data-tab-selected={isCurrent ? 'true' : undefined} onClick={function (e) { return onLinkClick(e, item.id); }} className={"block rounded-control py-1 pr-2 text-body2 hover:text-fg-primary ".concat(item.level === 3 ? 'pl-6' : 'pl-3', " ").concat(isCurrent ? 'text-fg-primary' : 'text-fg-secondary', " ").concat(focusRing)}>
|
|
144
|
+
{item.label}
|
|
145
|
+
</a>
|
|
146
|
+
</li>);
|
|
147
|
+
})}
|
|
148
|
+
</ul>
|
|
149
|
+
</nav>);
|
|
150
|
+
}
|
|
151
|
+
export { OnThisPage };
|
|
@@ -5,6 +5,12 @@ interface PageShellProps extends React.ComponentPropsWithoutRef<'main'> {
|
|
|
5
5
|
wide?: boolean;
|
|
6
6
|
/** Let the column run the full width of the window, for a page that is a feed of images. Keeps the side space. */
|
|
7
7
|
fluid?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* A column beside the page, for an `OnThisPage`: 220px and sticky from the xl breakpoint, hidden below it. It sticks below a `SiteHeader` (`--os-header-offset`).
|
|
10
|
+
* The page also gives each level 2 and 3 heading with an `id` a scroll margin the height of that header, so a `#hash` link lands below it.
|
|
11
|
+
* Not for content a phone needs.
|
|
12
|
+
*/
|
|
13
|
+
aside?: React.ReactNode;
|
|
8
14
|
}
|
|
9
|
-
export default function PageShell({ children, wide, fluid, className, ...rest }: PageShellProps): React.JSX.Element;
|
|
15
|
+
export default function PageShell({ children, wide, fluid, aside, className, ...rest }: PageShellProps): React.JSX.Element;
|
|
10
16
|
export {};
|
|
@@ -13,7 +13,20 @@ import React from 'react';
|
|
|
13
13
|
// The frame of a page: the column, its side space, and the space between sections.
|
|
14
14
|
// Anything else given (data-* attributes, an id) goes to the <main>.
|
|
15
15
|
export default function PageShell(_a) {
|
|
16
|
-
var children = _a.children, _b = _a.wide, wide = _b === void 0 ? false : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, _d = _a.className, className = _d === void 0 ? '' : _d, rest = __rest(_a, ["children", "wide", "fluid", "className"]);
|
|
16
|
+
var children = _a.children, _b = _a.wide, wide = _b === void 0 ? false : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, aside = _a.aside, _d = _a.className, className = _d === void 0 ? '' : _d, rest = __rest(_a, ["children", "wide", "fluid", "aside", "className"]);
|
|
17
|
+
if (aside) {
|
|
18
|
+
// The page column and the aside sit side by side from xl, centered together
|
|
19
|
+
return (<main className={"min-h-screen [&_:is(h2,h3)[id]]:scroll-mt-[var(--os-header-offset,0px)] ".concat(className)} {...rest}>
|
|
20
|
+
<div className="mx-auto flex w-full items-start justify-center">
|
|
21
|
+
<div className={"flex min-w-0 w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
|
|
22
|
+
{children}
|
|
23
|
+
</div>
|
|
24
|
+
<div className="sticky top-[calc(var(--os-header-offset,0px)+1.5rem)] mr-xxlarge mt-giant hidden max-h-[calc(100dvh-var(--os-header-offset,0px)-3rem)] w-[220px] shrink-0 overflow-y-auto xl:block">
|
|
25
|
+
{aside}
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</main>);
|
|
29
|
+
}
|
|
17
30
|
return (<main className={"min-h-screen ".concat(className)} {...rest}>
|
|
18
31
|
<div className={"mx-auto flex w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
|
|
19
32
|
{children}
|
|
@@ -5,6 +5,7 @@ import { usePopper } from 'react-popper';
|
|
|
5
5
|
import { overlayHidden, overlayTransition, overlayVisible } from './sharedStyles';
|
|
6
6
|
import { useOverlayTransition } from './useOverlayTransition';
|
|
7
7
|
import Menu from './menu';
|
|
8
|
+
import { isInTopOverlay } from '../internal/overlayStack';
|
|
8
9
|
export default function Popover(_a) {
|
|
9
10
|
var id = _a.id, anchorEl = _a.anchorEl, open = _a.open, onClose = _a.onClose, children = _a.children, _b = _a.returnFocus, returnFocus = _b === void 0 ? false : _b;
|
|
10
11
|
var _c = useState(null), popoverElement = _c[0], setPopoverElement = _c[1];
|
|
@@ -28,6 +29,9 @@ export default function Popover(_a) {
|
|
|
28
29
|
};
|
|
29
30
|
var handleKeyDown = function (event) {
|
|
30
31
|
if (event.key === 'Escape') {
|
|
32
|
+
// Under a Modal or Drawer opened after it, the Escape belongs to that overlay
|
|
33
|
+
if (!isInTopOverlay(anchorEl))
|
|
34
|
+
return;
|
|
31
35
|
// Close only the Popover: keep this Escape from reaching a Modal's window listener
|
|
32
36
|
event.stopPropagation();
|
|
33
37
|
onClose();
|
|
@@ -26,6 +26,11 @@ interface SettingsLayoutProps {
|
|
|
26
26
|
showContent: boolean;
|
|
27
27
|
/** A Button that goes back to the nav. Shown only below md, above the content. */
|
|
28
28
|
back?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* The nav column from md up: `narrow` (16rem, default) for a settings nav, `wide` (22rem) for a list of rows beside its detail.
|
|
31
|
+
* Below md a `wide` list is the whole screen: it drops its divider, and its open row (the one with `aria-current`) does not look selected.
|
|
32
|
+
*/
|
|
33
|
+
navWidth?: 'narrow' | 'wide';
|
|
29
34
|
}
|
|
30
|
-
export declare function SettingsLayout({ nav, children, showContent, back }: SettingsLayoutProps): React.JSX.Element;
|
|
35
|
+
export declare function SettingsLayout({ nav, children, showContent, back, navWidth }: SettingsLayoutProps): React.JSX.Element;
|
|
31
36
|
export { SettingsSection };
|
|
@@ -25,8 +25,15 @@ export function SettingsColumns(_a) {
|
|
|
25
25
|
// A side nav beside its content from md up. On a phone the nav is the page and an item opens its content, so only one shows at a time.
|
|
26
26
|
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
27
27
|
var isHidden = function (el) { return !el || getComputedStyle(el).display === 'none'; };
|
|
28
|
+
// Written out whole so the app's Tailwind finds them
|
|
29
|
+
var navColumns = {
|
|
30
|
+
narrow: 'md:grid-cols-[16rem_minmax(0,1fr)]',
|
|
31
|
+
wide: 'md:grid-cols-[22rem_minmax(0,1fr)]',
|
|
32
|
+
};
|
|
33
|
+
// Below md a list of rows is the screen on its own: no divider beside nothing, and no row marked open while nothing is open
|
|
34
|
+
var listOnPhone = 'max-md:[&>nav]:border-r-0 max-md:[&_[aria-current]:not([aria-current=false])]:bg-transparent max-md:[&_[aria-current]:not([aria-current=false])_*]:bg-transparent max-md:[&_[aria-current]:not([aria-current=false])_*]:text-fg-primary';
|
|
28
35
|
export function SettingsLayout(_a) {
|
|
29
|
-
var nav = _a.nav, children = _a.children, showContent = _a.showContent, back = _a.back;
|
|
36
|
+
var nav = _a.nav, children = _a.children, showContent = _a.showContent, back = _a.back, _b = _a.navWidth, navWidth = _b === void 0 ? 'narrow' : _b;
|
|
30
37
|
var navRef = useRef(null);
|
|
31
38
|
var contentRef = useRef(null);
|
|
32
39
|
var prev = useRef(showContent);
|
|
@@ -47,8 +54,8 @@ export function SettingsLayout(_a) {
|
|
|
47
54
|
(_d = ((_c = items === null || items === void 0 ? void 0 : items.querySelector('[aria-current]')) !== null && _c !== void 0 ? _c : items === null || items === void 0 ? void 0 : items.querySelector(FOCUSABLE))) === null || _d === void 0 ? void 0 : _d.focus();
|
|
48
55
|
}
|
|
49
56
|
}, [showContent]);
|
|
50
|
-
return (<div className="grid grid-cols-1 items-start gap-xlarge
|
|
51
|
-
<div ref={navRef} className={showContent ? 'hidden md:block' : 'block'}>{nav}</div>
|
|
57
|
+
return (<div className={"grid grid-cols-1 items-start gap-xlarge ".concat(navColumns[navWidth])}>
|
|
58
|
+
<div ref={navRef} className={"".concat(showContent ? 'hidden md:block' : 'block').concat(navWidth === 'wide' ? " ".concat(listOnPhone) : '')}>{nav}</div>
|
|
52
59
|
<div ref={contentRef} className={"flex-col gap-large ".concat(showContent ? 'flex' : 'hidden md:flex')}>
|
|
53
60
|
{back && <div className="md:hidden">{back}</div>}
|
|
54
61
|
{children}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface SidePaneProps {
|
|
3
|
+
/** Names the pane and shows in its title bar */
|
|
4
|
+
title: string;
|
|
5
|
+
/** Close and Escape call it; the page then removes the pane */
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/** Buttons in the title bar, before Close */
|
|
9
|
+
actions?: React.ReactNode;
|
|
10
|
+
/** The width in px from lg up. Default 24rem. */
|
|
11
|
+
width?: number;
|
|
12
|
+
/** Makes the start edge a handle that resizes the pane, by pointer or by arrow keys */
|
|
13
|
+
onWidthChange?: (width: number) => void;
|
|
14
|
+
/** The smallest width in px. Default 320. */
|
|
15
|
+
minWidth?: number;
|
|
16
|
+
/** The largest width in px. Default 60% of the window. */
|
|
17
|
+
maxWidth?: number;
|
|
18
|
+
/** The Close button's name. Default 'Close <title>'. */
|
|
19
|
+
closeLabel?: string;
|
|
20
|
+
}
|
|
21
|
+
/** What a ref on SidePane gets: `focus()` moves focus to the pane's title, to bring an open pane forward */
|
|
22
|
+
export interface SidePaneHandle {
|
|
23
|
+
focus(): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A pane beside the page, not over it: no scrim, the page stays usable. Focus moves to its title on
|
|
27
|
+
* open and back to the opener on close. Escape closes it while focus is inside and no overlay is on top.
|
|
28
|
+
* Escape anywhere inside the pane closes it, including an Escape that hides a tooltip or clears a field.
|
|
29
|
+
*/
|
|
30
|
+
declare const SidePane: React.ForwardRefExoticComponent<SidePaneProps & React.RefAttributes<SidePaneHandle>>;
|
|
31
|
+
export default SidePane;
|
|
32
|
+
export { SidePane };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { forwardRef, useEffect, useId, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
import IconButton from './iconButton';
|
|
5
|
+
import TitleBar from './titleBar';
|
|
6
|
+
import { focusRing } from './sharedStyles';
|
|
7
|
+
import { claimEvent, isInTopOverlay } from '../internal/overlayStack';
|
|
8
|
+
import { clampWidth, dragWidth, keyWidth, paneLimits } from '../internal/resize';
|
|
9
|
+
// useLayoutEffect warns on a server render, where it cannot run; useEffect is the same there and silent
|
|
10
|
+
var useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
11
|
+
var DEFAULT_WIDTH = 384;
|
|
12
|
+
/**
|
|
13
|
+
* A pane beside the page, not over it: no scrim, the page stays usable. Focus moves to its title on
|
|
14
|
+
* open and back to the opener on close. Escape closes it while focus is inside and no overlay is on top.
|
|
15
|
+
* Escape anywhere inside the pane closes it, including an Escape that hides a tooltip or clears a field.
|
|
16
|
+
*/
|
|
17
|
+
var SidePane = forwardRef(function SidePane(_a, ref) {
|
|
18
|
+
var title = _a.title, onClose = _a.onClose, children = _a.children, actions = _a.actions, width = _a.width, onWidthChange = _a.onWidthChange, _b = _a.minWidth, minWidth = _b === void 0 ? 320 : _b, maxWidth = _a.maxWidth, closeLabel = _a.closeLabel;
|
|
19
|
+
var asideRef = useRef(null);
|
|
20
|
+
var titleId = useId();
|
|
21
|
+
var onCloseRef = useRef(onClose);
|
|
22
|
+
onCloseRef.current = onClose;
|
|
23
|
+
var focusTitle = function () { var _a; return (_a = document.getElementById(titleId)) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
24
|
+
useImperativeHandle(ref, function () { return ({ focus: focusTitle }); });
|
|
25
|
+
// Focus the title on mount, and on unmount give focus back to what had it, if focus was in the pane.
|
|
26
|
+
// A layout effect, so the cleanup runs while the pane is still on the page and can tell.
|
|
27
|
+
var returnTo = useRef(null);
|
|
28
|
+
var mounted = useRef(false);
|
|
29
|
+
useIsomorphicLayoutEffect(function () {
|
|
30
|
+
mounted.current = true;
|
|
31
|
+
var aside = asideRef.current;
|
|
32
|
+
var active = document.activeElement;
|
|
33
|
+
// StrictMode runs this twice; the second run finds focus already in the pane and keeps the opener
|
|
34
|
+
if (active && !(aside === null || aside === void 0 ? void 0 : aside.contains(active)))
|
|
35
|
+
returnTo.current = active;
|
|
36
|
+
focusTitle();
|
|
37
|
+
return function () {
|
|
38
|
+
mounted.current = false;
|
|
39
|
+
if (!(aside === null || aside === void 0 ? void 0 : aside.contains(document.activeElement)))
|
|
40
|
+
return;
|
|
41
|
+
var target = returnTo.current;
|
|
42
|
+
// After the commit: the opener may be in content that shows again in the same update
|
|
43
|
+
// (AppShell hides main beside a pane below lg). A remount in StrictMode cancels it.
|
|
44
|
+
queueMicrotask(function () {
|
|
45
|
+
if (!mounted.current)
|
|
46
|
+
target === null || target === void 0 ? void 0 : target.focus();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
50
|
+
// On window, after Popover's document listener, which keeps a menu's Escape to itself
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
var handleKeyDown = function (e) {
|
|
53
|
+
if (e.key !== 'Escape' || e.defaultPrevented)
|
|
54
|
+
return;
|
|
55
|
+
var aside = asideRef.current;
|
|
56
|
+
if (!aside || !aside.contains(document.activeElement) || !isInTopOverlay(aside))
|
|
57
|
+
return;
|
|
58
|
+
if (claimEvent(e))
|
|
59
|
+
onCloseRef.current();
|
|
60
|
+
};
|
|
61
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
62
|
+
return function () { return window.removeEventListener('keydown', handleKeyDown); };
|
|
63
|
+
}, []);
|
|
64
|
+
var resizable = !!onWidthChange;
|
|
65
|
+
var sized = resizable || width !== undefined;
|
|
66
|
+
// The default maximum needs the window, so it is known only after mount (the server uses the width)
|
|
67
|
+
var _c = useState(null), windowWidth = _c[0], setWindowWidth = _c[1];
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
if (!sized || maxWidth !== undefined)
|
|
70
|
+
return;
|
|
71
|
+
var update = function () { return setWindowWidth(window.innerWidth); };
|
|
72
|
+
update();
|
|
73
|
+
window.addEventListener('resize', update);
|
|
74
|
+
return function () { return window.removeEventListener('resize', update); };
|
|
75
|
+
}, [sized, maxWidth]);
|
|
76
|
+
var limits = maxWidth !== undefined || windowWidth !== null
|
|
77
|
+
? paneLimits(minWidth, maxWidth, windowWidth !== null && windowWidth !== void 0 ? windowWidth : 0)
|
|
78
|
+
: { min: minWidth, max: Math.max(minWidth, width !== null && width !== void 0 ? width : DEFAULT_WIDTH) };
|
|
79
|
+
var current = clampWidth(width !== null && width !== void 0 ? width : DEFAULT_WIDTH, limits.min, limits.max);
|
|
80
|
+
var drag = useRef(null);
|
|
81
|
+
var endDrag = function (e) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
drag.current = null;
|
|
84
|
+
if ((_b = (_a = e.currentTarget).hasPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, e.pointerId))
|
|
85
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
86
|
+
};
|
|
87
|
+
return (<aside ref={asideRef} aria-labelledby={titleId} style={sized ? { '--side-pane-width': "".concat(current, "px") } : undefined} className={"relative flex w-full min-w-0 flex-col bg-background-default lg:h-full lg:shrink-0 lg:border-l lg:border-misc-divider ".concat(sized ? 'lg:w-[var(--side-pane-width)]' : 'lg:w-[24rem]')}>
|
|
88
|
+
{resizable && (<div role="separator" aria-orientation="vertical" aria-valuenow={current} aria-valuemin={limits.min} aria-valuemax={limits.max} aria-label={"Resize ".concat(title)} tabIndex={0} className={"group absolute inset-y-0 left-0 z-10 w-3 -translate-x-1/2 cursor-col-resize touch-none hidden lg:block ".concat(focusRing)} onKeyDown={function (e) {
|
|
89
|
+
var next = keyWidth(e.key, current, limits.min, limits.max);
|
|
90
|
+
if (next === null)
|
|
91
|
+
return;
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
onWidthChange(next);
|
|
94
|
+
}} onPointerDown={function (e) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
if (e.button !== 0)
|
|
97
|
+
return;
|
|
98
|
+
// No text selection while dragging
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
(_b = (_a = e.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, e.pointerId);
|
|
101
|
+
drag.current = { x: e.clientX, width: current };
|
|
102
|
+
}} onPointerMove={function (e) {
|
|
103
|
+
if (!drag.current)
|
|
104
|
+
return;
|
|
105
|
+
// The button came up somewhere the up event never reached us
|
|
106
|
+
if (e.buttons === 0) {
|
|
107
|
+
drag.current = null;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
onWidthChange(dragWidth(drag.current.width, drag.current.x, e.clientX, limits.min, limits.max));
|
|
111
|
+
}} onPointerUp={endDrag} onPointerCancel={endDrag} onLostPointerCapture={function () {
|
|
112
|
+
drag.current = null;
|
|
113
|
+
}}>
|
|
114
|
+
<div className="mx-auto h-full w-0.5 group-hover:bg-fg-secondary group-active:bg-fg-primary"/>
|
|
115
|
+
</div>)}
|
|
116
|
+
<div className="shrink-0 border-b border-misc-divider py-2 pl-4 pr-2">
|
|
117
|
+
<TitleBar title={title} level={2} id={titleId} actions={<>
|
|
118
|
+
{actions}
|
|
119
|
+
<IconButton color="iconOnly" state="enabled" size="medium" icon={X} ariaLabel={closeLabel !== null && closeLabel !== void 0 ? closeLabel : "Close ".concat(title)} onClick={onClose}/>
|
|
120
|
+
</>}/>
|
|
121
|
+
</div>
|
|
122
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-4 py-4 text-body1 text-fg-primary" style={{ scrollbarWidth: 'thin' }}>
|
|
123
|
+
{children}
|
|
124
|
+
</div>
|
|
125
|
+
</aside>);
|
|
126
|
+
});
|
|
127
|
+
export default SidePane;
|
|
128
|
+
export { SidePane };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SiteBrand } from './siteHeader';
|
|
3
|
+
export interface SiteFooterLink {
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
/** Opens in a new tab and says so: a small icon and the hidden words '(opens in a new tab)' */
|
|
7
|
+
external?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SiteFooterColumn {
|
|
10
|
+
title: string;
|
|
11
|
+
links: SiteFooterLink[];
|
|
12
|
+
}
|
|
13
|
+
interface SiteFooterProps {
|
|
14
|
+
brand?: SiteBrand;
|
|
15
|
+
/** Titled lists of links: two across on a phone, up to four from md */
|
|
16
|
+
columns?: SiteFooterColumn[];
|
|
17
|
+
/** Links without a column: one row that wraps */
|
|
18
|
+
links?: SiteFooterLink[];
|
|
19
|
+
/** The caption line, e.g. '© 2026 Acme' */
|
|
20
|
+
legal?: string;
|
|
21
|
+
}
|
|
22
|
+
/** A site's footer: the brand, a `<nav aria-label="Footer">` of linked columns and a row of links, and a legal line */
|
|
23
|
+
export default function SiteFooter({ brand, columns, links, legal }: SiteFooterProps): React.JSX.Element;
|
|
24
|
+
export { SiteFooter };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useId } from 'react';
|
|
3
|
+
import Link from './link';
|
|
4
|
+
import { SiteBrandLink } from '../internal/siteBrand';
|
|
5
|
+
// Written out whole so Tailwind finds them
|
|
6
|
+
var columnCount = ['md:grid-cols-1', 'md:grid-cols-1', 'md:grid-cols-2', 'md:grid-cols-3', 'md:grid-cols-4'];
|
|
7
|
+
var FooterLink = function (_a) {
|
|
8
|
+
var link = _a.link;
|
|
9
|
+
return (<Link href={link.href} size="body2" openInNewTab={link.external} announceNewTab={link.external}>
|
|
10
|
+
{link.label}
|
|
11
|
+
</Link>);
|
|
12
|
+
};
|
|
13
|
+
/** A site's footer: the brand, a `<nav aria-label="Footer">` of linked columns and a row of links, and a legal line */
|
|
14
|
+
export default function SiteFooter(_a) {
|
|
15
|
+
var brand = _a.brand, columns = _a.columns, links = _a.links, legal = _a.legal;
|
|
16
|
+
var hasNav = !!(columns === null || columns === void 0 ? void 0 : columns.length) || !!(links === null || links === void 0 ? void 0 : links.length);
|
|
17
|
+
return (<footer className="border-t border-misc-divider bg-background-default">
|
|
18
|
+
<div className="mx-auto flex w-full max-w-page-wide flex-col gap-xlarge px-xlarge py-xxlarge md:px-xxlarge">
|
|
19
|
+
{brand && <SiteBrandLink brand={brand}/>}
|
|
20
|
+
{hasNav && (<nav aria-label="Footer" className="flex flex-col gap-xlarge">
|
|
21
|
+
{!!(columns === null || columns === void 0 ? void 0 : columns.length) && (<div className={"grid grid-cols-2 gap-x-4 gap-y-xlarge ".concat(columnCount[Math.min(columns.length, 4)])}>
|
|
22
|
+
{columns.map(function (column) { return (<FooterColumn key={column.title} column={column}/>); })}
|
|
23
|
+
</div>)}
|
|
24
|
+
{!!(links === null || links === void 0 ? void 0 : links.length) && (<ul className="m-0 flex list-none flex-wrap gap-x-4 gap-y-2 p-0">
|
|
25
|
+
{links.map(function (link) { return (<li key={link.href + link.label}>
|
|
26
|
+
<FooterLink link={link}/>
|
|
27
|
+
</li>); })}
|
|
28
|
+
</ul>)}
|
|
29
|
+
</nav>)}
|
|
30
|
+
{legal && <p className="m-0 text-caption text-fg-secondary">{legal}</p>}
|
|
31
|
+
</div>
|
|
32
|
+
</footer>);
|
|
33
|
+
}
|
|
34
|
+
function FooterColumn(_a) {
|
|
35
|
+
var column = _a.column;
|
|
36
|
+
var titleId = useId();
|
|
37
|
+
return (<div className="flex min-w-0 flex-col gap-2">
|
|
38
|
+
<p id={titleId} className="m-0 text-subtitle2 text-fg-primary">
|
|
39
|
+
{column.title}
|
|
40
|
+
</p>
|
|
41
|
+
<ul aria-labelledby={titleId} className="m-0 flex list-none flex-col gap-2 p-0">
|
|
42
|
+
{column.links.map(function (link) { return (<li key={link.href + link.label}>
|
|
43
|
+
<FooterLink link={link}/>
|
|
44
|
+
</li>); })}
|
|
45
|
+
</ul>
|
|
46
|
+
</div>);
|
|
47
|
+
}
|
|
48
|
+
export { SiteFooter };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** The site's name and its way home, shared by `SiteHeader` and `SiteFooter` */
|
|
3
|
+
export interface SiteBrand {
|
|
4
|
+
/** Where the brand goes: the home page */
|
|
5
|
+
href: string;
|
|
6
|
+
/** The site's name. It is the logo's alt text, and the text shown when there is no logo. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The logo's file. Without it the name is shown as text. */
|
|
9
|
+
src?: string;
|
|
10
|
+
/** The logo's size in px; set both so the bar keeps its height while the file loads. Default height 28. */
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SiteHeaderLink {
|
|
15
|
+
label: string;
|
|
16
|
+
href: string;
|
|
17
|
+
/** The page the reader is on: gets `aria-current="page"` */
|
|
18
|
+
current?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface SiteHeaderProps {
|
|
21
|
+
brand: SiteBrand;
|
|
22
|
+
/** The main places, in order. From md a row in the bar; below md in the menu. */
|
|
23
|
+
links: SiteHeaderLink[];
|
|
24
|
+
/**
|
|
25
|
+
* The secondary Buttons, e.g. 'Log In': at the end of the bar from md; below md under the links in the menu,
|
|
26
|
+
* and only there. A Button here that opens its own Modal or menu should be moved out: choosing in the menu closes it.
|
|
27
|
+
*/
|
|
28
|
+
actions?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* The main action, e.g. 'Sign Up': last in the bar at every width, so below md it stays beside the brand and the
|
|
31
|
+
* Menu IconButton. It is not in the menu, so do not repeat it in `actions`.
|
|
32
|
+
*/
|
|
33
|
+
phoneAction?: React.ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* A second row inside the bar at every width, under the brand and the actions: e.g. the section `Tab`s of a docs site.
|
|
36
|
+
* It never moves into the Menu, so keep it short enough for a phone.
|
|
37
|
+
*/
|
|
38
|
+
nav?: React.ReactNode;
|
|
39
|
+
/** The Menu IconButton's name, and the Drawer's. Default 'Menu'. */
|
|
40
|
+
menuLabel?: string;
|
|
41
|
+
/** The skip link's text. Default 'Skip to content'. */
|
|
42
|
+
skipLabel?: string;
|
|
43
|
+
/** The id the skip link goes to. Default 'main'. Give `PageShell` (or your `<main>`) `id={mainId}` and `tabIndex={-1}`, so focus can move into it. */
|
|
44
|
+
mainId?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A site's bar, sticky at the top: a skip link, the brand, the main links and the actions. Below md the
|
|
48
|
+
* links and `actions` move into a start Drawer a Menu IconButton opens; the brand and the `phoneAction` stay.
|
|
49
|
+
* With no `links` and no `actions` there is no Main nav, no Menu IconButton and no Drawer.
|
|
50
|
+
* While mounted it sets `--os-header-offset` (its height) on `<html>`; `PageShell` with `aside` gives its level 2 and 3 headings
|
|
51
|
+
* `scroll-margin-top: var(--os-header-offset, 0px)`, so a `#hash` link lands below the bar. Other headings need the same.
|
|
52
|
+
* Use one SiteHeader per page: there is one `--os-header-offset`, and unmounting any header removes it.
|
|
53
|
+
*/
|
|
54
|
+
export default function SiteHeader({ brand, links, actions, phoneAction, nav, menuLabel, skipLabel, mainId, }: SiteHeaderProps): React.JSX.Element;
|
|
55
|
+
export { SiteHeader };
|