@progressive-development/pd-forms 0.0.60 → 0.1.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.
@@ -0,0 +1,4 @@
1
+ <link rel="preconnect" href="https://fonts.gstatic.com">
2
+ <link href="https://family=Roboto:wght@300;400&display=swap" rel="stylesheet">
3
+ <link href="https://webfonts.ffonts.net/Gidolinya-Regular.font" rel="stylesheet">
4
+
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.0.60",
6
+ "version": "0.1.1",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@lit-labs/motion": "^1.0.2",
23
23
  "@lit/localize": "^0.11.2",
24
- "@progressive-development/pd-icon": "^0.0.9",
24
+ "@progressive-development/pd-icon": "^0.1.6",
25
25
  "lit": "^2.2.0"
26
26
  },
27
27
  "devDependencies": {
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ *
5
+ * Abstract base lit class for pd-input elements.
6
+ *
7
+ * Used from:
8
+ * - pd-input
9
+ * - pd-input-area
10
+ * - pd-select
11
+ *
12
+ * Used to:
13
+ * - define element specific css
14
+ * - handle auto completion
15
+ *
16
+ * Events:
17
+ * - TODO
18
+ *
19
+ * Custom Properties (shared-input-field-styles):
20
+ * ... TODO
21
+ *
22
+ */
23
+ import {
24
+ PdBaseUIInput,
25
+ INPUT_TYPE_AREA,
26
+ INPUT_TYPE_SELECT,
27
+ INPUT_TYPE_TEXT,
28
+ } from './PdBaseUiInput.js';
29
+
30
+ import { SharedInputFieldStyles } from './shared-input-field-styles.js';
31
+
32
+ export class PdBaseInputElement extends PdBaseUIInput {
33
+
34
+ /**
35
+ * Fire when the `pd-input` loses focus.
36
+ * @event focus-lost
37
+ */
38
+
39
+ static get styles() {
40
+ return [PdBaseUIInput.styles, SharedInputFieldStyles];
41
+ }
42
+
43
+ static get properties() {
44
+ return {
45
+ placeHolder: { type: String },
46
+ /* not used at the moment */
47
+ name: { type: String },
48
+ autoCompleteName: { type: String },
49
+ };
50
+ }
51
+
52
+ constructor() {
53
+ super();
54
+ this.placeHolder = '';
55
+ this.name = '';
56
+ this._input = {};
57
+ }
58
+
59
+ firstUpdated() {
60
+ // Save input reference for performance (bind html element to class property)
61
+ this._input = this.shadowRoot.querySelector(this._getElementName());
62
+ }
63
+
64
+ _onBlur() {
65
+ this.dispatchEvent(
66
+ new CustomEvent('focus-lost', {
67
+ detail: {
68
+ value: this._input.value,
69
+ },
70
+ composed: true,
71
+ bubbles: true,
72
+ })
73
+ );
74
+ }
75
+
76
+ _onKeyUp(event) {
77
+ // set changed value and generate events (key-pressed, enter-pressed, validateForm)
78
+ // if neccessary
79
+ this._handleChangedValue(this._input.value, event, true);
80
+ }
81
+
82
+ _getElementName() {
83
+ switch (this._inputType) {
84
+ case INPUT_TYPE_AREA:
85
+ return 'textarea';
86
+ case INPUT_TYPE_SELECT:
87
+ return 'select';
88
+ case INPUT_TYPE_TEXT:
89
+ return 'input';
90
+ default:
91
+ return '';
92
+ }
93
+ }
94
+ }
package/src/PdBaseUi.js CHANGED
@@ -1,16 +1,35 @@
1
1
  /**
2
2
  * @license
3
3
  * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ *
5
+ * Abstract base lit class for all pd-form elements.
6
+ * Import shared-global-style to make common custom properties available to all components.
7
+ *
8
+ * Used from:
9
+ * - pd-base-ui-input
10
+ *
11
+ * Used to:
12
+ * - define css (import shared-global-styles.js)
13
+ * - define common properties (detailieren, aktuell keine)
14
+ * - define updateWhenLocaleChanges for all pd-elements (check, aktuell nur für pd-form-container benötigt)
15
+ *
16
+ * Custom Properties (shared-global-styles):
17
+ * ... TODO
4
18
  */
5
-
19
+
6
20
  import { LitElement } from 'lit';
7
21
  import { updateWhenLocaleChanges } from '@lit/localize';
8
22
 
23
+ import { SharedGlobalStyles } from './shared-global-styles.js';
24
+
9
25
  export class PdBaseUI extends LitElement {
10
26
 
11
- constructor() {
12
- super();
13
- updateWhenLocaleChanges(this);
27
+ static get styles() {
28
+ return [SharedGlobalStyles];
14
29
  }
15
30
 
31
+ constructor() {
32
+ super();
33
+ updateWhenLocaleChanges(this);
34
+ }
16
35
  }
@@ -1,18 +1,83 @@
1
1
  /**
2
2
  * @license
3
3
  * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ *
5
+ * Abstract base lit class for pd-input elements.
6
+ *
7
+ * Used from:
8
+ * - pd-checkbox
9
+ * - pd-input
10
+ * - pd-input-area
11
+ * - pd-radio-group
12
+ * - pd-range
13
+ * - pd-select
14
+ *
15
+ * Used to:
16
+ * - define css (import additional shared-input-styles.js)
17
+ * - define common properties (detailieren, aktuell zu viele bzw. nicht für alle sub-elemente gültig)
18
+ * - handle error msg (getter/setter)
19
+ * - helpers for validation event after change and render label/error elements.
20
+ *
21
+ * Events:
22
+ * - validate-form => fired when input element changed its value.
23
+ * - enter-pressed => fired when enter pressed.
24
+ * - field-change => fired when input element changed its value.
25
+ *
26
+ * Custom Properties (shared-input-styles):
27
+ * ... TODO
28
+ *
4
29
  */
5
-
30
+ import { html } from 'lit';
6
31
  import { PdBaseUI } from './PdBaseUi.js';
7
32
 
33
+ import { SharedInputStyles } from './shared-input-styles.js';
34
+
35
+ /**
36
+ * Available input types.
37
+ * Each input elemt set it's own type during constructor call.
38
+ *
39
+ * Comment: Not really needed/used at the moment.
40
+ */
8
41
  export const INPUT_TYPE_TEXT = 1;
9
42
  export const INPUT_TYPE_SELECT = 2;
10
43
  export const INPUT_TYPE_CHECK = 3;
11
44
  export const INPUT_TYPE_RANGE = 4;
12
45
  export const INPUT_TYPE_AREA = 5;
46
+ export const INPUT_TYPE_CHECK_GROUP = 6;
13
47
 
48
+ /**
49
+ * Specific key codes for input events.
50
+ */
51
+ const KEY_RETURN = 13;
52
+
53
+ // timer is used to delay validation event on user typing
54
+ let delayTimer = 0;
55
+ const DELAY_WAIT_TIME_MS = 400;
56
+
14
57
  export class PdBaseUIInput extends PdBaseUI {
15
-
58
+
59
+ /**
60
+ * Fired when an input element change its values.
61
+ * @event validate-form
62
+ */
63
+
64
+ /**
65
+ * Fired when enter was pressend during focus on input element.
66
+ * @event enter-pressed
67
+ */
68
+
69
+ /**
70
+ * Fired when field-value changed.
71
+ * @event field-change
72
+ */
73
+
74
+ static get styles() {
75
+ return [
76
+ PdBaseUI.styles,
77
+ SharedInputStyles
78
+ ];
79
+ }
80
+
16
81
  static get properties() {
17
82
  return {
18
83
  gradient: { type: Boolean }, // true for gradient background
@@ -26,8 +91,7 @@
26
91
  label: { type: String }, // label text for input
27
92
  value: {type: String}, // current value (set from outside) TODO: Typ (Object, Number, Txt, Bool...)
28
93
  _errorMsg: {type: String, state: true}, // errorMsg (could set fronm outside for busines validation, internal validation=> todo)
29
- _inputType: {type: Number}, // number value for type (text, select, range....), set constructor of sub-class
30
- _input: { type: Object } // reference for input html element
94
+ _inputType: {type: Number, state: true}, // number value for type (text, select, range....), set constructor of sub-class
31
95
  };
32
96
  }
33
97
 
@@ -41,7 +105,6 @@
41
105
  this.value = '';
42
106
  this._errorMsg = '';
43
107
  this._inputType = -1;
44
- this._input = {};
45
108
  this.valueName = '';
46
109
 
47
110
  this.defaultRequiredChar = '*';
@@ -50,13 +113,13 @@
50
113
  // Test: Clear input with value => Dann in BasisKlasse und alle leiten von Basis UI Element ab
51
114
  clear() {
52
115
  this.value = '';
53
- this._input.value = this.value;
116
+ // this._input.value = this.value;
54
117
  }
55
118
 
56
119
  // Test: Reset input with value
57
120
  reset() {
58
121
  this.value = this.defaultValue || '';
59
- this._input.value = this.value;
122
+ // this._input.value = this.value;
60
123
  }
61
124
 
62
125
  get errorMsg() {
@@ -79,5 +142,71 @@
79
142
  console.info("Meine Werte nach Set: ", this._value, this._input.value, newValue);
80
143
  }
81
144
  */
145
+
146
+ _generateValidateEvent () {
147
+ this.dispatchEvent(
148
+ new CustomEvent('validate-form', {
149
+ detail: {
150
+ singleElement: this,
151
+ errorMap: new Map()
152
+ },
153
+ composed: true,
154
+ bubbles: true,
155
+ })
156
+ );
157
+ }
158
+
159
+ _handleChangedValue(newValue, event, checkReturn) {
160
+ const changed = this.value !== newValue;
161
+
162
+ this.value = newValue;
163
+ const keyCode = event.keyCode ? Number(event.keyCode) : -1;
164
+ const eventDetail = {
165
+ value: newValue,
166
+ name: this.valueName,
167
+ keyCode, changed
168
+ }
169
+ const handleReturn = checkReturn && keyCode === KEY_RETURN;
170
+ if (handleReturn) {
171
+ this.dispatchEvent(
172
+ new CustomEvent('enter-pressed', {
173
+ detail: eventDetail,
174
+ composed: true,
175
+ bubbles: true,
176
+ })
177
+ );
178
+ event.preventDefault();
179
+
180
+ }
181
+
182
+ if (changed) {
183
+ // generate changed event
184
+ this.dispatchEvent(
185
+ new CustomEvent('field-change', {
186
+ detail: eventDetail,
187
+ composed: true,
188
+ bubbles: true,
189
+ })
190
+ );
191
+ // generate validation event after delay
192
+ clearTimeout(delayTimer);
193
+ delayTimer = setTimeout(this._generateValidateEvent.bind(this),
194
+ DELAY_WAIT_TIME_MS);
195
+ }
196
+ }
197
+
198
+ _renderErrorMsg() {
199
+ return this.errorMsg && this.errorMsg.length > 0 ? html`
200
+ <div class="error-box error">
201
+ <p class="error-msg">${this.errorMsg}</p>
202
+ </div>
203
+ ` : '';
204
+ }
205
+
206
+ _renderLabel(forParam) {
207
+ return html`
208
+ <label for="${forParam}">${this.label}${this.required && this.label ? this.defaultRequiredChar : ''}</label>
209
+ `;
210
+ }
211
+
82
212
  }
83
-
package/src/PdButton.js CHANGED
@@ -1,115 +1,102 @@
1
+ /* eslint-disable lit-a11y/anchor-is-valid */
1
2
  /**
2
3
  * @license
3
4
  * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
5
  */
5
6
 
6
- import { html, css , LitElement } from 'lit';
7
+ import { html, css } from 'lit';
8
+ import { PdBaseUI } from './PdBaseUi.js';
7
9
 
8
- import { SharedInputStyles } from './shared-input-styles.js';
10
+ export class PdButton extends PdBaseUI {
9
11
 
10
- export class PdButton extends LitElement {
12
+ /**
13
+ * @event button-clicked
14
+ */
11
15
 
12
16
  static get styles() {
13
- return [
14
- // Import Shared Styles for defined styles vars
15
- SharedInputStyles,
16
- css`
17
-
17
+ return [
18
+ PdBaseUI.styles,
19
+ css`
18
20
  :host {
19
- --my-primary-color: var(--squi-primary-color, #177E89);
20
- --my-button-background-color: var(--squi-button-background-color, #ffc857);
21
- --my-button-background-hover-color: var(--squi-button-background-color, #ffb724);
22
- --my-button-text-color: var(--squi-button-text-color, #084c61);
23
- --my-button-font-family: var(--squi-primary-font-family, Oswald);
24
21
 
25
- --my-button-width: var(--squi-input-width, 140px);
22
+ display: flex;
23
+ justify-content: center;
24
+
25
+ width: var(--pd-button-width, 140px);
26
+ height: var(--pd-button-height, 2rem);
27
+
28
+
29
+ border-radius: var(--pd-border-radius, 1px);
30
+
31
+ background-color: var(--pd-button-bg-col, var(--pd-default-dark-col));
32
+ color: var(--pd-button-font-col, var(--pd-default-bg-color));
33
+
34
+ font-family: var(--pd-default-font-title-family);
35
+ font-size: var(--pd-button-font-size, var(--pd-default-font-content-size));
36
+ font-weight: var(--pd-button-font-weight, normal);
37
+
38
+ cursor: pointer;
39
+
40
+ box-shadow: var(--pd-button-box-shadow, -1px 1px 2px var(--pd-default-dark-col));
41
+
42
+ margin: 0.5rem;
26
43
 
27
- display: block;
28
44
  /*
29
45
  height: 100%;
30
46
  width: 100%; => Ohne diese Angabe eht die % Angaben icht
31
47
  */
32
48
  }
33
-
49
+
50
+ :host(:not([disabled]):hover) {
51
+ background-color: var(--pd-button-bg-col-hover, var(--pd-default-hover-col));
52
+ color: var(--pd-button-font-col-hover, var(--pd-default-dark-col));
53
+ transition: background-color 0.4s ease 0s;
54
+ }
55
+
56
+ :host([primary]) {
57
+ background-color: var(--pd-button-primary-bg-col, var(--pd-default-col));
58
+ color: var(--pd-button-primary-font-col, var(--pd-default-bg-color));
59
+ }
60
+
61
+ :host([gradient]) {
62
+ background: linear-gradient(to right, var(--my-background-gradient-color, red) 0%, var(--my-background-color, blue) 100%);
63
+ }
64
+
65
+ :host([disabled]) {
66
+ cursor: auto;
67
+ border-color: var(--pd-default-disabled-col);
68
+ background-color: var(--pd-button-bg-col-disabled, var(--pd-default-disabled-col));
69
+ color: var(--pd-button-font-col-disabled, black);
70
+ }
71
+
34
72
  /* Style for Button */
35
73
  a {
36
74
  display: inline-block;
37
75
  text-decoration: none;
38
- font-family: var(--my-button-font-family);
39
- font-size: var(--my-font-size);
40
- line-height: 2.3em;
41
-
42
- text-align: center;
76
+ border: none;
77
+ white-space: nowrap;
78
+ margin: 0.5rem;
79
+
43
80
  /*box-shadow: -2px 2px 4px #999;/* TODO: From var */
44
81
  /*border-bottom: 1px solid var(--my-border-color);*/
45
-
46
- background-color: var(--my-button-background-color);
47
- border-radius: var(--my-border-radius);
48
- border: none;
49
- cursor: pointer;
50
82
  /*will-change: transform; Dann über Menu bei Scroll...*/
51
-
52
- color: var(--my-button-text-color);
83
+
84
+ /*
53
85
  transition-property: box-shadow, background;
54
86
  transition: .2s ease-in;
55
87
  box-sizing: border-box;
56
- white-space: nowrap;
88
+ */
57
89
 
58
90
  /*overflow: hidden;
59
91
  text-overflow: ellipsis;*/
60
- margin: 1rem auto;
61
-
62
92
 
63
93
  /*padding: var(--squi-input-padding, .5rem);*/
64
-
65
- width: var(--my-button-width);
66
- height: var(--my-input-height);
67
-
68
94
  }
69
95
 
70
96
  a *{
71
- pointer-events: none;
72
- cursor: pointer;
73
- }
74
-
75
- a[disabled] {
76
- border-color: #5a5858;
77
- color: var(--raw-game-color-light-lightest, #4b4848);
78
- background-color: #d3d2d2;
79
- text-shadow: 2px 2px 3px var(--raw-game-color-dark-darker, #999);
80
- }
81
-
82
- a:not([disabled]):hover {
83
- box-shadow: -1px 1px 2px #1f2b2a;
84
- background: var(--my-button-background-hover-color);
85
- }
86
-
87
- a.primary:not([disabled]):hover {
88
- /* tbd: at the momment the same definition as without primary style */
89
- box-shadow: -1px 1px 2px #1f2b2a;
90
- background: var(--my-border-color-hover);
97
+ pointer-events: none;
91
98
  }
92
-
93
- a.primary {
94
- background-color: var(--my-primary-color);
95
- color: #fefefe; /* ToDo */
96
- }
97
-
98
- a.primary[disabled] {
99
- background-color: #d3d2d2;
100
- }
101
-
102
- .b-gradient {
103
- background: linear-gradient(to right, var(--my-background-gradient-color) 0%, var(--my-background-color) 100%);
104
- }
105
-
106
- .b-gradient.primary {
107
- background: linear-gradient(to right, var(--my-primary-color) 0%, var(--my-background-color) 100%);
108
- }
109
-
110
- .b-gradient[disabled] {
111
- background: linear-gradient(to right, lightgrey 0%, grey 100%);
112
- }
99
+
113
100
 
114
101
  /* button icon not integrated at the moment */
115
102
  .button-icon {
@@ -183,10 +170,15 @@ export class PdButton extends LitElement {
183
170
  }
184
171
 
185
172
  render() {
186
- // eslint-disable-next-line lit-a11y/anchor-is-valid
187
- return html`<a class="${this.gradient ? 'b-gradient' : ''} ${this.primary ? 'primary' : ''}" ?disabled="${this.disabled}">
188
- ${this.text}
189
- </a>`;
173
+ return html`
174
+ <div @onClick="${this._handleClick}">
175
+ <a ?disabled="${this.disabled}">${this.text}</a>
176
+ </div>`;
190
177
  }
191
178
 
179
+ _handleClick() {
180
+ if (!this.disabled) {
181
+ this.dispatchEvent(new CustomEvent("button-clicked"));
182
+ }
183
+ }
192
184
  }