-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
You can try it live or on a phone: |
The live preview link is dead for me @magland:
|
@WardBrian this is due to #89 |
Yep, that worked. |
There was a problem hiding this 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.
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]) |
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.