@nys-cui/cui-section 0.2.6 → 0.2.8

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 CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "main": "./dist/js/section.js",
8
8
  "type": "module",
9
- "version": "0.2.6",
9
+ "version": "0.2.8",
10
10
  "scripts": {
11
11
  "clean": "rm -rf ./dist",
12
12
  "build": "npm run clean && cui --dep",
package/src/section.js CHANGED
@@ -6,7 +6,7 @@ export default class CUI_SECTION extends HTMLElement {
6
6
 
7
7
  super();
8
8
 
9
- this.attachShadow({mode: 'open'});
9
+ this.attachShadow({ mode: 'open' });
10
10
 
11
11
  this.state = {
12
12
  sTitle: null
@@ -96,17 +96,19 @@ export default class CUI_SECTION extends HTMLElement {
96
96
  // have the dContainer transition to the height of its inner content
97
97
  dContainer.style.height = sectionHeight + 'px';
98
98
  dContainer.style.overflow = "hidden";
99
+
100
+ this.sdSection.style.removeProperty('height');
99
101
 
100
102
  // when the next css transition finishes (which should be the one we just triggered)
101
103
  dContainer.addEventListener('transitionend', transitionEnd, true);
102
-
104
+
103
105
 
104
106
  }
105
107
 
106
108
  collapse(dContainer) {
107
109
 
108
110
  function transitionEnd(e) {
109
-
111
+
110
112
  dContainer.style.height = "";
111
113
  dContainer.style.overflow = null;
112
114
 
@@ -121,31 +123,44 @@ export default class CUI_SECTION extends HTMLElement {
121
123
 
122
124
  // get the height of the dContainer's inner content, regardless of its actual size
123
125
  var sectionHeight = dContainer.scrollHeight;
124
-
126
+
125
127
  // temporarily disable all css transitions
126
128
  var dContainerTransition = dContainer.style.transition;
127
129
  dContainer.style.transition = '';
130
+
131
+ let sdSection = this.sdSection;
132
+
133
+ //sdSection.style.transition = '';
134
+ let header = sdSection.querySelector("header");
135
+ let headerStyle = getComputedStyle(header);
136
+ let sectionStyle = getComputedStyle(sdSection);
137
+ let collapseSectionHeight = header.offsetHeight + parseInt(headerStyle.marginBottom) + parseInt(headerStyle.marginTop);
138
+ collapseSectionHeight += parseInt(sectionStyle.borderBottom) + parseInt(sectionStyle.borderTop);
128
139
 
129
140
  // on the next frame (as soon as the previous style change has taken effect),
130
141
  // explicitly set the dContainer's height to its current pixel height, so we
131
142
  // aren't transitioning out of 'auto'
132
- requestAnimationFrame(function() {
143
+ requestAnimationFrame(function () {
133
144
  dContainer.style.height = sectionHeight + 'px';
134
145
  dContainer.style.transition = dContainerTransition;
135
146
  dContainer.style.overflow = "hidden";
147
+
148
+ sdSection.style.setProperty("height", sdSection.offsetHeight + 'px', "important");
136
149
 
137
150
  // on the next frame (as soon as the previous style change has taken effect),
138
151
  // have the dContainer transition to height: 0
139
- requestAnimationFrame(function() {
152
+ requestAnimationFrame(function () {
140
153
 
141
154
  dContainer.style.height = 0 + 'px';
142
155
 
156
+ sdSection.style.setProperty("height", collapseSectionHeight + 'px', "important");
157
+
143
158
  dContainer.addEventListener('transitionend', transitionEnd, true);
144
159
 
145
160
  });
146
161
 
147
162
  });
148
-
163
+
149
164
 
150
165
  }
151
166
 
@@ -161,7 +176,7 @@ export default class CUI_SECTION extends HTMLElement {
161
176
  this.sIconBasePath = this.getAttribute('iconbase') || null;
162
177
 
163
178
  let dMessageList = this.querySelector(`[slot="section-messages"]`);
164
- if(dMessageList) {
179
+ if (dMessageList) {
165
180
  this._cMessageList = dMessageList;
166
181
  }
167
182
 
@@ -178,7 +193,7 @@ export default class CUI_SECTION extends HTMLElement {
178
193
 
179
194
  this.sdSectionTitle.appendChild(document.createTextNode(this.state.sTitle));
180
195
 
181
- if (!this.state.bHideControls) {
196
+ if (!this.state.bHideControls) {
182
197
 
183
198
  this.sdSectionCollapseControl = this.shadowRoot.querySelector(`#collapse-control`);
184
199
 
@@ -190,28 +205,29 @@ export default class CUI_SECTION extends HTMLElement {
190
205
 
191
206
  this.sdSectionCollapseControl.classList.add('collapsed');
192
207
  this.sdContentsContainer.setAttribute('data-collapsed', "true");
208
+ this.sdSection.style.setProperty("height", 'auto', "important");
193
209
  }
194
210
 
195
211
  this.sdSectionCollapseControl.addEventListener('click', () => {
196
-
212
+
197
213
  if (!this.bLock) {
198
-
214
+
199
215
  if (this.sdContentsContainer.getAttribute('data-collapsed') === "true") {
200
-
216
+
201
217
  this.sdSectionCollapseControl.classList.remove('collapsed');
202
-
218
+
203
219
  this.expand(this.sdContentsContainer);
204
220
  }
205
221
  else {
206
-
222
+
207
223
  this.sdSectionCollapseControl.classList.add('collapsed');
208
-
224
+
209
225
  this.collapse(this.sdContentsContainer);
210
226
  }
211
-
227
+
212
228
  this.bLock = false;
213
229
  }
214
-
230
+
215
231
  });
216
232
  }
217
233
 
@@ -221,7 +237,7 @@ export default class CUI_SECTION extends HTMLElement {
221
237
 
222
238
  for (let sStyle of this.state.asStyles) {
223
239
 
224
- switch(sStyle.toLowerCase()) {
240
+ switch (sStyle.toLowerCase()) {
225
241
 
226
242
  case "subsection":
227
243
 
@@ -243,10 +259,8 @@ export default class CUI_SECTION extends HTMLElement {
243
259
 
244
260
  }
245
261
 
246
- get messages()
247
- {
248
- if(!this._cMessageList)
249
- {
262
+ get messages() {
263
+ if (!this._cMessageList) {
250
264
  this._cMessageList = document.createElement('cui-message-list');
251
265
  this._cMessageList.slot = "section-messages";
252
266
  this.appendChild(this._cMessageList);
@@ -255,12 +269,30 @@ export default class CUI_SECTION extends HTMLElement {
255
269
  return this._cMessageList;
256
270
  }
257
271
 
258
- reset()
259
- {
260
- if(this._cMessageList)
261
- {
272
+ reset() {
273
+ if (this._cMessageList) {
262
274
  this._cMessageList.reset();
263
275
  }
264
276
  }
265
277
 
278
+ setMessages(aoMessages) {
279
+ for (let i = 0; i < aoMessages.length; i++) {
280
+ if (this.messages) {
281
+ this.messages.add(aoMessages[i]);
282
+ }
283
+ }
284
+ }
285
+
286
+ removeMessages() {
287
+ this.messages.removeAll();
288
+ }
289
+
290
+ removeMessage(id) {
291
+ this.messages.removeMessageWithId(id);
292
+ }
293
+
294
+ removeMessageIndex(index) {
295
+ this.messages.removeMessageAtIndex(index);
296
+ }
297
+
266
298
  }
package/src/section.scss CHANGED
@@ -89,6 +89,7 @@
89
89
  section {
90
90
  border: 1px solid var(--section-header-border-color);
91
91
  box-shadow: none;
92
+ transition: height 0.5s ease;
92
93
 
93
94
  header {
94
95
  margin: 0 0 20px;