10
10
:id =" sectionKey"
11
11
class =" toggle"
12
12
type =" checkbox"
13
- :checked =" isExpanded"
14
- @change =" collapseChanged"
13
+ v-model =" checkboxState"
15
14
tabIndex =" -1"
16
15
>
17
16
<label :for =" sectionKey" class =" lbl-toggle" tabindex =" -1"
@@ -75,34 +74,42 @@ export default {
75
74
const { rows , cols , checkSpanNum } = this ;
76
75
return ` ${ checkSpanNum (cols, ' col' )} ${ checkSpanNum (rows, ' row' )} ` ;
77
76
},
77
+ /* Used to fetch initial collapse state, and set new collapse state on change */
78
78
isExpanded: {
79
- // getter
80
79
get () {
81
80
if (this .collapsed !== undefined ) return ! this .collapsed ;
82
- const collapseStateObject = this .initialiseStorage (); // Check local storage
81
+ const collapseStateObject = this .locallyStoredCollapseStates ();
83
82
if (collapseStateObject[this .uniqueKey ] !== undefined ) {
84
83
return collapseStateObject[this .uniqueKey ];
85
84
}
86
- return true ; // Nothing specified, return Open
85
+ return true ;
87
86
},
88
- // setter
89
87
set (newState ) {
90
- // Get the current localstorage collapse state object
91
- const collapseState = JSON .parse (localStorage[localStorageKeys .COLLAPSE_STATE ]);
92
- // Add the new state to it
88
+ const collapseState = this .locallyStoredCollapseStates ();
93
89
collapseState[this .uniqueKey ] = newState;
94
- // Stringify, and set the new object into local storage
95
90
localStorage .setItem (localStorageKeys .COLLAPSE_STATE , JSON .stringify (collapseState));
96
91
},
97
92
},
98
93
},
99
94
data : () => ({
100
- // isExpanded: false ,
95
+ checkboxState : true ,
101
96
}),
102
97
mounted () {
103
- // this.isExpanded = this.getCollapseState();
98
+ this .checkboxState = this .isExpanded ;
99
+ },
100
+ watch: {
101
+ checkboxState (newState ) {
102
+ this .isExpanded = newState;
103
+ },
104
+ uniqueKey () {
105
+ this .checkboxState = this .isExpanded ;
106
+ },
104
107
},
105
108
methods: {
109
+ /* Either expand or collapse section, based on it's current state */
110
+ toggle () {
111
+ this .checkboxState = ! this .checkboxState ;
112
+ },
106
113
/* Check that row & column span is valid, and not over the max */
107
114
checkSpanNum (span , classPrefix ) {
108
115
const maxSpan = 6 ;
@@ -115,7 +122,7 @@ export default {
115
122
return userCss ? userCss .replace (/ [^ a-zA-Z0-9 - :;. ] / g , ' ' ) : ' ' ;
116
123
},
117
124
/* Returns local storage collapse state data, and if not yet set then initialized is */
118
- initialiseStorage () {
125
+ locallyStoredCollapseStates () {
119
126
// If not yet set, then call initialize
120
127
if (! localStorage[localStorageKeys .COLLAPSE_STATE ]) {
121
128
localStorage .setItem (localStorageKeys .COLLAPSE_STATE , JSON .stringify ({}));
@@ -124,10 +131,6 @@ export default {
124
131
// Otherwise, return value of local storage
125
132
return JSON .parse (localStorage[localStorageKeys .COLLAPSE_STATE ]);
126
133
},
127
- // /* Called when collapse state changes, trigger local storage update if needed */
128
- collapseChanged (whatChanged ) {
129
- this .isExpanded = whatChanged .srcElement .checked ;
130
- },
131
134
openEditModal () {
132
135
this .$emit (' openEditSection' );
133
136
},
@@ -214,6 +217,8 @@ export default {
214
217
margin-right : .7rem ;
215
218
transform : translateY (-2px );
216
219
transition : transform .2s ease-out ;
220
+ opacity : 0.3 ;
221
+ transition : all 0.4s ease-in-out ;
217
222
}
218
223
}
219
224
@@ -251,6 +256,16 @@ export default {
251
256
top : 0.5rem ;
252
257
margin-left : 0.2rem ;
253
258
margin-right : 0.2rem ;
259
+ opacity : 0.3 ;
260
+ transition : all 0.4s ease-in-out ;
261
+ }
262
+
263
+ /* On section hover, set interface icons to full visible */
264
+ & :hover {
265
+ .edit-mode-item , label .lbl-toggle ::before {
266
+ opacity : 1 ;
267
+ transition : all 0.2s ease-out ;
268
+ }
254
269
}
255
270
256
271
/* Makes sections fill available space */
0 commit comments