diff --git a/src/component/elements/Sections.tsx b/src/component/elements/Sections.tsx index bd1b2dad5..bc1c7a316 100644 --- a/src/component/elements/Sections.tsx +++ b/src/component/elements/Sections.tsx @@ -47,11 +47,14 @@ const Container = styled.div<{ overflow: boolean }>( `, ); -const SectionWrapper = styled.div( - ({ isOpen, overflow }) => ` +const SectionWrapper = styled.div< + ActiveProps & { matchContentHeight: boolean } +>( + ({ isOpen, overflow, matchContentHeight }) => ` display: flex; flex-direction: column; - flex: ${isOpen ? (overflow ? '1' : overflow ? '1' : '1 1 1px') : 'none'}; + flex:none; + flex: ${isOpen && !matchContentHeight ? (overflow ? '1' : overflow ? '1' : '1 1 1px') : 'none'}; `, ); @@ -88,12 +91,10 @@ const OpenIcon = styled(Icon)` const ContentWrapper = styled.div( ({ isOpen, overflow }) => ` background-color: white; - // overflow: hidden; display: ${isOpen ? 'flex' : 'none'}; flex: ${isOpen ? (overflow ? '1' : '1 1 1px') : 'none'}; max-height: 100%; flex-direction:column; - `, ); const Content = styled.div` @@ -104,7 +105,7 @@ const Content = styled.div` flex-direction: column; padding: 10px; `; -const RightElementsContainer = styled.div` +const ElementsContainer = styled.div` display: flex; align-items: center; `; @@ -136,6 +137,7 @@ interface BaseSectionProps { title: string; serial?: number; rightElement?: ReactNode | ((isOpen) => ReactNode); + leftElement?: ReactNode | ((isOpen) => ReactNode); headerStyle?: CSSProperties; } @@ -143,8 +145,9 @@ interface SectionItemProps extends BaseSectionProps { id?: string; onClick?: (id, event?: MouseEvent) => void; children?: ReactNode | ((options: { isOpen?: boolean }) => ReactNode); - selectedSectionId?: string; + isOpen: boolean; sticky?: boolean; + matchContentHeight?: boolean; } interface SectionProps { @@ -188,29 +191,33 @@ function SectionItem(props: SectionItemProps) { onClick, serial, rightElement, + leftElement, children, - selectedSectionId, headerStyle, + isOpen, sticky = false, + matchContentHeight = false, } = props; - const isOpen = selectedSectionId === id; const { overflow } = useSections(); return ( - + onClick?.(id, event)} serial={serial} rightElement={rightElement} + leftElement={leftElement} headerStyle={headerStyle} sticky={sticky} /> - - {children} - + {children} ); } @@ -218,16 +225,14 @@ function SectionItem(props: SectionItemProps) { interface WrapperProps { children: ReactNode | ((options: { isOpen?: boolean }) => ReactNode); isOpen: boolean; - id: string; - selectedSectionId?: string; } function Wrapper(props: WrapperProps) { const { overflow, renderActiveSectionContentOnly } = useSections(); - const { children, isOpen, selectedSectionId, id } = props; + const { children, isOpen } = props; - if (renderActiveSectionContentOnly && id !== selectedSectionId) { + if (renderActiveSectionContentOnly && !isOpen) { return null; } @@ -252,6 +257,7 @@ function MainSectionHeader(props: MainSectionHeaderProps) { onClick, serial, rightElement, + leftElement, headerStyle = {}, sticky, } = props; @@ -268,19 +274,26 @@ function MainSectionHeader(props: MainSectionHeaderProps) { }} > - - {serial} - + {typeof serial === 'number' && ( + + {serial} + + )} + event.stopPropagation()}> + {typeof leftElement === 'function' + ? leftElement(isOpen) + : leftElement} + {title} - - event.stopPropagation()}> + + event.stopPropagation()}> {typeof rightElement === 'function' ? rightElement(isOpen) : rightElement} - + - + ); } diff --git a/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx b/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx index fdddc18c9..abad2c552 100644 --- a/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx +++ b/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx @@ -257,7 +257,7 @@ function FiltersInner(props: FiltersInnerProps) { onClick={(id) => { toggleSection(id); }} - selectedSectionId={selectedSection} + isOpen={name === selectedSection} rightElement={