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

feat: dynamically collapse legs based on available space #55

Merged
merged 13 commits into from
Nov 9, 2023

Conversation

adriansberg
Copy link
Contributor

@adriansberg adriansberg commented Nov 4, 2023

Dynamically collapse legs based on available space

This PR introduces a significant enhancement in leg-handle feature in our system. It adds a dynamic collapsing functionality based on the available space. This attribute adapts to the space available and smartly collapses the leg elements to ensure optimal utilization of the space without compromising on the user's interaction.

This feature not only optimizes the design for minimal spaces but also enhances the user interface by providing more flexibility and usability, especially in designs with space constraints. Now, the elements on our interface will be optimally adjusted to provide the best user experience in any given viewing area.

I have reused the logic used in the app for dynamically collapsing the legs based on the width available. The implemented logic only collapses the legs however, we might want to look into expanding them as well if the user e.g. shrinks then grows their browser, the wanted effect is probably expanding the previously collapsed legs.

Introduced the @react-hook/resize-observer and made a custom hook for getting the width of the elements needed to decide whether legs should collapse or not. Could have not added this hook and gone for a solution that only collapses on load, but I figured it would be nice to collapse on the fly when shrinking as well.

👇 Screenshots and a GIF 👇

image image

2023-11-04 at 23 21 30

Fixes https://github.com/AtB-AS/kundevendt/issues/14914

Copy link

vercel bot commented Nov 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
planner-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 0:05am

Copy link
Contributor

@mortennordseth mortennordseth left a comment

Choose a reason for hiding this comment

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

It overflows sometimes when I use the device toolbar in chrome 🤔

image image

@adriansberg
Copy link
Contributor Author

It overflows sometimes when I use the device toolbar in chrome 🤔

image image

Should be fixed now, please test.

// Dynamically collapse legs to fit horizontally
useEffect(() => {
if (legsParentWidth && legsContentWidth) {
if (legsContentWidth >= legsParentWidth - LAST_LEG_PADDING) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a LAST_LEG_PADDING here to make some space between the destination leg and second to last leg. Couldn't do it in a nice way with CSS without sacrificing the line in some way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing a better approach right now, so I'm fine with this 👍

@mortennordseth
Copy link
Contributor

I'm getting a lot of errors on the assistant page, but might not be relevant to this PR 🤔

framework-63157d71ad419e09.js:9 Uncaught Error: Minified React error #423; visit https://reactjs.org/docs/error-decoder.html?invariant=423 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.

@adriansberg
Copy link
Contributor Author

I'm getting a lot of errors on the assistant page, but might not be relevant to this PR 🤔

framework-63157d71ad419e09.js:9 Uncaught Error: Minified React error #423; visit https://reactjs.org/docs/error-decoder.html?invariant=423 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.

Hmm, haven't seen this.

Copy link
Contributor

@mortennordseth mortennordseth left a comment

Choose a reason for hiding this comment

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

Nice work 🤩

@adriansberg adriansberg merged commit 6ca8716 into main Nov 9, 2023
5 checks passed
@adriansberg adriansberg deleted the adriansberg/collapse-legs branch November 9, 2023 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants