@progressive-development/pd-forms 0.0.60 → 0.0.61

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/src/PdSelect.js CHANGED
@@ -4,13 +4,12 @@
4
4
  */
5
5
 
6
6
  import { html, css } from 'lit';
7
- import { classMap } from 'lit/directives/class-map.js';
8
- import { SharedInputStyles } from './shared-input-styles.js';
9
-
10
- import { PdBaseUIInput, INPUT_TYPE_SELECT } from './PdBaseUiInput.js';
11
7
 
12
8
  import '@progressive-development/pd-icon/pd-icon.js';
13
9
 
10
+ import { INPUT_TYPE_SELECT } from './PdBaseUiInput.js';
11
+ import { PdBaseInputElement } from './PdBaseInputElement.js';
12
+
14
13
  // https://github.com/Victor-Bernabe/lit-input
15
14
  // https://levelup.gitconnected.com/build-a-material-like-input-web-component-using-litelement-20e9e0d203b6
16
15
  /**
@@ -24,7 +23,7 @@ import '@progressive-development/pd-icon/pd-icon.js';
24
23
  *
25
24
  * Custom property | Description | Default
26
25
  * ----------------|-------------|--------
27
- * `--squi-input-width` | Width | `250px`
26
+ * `--pd-input-field-width` | Width | `250px`
28
27
  * `--my-input-height` | Height | `30px`
29
28
  * `--squi-input-border` | Border | `1px solid black`
30
29
  * `--squi-input-border-focus` | Border when focused | `1px solid #4d90fe`
@@ -49,35 +48,11 @@ import '@progressive-development/pd-icon/pd-icon.js';
49
48
  * <pd-input text-right></pd-input>
50
49
  * <pd-input text-left></pd-input>
51
50
  */
52
- export class PdSelect extends PdBaseUIInput {
53
- /**
54
- * Fired when `squi-input` has focus and the user press `Enter` key.
55
- * @event enter-pressed
56
- */
57
-
58
- /**
59
- * Fired when `squi-input` has focus and the user press any key except `Enter`.
60
- * @event key-pressed
61
- */
62
-
63
- /**
64
- * Fired when value is changed
65
- * @event change-value
66
- */
67
-
68
- /**
69
- * Fire when the `squi-input` loses focus.
70
- * @event focus-lost
71
- */
72
-
73
- /**
74
- * Fire when the icon inside `squi-input` is clicked.
75
- * @event icon-clicked
76
- */
51
+ export class PdSelect extends PdBaseInputElement {
77
52
 
78
53
  static get styles() {
79
54
  return [
80
- SharedInputStyles,
55
+ PdBaseInputElement.styles,
81
56
  css`
82
57
  /* Select style */
83
58
  /* https://css-tricks.com/styling-a-select-like-its-2019/
@@ -88,19 +63,30 @@ export class PdSelect extends PdBaseUIInput {
88
63
  -moz-appearance: none;
89
64
  -webkit-appearance: none;
90
65
  appearance: none;
91
- color: var(--my-input-placeholder-color);
66
+ padding: 5px;
92
67
 
93
- /* Define color */
94
68
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
95
69
  background-repeat: no-repeat, repeat;
96
70
  /* arrow icon position (1em from the right, 50% vertical) , then gradient position*/
97
71
  background-position: right 0.5em top 50%, 0 0;
98
72
  /* icon size, then gradient */
99
73
  background-size: 0.65em auto, 100%;
100
-
101
74
  max-width: 100%; /* useful when width is set to anything other than 100% */
102
75
  }
103
76
 
77
+ /* Hide arrow icon in IE browsers */
78
+ .select-css::-ms-expand {
79
+ display: none;
80
+ }
81
+
82
+ /* Set options to normal weight */
83
+ .select-css option {
84
+ font-weight: normal;
85
+ text-indent: 5px;
86
+ }
87
+
88
+ /* [aria-disabled='true'] */
89
+
104
90
  .gradient {
105
91
  /* Define color */
106
92
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E'),
@@ -112,34 +98,6 @@ export class PdSelect extends PdBaseUIInput {
112
98
  background-color: var(--my-background-color);
113
99
  }
114
100
 
115
- /* Hide arrow icon in IE browsers */
116
- .select-css::-ms-expand {
117
- display: none;
118
- }
119
-
120
- /* Focus style */
121
- .select-css:focus {
122
- border-color: var(--my-border-color-focus);
123
- /* It'd be nice to use -webkit-focus-ring-color here but it doesn't work on box-shadow */
124
-
125
- /* Angaben nach MF DJK Umstellung entfernt
126
- box-shadow: 0 0 1px 3px rgba(59, 153, 252, 0.7);
127
- box-shadow: 0 0 0 3px -moz-mac-focusring;
128
- color: #222;
129
- outline: none;
130
- */
131
- }
132
-
133
- .error .select-css {
134
- background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22graytext%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
135
- /* repeat instructions because of setted background in shared-styles */
136
- background-repeat: no-repeat, repeat;
137
- /* arrow icon position (1em from the right, 50% vertical) , then gradient position*/
138
- background-position: right 0.5em top 50%, 0 0;
139
- /* icon size, then gradient */
140
- background-size: 0.65em auto, 100%;
141
- }
142
-
143
101
  .error .gradient {
144
102
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22graytext%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E'),
145
103
  linear-gradient(
@@ -155,42 +113,12 @@ export class PdSelect extends PdBaseUIInput {
155
113
  background-size: 0.65em auto, 100%;
156
114
  background-color: var(--my-error-background-color);
157
115
  }
158
-
159
- /* Set options to normal weight */
160
- .select-css option {
161
- font-weight: normal;
162
- }
163
-
164
- /* Disabled styles */
165
- .select-css:disabled,
166
- .select-css[aria-disabled='true'] {
167
- background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22graytext%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
168
- /* repeat instructions because of setted background in shared-styles */
169
- background-repeat: no-repeat, repeat;
170
- /* arrow icon position (1em from the right, 50% vertical) , then gradient position*/
171
- background-position: right 0.5em top 50%, 0 0;
172
- /* icon size, then gradient */
173
- background-size: 0.65em auto, 100%;
174
- }
175
-
176
- .gradient:disabled,
177
- .gradient[aria-disabled='true'] {
178
- background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22graytext%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E'),
179
- linear-gradient(to bottom, #ebebeb 0%, #999 100%);
180
- /* repeat instructions because of setted background in shared-styles */
181
- background-repeat: no-repeat, repeat;
182
- /* arrow icon position (1em from the right, 50% vertical) , then gradient position*/
183
- background-position: right 0.5em top 50%, 0 0;
184
- /* icon size, then gradient */
185
- background-size: 0.65em auto, 100%;
186
- }
187
116
  `,
188
117
  ];
189
118
  }
190
119
 
191
120
  static get properties() {
192
121
  return {
193
- icon: { type: String },
194
122
  values: { type: Array },
195
123
  };
196
124
  }
@@ -198,24 +126,22 @@ export class PdSelect extends PdBaseUIInput {
198
126
  constructor() {
199
127
  super();
200
128
  this._inputType = INPUT_TYPE_SELECT;
201
- this.icon = 'toggleCollapse';
202
129
  this.values = [];
203
130
  }
204
131
 
205
132
  render() {
133
+ const selectId = `${this.id}Select`;
206
134
  return html`
207
- <label for="${this.id}Select">${this.label}${this.required && this.label ? this.defaultRequiredChar : ''}</label>
208
- <div class="input ${classMap({ error: this.errorMsg.length > 0 })}">
209
- <pd-icon
210
- icon="toggleCollapse"
211
- @click="${this._onIconClick}"
212
- ></pd-icon>
135
+ ${this._renderLabel(selectId)}
136
+ <div class="input ${this.errorMsg.length > 0 ? 'error' : ''}">
213
137
  <select
214
- id="${this.id}Select"
215
- class="select-css input-style ${this.gradient ? 'gradient' : ''}"
138
+ id="${selectId}"
139
+ class="input-style select-css ${this.gradient ? 'gradient' : ''}"
216
140
  ?disabled="${this.disabled}"
217
- @change="${this._onChange}"
218
- @keyup="${this._onKeyUp}"
141
+ name="${this.autoCompleteName}"
142
+ autocomplete=${this.autoCompleteName}
143
+ @change="${this._onKeyUp}"
144
+ @keyup="${this._onSelectKeyUp}"
219
145
  @blur="${this._onBlur}"
220
146
  >
221
147
  ${this.values.map(
@@ -232,97 +158,17 @@ export class PdSelect extends PdBaseUIInput {
232
158
  `
233
159
  )}
234
160
  </select>
235
- <!-- Sollte erst Clientseitig im Input validiert werden. Meldung verschwindet erst beim Submit nicht mehr zeitgemäß-->
236
- ${this.errorMsg.length > 0
237
- ? html`<span class="error-msg">${this.errorMsg}</span>`
238
- : ''}
239
161
  </div>
162
+ ${this._renderErrorMsg()}
240
163
  `;
241
164
  }
242
165
 
243
- firstUpdated() {
244
- // Save input reference for performance (bind html element to class property)
245
- this._input = this.shadowRoot.querySelector('select');
246
- }
247
-
248
- _onKeyUp(event) {
249
- // set value (tbd überdenken)
250
- this.value = this._input.value;
251
-
252
- // If Enter key pressed, fire 'enter-pressed'
253
- // eslint-disable-next-line eqeqeq
254
- if (event.keyCode == 13) {
255
- this.dispatchEvent(
256
- new CustomEvent('enter-pressed', {
257
- detail: {
258
- value: this._input.value,
259
- },
260
- composed: true,
261
- bubbles: true,
262
- })
263
- );
264
- event.preventDefault();
265
- } else {
266
- // If any other key, fire 'key-pressed'
267
- this.dispatchEvent(
268
- new CustomEvent('key-pressed', {
269
- detail: {
270
- value: this._input.value,
271
- },
272
- composed: true,
273
- bubbles: true,
274
- })
275
- );
276
- }
277
- }
278
-
279
- _onChange() {
280
- this.value = this._input.value;
281
-
282
- this.dispatchEvent(
283
- new CustomEvent('validate-form', {
284
- detail: {
285
- singleElement: this,
286
- errorMap: new Map()
287
- },
288
- composed: true,
289
- bubbles: true,
290
- })
291
- );
292
-
293
- this.dispatchEvent(
294
- new CustomEvent('change-value', {
295
- detail: {
296
- value: this._input.value,
297
- name: this.valueName,
298
- },
299
- composed: true,
300
- bubbles: true,
301
- })
302
- );
303
- }
304
-
305
- _onBlur() {
306
- this.dispatchEvent(
307
- new CustomEvent('focus-lost', {
308
- detail: {
309
- value: this._input.value,
310
- },
311
- composed: true,
312
- bubbles: true,
313
- })
314
- );
166
+ /**
167
+ * At the moment specific for select.
168
+ */
169
+ // eslint-disable-next-line class-methods-use-this
170
+ _onSelectKeyUp() {
171
+ // this._handleChangedValue(this._input.value, event, true);
315
172
  }
316
173
 
317
- _onIconClick() {
318
- this.dispatchEvent(
319
- new CustomEvent('icon-clicked', {
320
- detail: {
321
- value: this._input.value,
322
- },
323
- composed: true,
324
- bubbles: true,
325
- })
326
- );
327
- }
328
174
  }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ */
5
+
6
+ import { css } from 'lit';
7
+
8
+ export const SharedGlobalStyles = css`
9
+
10
+ :host {
11
+
12
+ /* set default fonts for all pd-components.
13
+ * Use content, title and input categories for fonts.
14
+ */
15
+ --pd-default-font-title-family: var(--app-font-title-family, Gidolinya Regular);
16
+ --pd-default-font-content-family: var(--app-font-content-family, Roboto);
17
+ --pd-default-font-input-family: var(--app-font-input-family, Roboto);
18
+
19
+ --pd-default-font-title-col: var(--app-font-title-col, #0A3A48);
20
+ --pd-default-font-content-col: var(--app-font-content-col, #0A3A48);
21
+ --pd-default-font-input-col: var(--app-font-input-col, #0A3A48);
22
+
23
+ --pd-default-font-content-size: var(--app-font-content-size, 1em);
24
+ --pd-default-font-input-size: var(--app-font-input-size, 1em);
25
+
26
+ /* set default colors for all pd-components */
27
+ --pd-default-color: var(--app-primary-col, #067394);
28
+ --pd-default-primary-color: var(--app-primary-element-col, #0A3A48);
29
+ --pd-default-secondary-color: var(--app-secondary-element-col, #AFC1D2);
30
+ --pd-default-third-color: var(--app-third-element-col, #353738);
31
+ --pd-default-bg-color: var(--app-primary-col, #fefefe);
32
+ --pd-default-hover-color: var(--app-hover-col, #E1E03D);
33
+ --pd-default-error-color: #cc2029;
34
+ --pd-default-disabled-color: #7a7777;
35
+ --pd-default-success-color: #42a01c;
36
+ }
37
+
38
+ `;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ */
5
+
6
+ import { css } from 'lit';
7
+
8
+ /**
9
+ * Shared styles for pd-input, pd-input-area and pd-select.
10
+ */
11
+ export const SharedInputFieldStyles = css`
12
+
13
+ /* Describe input div (with icon) around input/select/area element */
14
+ .input {
15
+ display: inline-block;
16
+ /*position: relative; Prüfen: Wenn das an ist, felder über scroll-menu?*/
17
+ /* pd-icon smaller than input
18
+ --pd-icon-computed-size: calc(var(--my-input-height) * 0.75); /* calc */
19
+
20
+ /* Hack um eine Form Row (input mit Button => Booking) zu bekommen*/
21
+ /*padding-top: var(--squi-input-padding, 0.5rem); */
22
+ }
23
+
24
+ /* check,not work at the moment => in any case left aligned */
25
+ :host([text-right]) > input {
26
+ text-align: right;
27
+ }
28
+ :host([text-left]) > input {
29
+ text-align: left;
30
+ }
31
+
32
+ /*
33
+ * Class input style used for input, select and text-area element.
34
+ * Not use iput here => because of own select css... => Nachtrag: Aber ein paar allgemeine Angaben rausziehen
35
+ */
36
+ .input-style {
37
+ width: var(--pd-input-field-width, 250px);
38
+ /* padding: var(--squi-input-padding, 0.5rem); */
39
+ background-color: var(--pd-input-field-bg-col, var(--pd-default-bg-color));
40
+ /*opacity: 80%;*/
41
+ color: var(--pd-input-field-font-col, var(--pd-default-font-input-col));
42
+ /*font-size: var(--squi-input-font-size, calc(var(--squi-input-height) / 1.8));*/
43
+ font-size: var(--pd-default-font-input-size);
44
+ font-family: var(--pd-default-font-input-family);
45
+
46
+ border: var(--pd-input-field-border, 1px solid var(--pd-default-secondary-color));
47
+ box-shadow: inset 0 1px 2px rgba(50, 48, 49, 0.1);
48
+ border-bottom: var(--pd-input-field-border-bottom,
49
+ 2px solid var(--pd-default-color));
50
+ border-radius: var(--pd-border-radius, 0);
51
+ }
52
+
53
+ /* Hover for input, area, select */
54
+ .input-style:hover {
55
+ border-color: var(--pd-input-field-border-col-hover, var(--pd-default-hover-color));
56
+ }
57
+
58
+ /* Fokus for input, area => select with own css.? */
59
+ .input-style:focus {
60
+ border: var(--pd-input-field-border-focus, 2px solid var(--pd-default-color));
61
+ outline: 0;
62
+ }
63
+
64
+ /* Höhe soll nicht für Text Area gelten, daher ausgelagert (überschreibt sonst rows) */
65
+ input.input-style,
66
+ select.input-style {
67
+ height: var(--pd-input-field-height, 2.2rem);
68
+ }
69
+
70
+ /* Disabled for input, area => select with own css.? */
71
+ .input-style[disabled] {
72
+ opacity: 0.5;
73
+ cursor: auto;
74
+ background-color: var(--pd-input-field-bg-col-disabled, #e9e9e9);
75
+ border-bottom: var(--pd-input-field-border-bottom-disabled,
76
+ 2px solid var(--pd-default-disabled-color));
77
+ }
78
+
79
+ .input-style[readonly]:hover,
80
+ .input-style[disabled]:hover {
81
+ border-color: var(--pd-default-disabled-color);
82
+ }
83
+
84
+ /* Disabled for input, area => select with own css.? */
85
+ .input-style[readonly] {
86
+ border-bottom: var(--pd-input-field-border-bottom-disabled,
87
+ 2px solid var(--pd-default-disabled-color));
88
+ }
89
+
90
+ /* error element style for input, area => select has own css.? */
91
+ .error .input-style {
92
+ border: 1px solid var(--pd-default-error-color);
93
+ color: var(--pd-default-error-color);
94
+ background-color: var(--pd-error-bg-col, #ffe8e8);
95
+ }
96
+
97
+ /* Error Focus for input, area, select */
98
+ .error .input-style:focus {
99
+ border: 2px solid var(--pd-default-error-color);
100
+ }
101
+
102
+ /* Placeholder color for input and input-area */
103
+ ::placeholder {
104
+ color: var(--pd-input-placeholder-color, #474747e4);
105
+ }
106
+ :-ms-input-placeholder {
107
+ color: var(--pd-input-placeholder-color, #474747e4);
108
+ }
109
+ ::-ms-input-placeholder {
110
+ color: var(--pd-input-placeholder-color, #474747e4);
111
+ }
112
+
113
+ /**
114
+ * Folgender Part noch nicht in benutzug, einbau wenn Icon integriert wird */
115
+
116
+ /* squi icon depends on input styles to fit inside */
117
+ pd-icon {
118
+ display: none;
119
+ position: absolute;
120
+ --pd-icon-height: var(--pd-icon-computed-size, 2rem);
121
+ --pd-icon-width: var(--pd-icon-computed-size, 2rem);
122
+ --pd-icon-fill-color: var(--squi-input-icon-fill-color, currentcolor);
123
+ --pd-icon-stroke-color: var(--squi-input-icon-stroke-color, none);
124
+ }
125
+ pd-icon:hover {
126
+ cursor: pointer;
127
+ }
128
+ /* Display icon if it's positioned */
129
+ :host([icon-right]) .input pd-icon {
130
+ display: inline-block;
131
+ right: 0;
132
+ }
133
+ :host([icon-left]) .input pd-icon {
134
+ display: inline-block;
135
+ left: 0;
136
+ }
137
+
138
+ /* Padding space for pd-icon => Noch input spezifisch? */
139
+ :host([icon-right]) > input {
140
+ padding-right: var(--my-input-height);
141
+ }
142
+ :host([icon-left]) > input {
143
+ padding-left: var(--my-input-height);
144
+ }
145
+
146
+
147
+ `;