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,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 };
|
|
@@ -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 };
|
|
@@ -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
|
}
|
|
@@ -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 {};
|
package/dist/components/link.jsx
CHANGED
|
@@ -12,9 +12,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import NextLink from 'next/link';
|
|
15
|
+
import { ExternalLink } from 'lucide-react';
|
|
15
16
|
import { focusRing } from './sharedStyles';
|
|
16
17
|
export default function Link(_a) {
|
|
17
|
-
var href = _a.href, children = _a.children, _b = _a.color, color = _b === void 0 ? 'info' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.openInNewTab, openInNewTab = _d === void 0 ? false : _d, _e = _a.className, className =
|
|
18
|
+
var href = _a.href, children = _a.children, _b = _a.color, color = _b === void 0 ? 'info' : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c, _d = _a.openInNewTab, openInNewTab = _d === void 0 ? false : _d, _e = _a.announceNewTab, announceNewTab = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? '' : _f;
|
|
18
19
|
// Color classes based on the color prop
|
|
19
20
|
// Light mode uses the -dark shade so link text keeps 4.5:1 on light backgrounds
|
|
20
21
|
var colorClasses = {
|
|
@@ -63,13 +64,20 @@ export default function Link(_a) {
|
|
|
63
64
|
target: '_blank',
|
|
64
65
|
rel: 'noopener noreferrer',
|
|
65
66
|
}));
|
|
67
|
+
var content = (<>
|
|
68
|
+
{children}
|
|
69
|
+
{announceNewTab && shouldOpenInNewTab && (<>
|
|
70
|
+
<ExternalLink aria-hidden="true" className="ml-1 inline size-[1em] align-[-0.125em]"/>
|
|
71
|
+
<span className="sr-only"> (opens in a new tab)</span>
|
|
72
|
+
</>)}
|
|
73
|
+
</>);
|
|
66
74
|
// Use NextLink for internal links, regular <a> for external
|
|
67
75
|
if (isExternal || shouldOpenInNewTab) {
|
|
68
76
|
return (<a href={href} {...commonProps}>
|
|
69
|
-
{children}
|
|
77
|
+
{announceNewTab ? content : children}
|
|
70
78
|
</a>);
|
|
71
79
|
}
|
|
72
80
|
return (<NextLink href={href} {...commonProps}>
|
|
73
|
-
{children}
|
|
81
|
+
{announceNewTab ? content : children}
|
|
74
82
|
</NextLink>);
|
|
75
83
|
}
|
|
@@ -36,6 +36,12 @@ interface MenuItemProps {
|
|
|
36
36
|
color?: 'default' | 'danger';
|
|
37
37
|
/** Marks the current page in a side nav so a screen reader announces it. On a link it goes on the `<a>`, otherwise on the row. */
|
|
38
38
|
'aria-current'?: 'page' | boolean;
|
|
39
|
+
/** The row's name when the label and tag alone do not say it, e.g. a count: 'Inbox, 3 unread'. On a link it goes on the `<a>`. */
|
|
40
|
+
'aria-label'?: string;
|
|
41
|
+
/** For a row that shows or hides others (a group of places): whether they are shown. Use with `role="button"`. On a link it goes on the `<a>`. */
|
|
42
|
+
'aria-expanded'?: boolean;
|
|
43
|
+
/** `2` indents the row one step, for a place inside another place. Default 1. */
|
|
44
|
+
level?: 1 | 2;
|
|
39
45
|
}
|
|
40
|
-
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, 'aria-current': ariaCurrent, }: MenuItemProps): React.JSX.Element;
|
|
46
|
+
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, 'aria-current': ariaCurrent, 'aria-label': ariaLabel, 'aria-expanded': ariaExpanded, level, }: MenuItemProps): React.JSX.Element;
|
|
41
47
|
export {};
|
|
@@ -7,7 +7,7 @@ import Tag from './tag';
|
|
|
7
7
|
import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
8
8
|
export default function MenuItem(_a) {
|
|
9
9
|
var _b;
|
|
10
|
-
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h, ariaCurrent = _a["aria-current"];
|
|
10
|
+
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h, ariaCurrent = _a["aria-current"], ariaLabel = _a["aria-label"], ariaExpanded = _a["aria-expanded"], _j = _a.level, level = _j === void 0 ? 1 : _j;
|
|
11
11
|
// Size-based icon and text classes
|
|
12
12
|
var iconSize = { tiny: 'w-4 h-4', small: 'w-5 h-5', medium: 'w-6 h-6' }[size];
|
|
13
13
|
var labelClass = { tiny: 'text-caption', small: 'text-body2', medium: 'text-body1' }[size];
|
|
@@ -18,7 +18,7 @@ export default function MenuItem(_a) {
|
|
|
18
18
|
var danger = color === 'danger' && !isSelected;
|
|
19
19
|
var content = (<div id={id} role={href ? undefined : role}
|
|
20
20
|
// A link wrapper is already focusable; otherwise the row itself takes focus
|
|
21
|
-
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
21
|
+
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} aria-label={href ? undefined : ariaLabel} aria-expanded={href ? undefined : ariaExpanded} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
22
22
|
? 'bg-primary-dark text-primary-contrast'
|
|
23
23
|
: "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
|
|
24
24
|
if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
|
|
@@ -50,5 +50,6 @@ export default function MenuItem(_a) {
|
|
|
50
50
|
</div>)}
|
|
51
51
|
</div>
|
|
52
52
|
</div>);
|
|
53
|
-
|
|
53
|
+
var row = href ? <NextLink href={href} aria-label={ariaLabel} aria-current={ariaCurrent} aria-expanded={ariaExpanded} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
|
|
54
|
+
return level === 2 ? <div className="pl-6">{row}</div> : row;
|
|
54
55
|
}
|
|
@@ -3,9 +3,7 @@ import React, { useEffect, useId, useRef } from 'react';
|
|
|
3
3
|
import { overlayHidden, overlayTransition, overlayVisible } from './sharedStyles';
|
|
4
4
|
import { useOverlayTransition } from './useOverlayTransition';
|
|
5
5
|
import { initialFocusCandidates } from '../internal/modal';
|
|
6
|
-
|
|
7
|
-
// For the first focus and the Tab trap: the same, minus a hidden input, which matches but cannot take focus
|
|
8
|
-
var PICKABLE = FOCUSABLE.replace('input:not([disabled])', 'input:not([disabled]):not([type="hidden"])');
|
|
6
|
+
import { PICKABLE, claimEvent, isTopOverlay, lockScroll, popOverlay, pushOverlay, trapTab, unlockScroll } from '../internal/overlayStack';
|
|
9
7
|
export default function Modal(_a) {
|
|
10
8
|
var isOpen = _a.isOpen, title = _a.title, secondTitle = _a.secondTitle, children = _a.children, onClose = _a.onClose, actions = _a.actions, _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.initialFocus, initialFocus = _c === void 0 ? 'first' : _c;
|
|
11
9
|
var panelRef = useRef(null);
|
|
@@ -16,7 +14,8 @@ export default function Modal(_a) {
|
|
|
16
14
|
var onCloseRef = useRef(onClose);
|
|
17
15
|
onCloseRef.current = onClose;
|
|
18
16
|
// Move focus into the panel, trap Tab inside it, close on Escape,
|
|
19
|
-
// lock page scroll, and give focus back to the trigger on close
|
|
17
|
+
// lock page scroll, and give focus back to the trigger on close.
|
|
18
|
+
// Escape and Tab act only while this Modal is the top overlay (see internal/overlayStack).
|
|
20
19
|
useEffect(function () {
|
|
21
20
|
var _a, _b, _c;
|
|
22
21
|
// Wait for the panel to mount before moving focus into it
|
|
@@ -34,36 +33,26 @@ export default function Modal(_a) {
|
|
|
34
33
|
}
|
|
35
34
|
if (panel && !panel.contains(document.activeElement))
|
|
36
35
|
panel.focus();
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
pushOverlay(titleId, panel);
|
|
37
|
+
lockScroll();
|
|
39
38
|
var handleKeyDown = function (e) {
|
|
39
|
+
if (!isTopOverlay(titleId))
|
|
40
|
+
return;
|
|
40
41
|
if (e.key === 'Escape') {
|
|
41
|
-
|
|
42
|
+
if (claimEvent(e))
|
|
43
|
+
onCloseRef.current();
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
if (e.key !== 'Tab' || !panel)
|
|
45
47
|
return;
|
|
46
|
-
|
|
47
|
-
if (focusable.length === 0) {
|
|
48
|
-
e.preventDefault();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
var first = focusable[0];
|
|
52
|
-
var last = focusable[focusable.length - 1];
|
|
53
|
-
if (e.shiftKey && document.activeElement === first) {
|
|
54
|
-
e.preventDefault();
|
|
55
|
-
last.focus();
|
|
56
|
-
}
|
|
57
|
-
else if (!e.shiftKey && document.activeElement === last) {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
first.focus();
|
|
60
|
-
}
|
|
48
|
+
trapTab(panel, e);
|
|
61
49
|
};
|
|
62
50
|
window.addEventListener('keydown', handleKeyDown);
|
|
63
51
|
return function () {
|
|
64
52
|
var _a;
|
|
65
53
|
window.removeEventListener('keydown', handleKeyDown);
|
|
66
|
-
|
|
54
|
+
popOverlay(titleId);
|
|
55
|
+
unlockScroll();
|
|
67
56
|
(_a = previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocused);
|
|
68
57
|
};
|
|
69
58
|
}, [isOpen, mounted]);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface OnThisPageItem {
|
|
3
|
+
/** The id of the heading on the page; the link goes to `#id` */
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** 3 is indented under the 2 above it. Default 2. */
|
|
7
|
+
level?: 2 | 3;
|
|
8
|
+
}
|
|
9
|
+
interface OnThisPageProps {
|
|
10
|
+
/** The page's headings, in page order. Fewer than two render nothing. */
|
|
11
|
+
items: OnThisPageItem[];
|
|
12
|
+
/** Names the nav. Default 'On this page'. */
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
/** The id of the element that scrolls, when it is not the window */
|
|
15
|
+
root?: string;
|
|
16
|
+
/**
|
|
17
|
+
* How far below the top of the scroll area a heading counts as reached, in px. Default 40, plus the height of a
|
|
18
|
+
* `SiteHeader` above the page (`--os-header-offset`) when the window scrolls. A click scrolls the heading to just
|
|
19
|
+
* under that header.
|
|
20
|
+
*/
|
|
21
|
+
offset?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Links to a long page's headings, with the one the reader is at marked. The current heading is the last one
|
|
25
|
+
* above `offset`; the last item at the end of the scroll; the one in the `#hash` on load. A click keeps its item
|
|
26
|
+
* current until the scroll ends. Reduced motion jumps instead of scrolling.
|
|
27
|
+
*/
|
|
28
|
+
export default function OnThisPage({ items, 'aria-label': ariaLabel, root, offset }: OnThisPageProps): React.JSX.Element | null;
|
|
29
|
+
export { OnThisPage };
|