Skip to content

Commit 04d9d9c

Browse files
colebemisjoshblack
andauthored
PageLayout.Pane: Add sticky prop (#2212)
* Add storybook story to test sticky behavior * First draft of sticky implementation * Update stories * Fix overflow * wip * Create useStickyPaneHeight hook * Update comments * Add TODO comments * Avoid recalculating sticky pane height when sticky is disabled * Calculate intital height * Handle elastic scroll in safari * Clean up max() functions * Add docs * Create serious-pots-confess.md * Update serious-pots-confess.md * Update tests * Import React in tests * Remove position: relative from content region * Update snapshots * Handle nested scroll containers Co-authored-by: Josh Black <joshblack@users.noreply.github.com> * Update sticky prop docs * Update sticky pane docs example * Update src/PageLayout/PageLayout.stories.tsx Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
1 parent 1ffe4da commit 04d9d9c

File tree

11 files changed

+891
-271
lines changed

11 files changed

+891
-271
lines changed

.changeset/serious-pots-confess.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Add a `sticky` prop to the `PageLayout.Pane` component that provides a convenient way for you to make side panes sticky:
6+
7+
```diff
8+
<PageLayout>
9+
- <PageLayout.Pane>...</PageLayout.Pane>
10+
+ <PageLayout.Pane sticky>...</PageLayout.Pane>
11+
<PageLayout.Content>...</PageLayout.Content>
12+
</PageLayout>
13+
```

docs/content/PageLayout.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,27 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo
147147
</PageLayout>
148148
```
149149

150+
### With a sticky pane
151+
152+
```jsx live
153+
<Box sx={{height: 320, overflowY: 'auto', border: '1px solid', borderColor: 'border.default'}}>
154+
<PageLayout>
155+
<PageLayout.Header>
156+
<Placeholder label="Header" height={64} />
157+
</PageLayout.Header>
158+
<PageLayout.Content>
159+
<Placeholder label="Content" height={320} />
160+
</PageLayout.Content>
161+
<PageLayout.Pane sticky>
162+
<Placeholder label="Pane" height={120} />
163+
</PageLayout.Pane>
164+
<PageLayout.Footer>
165+
<Placeholder label="Footer" height={64} />
166+
</PageLayout.Footer>
167+
</PageLayout>
168+
</Box>
169+
```
170+
150171
## Props
151172

152173
### PageLayout
@@ -310,6 +331,12 @@ See [storybook](https://primer.style/react/storybook?path=/story/layout-pagelayo
310331
defaultValue="'medium'"
311332
description="The width of the pane."
312333
/>
334+
<PropsTableRow
335+
name="sticky"
336+
type="boolean"
337+
defaultValue="false"
338+
description="Whether the pane should stick to the top of the screen while the content scrolls."
339+
/>
313340
<PropsTableRow
314341
name="padding"
315342
type={`| 'none'

docs/content/SplitPageLayout.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ description: Provides structure for a split page layout, including independent s
240240
defaultValue="'medium'"
241241
description="The width of the pane."
242242
/>
243+
<PropsTableRow name="sticky" type="boolean" defaultValue="true" description="Whether the pane is sticky." />
243244
<PropsTableRow
244245
name="divider"
245246
type={`ResponsiveValue<

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"focus-visible": "^5.2.0",
103103
"fzy.js": "0.4.1",
104104
"history": "^5.0.0",
105+
"react-intersection-observer": "9.4.0",
105106
"styled-system": "^5.1.5"
106107
},
107108
"devDependencies": {

0 commit comments

Comments
 (0)