@nys-cui/cui-section 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/section.js +32 -3
package/package.json
CHANGED
package/src/section.js
CHANGED
|
@@ -25,6 +25,14 @@ export default class CUI_SECTION extends HTMLElement {
|
|
|
25
25
|
this.sdContentsContainer = null;
|
|
26
26
|
|
|
27
27
|
this.bLock = false;
|
|
28
|
+
|
|
29
|
+
this.oPropsToStateNames = {
|
|
30
|
+
"sectiontitle": "sTitle",
|
|
31
|
+
"hideControls": "bHideControls",
|
|
32
|
+
"collapsed": "bCollapsed",
|
|
33
|
+
"styles": "asStyles"
|
|
34
|
+
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
get style() {
|
|
@@ -70,6 +78,27 @@ export default class CUI_SECTION extends HTMLElement {
|
|
|
70
78
|
return sTemplate;
|
|
71
79
|
}
|
|
72
80
|
|
|
81
|
+
setState(props) {
|
|
82
|
+
// Need to map props to state variable names if we want to keep them prefixed.
|
|
83
|
+
this.state = Object.assign(this.state, this.normalizeProps(props));
|
|
84
|
+
|
|
85
|
+
if (this.isConnected) {
|
|
86
|
+
this.render();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
normalizeProps(props) {
|
|
91
|
+
let updatedProps = {};
|
|
92
|
+
|
|
93
|
+
for (const [key, value] of Object.entries(props)) {
|
|
94
|
+
if (this.oPropsToStateNames[key]) {
|
|
95
|
+
updatedProps[this.oPropsToStateNames[key]] = value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return updatedProps;
|
|
100
|
+
}
|
|
101
|
+
|
|
73
102
|
expand(dContainer) {
|
|
74
103
|
|
|
75
104
|
function transitionEnd() {
|
|
@@ -98,7 +127,7 @@ export default class CUI_SECTION extends HTMLElement {
|
|
|
98
127
|
dContainer.style.overflow = "hidden";
|
|
99
128
|
|
|
100
129
|
this.sdSection.style.removeProperty('height');
|
|
101
|
-
|
|
130
|
+
|
|
102
131
|
// when the next css transition finishes (which should be the one we just triggered)
|
|
103
132
|
dContainer.addEventListener('transitionend', transitionEnd, true);
|
|
104
133
|
|
|
@@ -137,7 +166,7 @@ export default class CUI_SECTION extends HTMLElement {
|
|
|
137
166
|
let sectionStyle = getComputedStyle(sdSection);
|
|
138
167
|
let collapseSectionHeight = header.offsetHeight + parseInt(headerStyle.marginBottom) + parseInt(headerStyle.marginTop);
|
|
139
168
|
collapseSectionHeight += parseInt(sectionStyle.borderBottom) + parseInt(sectionStyle.borderTop);
|
|
140
|
-
|
|
169
|
+
|
|
141
170
|
// on the next frame (as soon as the previous style change has taken effect),
|
|
142
171
|
// explicitly set the dContainer's height to its current pixel height, so we
|
|
143
172
|
// aren't transitioning out of 'auto'
|
|
@@ -147,7 +176,7 @@ export default class CUI_SECTION extends HTMLElement {
|
|
|
147
176
|
dContainer.style.overflow = "hidden";
|
|
148
177
|
|
|
149
178
|
sdSection.style.setProperty("height", sdSection.offsetHeight + 'px', "important");
|
|
150
|
-
|
|
179
|
+
|
|
151
180
|
// on the next frame (as soon as the previous style change has taken effect),
|
|
152
181
|
// have the dContainer transition to height: 0
|
|
153
182
|
requestAnimationFrame(function () {
|