11import * as _ from 'lodash' ;
22import * as React from 'react' ;
3- import { observer } from 'mobx-react' ;
3+ import { inject , observer } from 'mobx-react' ;
44import { observable , action } from 'mobx' ;
55
66import { styled , css } from "../../styles" ;
7+ import { CollapsibleSectionKey , UiStore } from '../../model/ui/ui-store' ;
8+
79import { isReactElement } from '../../util/ui' ;
810import { Icon , IconProp } from '../../icons' ;
911
@@ -13,6 +15,9 @@ interface CollapsibleSectionProps {
1315 withinGrid ?: boolean ;
1416 prefixTrigger ?: boolean ;
1517 contentName : string ;
18+
19+ collapsePersistKey ?: CollapsibleSectionKey ;
20+ uiStore ?: UiStore ;
1621}
1722
1823const CollapsibleSectionWrapper = styled . section `
@@ -62,14 +67,17 @@ const SummaryAsSpacer = styled.div`
6267 * This component also works if there is no body provided - it falls back to just
6368 * showing the summary without the expand/collapse toggle.
6469 */
70+ @inject ( 'uiStore' )
6571@observer
6672export class CollapsibleSection extends React . Component < CollapsibleSectionProps > {
6773
6874 static idCounter = 0 ;
6975 id = `collapsible-${ CollapsibleSection . idCounter ++ } ` ;
7076
7177 @observable
72- open = false ;
78+ open = this . props . collapsePersistKey
79+ ? ! ! this . props . uiStore ?. collapsibleSectionStates [ this . props . collapsePersistKey ]
80+ : false ;
7381
7482 render ( ) {
7583 const {
@@ -150,6 +158,10 @@ export class CollapsibleSection extends React.Component<CollapsibleSectionProps>
150158 toggleOpen ( e : React . SyntheticEvent ) {
151159 e . preventDefault ( ) ;
152160 this . open = ! this . open ;
161+
162+ if ( this . props . collapsePersistKey ) {
163+ this . props . uiStore ! . collapsibleSectionStates [ this . props . collapsePersistKey ] = this . open ;
164+ }
153165 }
154166}
155167
0 commit comments