Skip to content

Commit a414886

Browse files
committed
support subpage list under the ToC
1 parent 59e9400 commit a414886

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

packages/dev/s2-docs/pages/s2/styling.mdx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export default Layout;
88
export const section = 'Guides';
99
export const tags = ['style', 'macro', 'spectrum', 'custom'];
1010
export const description = 'Styling in React Spectrum';
11+
export const relatedPages = [
12+
{title: 'Advanced', url: './styling/advanced.html'},
13+
{title: 'Reference Table', url: './styling/reference.html'}
14+
];
1115

1216
# Styling
1317

@@ -165,23 +169,6 @@ Type scales include: UI, Body, Heading, Title, Detail, and Code. Each scale has
165169
</Content>
166170
</InlineAlert>
167171

168-
## Conditional styles
169-
170-
Define conditional values as objects to handle media queries, UI states (hover/press), and variants. This keeps all values for a property together.
171-
172-
```tsx
173-
<div
174-
className={style({
175-
padding: {
176-
default: 8,
177-
lg: 32
178-
}
179-
})}
180-
/>
181-
```
182-
183-
Conditions are mutually exclusive and ordered. The macro uses CSS cascade layers so the last matching condition wins without specificity issues.
184-
185172
## CSS optimization
186173

187174
The `style` macro relies on CSS bundling and minification for optimal output. Follow these best practices:

packages/dev/s2-docs/pages/s2/styling/Advanced.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Layout} from '../../../src/Layout';
22
export default Layout;
33

4+
export const omitFromNav = true;
45
export const tags = ['style', 'macro', 'spectrum', 'custom', 'advanced'];
56
export const description = 'Style macro advanced usage guide';
67

packages/dev/s2-docs/pages/s2/styling/Reference.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {StyleMacroProperties} from '../../../src/types';
66
import {getPropertyDefinitions, getShorthandDefinitions} from '../../../src/styleProperties';
77
export default Layout;
88

9+
export const omitFromNav = true;
910
export const tags = ['style', 'macro', 'spectrum', 'custom', 'values', 'reference'];
1011
export const description = 'Reference table for the `style` macro';
1112

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ export function Layout(props: PageProps & {children: ReactElement<any>}) {
262262
<div className={style({font: 'title', minHeight: 32, paddingX: 12, display: 'flex', alignItems: 'center'})}>Contents</div>
263263
)}
264264
<Toc toc={currentPage.tableOfContents?.[0]?.children ?? []} />
265+
{currentPage.exports?.relatedPages && (
266+
<RelatedPages pages={currentPage.exports.relatedPages} />
267+
)}
265268
</aside>
266269
</main>
267270
</div>
@@ -286,10 +289,31 @@ function Toc({toc}) {
286289
);
287290
}
288291

292+
function RelatedPages({pages}: {pages: Array<{title: string, url: string}>}) {
293+
return (
294+
<div className={style({paddingTop: 24})}>
295+
<div className={style({font: 'title', minHeight: 32, paddingX: 12, display: 'flex', alignItems: 'center'})}>Related pages</div>
296+
<OnPageNav>
297+
<SideNav>
298+
{pages.map((page, i) => (
299+
<SideNavItem key={i}>
300+
<SideNavLink href={page.url}>{page.title}</SideNavLink>
301+
</SideNavItem>
302+
))}
303+
</SideNav>
304+
</OnPageNav>
305+
</div>
306+
);
307+
}
308+
289309
function MobileToc({toc, currentPage}) {
310+
let relatedPages = currentPage.exports?.relatedPages;
290311
return (
291312
<MobileOnPageNav currentPage={currentPage}>
292313
{renderMobileToc(toc)}
314+
{relatedPages && relatedPages.map((page, i) => (
315+
<PickerItem key={`related-${i}`} id={page.url} href={page.url}>{page.title}</PickerItem>
316+
))}
293317
</MobileOnPageNav>
294318
);
295319
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function Nav({pages, currentPage}: PageProps) {
1111
let currentLibrary = getLibraryFromPage(currentPage);
1212
let sections = new Map();
1313
for (let page of pages) {
14-
if (page.exports?.hideNav || page.exports?.hideFromSearch) {
14+
if (page.exports?.hideNav || page.exports?.hideFromSearch || page.exports?.omitFromNav) {
1515
continue;
1616
}
17-
17+
1818
let library = getLibraryFromPage(page);
1919
if (library !== currentLibrary) {
2020
continue;

0 commit comments

Comments
 (0)