@progressive-development/pd-forms 0.1.14 → 0.1.15

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
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent pd-forms following open-wc recommendations",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.1.14",
6
+ "version": "0.1.15",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -205,7 +205,7 @@ import { SharedInputStyles } from './shared-input-styles.js';
205
205
 
206
206
  _renderLabel(forParam, additionalValue) {
207
207
  return html`
208
- <label for="${forParam}">${this.label}${this.required && this.label ? this.defaultRequiredChar : ''}${additionalValue ? ` - ${additionalValue}` : ''}</label>
208
+ <label for="${forParam}">${this.label}${this.required && this.label ? this.defaultRequiredChar : ''}${additionalValue ? html` - <b>${additionalValue}</b>` : ''}</label>
209
209
  `;
210
210
  }
211
211
 
@@ -12,6 +12,8 @@
12
12
  import { html, css } from 'lit';
13
13
  import { msg } from '@lit/localize';
14
14
 
15
+ import { INPUT_TYPE_RANGE } from './PdBaseUiInput.js';
16
+
15
17
  import { PdBaseUI } from './PdBaseUi.js';
16
18
 
17
19
  /**
@@ -102,7 +104,10 @@ export class PdFormContainer extends PdBaseUI {
102
104
  reqEl.forEach(el => {
103
105
  const tmpEl = el;
104
106
 
105
- if (!el.value || el.value === "" || el.value === "false") {
107
+ console.log("Check EL: ", el._inputType, el.value);
108
+
109
+ if (!el.value || el.value === "" || el.value === "false" ||
110
+ (el._inputType === INPUT_TYPE_RANGE && el.value === '0')) {
106
111
  const erMsg = el.requiredMsg || msg('Eingabe erforderlich',{desc: '#pd.form.field.required#'});
107
112
  if (!e.detail.singleElement || e.detail.singleElement === el) {
108
113
  tmpEl.errorMsg = erMsg;
package/src/PdRange.js CHANGED
@@ -15,13 +15,15 @@ export class PdRange extends PdBaseUIInput {
15
15
  min: { type: String },
16
16
  max: { type: String },
17
17
  step: { type: Number},
18
+ optionValueMapper: { type: Object },
18
19
  };
19
20
  }
20
21
 
21
22
  constructor() {
22
23
  super();
23
24
  this._inputType = INPUT_TYPE_RANGE;
24
- this.step = 0.1;
25
+ this.step = 1;
26
+ this.optionValueMapper = {};
25
27
  }
26
28
 
27
29
  static get styles() {
@@ -30,9 +32,10 @@ export class PdRange extends PdBaseUIInput {
30
32
  css`
31
33
 
32
34
  /* Link:
33
- * css styling: - https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
34
- * no-empty-default - https://stackoverflow.com/questions/40302515/is-there-a-way-to-set-default-value-of-range-input-to-be-empty
35
- * => Könnte ich vlt. mit dummy element lösen => Kein Wert => Dummy wird angezeigt => Bei Klick wird Wert gesetzt und PdRange angezeigt.
35
+ * css styling: - https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
36
+ * no-empty-default - https://stackoverflow.com/questions/40302515/is-there-a-way-to-set-default-value-of-range-input-to-be-empty
37
+ * => Könnte ich vlt. mit dummy element lösen => Kein Wert => Dummy wird angezeigt => Bei Klick wird Wert gesetzt und PdRange angezeigt. Oder doch Vorschlag aus StackOverflow => -1 als default Wert => Kein gesetzer Wert
38
+ * Style Ticks/Lables: - https://stackoverflow.com/questions/26612700/ticks-for-type-range-html-input
36
39
  */
37
40
 
38
41
  /****************************************************
@@ -48,6 +51,8 @@ export class PdRange extends PdBaseUIInput {
48
51
  padding: 0.5rem;
49
52
  height: var(--pd-input-field-height, 2.2rem);
50
53
  box-sizing: border-box;
54
+
55
+ border-radius: 0.75rem;
51
56
  }
52
57
 
53
58
  input[type=range]:focus {
@@ -127,9 +132,10 @@ export class PdRange extends PdBaseUIInput {
127
132
  height: 8.4px;
128
133
  cursor: pointer;
129
134
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
130
- background: var(--pd-range-track-col, var(--pd-default-light-col));
131
- border-radius: 1.3px;
135
+ background: var(--pd-range-track-col, var(--pd-default-light-col));
132
136
  border: 0.2px solid #010101;
137
+
138
+ border-radius: 0.75rem;
133
139
  }
134
140
 
135
141
  input[type=range]:focus::-webkit-slider-runnable-track {
@@ -146,7 +152,7 @@ export class PdRange extends PdBaseUIInput {
146
152
  cursor: pointer;
147
153
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
148
154
  background: var(--pd-range-track-col, var(--pd-default-light-col));
149
- border-radius: 1.3px;
155
+ border-radius: 0.75rem;
150
156
  border: 0.2px solid #010101;
151
157
  }
152
158
 
@@ -169,8 +175,8 @@ export class PdRange extends PdBaseUIInput {
169
175
  }
170
176
  input[type=range]::-ms-fill-lower {
171
177
  background: var(--pd-range-track-col, var(--pd-default-light-col));
172
- border: 0.2px solid #010101;
173
- border-radius: 2.6px;
178
+ border: 0.2px solid #010101;
179
+ border-radius: 0.75rem;
174
180
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
175
181
  }
176
182
  input[type=range]:focus::-ms-fill-lower {
@@ -179,7 +185,7 @@ export class PdRange extends PdBaseUIInput {
179
185
  input[type=range]::-ms-fill-upper {
180
186
  background: var(--pd-range-track-col, var(--pd-default-light-col));
181
187
  border: 0.2px solid #010101;
182
- border-radius: 2.6px;
188
+ border-radius: 0.75rem;
183
189
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
184
190
  }
185
191
  input[type=range]:focus::-ms-fill-upper {
@@ -193,16 +199,18 @@ export class PdRange extends PdBaseUIInput {
193
199
  const inputId = `${this.id}Range`;
194
200
  // TODO: step kann hier nicht übergeben werden, wird dann initial nicht immer richtig angezeigt (bei komma rundungen)???
195
201
  return html`
196
- ${this._renderLabel(inputId, this.value)}
197
- <div class="input ${classMap({ error: this.errorMsg.length > 0 })}">
202
+ ${this._renderLabel(inputId, this.optionValueMapper[this.value] || this.value)}
203
+ <div class="input-range ${classMap({ error: this.errorMsg.length > 0 })}">
198
204
  <input
199
205
  id="${inputId}"
200
- ?disabled=${this.disabled}
201
- type="range"
202
206
  name="${this.name || this.valueName}"
203
- @change="${this._onChange}"
204
- min="${this.min}" max="${this.max}" step="${this.step}"
205
- .value="${this.value}"
207
+ class="input-range-style ${this.gradient ? 'gradient' : ''}"
208
+ type="range"
209
+ .value="${this.value}"
210
+ ?readonly="${this.readonly}"
211
+ ?disabled="${this.disabled}"
212
+ min="0" max="${this.max}" step="1"
213
+ @change="${this._onChange}"
206
214
  />
207
215
  </div>
208
216
  ${this._renderErrorMsg()}
@@ -214,15 +222,8 @@ export class PdRange extends PdBaseUIInput {
214
222
  this._input = this.shadowRoot.querySelector('input');
215
223
  }
216
224
 
217
- _onChange() {
218
- this.value = this._input.value;
219
- this.dispatchEvent(new CustomEvent('changed', {
220
- detail: {
221
- value: this._input.value
222
- },
223
- composed: true,
224
- bubbles: true
225
- }));
225
+ _onChange(e) {
226
+ this._handleChangedValue(this._input.value, e, false);
226
227
  }
227
228
 
228
229
  }
@@ -2,6 +2,7 @@ import { html } from 'lit';
2
2
  import '../pd-form-container.js';
3
3
  import '../pd-form-row.js';
4
4
  import '../pd-input.js';
5
+ import '../pd-range.js';
5
6
 
6
7
  export default {
7
8
  title: 'PdForms/Form Container',
@@ -9,6 +10,14 @@ export default {
9
10
  argTypes: {},
10
11
  };
11
12
 
13
+ const OPTIONS_GENRE = {
14
+ 0: "Keine Auswahl",
15
+ 1: "No-Go",
16
+ 2: "Wenig",
17
+ 3: "Mittel",
18
+ 4: "Viel",
19
+ };
20
+
12
21
  function Template() {
13
22
  return html`
14
23
  <h3>Mit Forms</h3>
@@ -55,7 +64,14 @@ function Template() {
55
64
  <pd-input-area class="quarter2-area" id="test17Id" label="Label Area" required></pd-input-area>
56
65
  <pd-input-area class="quarter2-area" id="test18Id" label="Label Area" required
57
66
  requiredMsg="Das ist eine richtig lange Fehlermeldung. Diese kann per Parameter für spezielle Felder wie die AGB Checkbox gesetzt werden."></pd-input-area>
58
- </pd-form-row>
67
+ </pd-form-row>
68
+ <pd-form-row>
69
+ <pd-range id="testRangeId"
70
+ label="Range Label"
71
+ max="12"
72
+ value="0" .optionValueMapper="${OPTIONS_GENRE}" required>
73
+ </pd-range>
74
+ </pd-form-row>
59
75
  </pd-form-container>
60
76
 
61
77
  <h2>Test Validation</h2>
@@ -1,5 +1,7 @@
1
1
  import { html } from 'lit';
2
2
  import '../pd-range.js';
3
+ import '../pd-form-container.js';
4
+ import '../pd-form-row.js';
3
5
 
4
6
  export default {
5
7
  title: 'PdForms/Range',
@@ -17,15 +19,41 @@ export default {
17
19
  },
18
20
  };
19
21
 
22
+ const OPTIONS_GENRE = {
23
+ 0: "Keine Auswahl",
24
+ 1: "No-Go",
25
+ 2: "Wenig",
26
+ 3: "Mittel",
27
+ 4: "Viel",
28
+ };
29
+
30
+
20
31
  function Template() {
21
32
  return html`
22
33
  <h3>Default Input Range</h3>
23
- <pd-range id="testRangeId"
24
- label="Range Label"
25
- min="1" max="12" step="1"
26
- defaultValue="6"
27
- showLegend>
28
- </pd-range>
34
+ <pd-form-container id="testFormContainerId" requiredFieldInfo>
35
+ <pd-form-row>
36
+ <pd-range id="range5060Id"
37
+ class="quarter4"
38
+ label="50er/60er"
39
+ required
40
+ max="4"
41
+ value="0"
42
+ .optionValueMapper="${OPTIONS_GENRE}">
43
+ </pd-range>
44
+ </pd-form-row>
45
+ </pd-form-container>
46
+
47
+ <h2>Test Validation</h2>
48
+ <button
49
+ @click="${() => {
50
+ document.getElementById('testFormContainerId').dispatchEvent(
51
+ new CustomEvent("validate-form", {detail: {errorMap: new Map()}})
52
+ );
53
+ }}"
54
+ >
55
+ Test Validate
56
+ </button>
29
57
  `;
30
58
  }
31
59