-
Notifications
You must be signed in to change notification settings - Fork 66
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) Restore ability to collapse and expand the entire form #413
Conversation
Size Change: -252 kB (-17.07%) 👏 Total Size: 1.22 MB
ℹ️ View Unchanged
|
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.
Great work, @samuelmale. I've left some comments.
<CollapsibleSectionContainer | ||
section={section} | ||
sectionIndex={index} | ||
visibleSections={visibleSections} | ||
isFormExpanded={isFormExpanded} | ||
/> |
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.
<CollapsibleSectionContainer | |
section={section} | |
sectionIndex={index} | |
visibleSections={visibleSections} | |
isFormExpanded={isFormExpanded} | |
/> | |
<CollapsibleSectionContainer | |
key={`section-${section.label}`} | |
section={section} | |
sectionIndex={index} | |
visibleSections={visibleSections} | |
isFormExpanded={isFormExpanded} | |
/> |
<SectionRenderer section={section} /> | ||
</div> | ||
</AccordionItem> | ||
{visibleSections.map((section, index) => ( |
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.
Unrelated to your changes, but maybe visibleSections
could benefit from memoization:
const visibleSections = useMemo(() => {
return page.sections.filter((section) => {
const hasVisibleQuestions = section.questions.some((question) => !isTrue(question.isHidden));
return !isTrue(section.isHidden) && hasVisibleQuestions;
});
}, [page.sections]);
@@ -42,25 +55,51 @@ function PageRenderer({ page }: PageRendererProps) { | |||
</span> | |||
</p> | |||
</div> | |||
{!isCollapsed && ( | |||
<div className={isCollapsed ? styles.hiddenAccordion : styles.accordionContainer}> |
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.
<div className={isCollapsed ? styles.hiddenAccordion : styles.accordionContainer}> | |
<div className={classNames({ | |
[styles.hiddenAccordion]: isCollapsed, | |
[styles.accordionContainer]: !isCollapsed | |
})}> |
[styles.firstSection]: sectionIndex === 0, | ||
[styles.lastSection]: sectionIndex === visibleSections.length - 1, | ||
})} | ||
key={`section-${section.label}`}> |
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.
key={`section-${section.label}`}> | |
> |
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.
Thanks @samuelmale
Requirements
Summary
This PR primarily restores the ability to collapse and expand all visible form pages and sections.
Out of scope:
Screenshots
Unmounting Issue:
(The Encounter Provider and Location fields are remounted)
Unmounting Issue Fixed:
Other features:
Related Issue
N/A
Other
Note: Carbon doesn't support nesting accordions, which is why I resorted to manipulating the visibility of the sections during page collapse; see: