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 resizable support to the <PageLayout> component #2352

Merged
merged 27 commits into from
Oct 31, 2022
Merged

Conversation

japf
Copy link
Contributor

@japf japf commented Sep 20, 2022

Describe your changes here.

This PR adds resizable support to the <PageLayout> component.

Screenshots

Please provide before/after screenshots for any visual changes

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 Sep 20, 2022

🦋 Changeset detected

Latest commit: 6edaf11

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 78.8 KB (+0.85% 🔺)
dist/browser.umd.js 79.44 KB (+0.84% 🔺)

@japf japf temporarily deployed to github-pages September 20, 2022 10:05 Inactive
@japf japf temporarily deployed to github-pages September 20, 2022 12:32 Inactive
@colebemis
Copy link
Contributor

This is looking great, @japf! 💖

I was poking around in the storybook and noticed that the pane width seems to "jump" when you start dragging. Any ideas why this might be happening?

CleanShot.2022-09-20.at.09.25.36.mp4

I see this PR is marked as "work in progress" so feel free to ignore if this is a known issue :)

@japf
Copy link
Contributor Author

japf commented Sep 23, 2022

👋 @colebemis I pushed a few fixes, feel free to have another look. Please let me know what you think is missing to mark the PR as ready for review. I guess I should update the docs?

Edit: there is an issue with the positioning of the divider, I'll look into that.

@japf japf temporarily deployed to github-pages September 23, 2022 13:02 Inactive
@japf
Copy link
Contributor Author

japf commented Sep 26, 2022

@colebemis updated again, please have another look 😄

@japf japf temporarily deployed to github-pages September 26, 2022 12:12 Inactive
@japf japf temporarily deployed to github-pages September 26, 2022 14:35 Inactive
@colebemis
Copy link
Contributor

@japf this is looking great! @joshblack is going to take the lead on code review. He'll be your point-of-contact for any questions you have :)

@japf japf temporarily deployed to github-pages September 28, 2022 11:30 Inactive
@joshblack
Copy link
Member

joshblack commented Sep 28, 2022

Looking great! 🥳 Thanks so much for taking this on 🙏 Just wanted to leave some notes/questions on behavior since I wasn't sure what was expected

  1. SC seems to be generating class names per clamp value

    It seems like Styled Components might be generating class names for each value in the clamp() 🤔 Would it be possible to pull the value out into an inline style or CSS Custom Property to avoid generating the class names? Or is there potentially something we can do with SC?

    Screen.Recording.2022-09-28.at.11.27.33.AM.mov
  2. What's the expectation for when the layout goes narrow?

    I wasn't sure what the intent was for when the layout goes narrow, should the resize bar effectively be hidden at that breakpoint? Just wanted to double-check

    image

  3. Text selection when resizing on FF

    Super minor, but noticed that text selection was happening for FF when hitting the edges of the resize behavior 🤔

    Screen.Recording.2022-09-28.at.11.30.36.AM.mov
  4. Safari on iPad

    I wasn't sure how to get this to work when testing on iPad, it seems like the resize bar is interactive but when dragging it didn't seem to work (I guess because of onMouseDown?) Would we need to use something like onPointerDown to try and capture both cases or is the intent to drop down to touch events for iPad support?

  5. Making the resize focusable

    Was curious what direction we were thinking about for making this keyboard operable 👀
    One idea I had was to give the resize bar role="separator" and tabindex="0" to make it focusable. We could then use the following attributes to communicate state + purpose as it changes:

    • aria-label to label the resize bar
    • aria-valuenow to set the number reflecting the current position
    • aria-valuemin and aria-valuemax to represent the min/max values for resize
    • aria-orientation="vertical" to reflect orientation

    We could use onKeyDown on that element then and listen to ArrowLeft/ArrowRight to adjust it by px values and Shift+ArrowLeft, Shift+ArrowRight for increments of 10

    Reference: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/separator_role#focusable_separator

Sorry for the long list here! Just wanted to say thanks again for taking this on and let me know if you have any questions or if I'm missing anything!

@davekenn
Copy link

davekenn commented Oct 3, 2022

Just a note that our new code view is getting feedback that our file tree is too narrow when searching for files (goto file). This resizing will solve that problem for us! Cant wait for this to get to production!

@colebemis
Copy link
Contributor

Looks like this change causes the gap between the pane and content to be twice as large when there's no divider displayed:

CleanShot 2022-10-19 at 10 41 02

@colebemis
Copy link
Contributor

👋 @japf FYI I'm going to work on getting this over the finish line today. Planning to polish some of the interactions and styling.

useEffect(() => {
let hasValue = false
if (storageKey) {
const storedWidth = window.localStorage.getItem(storageKey)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @mattcosta7 pointed out in https://github.com/github/issues/issues/3652 we might want to use a wrapped around the localStorage call to avoid throwing an error for folks who disabled 3rd party tracking in their browser.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call. Updated ✅

* Update stories

* Refactor resizable pane implementation

* Clamp pane width resizing

* Delay drag hover effect

* Reset pane width on double click

* Handle styles while dragging

* Add resizable example to SplitPageLayout docs

* Remove comment

* Add comment about touch events

* Update docs

* Update resizable pane story

* Update snapshots
@colebemis
Copy link
Contributor

Update: I finished addressing @joshblack's comments. Here's a quick video demo: https://share.cleanshot.com/imPRk8

This should be ready for another round of review. cc @joshblack

@colebemis colebemis temporarily deployed to github-pages October 27, 2022 01:47 Inactive
@colebemis colebemis temporarily deployed to github-pages October 27, 2022 01:57 Inactive
@colebemis colebemis temporarily deployed to github-pages October 27, 2022 15:12 Inactive
@colebemis colebemis temporarily deployed to github-pages October 27, 2022 15:54 Inactive
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Looks great! Noticed a couple odd behaviors when testing in Safari and Firefox, curious if you know what's going on @colebemis 🤔

Safari

Screen.Recording.2022-10-27.at.4.20.04.PM.mov

Firefox

Screen.Recording.2022-10-27.at.4.21.11.PM.mov

@colebemis
Copy link
Contributor

@joshblack I think those odd behaviors are related to how we set the max width of the pane. The max width of the pane is relative to the entire viewport size (vw), which can lead to unexpected behavior when PageLayout is nested inside smaller containers (as seen in the docs). Do those odd behaviors occur in Firefox and Safari in the fullscreen storybook example?

@colebemis
Copy link
Contributor

@joshblack I'm open to new ideas about how to handle min/max pane width if you have any! Here's the spec from @vdepizzol: https://github.com/github/primer/issues/581

@colebemis colebemis temporarily deployed to github-pages October 31, 2022 22:31 Inactive
@colebemis colebemis temporarily deployed to github-pages October 31, 2022 23:09 Inactive
@colebemis colebemis temporarily deployed to github-pages October 31, 2022 23:17 Inactive
@colebemis colebemis merged commit 0c2db83 into main Oct 31, 2022
@colebemis colebemis deleted the japf/resizable-pane branch October 31, 2022 23:17
@primer-css primer-css mentioned this pull request Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants