Skip to content

Commit 4a53689

Browse files
committed
generalize the up one level
1 parent d900ca0 commit 4a53689

File tree

3 files changed

+31
-77
lines changed

3 files changed

+31
-77
lines changed

packages/dev/s2-docs/src/GoUpOneLink.tsx

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/dev/s2-docs/src/Layout.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import {CodePlatterProvider} from './CodePlatter';
1616
import {ExampleSwitcher} from './ExampleSwitcher';
1717
import {getLibraryFromPage, getLibraryFromUrl, getLibraryLabel} from './library';
1818
import {getTextWidth} from './textWidth';
19-
import {GoUpOneLink} from './GoUpOneLink';
19+
import ChevronRightIcon from '@react-spectrum/s2/icons/ChevronRight';
2020
import {H2, H3, H4} from './Headings';
2121
import Header from './Header';
22-
import {Link} from './Link';
22+
import {Link, TitleLink} from './Link';
2323
import {MobileHeader} from './MobileHeader';
2424
import {PickerItem, Provider} from '@react-spectrum/s2';
2525
import {PropTable} from './PropTable';
2626
import {StateTable} from './StateTable';
27-
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
27+
import {iconStyle, style} from '@react-spectrum/s2/style' with {type: 'macro'};
2828
import {TypeLink} from './types';
2929
import {VersionBadge} from './VersionBadge';
3030
import {VisualExample} from './VisualExample';
@@ -64,15 +64,16 @@ const components = {
6464
ExampleList
6565
};
6666

67-
const subPageComponents = {
67+
const subPageComponents = (previousPage?: Page) => ({
6868
...components,
6969
h1: ({children, ...props}) => (
7070
<div className={style({display: 'flex', alignItems: 'center', gap: 8})}>
71-
<GoUpOneLink />
71+
<TitleLink href="./index.html">{previousPage?.exports?.title}</TitleLink>
72+
<ChevronRightIcon styles={iconStyle({size: 'XL'})} />
7273
<h1 {...props} id="top" style={{'--width-per-em': getTextWidth(children)} as any} className={h1}>{children}</h1>
7374
</div>
7475
)
75-
};
76+
});
7677

7778
function anchorId(children) {
7879
return children.replace(/\s/g, '-').replace(/[^a-zA-Z0-9-_]/g, '').toLowerCase();
@@ -145,6 +146,10 @@ export function Layout(props: PageProps & {children: ReactElement<any>}) {
145146
let title = getTitle(currentPage);
146147
let description = getDescription(currentPage);
147148
let isSubpage = currentPage.exports?.isSubpage;
149+
let parentPage = pages.find(p => {
150+
return p.url === currentPage.url.replace(/\/[^/]+\.html$/, '/index.html');
151+
});
152+
console.log(parentPage);
148153
return (
149154
<Provider elementType="html" locale="en" background="layer-1" styles={style({scrollPaddingTop: {default: 64, lg: 0}})}>
150155
<head>
@@ -255,7 +260,12 @@ export function Layout(props: PageProps & {children: ReactElement<any>}) {
255260
<article
256261
className={articleStyles({isWithToC: hasToC})}>
257262
{currentPage.exports?.version && <VersionBadge version={currentPage.exports.version} />}
258-
{React.cloneElement(children, {components: isSubpage ? subPageComponents : components, pages})}
263+
{React.cloneElement(children, {
264+
components: isSubpage ?
265+
subPageComponents(parentPage) :
266+
components,
267+
pages
268+
})}
259269
</article>
260270
</CodePlatterProvider>
261271
{hasToC && <aside

packages/dev/s2-docs/src/Link.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,17 @@ export function ColorLink({type, ...props}: RACLinkProps & {type?: 'keyword' | '
4747
export function CodeLink(props: RACLinkProps) {
4848
return <RACLink {...props} style={({isHovered}) => ({textDecorationStyle: isHovered ? 'solid' : 'dotted'})} />;
4949
}
50+
51+
const titleLink = style({
52+
font: 'heading-3xl',
53+
fontSize: {
54+
// On mobile, adjust heading to fit in the viewport, and clamp between a min and max font size.
55+
default: 'clamp(35px, (100vw - 32px) / var(--width-per-em), 55px)',
56+
lg: 'heading-3xl'
57+
},
58+
marginY: 0
59+
});
60+
61+
export function TitleLink(props: RACLinkProps) {
62+
return <RACLink {...props} className={titleLink} />;
63+
}

0 commit comments

Comments
 (0)