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

Add stickyTop prop to PageLayout.Pane #2232

Merged
merged 13 commits into from
Aug 18, 2022
Merged

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Aug 16, 2022

Closes this 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
Copy link

changeset-bot bot commented Aug 16, 2022

🦋 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
Name Type
@primer/react Minor

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 main August 16, 2022 06:22
@broccolinisoup broccolinisoup marked this pull request as draft August 16, 2022 11:36
@github-actions
Copy link
Contributor

github-actions bot commented Aug 16, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 74.26 KB (+0.08% 🔺)
dist/browser.umd.js 74.82 KB (+0.1% 🔺)

@broccolinisoup broccolinisoup temporarily deployed to github-pages August 16, 2022 23:03 Inactive
@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
@broccolinisoup broccolinisoup marked this pull request as ready for review August 17, 2022 02:28
Copy link
Contributor

@colebemis colebemis left a comment

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 🚢

docs/content/PageLayout.mdx Outdated Show resolved Hide resolved
docs/content/PageLayout.mdx Outdated Show resolved Hide resolved
docs/content/PageLayout.mdx Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages August 17, 2022 18:04 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"
Copy link
Member Author

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
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
Member Author

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
Member Author

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
Member Author

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
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
@colebemis colebemis temporarily deployed to github-pages August 18, 2022 01:03 Inactive
@broccolinisoup broccolinisoup merged commit a0fcce6 into main Aug 18, 2022
@broccolinisoup broccolinisoup deleted the pagelayout-stickyTop-prop branch August 18, 2022 01:08
@primer-css primer-css mentioned this pull request Aug 18, 2022
@siddharthkp
Copy link
Member

siddharthkp commented Aug 22, 2022

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.Pane position="start" sticky offset={64}> 
// because you use it with the sticky prop, ↑ i like this one the most

2. <PageLayout.Pane position="start" sticky offsetTop={64}>
// this is a close second for explicit direction

3. <PageLayout.Pane position="start" sticky offsetHeader={64}>
// i lowkey like this one because it tells you offset from what

4. <PageLayout.Pane position="start" sticky stickyOffset={64}>
// stick-offset is bit redundant when used with sticky, but more clear

5. <PageLayout.Pane position="start" sticky stickyOffsetTop={64}>
// this is the most clear we can be 😅 also the most verbose

@colebemis
Copy link
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
Member Author

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
Copy link
Member

siddharthkp commented Aug 23, 2022

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
Member Author

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 free to 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.

None yet

3 participants