@nys-cui/cui-section 0.2.6 → 0.2.7

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 +45 -29
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.7",
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,17 @@ 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
-
99
+
100
100
  // when the next css transition finishes (which should be the one we just triggered)
101
101
  dContainer.addEventListener('transitionend', transitionEnd, true);
102
-
102
+
103
103
 
104
104
  }
105
105
 
106
106
  collapse(dContainer) {
107
107
 
108
108
  function transitionEnd(e) {
109
-
109
+
110
110
  dContainer.style.height = "";
111
111
  dContainer.style.overflow = null;
112
112
 
@@ -121,22 +121,22 @@ export default class CUI_SECTION extends HTMLElement {
121
121
 
122
122
  // get the height of the dContainer's inner content, regardless of its actual size
123
123
  var sectionHeight = dContainer.scrollHeight;
124
-
124
+
125
125
  // temporarily disable all css transitions
126
126
  var dContainerTransition = dContainer.style.transition;
127
127
  dContainer.style.transition = '';
128
-
128
+
129
129
  // on the next frame (as soon as the previous style change has taken effect),
130
130
  // explicitly set the dContainer's height to its current pixel height, so we
131
131
  // aren't transitioning out of 'auto'
132
- requestAnimationFrame(function() {
132
+ requestAnimationFrame(function () {
133
133
  dContainer.style.height = sectionHeight + 'px';
134
134
  dContainer.style.transition = dContainerTransition;
135
135
  dContainer.style.overflow = "hidden";
136
-
136
+
137
137
  // on the next frame (as soon as the previous style change has taken effect),
138
138
  // have the dContainer transition to height: 0
139
- requestAnimationFrame(function() {
139
+ requestAnimationFrame(function () {
140
140
 
141
141
  dContainer.style.height = 0 + 'px';
142
142
 
@@ -145,7 +145,7 @@ export default class CUI_SECTION extends HTMLElement {
145
145
  });
146
146
 
147
147
  });
148
-
148
+
149
149
 
150
150
  }
151
151
 
@@ -161,7 +161,7 @@ export default class CUI_SECTION extends HTMLElement {
161
161
  this.sIconBasePath = this.getAttribute('iconbase') || null;
162
162
 
163
163
  let dMessageList = this.querySelector(`[slot="section-messages"]`);
164
- if(dMessageList) {
164
+ if (dMessageList) {
165
165
  this._cMessageList = dMessageList;
166
166
  }
167
167
 
@@ -178,7 +178,7 @@ export default class CUI_SECTION extends HTMLElement {
178
178
 
179
179
  this.sdSectionTitle.appendChild(document.createTextNode(this.state.sTitle));
180
180
 
181
- if (!this.state.bHideControls) {
181
+ if (!this.state.bHideControls) {
182
182
 
183
183
  this.sdSectionCollapseControl = this.shadowRoot.querySelector(`#collapse-control`);
184
184
 
@@ -193,25 +193,25 @@ export default class CUI_SECTION extends HTMLElement {
193
193
  }
194
194
 
195
195
  this.sdSectionCollapseControl.addEventListener('click', () => {
196
-
196
+
197
197
  if (!this.bLock) {
198
-
198
+
199
199
  if (this.sdContentsContainer.getAttribute('data-collapsed') === "true") {
200
-
200
+
201
201
  this.sdSectionCollapseControl.classList.remove('collapsed');
202
-
202
+
203
203
  this.expand(this.sdContentsContainer);
204
204
  }
205
205
  else {
206
-
206
+
207
207
  this.sdSectionCollapseControl.classList.add('collapsed');
208
-
208
+
209
209
  this.collapse(this.sdContentsContainer);
210
210
  }
211
-
211
+
212
212
  this.bLock = false;
213
213
  }
214
-
214
+
215
215
  });
216
216
  }
217
217
 
@@ -221,7 +221,7 @@ export default class CUI_SECTION extends HTMLElement {
221
221
 
222
222
  for (let sStyle of this.state.asStyles) {
223
223
 
224
- switch(sStyle.toLowerCase()) {
224
+ switch (sStyle.toLowerCase()) {
225
225
 
226
226
  case "subsection":
227
227
 
@@ -243,10 +243,8 @@ export default class CUI_SECTION extends HTMLElement {
243
243
 
244
244
  }
245
245
 
246
- get messages()
247
- {
248
- if(!this._cMessageList)
249
- {
246
+ get messages() {
247
+ if (!this._cMessageList) {
250
248
  this._cMessageList = document.createElement('cui-message-list');
251
249
  this._cMessageList.slot = "section-messages";
252
250
  this.appendChild(this._cMessageList);
@@ -255,12 +253,30 @@ export default class CUI_SECTION extends HTMLElement {
255
253
  return this._cMessageList;
256
254
  }
257
255
 
258
- reset()
259
- {
260
- if(this._cMessageList)
261
- {
256
+ reset() {
257
+ if (this._cMessageList) {
262
258
  this._cMessageList.reset();
263
259
  }
264
260
  }
265
261
 
262
+ setMessages(aoMessages) {
263
+ for (let i = 0; i < aoMessages.length; i++) {
264
+ if (this.messages) {
265
+ this.messages.add(aoMessages[i]);
266
+ }
267
+ }
268
+ }
269
+
270
+ removeMessages() {
271
+ this.messages.removeAll();
272
+ }
273
+
274
+ removeMessage(id) {
275
+ this.messages.removeMessageWithId(id);
276
+ }
277
+
278
+ removeMessageIndex(index) {
279
+ this.messages.removeMessageAtIndex(index);
280
+ }
281
+
266
282
  }