@dile/ui 2.20.1 → 2.21.1

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.
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import { DileEmmitChange } from '../../../mixins/form/index.js';
3
3
  import '../radio.js';
4
+ import '../input/input-message.js';
4
5
 
5
6
  export class DileRadioGroup extends DileEmmitChange(LitElement) {
6
7
  static styles = [
@@ -31,6 +32,9 @@ export class DileRadioGroup extends DileEmmitChange(LitElement) {
31
32
  label: { type: String },
32
33
  value: { type: String },
33
34
  name: { type: String },
35
+ message: { type: String },
36
+ errored: { type: Boolean },
37
+ hideErrorOnInput: { type: Boolean },
34
38
  disabled: {
35
39
  type: Boolean,
36
40
  reflect: true
@@ -43,6 +47,7 @@ export class DileRadioGroup extends DileEmmitChange(LitElement) {
43
47
  this.init = false;
44
48
  this.disabled = false;
45
49
  this.internals = this.attachInternals();
50
+ this.message = '';
46
51
  }
47
52
 
48
53
  updated(changedProperties) {
@@ -72,11 +77,19 @@ export class DileRadioGroup extends DileEmmitChange(LitElement) {
72
77
  }
73
78
  <slot></slot>
74
79
  </div>
80
+ ${this.message
81
+ ? html`<dile-input-message message="${this.message}" ?errored=${this.errored}></dile-input-message>`
82
+ : ''
83
+ }
75
84
  `;
76
85
  }
77
86
 
78
87
  changeValue(e) {
79
88
  if(!this.disabled) {
89
+ if(this.hideErrorOnInput && this.errored) {
90
+ this.message = '';
91
+ this.errored = false;
92
+ }
80
93
  this.value = e.detail.value;
81
94
  }
82
95
  }
@@ -44,32 +44,33 @@ export const DileForm = (superclass) => class extends superclass {
44
44
  data[fieldName] = node.value;
45
45
  }
46
46
  });
47
- return data;
47
+ return this.adaptDataOut(data);
48
48
  }
49
49
 
50
50
  setData(data) {
51
+ const adaptedData = this.adaptDataIn(data);
51
52
  this.allNodeElements.forEach(node => {
52
53
  const name = node.getAttribute('name');
53
54
  const isArray = name.endsWith('[]');
54
55
  const fieldName = isArray ? name.slice(0, -2) : name;
55
56
 
56
- if (isArray && Array.isArray(data[fieldName])) {
57
+ if (isArray && Array.isArray(adaptedData[fieldName])) {
57
58
  // with arrays, the index is the element order in the DOM
58
59
  const arrayElements = Array.from(this.allNodeElements).filter(el => el.getAttribute('name') === name);
59
60
  const elementIndex = arrayElements.indexOf(node);
60
- if (elementIndex >= 0 && elementIndex < data[fieldName].length) {
61
- const value = data[fieldName][elementIndex];
61
+ if (elementIndex >= 0 && elementIndex < adaptedData[fieldName].length) {
62
+ const value = adaptedData[fieldName][elementIndex];
62
63
  if (typeof node.set === "function") {
63
64
  node.set(value);
64
65
  } else {
65
66
  node.value = value;
66
67
  }
67
68
  }
68
- } else if (!isArray && data[fieldName] !== undefined && data[fieldName] !== null) {
69
+ } else if (!isArray && adaptedData[fieldName] !== undefined && adaptedData[fieldName] !== null) {
69
70
  if (typeof node.set === "function") {
70
- node.set(data[fieldName]);
71
+ node.set(adaptedData[fieldName]);
71
72
  } else {
72
- node.value = data[fieldName];
73
+ node.value = adaptedData[fieldName];
73
74
  }
74
75
  }
75
76
  });
@@ -196,4 +197,24 @@ export const DileForm = (superclass) => class extends superclass {
196
197
  return false;
197
198
  }
198
199
 
200
+ /**
201
+ * Template method: Adapt data before it's returned from getData()
202
+ * Override this method in your component to transform the structure of outgoing data
203
+ * @param {Object} data - The data object from form fields
204
+ * @returns {Object} - The adapted data object
205
+ */
206
+ adaptDataOut(data) {
207
+ return data;
208
+ }
209
+
210
+ /**
211
+ * Template method: Adapt data before it's set to form fields in setData()
212
+ * Override this method in your component to transform the structure of incoming data
213
+ * @param {Object} data - The data object to be set
214
+ * @returns {Object} - The adapted data object
215
+ */
216
+ adaptDataIn(data) {
217
+ return data;
218
+ }
219
+
199
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/ui",
3
- "version": "2.20.1",
3
+ "version": "2.21.1",
4
4
  "description": "UI Core components from dile-components.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "7194ae653716358e673eb70383662cfb86247260"
29
+ "gitHead": "e9639442e17f7bd3e467a1177dc233bb9913dc1e"
30
30
  }
package/styles/colors.css CHANGED
@@ -20,7 +20,7 @@
20
20
  --dile-link-color: #3399ff;
21
21
 
22
22
  /* Color variations */
23
- --dile-primary-light-color: #fbfbe9;
23
+ --dile-primary-light-color: #fafadf;
24
24
  --dile-on-primary-light-color: #303030;
25
25
  --dile-primary-dark-color: #d7d353;
26
26
  --dile-on-primary-dark-color: #303030;