1
1
import * as _ from 'lodash' ;
2
2
import * as React from 'react' ;
3
- import { observer } from 'mobx-react' ;
3
+ import { inject , observer } from 'mobx-react' ;
4
4
import { observable , action } from 'mobx' ;
5
5
6
6
import { styled , css } from "../../styles" ;
7
+ import { CollapsibleSectionKey , UiStore } from '../../model/ui/ui-store' ;
8
+
7
9
import { isReactElement } from '../../util/ui' ;
8
10
import { Icon , IconProp } from '../../icons' ;
9
11
@@ -13,6 +15,9 @@ interface CollapsibleSectionProps {
13
15
withinGrid ?: boolean ;
14
16
prefixTrigger ?: boolean ;
15
17
contentName : string ;
18
+
19
+ collapsePersistKey ?: CollapsibleSectionKey ;
20
+ uiStore ?: UiStore ;
16
21
}
17
22
18
23
const CollapsibleSectionWrapper = styled . section `
@@ -62,14 +67,17 @@ const SummaryAsSpacer = styled.div`
62
67
* This component also works if there is no body provided - it falls back to just
63
68
* showing the summary without the expand/collapse toggle.
64
69
*/
70
+ @inject ( 'uiStore' )
65
71
@observer
66
72
export class CollapsibleSection extends React . Component < CollapsibleSectionProps > {
67
73
68
74
static idCounter = 0 ;
69
75
id = `collapsible-${ CollapsibleSection . idCounter ++ } ` ;
70
76
71
77
@observable
72
- open = false ;
78
+ open = this . props . collapsePersistKey
79
+ ? ! ! this . props . uiStore ?. collapsibleSectionStates [ this . props . collapsePersistKey ]
80
+ : false ;
73
81
74
82
render ( ) {
75
83
const {
@@ -150,6 +158,10 @@ export class CollapsibleSection extends React.Component<CollapsibleSectionProps>
150
158
toggleOpen ( e : React . SyntheticEvent ) {
151
159
e . preventDefault ( ) ;
152
160
this . open = ! this . open ;
161
+
162
+ if ( this . props . collapsePersistKey ) {
163
+ this . props . uiStore ! . collapsibleSectionStates [ this . props . collapsePersistKey ] = this . open ;
164
+ }
153
165
}
154
166
}
155
167
0 commit comments