Skip to content
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/warm-seals-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Switch to a CSS based solution for the PageLayout sticky pane
3 changes: 1 addition & 2 deletions packages/react/src/PageLayout/PageLayout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ body[data-page-layout-dragging='true'] * {
--spacing-column: 0;
--spacing-divider: 0;
--offset-header: 0;
--sticky-pane-height: 0;
--pane-width: 0;
--pane-min-width: 0;
--pane-max-width: 0;
Expand Down Expand Up @@ -250,7 +249,7 @@ body[data-page-layout-dragging='true'] * {
position: sticky;
/* stylelint-disable-next-line primer/spacing */
top: var(--offset-header);
max-height: var(--sticky-pane-height);
max-height: 100vh;
}

&:where([data-position='end']) {
Expand Down
33 changes: 2 additions & 31 deletions packages/react/src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {SxProp} from '../sx'
import {canUseDOM} from '../utils/environment'
import {useOverflow} from '../hooks/useOverflow'
import {warning} from '../utils/warning'
import {useStickyPaneHeight} from './useStickyPaneHeight'

import classes from './PageLayout.module.css'
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
Expand All @@ -34,10 +33,6 @@ const PageLayoutContext = React.createContext<{
rowGap: keyof typeof SPACING_MAP
columnGap: keyof typeof SPACING_MAP
paneRef: React.RefObject<HTMLDivElement>
enableStickyPane?: (top: number | string) => void
disableStickyPane?: () => void
contentTopRef?: (node?: Element | null | undefined) => void
contentBottomRef?: (node?: Element | null | undefined) => void
}>({
padding: 'normal',
rowGap: 'normal',
Expand Down Expand Up @@ -81,9 +76,6 @@ const Root: React.FC<React.PropsWithChildren<PageLayoutProps>> = ({
style,
_slotsConfig: slotsConfig,
}) => {
const {rootRef, enableStickyPane, disableStickyPane, contentTopRef, contentBottomRef, stickyPaneHeight} =
useStickyPaneHeight()

const paneRef = useRef<HTMLDivElement>(null)

const [slots, rest] = useSlots(children, slotsConfig ?? {header: Header, footer: Footer})
Expand All @@ -93,21 +85,15 @@ const Root: React.FC<React.PropsWithChildren<PageLayoutProps>> = ({
padding,
rowGap,
columnGap,
enableStickyPane,
disableStickyPane,
contentTopRef,
contentBottomRef,
paneRef,
}
}, [padding, rowGap, columnGap, enableStickyPane, disableStickyPane, contentTopRef, contentBottomRef, paneRef])
}, [padding, rowGap, columnGap, paneRef])

return (
<PageLayoutContext.Provider value={memoizedContextValue}>
<BoxWithFallback
ref={rootRef}
style={
{
'--sticky-pane-height': stickyPaneHeight,
'--spacing': `var(--spacing-${padding})`,
...style,
} as React.CSSProperties
Expand Down Expand Up @@ -478,7 +464,6 @@ const Content: React.FC<React.PropsWithChildren<PageLayoutContentProps>> = ({
style,
}) => {
const isHidden = useResponsiveValue(hidden, false)
const {contentTopRef, contentBottomRef} = React.useContext(PageLayoutContext)

return (
<BoxWithFallback
Expand All @@ -490,9 +475,6 @@ const Content: React.FC<React.PropsWithChildren<PageLayoutContentProps>> = ({
className={clsx(classes.ContentWrapper, className)}
data-is-hidden={isHidden}
>
{/* Track the top of the content region so we can calculate the height of the pane region */}
<div ref={contentTopRef} />

<div
className={classes.Content}
data-width={width}
Expand All @@ -504,9 +486,6 @@ const Content: React.FC<React.PropsWithChildren<PageLayoutContentProps>> = ({
>
{children}
</div>

{/* Track the bottom of the content region so we can calculate the height of the pane region */}
<div ref={contentBottomRef} />
</BoxWithFallback>
)
}
Expand Down Expand Up @@ -641,15 +620,7 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout

const isHidden = useResponsiveValue(responsiveHidden, false)

const {rowGap, columnGap, enableStickyPane, disableStickyPane, paneRef} = React.useContext(PageLayoutContext)

React.useEffect(() => {
if (sticky) {
enableStickyPane?.(offsetHeader)
} else {
disableStickyPane?.()
}
}, [sticky, enableStickyPane, disableStickyPane, offsetHeader])
const {rowGap, columnGap, paneRef} = React.useContext(PageLayoutContext)

const getDefaultPaneWidth = (width: PaneWidth | CustomWidthOptions): number => {
if (isPaneWidth(width)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`PageLayout renders condensed layout 1`] = `
<div>
<div
class="PageLayoutRoot"
style="--sticky-pane-height: 100vh; --spacing: var(--spacing-condensed);"
style="--spacing: var(--spacing-condensed);"
>
<div
class="PageLayoutWrapper"
Expand Down Expand Up @@ -33,15 +33,13 @@ exports[`PageLayout renders condensed layout 1`] = `
class="ContentWrapper"
data-is-hidden="false"
>
<div />
<div
class="Content"
data-width="full"
style="--spacing: var(--spacing-none);"
>
Content
</div>
<div />
</main>
<div
class="PaneWrapper"
Expand Down Expand Up @@ -94,7 +92,7 @@ exports[`PageLayout renders default layout 1`] = `
<div>
<div
class="PageLayoutRoot"
style="--sticky-pane-height: 100vh; --spacing: var(--spacing-normal);"
style="--spacing: var(--spacing-normal);"
>
<div
class="PageLayoutWrapper"
Expand Down Expand Up @@ -123,15 +121,13 @@ exports[`PageLayout renders default layout 1`] = `
class="ContentWrapper"
data-is-hidden="false"
>
<div />
<div
class="Content"
data-width="full"
style="--spacing: var(--spacing-none);"
>
Content
</div>
<div />
</main>
<div
class="PaneWrapper"
Expand Down Expand Up @@ -184,7 +180,7 @@ exports[`PageLayout renders pane in different position when narrow 1`] = `
<div>
<div
class="PageLayoutRoot"
style="--sticky-pane-height: 100vh; --spacing: var(--spacing-normal);"
style="--spacing: var(--spacing-normal);"
>
<div
class="PageLayoutWrapper"
Expand Down Expand Up @@ -213,15 +209,13 @@ exports[`PageLayout renders pane in different position when narrow 1`] = `
class="ContentWrapper"
data-is-hidden="false"
>
<div />
<div
class="Content"
data-width="full"
style="--spacing: var(--spacing-none);"
>
Content
</div>
<div />
</main>
<div
class="PaneWrapper"
Expand Down Expand Up @@ -274,7 +268,7 @@ exports[`PageLayout renders with dividers 1`] = `
<div>
<div
class="PageLayoutRoot"
style="--sticky-pane-height: 100vh; --spacing: var(--spacing-normal);"
style="--spacing: var(--spacing-normal);"
>
<div
class="PageLayoutWrapper"
Expand Down Expand Up @@ -303,15 +297,13 @@ exports[`PageLayout renders with dividers 1`] = `
class="ContentWrapper"
data-is-hidden="false"
>
<div />
<div
class="Content"
data-width="full"
style="--spacing: var(--spacing-none);"
>
Content
</div>
<div />
</main>
<div
class="PaneWrapper"
Expand Down
136 changes: 0 additions & 136 deletions packages/react/src/PageLayout/useStickyPaneHeight.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`SplitPageLayout renders default layout 1`] = `
<div>
<div
class="PageLayoutRoot"
style="--sticky-pane-height: 100vh; --spacing: var(--spacing-none);"
style="--spacing: var(--spacing-none);"
>
<div
class="PageLayoutWrapper"
Expand Down Expand Up @@ -33,15 +33,13 @@ exports[`SplitPageLayout renders default layout 1`] = `
class="ContentWrapper"
data-is-hidden="false"
>
<div />
<div
class="Content"
data-width="large"
style="--spacing: var(--spacing-normal);"
>
Content
</div>
<div />
</main>
<div
class="PaneWrapper"
Expand Down
Loading