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(Accordion): new component #1310

Merged
merged 16 commits into from
Sep 5, 2024
Merged

Conversation

marcinsawicki
Copy link
Contributor

@marcinsawicki marcinsawicki commented Aug 29, 2024

Resolves: #1206

Description

Accordion new component.

Storybook

https://feature-accordion-new-component--613a8e945a5665003a05113b.chromatic.com/?path=/story/components-accordion--examples

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

@marcinsawicki marcinsawicki changed the title Feature/accordion new component feat(Accordion): new component Aug 29, 2024
@marcinsawicki marcinsawicki self-assigned this Sep 3, 2024
@marcinsawicki marcinsawicki added the feature New feature or request label Sep 3, 2024
@marcinsawicki marcinsawicki added this to the Cycle #9 milestone Sep 3, 2024
@marcinsawicki marcinsawicki marked this pull request as ready for review September 3, 2024 11:08

#### Example implementation

```jsx
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an import path for this example

top: 20px;
right: 20px;
transition: inherit;
z-index: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to set it to 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change that for pointer-events

}

&__label {
z-index: 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this z-index here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change that for pointer-events

className
);

const handleStateChange = (state: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest avoiding "empty words" like "state", "value" etc, because those words alone are not providing any context to the function/variable name - because the word "state" could mean anything. So I'd suggest using in this case the word "visibility": handleVisibilityChange, newVisibilityValue.


return () => resizeObserver.disconnect();
}
}, [contentRef]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this effect works as intended? The contentRef is a reference so it's mutable and the useEffect between the renders will not detect its changes.

Comment on lines 27 to 56
if (isOpen) {
setIsOpenMounted(true);
setIsClosedVisible(false);

requestAnimationFrame(() => setIsOpenVisible(true));

if (closeRef) {
closeRef.addEventListener(
'transitionend',
() => {
setIsClosedMounted(false);
},
{ once: true }
);
}
} else {
setIsClosedMounted(true);
setIsOpenVisible(false);

requestAnimationFrame(() => setIsClosedVisible(true));

if (openRef) {
openRef.addEventListener(
'transitionend',
() => {
setIsOpenMounted(false);
},
{ once: true }
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Both sides of the if statement are nearly identical and can be simplified using the ternary operator and the isOpen value itself

() => {
setIsOpenMounted(false);
},
{ once: true }
Copy link
Contributor

Choose a reason for hiding this comment

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

This option removes the event listener only if it was invoked, but if not - we need to clear ourselves.


return () => resizeObserver.disconnect();
}
}, [multilineRef]);
Copy link
Contributor

Choose a reason for hiding this comment

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

references in react a mutable, so the effect cannot detect the ref changes between the renders

Comment on lines 25 to 45
React.useEffect(() => {
const hasIOSupport = !!window.ResizeObserver;

if (multilineRef.current && hasIOSupport) {
const resizeObserver = new ResizeObserver((entries) => {
const entry = entries[0];
if (!entry) return;

const newSize = entry.contentRect.height;

if (previousMultilineSizeRef.current !== newSize) {
setSize(newSize);
previousMultilineSizeRef.current = newSize;
}
});

resizeObserver.observe(multilineRef.current);

return () => resizeObserver.disconnect();
}
}, [multilineRef]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is nearly identical to the effect from Accordion.tsx file.

@vladko-uxds
Copy link

vladko-uxds commented Sep 3, 2024

Caught a bug with picker inside accordion:

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

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

👍

@marcinsawicki marcinsawicki merged commit e4dc94c into main Sep 5, 2024
5 checks passed
@marcinsawicki marcinsawicki deleted the feature/accordion-new-component branch September 5, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Accordion] - new component
3 participants