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: horizontal mode #124

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

SaidMarar
Copy link

@SaidMarar SaidMarar commented Dec 24, 2022

This feature add an horizontal mode (width) to the collapser
enhancement request from #81
Without collapasedWidth option
expand-collapse
With collapasedWidth option
expand-collapse-2

@changeset-bot
Copy link

changeset-bot bot commented Dec 24, 2022

⚠️ No Changeset found

Latest commit: 3ae5a7e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@SaidMarar SaidMarar changed the title Feature/horizontal mode feat: horizontal mode Dec 24, 2022
@roginfarrer
Copy link
Owner

Thanks for the PR! I'm actually working on a major refactor in #122 that will make this difficult to merge. Once that is completed, this PR will need to be rebased against it.

@SaidMarar
Copy link
Author

Thanks for the PR! I'm actually working on a major refactor in #122 that will make this difficult to merge. Once that is completed, this PR will need to be rebased against it.

Great news @roginfarrer ! Do not worry i just read the code and it looks VERY CLEAN 😃 , i will wait for your release then i'll re-implement the horizontal mode.
I left a comment in your PR check it out, do not hesitate if you need some help on refacto ;)

@netlify
Copy link

netlify bot commented Jan 16, 2023

Deploy Preview for react-collapsed failed.

Name Link
🔨 Latest commit 3ae5a7e
🔍 Latest deploy log https://app.netlify.com/sites/react-collapsed/deploys/63c66b19f0c0c20008021f02

@SaidMarar
Copy link
Author

Hey @roginfarrer
Take a look, i just implemented it 😄

packages/core/src/Collapse.ts Show resolved Hide resolved
packages/core/src/Collapse.ts Outdated Show resolved Hide resolved
packages/core/src/Collapse.ts Outdated Show resolved Hide resolved
this.setStyles({
...this.getCollapsedStyles(),
// When expand = false and collapsing width we preserve initial height
...(this.options.isHorizontal ? {height: `${this.initialHeight}px`} : {}),
Copy link
Owner

Choose a reason for hiding this comment

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

I think this might be an issue with an element that's made the full height of the window. An example would be a drawer or a sidebar. Upon resizing, hardcoding the height would cause the sidebar to not stay adhered to the window edge.

We might need to use a resizeobserver in order to update the height

Copy link
Owner

Choose a reason for hiding this comment

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

Or maybe it should be an option to persist the height when the width is animated and collapsed? Not sure which is better

Copy link
Author

@SaidMarar SaidMarar Jan 16, 2023

Choose a reason for hiding this comment

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

There is two places where we persist the height:

  • In the init method when the default expand is equal to false.
  • In the close method when the width is animated and collapsed.

If we are going to use resizeobserver (observe height) on the element it will interfere with collapase when it is changing the height for animated width.

I think the second option you mentioned is already handled in close method and for me i go for this option, but if you have any suggestions to improve it let me know please ;)

Copy link
Owner

Choose a reason for hiding this comment

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

I pulled up the storybook, and it looks like the fixed height is always applied (it would need to be removed in the transitionend handler. I made an example in the example app that shows this quick and dirty sidebar demo.

sidebar demo

Copy link
Author

Choose a reason for hiding this comment

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

Good point, i think we should reset height on transitionEnd then I'll check other scenarios

Copy link
Author

@SaidMarar SaidMarar Jan 17, 2023

Choose a reason for hiding this comment

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

Actually responsive and fixed value of height will work perfectly without saving initial height.
The only issue that we will have is with the auto height, it is changing while animating width, so i think in this case it is up to the user to set the option collapseStyles what do you think ? I tried a solution by adding a setTimeout to detect if height is changed at middle of transition and it works ! but if the default expand is false at the initialization there is no chance to have this information ^^

colla

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.

2 participants