@nys-cui/cui-section 0.2.12 → 0.2.14

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/section.js +33 -4
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "main": "./dist/js/section.js",
8
8
  "type": "module",
9
- "version": "0.2.12",
9
+ "version": "0.2.14",
10
10
  "scripts": {
11
11
  "clean": "rm -rf ./dist",
12
12
  "build": "npm run clean && cui --dep",
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() {
@@ -43,7 +51,7 @@ export default class CUI_SECTION extends HTMLElement {
43
51
  sTemplate += `
44
52
  <div class="header-controls" part="header-controls">
45
53
  <button type="button" id="collapse-control" aria-controls="container" part="collapse-control">
46
- <cui-icon src="caret-down" base="${this.sIconBasePath}" part="collapse-control-icon"></cui-icon>
54
+ <cui-icon src="caret-down" basePath="${this.sIconBasePath}" part="collapse-control-icon"></cui-icon>
47
55
  </button>
48
56
  </div>`;
49
57
 
@@ -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 () {