Skip to content

Add stickyTop prop to PageLayout.Pane - #2232

Merged
broccolinisoup merged 13 commits into
mainfrom
pagelayout-stickyTop-prop
Aug 18, 2022
Merged

Add stickyTop prop to PageLayout.Pane#2232
broccolinisoup merged 13 commits into
mainfrom
pagelayout-stickyTop-prop

Conversation

@broccolinisoup

@broccolinisoupbroccolinisoup commented Aug 16, 2022

Copy link
Copy Markdown
Member

Closesthis issue which lives in the internal repo.

Motivation

This PR adds a prop called stickyTop to the PageLayout.Pane to be able to push the pane down and make space for the top sticky element (which lives outside of the PageLayout component) and sticks the pane to a position where the top element ends.

<PageLayout>
<PageLayout.Pane sticky stickyTop={100}>...</PageLayout.Pane>
<PageLayout.Content>...</PageLayout.Content>
</PageLayout>

Screen record

StickyTop.on.PageLayout.Pane.1.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot

changeset-botBot commented Aug 16, 2022

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0adf6b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/reactMinor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 16, 2022 05:53 Inactive
Base automatically changed from pagelayout-sticky-prop to mainAugust 16, 2022 06:22
@broccolinisoup
broccolinisoup marked this pull request as draft August 16, 2022 11:36
@github-actions

github-actionsBot commented Aug 16, 2022

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js74.26 KB (+0.08% 🔺)
dist/browser.umd.js74.82 KB (+0.1% 🔺)

@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 16, 2022 23:03 Inactive
@broccolinisoup
broccolinisoupforce-pushed the pagelayout-stickyTop-prop branch from a59d85a to 515992aCompareAugust 16, 2022 23:13
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 16, 2022 23:19 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 00:28 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 01:23 Inactive
Comment threadsrc/PageLayout/PageLayout.tsx Outdated
Comment threadsrc/PageLayout/useStickyPaneHeight.ts Outdated
@broccolinisoup
broccolinisoup marked this pull request as ready for review August 17, 2022 02:28

@colebemiscolebemis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, @broccolinisoup! 💖 Thank you for taking this on.

Left a couple of minor comments but I don't see any blockers. Feel free to merge this when you feel ready 🚢

Comment threaddocs/content/PageLayout.mdx Outdated
Comment threaddocs/content/PageLayout.mdx
Comment threaddocs/content/PageLayout.mdx Outdated
@colebemis
colebemis temporarily deployed to github-pages August 17, 2022 18:04 Inactive
Comment threaddocs/content/PageLayout.mdx Outdated
name="stickyTop"
type="number | string"
defaultValue="0"
description="Use stickyTop to push the sticky pane down to make room for a sticky header if necessary"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add into the description that if it is number, we expect px and if it is string value with units?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea!

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! 800b3ec let me know if you have a better wording :)

calculatedHeight = `calc(100vh - ${Math.max(topOffset, stickyTopHeight) + bottomOffset - overflowScroll}px)`
const stickyTopWithUnits = typeof stickyTop === 'number' ? `${stickyTop}px` : stickyTop

calculatedHeight = `calc(100vh - (max(${topOffset}px, ${stickyTopWithUnits}) + ${bottomOffset}px - ${overflowScroll}px))`

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love that! 🙌🏼

}}
>
<Heading>Sticky top content</Heading>
Custom sticky header

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this is very explanatory. Thanks for updating it!

Co-authored-by: Cole Bemis <colebemis@github.com>
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 22:59 Inactive
Co-authored-by: Cole Bemis <colebemis@github.com>
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 23:10 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 23:23 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 17, 2022 23:59 Inactive
name="stickyTop"
type="number | string"
defaultValue="0"
description="Use stickyTop to push the sticky pane down to make room for a sticky header if necessary. Use the type `string` to specify the height with a unit i.e. 5rem; otherwise the type `number` will be taken as px."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you copy this prop documentation and With custom sticky header example into the SplitPageLayout.mdx page as well?

@colebemis
colebemis temporarily deployed to github-pages August 18, 2022 00:36 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages August 18, 2022 00:47 Inactive
Comment threaddocs/content/SplitPageLayout.mdx Outdated
Comment threaddocs/content/SplitPageLayout.mdx
@colebemis
colebemis temporarily deployed to github-pages August 18, 2022 01:03 Inactive
@broccolinisoup
broccolinisoup merged commit a0fcce6 into mainAug 18, 2022
@broccolinisoup
broccolinisoup deleted the pagelayout-stickyTop-prop branch August 18, 2022 01:08
@primer-cssprimer-css mentioned this pull request Aug 18, 2022
@siddharthkp

siddharthkp commented Aug 22, 2022

Copy link
Copy Markdown
Member

Hi!

Sorry, late to the party, how do you feel about calling the prop offset, stickyOffset or even stickyOffsetTop or stickyOffsetHeader instead to make it more clear that we're talking about space.

1.<PageLayout.Paneposition="start"stickyoffset={64}>// because you use it with the sticky prop, ↑ i like this one the most2.<PageLayout.Paneposition="start"stickyoffsetTop={64}>// this is a close second for explicit direction3.<PageLayout.Paneposition="start"stickyoffsetHeader={64}>// i lowkey like this one because it tells you offset from what4.<PageLayout.Paneposition="start"stickystickyOffset={64}>// stick-offset is bit redundant when used with sticky, but more clear5.<PageLayout.Paneposition="start"stickystickyOffsetTop={64}>// this is the most clear we can be 😅 also the most verbose

@colebemis

Copy link
Copy Markdown
Contributor

I like the word "offset" 👍 I think offsetTop is my favorite of the options you listed because it still connects to the top CSS property. I'm curious if it's clear that offsetTop only applies when sticky is true. What do you think @siddharthkp@broccolinisoup?

@broccolinisoup

Copy link
Copy Markdown
MemberAuthor

I like offsetTop and because it needs to be used with the sticky prop I find this line self expressive.

<PageLayout.Pane position="start" sticky offsetTop={64}>
Like "stick my pane to the position start with the top offset 64. "

I am just now thinking we weren't super explicit about stickyTop needs sticky prop to work on the docs. Maybe we should mention that they need to be used together?

@colebemis@siddharthkp

@siddharthkp

siddharthkp commented Aug 23, 2022

Copy link
Copy Markdown
Member

Happy with offsetTop

I'm curious if it's clear that offsetTop only applies when sticky is true.

It's not super clear, we can make it more explicit with stickyOffsetTop or we can make the example in our docs better:

  1. Add description under the title "With a custom sticky header", to say what you should change when you have a custom header
  2. without line highlighting, it's not clear which prop in the code helps with custom headers 😓
  3. Flip the order of prop in the example
- <PageLayout.Pane position="start" offsetTop={64} sticky>+ <PageLayout.Pane position="start" sticky offsetTop={64}>

I am just now thinking we weren't super explicit about stickyTop needs sticky prop to work on the docs. Maybe we should mention that they need to be used together?

Yes good point! We should add that to the prop description of offsetTop

@broccolinisoup

Copy link
Copy Markdown
MemberAuthor

Good call to improve the docs!

I created a PR to get the feelings of the new name with the improved docs. Let me know what you think 😊

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@broccolinisoup@siddharthkp@colebemis