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

collapsible side panel #88

Merged
merged 5 commits into from
Jun 28, 2024
Merged

collapsible side panel #88

merged 5 commits into from
Jun 28, 2024

Conversation

magland
Copy link
Collaborator

@magland magland commented Jun 26, 2024

Addresses #86

Implement collapsible/expandable left panel.

Upon initial load, determines if width is too small (like on a device) and defaults to a collapsed panel.

When panel is collapsed there's a chevron button you can press or click to expand.

When expanded, width is determined based on overall width based on a formula.

When expanded, there's a chevron button you can press or click to collapse.

AND advanced: when resizing a browser window and you transition from large-enough to too-small the panel automatically collapses. Similarly when you transition from too-small to large-enough the panel automatically expands.

This is the functionality that I felt was most natural.

@magland
Copy link
Collaborator Author

magland commented Jun 26, 2024

You can try it live or on a phone:
https://stan-playground.vercel.app

@WardBrian
Copy link
Collaborator

The live preview link is dead for me @magland:

TypeError: n.meta is undefined
    pT https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:301
    Jf https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:38
    Dc https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    B0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    L0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    ob https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    $a https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    Vc https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    A0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    w https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:25
    C https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:25
[index-DLM3JXrp.js:40:161](https://stan-playground.vercel.app/assets/index-DLM3JXrp.js)
16:12:23.207
Uncaught TypeError: n.meta is undefined
    pT https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:301
    Jf https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:38
    Dc https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    B0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    L0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    ob https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    $a https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    Vc https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    A0 https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:40
    w https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:25
    C https://stan-playground.vercel.app/assets/index-DLM3JXrp.js:25

@magland
Copy link
Collaborator Author

magland commented Jun 26, 2024

@WardBrian this is due to #89
You'll need to clear your browser cache.

@WardBrian
Copy link
Collaborator

Yep, that worked.

Copy link
Collaborator

@jsoules jsoules left a comment

Choose a reason for hiding this comment

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

I have a suggested simplification, but otherwise this looks good to go.

Comment on lines 48 to 58
const lastWidth = useRef(width)
useEffect(() => {
if (!determineShouldBeInitiallyCollapsed(lastWidth.current) && determineShouldBeInitiallyCollapsed(width)) {
lastWidth.current = width
setLeftPanelCollapsed(true)
}
else if (determineShouldBeInitiallyCollapsed(lastWidth.current) && !determineShouldBeInitiallyCollapsed(width)) {
lastWidth.current = width
setLeftPanelCollapsed(false)
}
}, [width])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since all we care about for lastWidth is whether it implies a collapsed state, this could probably be simplified (reducing function calls) as something along the lines of:

const isCollapsed = useRef(determineShouldBeInitiallyCollapsed(width));
useEffect(() => {
  const shouldBeCollapsed = determineShouldBeInitiallyCollapsed(width);
  if (isCollapsed.current !== shouldBeCollapsed) {
    isCollapsed.current = shouldBeCollapsed;
    setLeftPanelCollapsed(shouldBeCollapsed);
  } 
}, [width])

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think your isCollapsed variable should really be named something like lastShouldBeCollapsed. Either way it's somewhat confusing. I think I'd prefer to stick with what I have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thinking more about it, I think your simplification is clearer. I essentially used your code but I used the name lastShouldBeCollapsed

@magland magland merged commit 7c55ce0 into main Jun 28, 2024
2 checks passed
@WardBrian WardBrian deleted the collapsible-side-panel branch July 1, 2024 16:26
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.

3 participants