Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(PageLayout): update sticky layout #2326

Merged
merged 14 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-bears-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update the sticky layout algorithm for PageLayout and PageLayout.Pane
3 changes: 2 additions & 1 deletion src/PageLayout/PageLayout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ export const CustomStickyHeader: Story = args => (
placeItems: 'center',
backgroundColor: 'canvas.subtle',
borderBottom: '1px solid',
borderColor: 'border.default'
borderColor: 'border.default',
zIndex: 100
}}
>
Custom sticky header
Expand Down
86 changes: 51 additions & 35 deletions src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {useStickyPaneHeight} from './useStickyPaneHeight'
import Box from '../Box'
import {isResponsiveValue, ResponsiveValue, useResponsiveValue} from '../hooks/useResponsiveValue'
import {BetterSystemStyleObject, merge, SxProp} from '../sx'
import createSlots from '../utils/create-slots'

const {Slots, Slot} = createSlots(['Header', 'Footer'])

const REGION_ORDER = {
header: 0,
Expand Down Expand Up @@ -90,7 +93,17 @@ const Root: React.FC<React.PropsWithChildren<PageLayoutProps>> = ({
flexWrap: 'wrap'
}}
>
{children}
<Slots>
{slots => {
return (
<>
{slots.Header}
<Box sx={{display: 'flex', flex: '1 1 100%', flexWrap: 'wrap'}}>{children}</Box>
{slots.Footer}
</>
)
}}
</Slots>
</Box>
</Box>
</PageLayoutContext.Provider>
Expand Down Expand Up @@ -245,23 +258,24 @@ const Header: React.FC<React.PropsWithChildren<PageLayoutHeaderProps>> = ({
const isHidden = useResponsiveValue(hidden, false)
const {rowGap} = React.useContext(PageLayoutContext)
return (
<Box
as="header"
aria-label={label}
aria-labelledby={labelledBy}
hidden={isHidden}
sx={merge<BetterSystemStyleObject>(
{
order: REGION_ORDER.header,
width: '100%',
marginBottom: SPACING_MAP[rowGap]
},
sx
)}
>
<Box sx={{padding: SPACING_MAP[padding]}}>{children}</Box>
<HorizontalDivider variant={dividerVariant} sx={{marginTop: SPACING_MAP[rowGap]}} />
</Box>
<Slot name="Header">
<Box
as="header"
aria-label={label}
aria-labelledby={labelledBy}
hidden={isHidden}
sx={merge<BetterSystemStyleObject>(
{
width: '100%',
marginBottom: SPACING_MAP[rowGap]
},
sx
)}
>
<Box sx={{padding: SPACING_MAP[padding]}}>{children}</Box>
<HorizontalDivider variant={dividerVariant} sx={{marginTop: SPACING_MAP[rowGap]}} />
</Box>
</Slot>
)
}

Expand Down Expand Up @@ -558,23 +572,25 @@ const Footer: React.FC<React.PropsWithChildren<PageLayoutFooterProps>> = ({
const isHidden = useResponsiveValue(hidden, false)
const {rowGap} = React.useContext(PageLayoutContext)
return (
<Box
as="footer"
aria-label={label}
aria-labelledby={labelledBy}
hidden={isHidden}
sx={merge<BetterSystemStyleObject>(
{
order: REGION_ORDER.footer,
width: '100%',
marginTop: SPACING_MAP[rowGap]
},
sx
)}
>
<HorizontalDivider variant={dividerVariant} sx={{marginBottom: SPACING_MAP[rowGap]}} />
<Box sx={{padding: SPACING_MAP[padding]}}>{children}</Box>
</Box>
<Slot name="Footer">
<Box
as="footer"
aria-label={label}
aria-labelledby={labelledBy}
hidden={isHidden}
sx={merge<BetterSystemStyleObject>(
{
order: REGION_ORDER.footer,
width: '100%',
marginTop: SPACING_MAP[rowGap]
},
sx
)}
>
<HorizontalDivider variant={dividerVariant} sx={{marginBottom: SPACING_MAP[rowGap]}} />
<Box sx={{padding: SPACING_MAP[padding]}}>{children}</Box>
</Box>
</Slot>
)
}

Expand Down
Loading