@progressive-development/pd-forms 0.2.16 → 0.5.0
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/dist/index.js +26 -0
- package/dist/locales/be.js +12 -0
- package/dist/locales/de.js +12 -0
- package/dist/locales/en.js +12 -0
- package/dist/pd-button.js +4 -0
- package/dist/pd-checkbox.js +4 -0
- package/dist/pd-form-container.js +4 -0
- package/dist/pd-form-row.js +4 -0
- package/dist/pd-hover-box.js +4 -0
- package/dist/pd-input-area.js +4 -0
- package/dist/pd-input-file.js +4 -0
- package/dist/pd-input.js +4 -0
- package/dist/pd-radio-group.js +4 -0
- package/dist/pd-range.js +4 -0
- package/dist/pd-select.js +4 -0
- package/{src → dist/src}/PdBaseInputElement.js +23 -42
- package/{src → dist/src}/PdBaseUi.js +11 -13
- package/dist/src/PdBaseUiInput.js +229 -0
- package/{src → dist/src}/PdButton.js +42 -48
- package/{src → dist/src}/PdCheckbox.js +16 -75
- package/{src → dist/src}/PdFormContainer.js +51 -79
- package/{src → dist/src}/PdFormRow.js +8 -17
- package/{src → dist/src}/PdHoverBox.js +20 -42
- package/dist/src/PdInput.js +79 -0
- package/dist/src/PdInputArea.js +61 -0
- package/dist/src/PdInputFile.js +73 -0
- package/dist/src/PdRadioGroup.js +72 -0
- package/{src → dist/src}/PdRange.js +38 -47
- package/{src → dist/src}/PdSelect.js +16 -65
- package/{src → dist/src}/shared-input-field-styles.js +6 -8
- package/{src → dist/src}/shared-input-styles.js +5 -8
- package/package.json +46 -25
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -13
- package/.storybook/preview-head.html +0 -4
- package/.storybook/preview.js +0 -14
- package/demo/index.html +0 -29
- package/index.js +0 -0
- package/lit-localize.json +0 -18
- package/pd-button.js +0 -3
- package/pd-checkbox.js +0 -3
- package/pd-form-container.js +0 -3
- package/pd-form-row.js +0 -3
- package/pd-hover-box.js +0 -3
- package/pd-input-area.js +0 -3
- package/pd-input-file.js +0 -3
- package/pd-input.js +0 -3
- package/pd-radio-group.js +0 -3
- package/pd-range.js +0 -3
- package/pd-select.js +0 -3
- package/src/PdBaseUiInput.js +0 -248
- package/src/PdInput.js +0 -146
- package/src/PdInputArea.js +0 -104
- package/src/PdInputFile.js +0 -121
- package/src/PdRadioGroup.js +0 -88
- package/src/PdRange copy.js +0 -197
- package/src/generated/locale/be.js +0 -19
- package/src/generated/locale/en.js +0 -19
- package/src/generated/locale-codes.js +0 -25
- package/src/stories/01_index.stories.js +0 -268
- package/src/stories/button.stories.js +0 -15
- package/src/stories/checkbox.stories.js +0 -103
- package/src/stories/form-container.stories.js +0 -100
- package/src/stories/form-row.stories.js +0 -23
- package/src/stories/input-area.stories.js +0 -129
- package/src/stories/input-file.stories.js +0 -111
- package/src/stories/input.stories.js +0 -179
- package/src/stories/radio-group.stories.js +0 -54
- package/src/stories/range.stories.js +0 -105
- package/src/stories/select.stories.js +0 -116
- package/test/pd-forms.test.js +0 -32
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
- package/xliff/be.xlf +0 -37
- package/xliff/en.xlf +0 -31
package/pd-form-row.js
DELETED
package/pd-hover-box.js
DELETED
package/pd-input-area.js
DELETED
package/pd-input-file.js
DELETED
package/pd-input.js
DELETED
package/pd-radio-group.js
DELETED
package/pd-range.js
DELETED
package/pd-select.js
DELETED
package/src/PdBaseUiInput.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
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-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
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
import {css, html} from 'lit';
|
|
31
|
-
import '@progressive-development/pd-icon/pd-icon.js';
|
|
32
|
-
|
|
33
|
-
import { PdBaseUI } from './PdBaseUi.js';
|
|
34
|
-
|
|
35
|
-
import { SharedInputStyles } from './shared-input-styles.js';
|
|
36
|
-
|
|
37
|
-
import '../pd-hover-box.js';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Available input types.
|
|
41
|
-
* Each input elemt set it's own type during constructor call.
|
|
42
|
-
*
|
|
43
|
-
* Comment: Not really needed/used at the moment.
|
|
44
|
-
*/
|
|
45
|
-
export const INPUT_TYPE_TEXT = 1;
|
|
46
|
-
export const INPUT_TYPE_SELECT = 2;
|
|
47
|
-
export const INPUT_TYPE_CHECK = 3;
|
|
48
|
-
export const INPUT_TYPE_RANGE = 4;
|
|
49
|
-
export const INPUT_TYPE_AREA = 5;
|
|
50
|
-
export const INPUT_TYPE_CHECK_GROUP = 6;
|
|
51
|
-
export const INPUT_TYPE_DATE = 7;
|
|
52
|
-
export const INPUT_TYPE_FILE = 8;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Specific key codes for input events.
|
|
56
|
-
*/
|
|
57
|
-
const KEY_RETURN = 13;
|
|
58
|
-
|
|
59
|
-
// timer is used to delay validation event on user typing
|
|
60
|
-
let delayTimer = 0;
|
|
61
|
-
const DELAY_WAIT_TIME_MS = 400;
|
|
62
|
-
|
|
63
|
-
export class PdBaseUIInput extends PdBaseUI {
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Fired when an input element change its values.
|
|
67
|
-
* @event validate-form
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Fired when enter was pressend during focus on input element.
|
|
72
|
-
* @event enter-pressed
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Fired when field-value changed.
|
|
77
|
-
* @event field-change
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
static get styles() {
|
|
81
|
-
return [
|
|
82
|
-
PdBaseUI.styles,
|
|
83
|
-
SharedInputStyles,
|
|
84
|
-
css`
|
|
85
|
-
.label-header {
|
|
86
|
-
display: flex;
|
|
87
|
-
align-items: end;
|
|
88
|
-
justify-content: space-between;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.label-header pd-icon {
|
|
92
|
-
--pd-icon-size: 1.25rem;
|
|
93
|
-
--pd-icon-col-active: var(--pd-default-col);
|
|
94
|
-
--pd-icon-col-active-hover: var(--pd-default-hover-col);
|
|
95
|
-
--pd-icon-stroke-width: 0;
|
|
96
|
-
padding-right: 5px;
|
|
97
|
-
cursor: help;
|
|
98
|
-
}
|
|
99
|
-
`
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static get properties() {
|
|
104
|
-
return {
|
|
105
|
-
gradient: { type: Boolean }, // true for gradient background
|
|
106
|
-
disabled: { type: Boolean }, // disabled flag for element
|
|
107
|
-
readonly: { type: Boolean }, // readonly flag for element
|
|
108
|
-
required: { type: Boolean }, // required flag for element
|
|
109
|
-
requiredMsg: { type: String }, // specific error msg for required field
|
|
110
|
-
helperTxt: { type: String }, // helper text
|
|
111
|
-
valueName: { type: String },
|
|
112
|
-
defaultRequiredChar: { type: String },
|
|
113
|
-
defaultValue: { type: String }, // default value for input element (used for reset) TODO: Das hier ggf. automatisch mit erstem gesetzten Wert füllen?
|
|
114
|
-
label: { type: String }, // label text for input
|
|
115
|
-
value: {type: String}, // current value (set from outside) TODO: Typ (Object, Number, Txt, Bool...)
|
|
116
|
-
_errorMsg: {type: String, state: true}, // errorMsg (could set fronm outside for busines validation, internal validation=> todo)
|
|
117
|
-
_inputType: {type: Number, state: true}, // number value for type (text, select, range....), set constructor of sub-class
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
constructor() {
|
|
122
|
-
super();
|
|
123
|
-
this.gradient = false;
|
|
124
|
-
this.disabled = false;
|
|
125
|
-
this.readonly = false;
|
|
126
|
-
this.defaultValue = '';
|
|
127
|
-
this.label = '';
|
|
128
|
-
this.value = '';
|
|
129
|
-
this._errorMsg = '';
|
|
130
|
-
this._inputType = -1;
|
|
131
|
-
this.valueName = '';
|
|
132
|
-
|
|
133
|
-
this.defaultRequiredChar = '*';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Test: Clear input with value => Dann in BasisKlasse und alle leiten von Basis UI Element ab
|
|
137
|
-
clear() {
|
|
138
|
-
this.value = '';
|
|
139
|
-
// this._input.value = this.value;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Test: Reset input with value
|
|
143
|
-
reset() {
|
|
144
|
-
this.value = this.defaultValue || '';
|
|
145
|
-
// this._input.value = this.value;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
get errorMsg() {
|
|
149
|
-
return this._errorMsg;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
set errorMsg(msg) {
|
|
153
|
-
this._errorMsg = msg;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/*
|
|
157
|
-
get value() {
|
|
158
|
-
return this._value;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
set value(newValue) {
|
|
162
|
-
console.info("Meine Werte vor Set _value, input.value, newValue: ", this._value, this._input.value, newValue);
|
|
163
|
-
this._value = newValue;
|
|
164
|
-
this._input.value = newValue;
|
|
165
|
-
console.info("Meine Werte nach Set: ", this._value, this._input.value, newValue);
|
|
166
|
-
}
|
|
167
|
-
*/
|
|
168
|
-
|
|
169
|
-
_generateValidateEvent () {
|
|
170
|
-
this.dispatchEvent(
|
|
171
|
-
new CustomEvent('validate-form', {
|
|
172
|
-
detail: {
|
|
173
|
-
singleElement: this,
|
|
174
|
-
errorMap: new Map()
|
|
175
|
-
},
|
|
176
|
-
composed: true,
|
|
177
|
-
bubbles: true,
|
|
178
|
-
})
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
_handleChangedValue(newValue, event, checkReturn, showValidateMsg) {
|
|
183
|
-
const changed = this.value !== newValue;
|
|
184
|
-
|
|
185
|
-
this.value = newValue;
|
|
186
|
-
const keyCode = event.keyCode ? Number(event.keyCode) : -1;
|
|
187
|
-
const eventDetail = {
|
|
188
|
-
value: newValue,
|
|
189
|
-
name: this.valueName,
|
|
190
|
-
keyCode, changed
|
|
191
|
-
}
|
|
192
|
-
const handleReturn = checkReturn && keyCode === KEY_RETURN;
|
|
193
|
-
if (handleReturn) {
|
|
194
|
-
this.dispatchEvent(
|
|
195
|
-
new CustomEvent('enter-pressed', {
|
|
196
|
-
detail: eventDetail,
|
|
197
|
-
composed: true,
|
|
198
|
-
bubbles: true,
|
|
199
|
-
})
|
|
200
|
-
);
|
|
201
|
-
event.preventDefault();
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (changed) {
|
|
206
|
-
// generate changed event
|
|
207
|
-
this.dispatchEvent(
|
|
208
|
-
new CustomEvent('field-change', {
|
|
209
|
-
detail: eventDetail,
|
|
210
|
-
composed: true,
|
|
211
|
-
bubbles: true,
|
|
212
|
-
})
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (showValidateMsg) {
|
|
217
|
-
// generate validation event after delay
|
|
218
|
-
clearTimeout(delayTimer);
|
|
219
|
-
delayTimer = setTimeout(this._generateValidateEvent.bind(this),
|
|
220
|
-
DELAY_WAIT_TIME_MS);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
_renderErrorMsg() {
|
|
225
|
-
return this.errorMsg && this.errorMsg.length > 0 ? html`
|
|
226
|
-
<div class="error-box error">
|
|
227
|
-
<p class="error-msg">${this.errorMsg}</p>
|
|
228
|
-
</div>
|
|
229
|
-
` : '';
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
_renderLabel(forParam, additionalValue) {
|
|
233
|
-
return html`
|
|
234
|
-
<div class="label-header">
|
|
235
|
-
<label for="${forParam}">${this.label}${this.required && this.label ? this.defaultRequiredChar : ''}${additionalValue ? html` - <b>${additionalValue}</b>` : ''}</label>
|
|
236
|
-
${this.helperTxt ? html`
|
|
237
|
-
|
|
238
|
-
<pd-hover-box>
|
|
239
|
-
<pd-icon slot="normal-view" icon="helpIcon" activeIcon></pd-icon>
|
|
240
|
-
<p slot="info-view">${this.helperTxt}</p>
|
|
241
|
-
</pd-hover-box>
|
|
242
|
-
|
|
243
|
-
` : ""}
|
|
244
|
-
</div>
|
|
245
|
-
`;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
}
|
package/src/PdInput.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { html, css } from 'lit';
|
|
7
|
-
import '@progressive-development/pd-icon/pd-icon.js';
|
|
8
|
-
|
|
9
|
-
import { INPUT_TYPE_TEXT } from './PdBaseUiInput.js';
|
|
10
|
-
import { PdBaseInputElement } from './PdBaseInputElement.js';
|
|
11
|
-
|
|
12
|
-
const onlyContainsNumbers = (str) => /^\d+$/.test(str);
|
|
13
|
-
|
|
14
|
-
// https://github.com/Victor-Bernabe/lit-input
|
|
15
|
-
// https://levelup.gitconnected.com/build-a-material-like-input-web-component-using-litelement-20e9e0d203b6
|
|
16
|
-
/**
|
|
17
|
-
* Web component to input text implemented with LitElement.
|
|
18
|
-
*
|
|
19
|
-
* ### Styling
|
|
20
|
-
*
|
|
21
|
-
* All custom properties should start with `--squi-input`.
|
|
22
|
-
*
|
|
23
|
-
* Font and icon size will scale automatically with `squi-input`'s height.
|
|
24
|
-
*
|
|
25
|
-
* Custom property | Description | Default
|
|
26
|
-
* ----------------|-------------|--------
|
|
27
|
-
* `--pd-input-field-width` | Width | `250px`
|
|
28
|
-
* `--my-input-height` | Height | `30px`
|
|
29
|
-
* `--squi-input-border` | Border | `1px solid black`
|
|
30
|
-
* `--squi-input-border-focus` | Border when focused | `1px solid #4d90fe`
|
|
31
|
-
* `--squi-input-background-color` | Background color | `white`
|
|
32
|
-
* `--squi-input-font-size` | Font size | `calc(var(--my-input-height) / 1.8)`
|
|
33
|
-
* `--squi-input-text-color` | Text color | `inherit`
|
|
34
|
-
* `--squi-input-placeholder-color` | Placeholder text color | `#a0a0a0`
|
|
35
|
-
* `--squi-input-icon-fill-color` | Icon fill color | `currentcolor`
|
|
36
|
-
* `--squi-input-icon-stroke-color` | Icon stroke color | `none`
|
|
37
|
-
*
|
|
38
|
-
* ### Icon and text alignment
|
|
39
|
-
*
|
|
40
|
-
* The icon inside `squi-input` is hidden by default. To show it, set the attribute `icon-right` or `icon-left`.
|
|
41
|
-
*
|
|
42
|
-
* <pd-input icon-left></pd-input>
|
|
43
|
-
* <pd-input icon-right></pd-input>
|
|
44
|
-
*
|
|
45
|
-
* <pd-input icon-left .icon="${'hardware:headset'}"></pd-input>
|
|
46
|
-
*
|
|
47
|
-
* Text can be left or right aligned. Default is left alignment.
|
|
48
|
-
*
|
|
49
|
-
* <pd-input text-right></pd-input>
|
|
50
|
-
* <pd-input text-left></pd-input>
|
|
51
|
-
*/
|
|
52
|
-
export class PdInput extends PdBaseInputElement {
|
|
53
|
-
|
|
54
|
-
static get styles() {
|
|
55
|
-
return [
|
|
56
|
-
PdBaseInputElement.styles,
|
|
57
|
-
css`
|
|
58
|
-
* {
|
|
59
|
-
box-sizing: border-box;
|
|
60
|
-
}
|
|
61
|
-
`,
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static get properties() {
|
|
66
|
-
return {
|
|
67
|
-
/**
|
|
68
|
-
* Icon to be shown inside `pd-input`.
|
|
69
|
-
*/
|
|
70
|
-
icon: { type: String },
|
|
71
|
-
secret: { type: Boolean }, // True for type password
|
|
72
|
-
minlength: { type: String },
|
|
73
|
-
maxlength: { type: String }, // max length for field,
|
|
74
|
-
onlyNumbers: { type: Boolean }, // if only numbers allowed => Refactor => dafür war type number vorgesehen, dieses attribut wird entfernt und auf type=number umgestellt
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
constructor() {
|
|
79
|
-
super();
|
|
80
|
-
this._inputType = INPUT_TYPE_TEXT;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
render() {
|
|
84
|
-
const inputId = `${this.id}Input`;
|
|
85
|
-
return html`
|
|
86
|
-
${this._renderLabel(inputId)}
|
|
87
|
-
<div class="input ${this.errorMsg.length > 0 ? 'error' : ''}">
|
|
88
|
-
${this.icon ? html`<pd-icon icon="${this.icon}" activeIcon @click="${this._iconClicked}"></pd-icon>` : ''}
|
|
89
|
-
<input
|
|
90
|
-
id="${inputId}"
|
|
91
|
-
name="${this.name || this.valueName || this.autoCompleteName}"
|
|
92
|
-
autocomplete=${this.autoCompleteName}
|
|
93
|
-
class="input-style ${this.gradient ? 'gradient' : ''}"
|
|
94
|
-
type="${this.secret ? 'password' : 'text'}"
|
|
95
|
-
placeholder="${this.placeHolder}"
|
|
96
|
-
.value="${this.value}"
|
|
97
|
-
minlength="${this.minlength}"
|
|
98
|
-
maxlength="${this.maxlength}"
|
|
99
|
-
?readonly="${this.readonly}"
|
|
100
|
-
?disabled="${this.disabled}"
|
|
101
|
-
@keyup="${this._onKeyUp}"
|
|
102
|
-
@blur="${this._onBlur}"
|
|
103
|
-
|
|
104
|
-
/>
|
|
105
|
-
</div>
|
|
106
|
-
${this._renderErrorMsg()}
|
|
107
|
-
`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
_onKeyUp(e) {
|
|
111
|
-
if (this.onlyNumbers && !onlyContainsNumbers(this._input.value)) {
|
|
112
|
-
this._input.value = this._input.value.replace(/\D/g, '')
|
|
113
|
-
} else {
|
|
114
|
-
super._onKeyUp(e);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
_iconClicked() {
|
|
119
|
-
this.dispatchEvent(new CustomEvent("input-icon-click"))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Aus Historien Doku noch stehen gelassen... => Dokumentieren und entfernen
|
|
127
|
-
*
|
|
128
|
-
// If any other key, fire 'key-pressed'
|
|
129
|
-
|
|
130
|
-
// Interessante Stelle, die error msg wird von außen gesetzt
|
|
131
|
-
// wenn die error msg hier gesetzt wird, danach nicht mehr für änderungen von außen für den gleichen typ gültig
|
|
132
|
-
// da der wert außen nicht verändert wurde, und daher nicht neu gesetzt wird...
|
|
133
|
-
// => Die eigentliche NAchricht ist nochgesetzt...
|
|
134
|
-
// Hack bevor das Thema richtig nachgezogen wird (recherche), es wird nicht für felder von bestimmten typ durchgeführt
|
|
135
|
-
// d.h. für zip und mail nicht
|
|
136
|
-
/*
|
|
137
|
-
if (this.key != 'mail' && this.key != 'zip' && this.key != 'phone') {
|
|
138
|
-
this.errorMsg = '';
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
Aufrund der gennanten Problematik auskommentiert, ein evenlistener sorgt nun dafür
|
|
142
|
-
|
|
143
|
-
Nachtrag: Nun auf interne propertie umgestellt, im Test...
|
|
144
|
-
*/
|
|
145
|
-
// if (this.errorMsg.length > 0) {
|
|
146
|
-
// }
|
package/src/PdInputArea.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { html, css } from 'lit';
|
|
7
|
-
import '@progressive-development/pd-icon/pd-icon.js';
|
|
8
|
-
|
|
9
|
-
import { INPUT_TYPE_AREA } from './PdBaseUiInput.js';
|
|
10
|
-
import { PdBaseInputElement } from './PdBaseInputElement.js';
|
|
11
|
-
|
|
12
|
-
// https://github.com/Victor-Bernabe/lit-input
|
|
13
|
-
// https://levelup.gitconnected.com/build-a-material-like-input-web-component-using-litelement-20e9e0d203b6
|
|
14
|
-
/**
|
|
15
|
-
* Web component to input text implemented with LitElement.
|
|
16
|
-
*
|
|
17
|
-
* ### Styling
|
|
18
|
-
*
|
|
19
|
-
* All custom properties should start with `--squi-input`.
|
|
20
|
-
*
|
|
21
|
-
* Font and icon size will scale automatically with `squi-input`'s height.
|
|
22
|
-
*
|
|
23
|
-
* Custom property | Description | Default
|
|
24
|
-
* ----------------|-------------|--------
|
|
25
|
-
* `--pd-input-field-width` | Width | `250px`
|
|
26
|
-
* `--my-input-height` | Height | `30px`
|
|
27
|
-
* `--squi-input-border` | Border | `1px solid black`
|
|
28
|
-
* `--squi-input-border-focus` | Border when focused | `1px solid #4d90fe`
|
|
29
|
-
* `--squi-input-background-color` | Background color | `white`
|
|
30
|
-
* `--squi-input-font-size` | Font size | `calc(var(--my-input-height) / 1.8)`
|
|
31
|
-
* `--squi-input-text-color` | Text color | `inherit`
|
|
32
|
-
* `--squi-input-placeholder-color` | Placeholder text color | `#a0a0a0`
|
|
33
|
-
* `--squi-input-icon-fill-color` | Icon fill color | `currentcolor`
|
|
34
|
-
* `--squi-input-icon-stroke-color` | Icon stroke color | `none`
|
|
35
|
-
*
|
|
36
|
-
* ### Icon and text alignment
|
|
37
|
-
*
|
|
38
|
-
* The icon inside `squi-input` is hidden by default. To show it, set the attribute `icon-right` or `icon-left`.
|
|
39
|
-
*
|
|
40
|
-
* <pd-input icon-left></pd-input>
|
|
41
|
-
* <pd-input icon-right></pd-input>
|
|
42
|
-
*
|
|
43
|
-
* <pd-input icon-left .icon="${'hardware:headset'}"></pd-input>
|
|
44
|
-
*
|
|
45
|
-
* Text can be left or right aligned. Default is left alignment.
|
|
46
|
-
*
|
|
47
|
-
* <pd-input text-right></pd-input>
|
|
48
|
-
* <pd-input text-left></pd-input>
|
|
49
|
-
*/
|
|
50
|
-
export class PdInputArea extends PdBaseInputElement {
|
|
51
|
-
|
|
52
|
-
static get styles() {
|
|
53
|
-
return [
|
|
54
|
-
PdBaseInputElement.styles,
|
|
55
|
-
css`
|
|
56
|
-
/* overwrite default (250px), area contains 10px scroll bar */
|
|
57
|
-
.input-style {
|
|
58
|
-
width: var(--pd-input-field-width, 240px);
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static get properties() {
|
|
65
|
-
return {
|
|
66
|
-
rows: { type: Number },
|
|
67
|
-
cols: { type: Number },
|
|
68
|
-
minlength: { type: String },
|
|
69
|
-
maxlength: { type: String }, // max length for field
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
constructor() {
|
|
74
|
-
super();
|
|
75
|
-
this._inputType = INPUT_TYPE_AREA;
|
|
76
|
-
this.maxlength = 500;
|
|
77
|
-
this.rows = 2;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
const inputAreaId = `${this.id}InputArea`;
|
|
82
|
-
return html`
|
|
83
|
-
${this._renderLabel(inputAreaId)}
|
|
84
|
-
<div class="input ${this.errorMsg.length > 0 ? 'error' : ''}">
|
|
85
|
-
<textarea
|
|
86
|
-
id="${inputAreaId}"
|
|
87
|
-
name="${this.name || this.valueName || this.autoCompleteName}"
|
|
88
|
-
autocomplete=${this.autoCompleteName}
|
|
89
|
-
class="input-style ${this.gradient ? 'gradient' : ''}"
|
|
90
|
-
rows="${this.rows}"
|
|
91
|
-
cols="${this.cols}"
|
|
92
|
-
placeholder="${this.placeHolder}"
|
|
93
|
-
?disabled="${this.disabled}"
|
|
94
|
-
?readonly="${this.readonly}"
|
|
95
|
-
.value="${this.value || ''}"
|
|
96
|
-
@keyup="${this._onKeyUp}"
|
|
97
|
-
@blur="${this._onBlur}"
|
|
98
|
-
></textarea>
|
|
99
|
-
</div>
|
|
100
|
-
${this._renderErrorMsg()}
|
|
101
|
-
`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
}
|
package/src/PdInputFile.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { html, css } from 'lit';
|
|
7
|
-
import '@progressive-development/pd-icon/pd-icon.js';
|
|
8
|
-
|
|
9
|
-
import { INPUT_TYPE_FILE } from './PdBaseUiInput.js';
|
|
10
|
-
import { PdBaseInputElement } from './PdBaseInputElement.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// https://github.com/Victor-Bernabe/lit-input
|
|
14
|
-
// https://levelup.gitconnected.com/build-a-material-like-input-web-component-using-litelement-20e9e0d203b6
|
|
15
|
-
/**
|
|
16
|
-
* Web component to input text implemented with LitElement.
|
|
17
|
-
*
|
|
18
|
-
* ### Styling
|
|
19
|
-
*
|
|
20
|
-
* All custom properties should start with `--squi-input`.
|
|
21
|
-
*
|
|
22
|
-
* Font and icon size will scale automatically with `squi-input`'s height.
|
|
23
|
-
*
|
|
24
|
-
* Custom property | Description | Default
|
|
25
|
-
* ----------------|-------------|--------
|
|
26
|
-
* `--pd-input-field-width` | Width | `250px`
|
|
27
|
-
* `--my-input-height` | Height | `30px`
|
|
28
|
-
* `--squi-input-border` | Border | `1px solid black`
|
|
29
|
-
* `--squi-input-border-focus` | Border when focused | `1px solid #4d90fe`
|
|
30
|
-
* `--squi-input-background-color` | Background color | `white`
|
|
31
|
-
* `--squi-input-font-size` | Font size | `calc(var(--my-input-height) / 1.8)`
|
|
32
|
-
* `--squi-input-text-color` | Text color | `inherit`
|
|
33
|
-
* `--squi-input-placeholder-color` | Placeholder text color | `#a0a0a0`
|
|
34
|
-
* `--squi-input-icon-fill-color` | Icon fill color | `currentcolor`
|
|
35
|
-
* `--squi-input-icon-stroke-color` | Icon stroke color | `none`
|
|
36
|
-
*
|
|
37
|
-
* ### Icon and text alignment
|
|
38
|
-
*
|
|
39
|
-
* The icon inside `squi-input` is hidden by default. To show it, set the attribute `icon-right` or `icon-left`.
|
|
40
|
-
*
|
|
41
|
-
* <pd-input icon-left></pd-input>
|
|
42
|
-
* <pd-input icon-right></pd-input>
|
|
43
|
-
*
|
|
44
|
-
* <pd-input icon-left .icon="${'hardware:headset'}"></pd-input>
|
|
45
|
-
*
|
|
46
|
-
* Text can be left or right aligned. Default is left alignment.
|
|
47
|
-
*
|
|
48
|
-
* <pd-input text-right></pd-input>
|
|
49
|
-
* <pd-input text-left></pd-input>
|
|
50
|
-
*/
|
|
51
|
-
export class PdInputFile extends PdBaseInputElement {
|
|
52
|
-
|
|
53
|
-
static get styles() {
|
|
54
|
-
return [
|
|
55
|
-
PdBaseInputElement.styles,
|
|
56
|
-
css`
|
|
57
|
-
* {
|
|
58
|
-
box-sizing: border-box;
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static get properties() {
|
|
65
|
-
return {
|
|
66
|
-
/**
|
|
67
|
-
* Icon to be shown inside `pd-input`.
|
|
68
|
-
*/
|
|
69
|
-
icon: { type: String },
|
|
70
|
-
accept: { type: String },
|
|
71
|
-
maxlength: { type: String }, // max length for field,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
constructor() {
|
|
76
|
-
super();
|
|
77
|
-
this._inputType = INPUT_TYPE_FILE;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
const inputId = `${this.id}Input`;
|
|
82
|
-
return html`
|
|
83
|
-
${this._renderLabel(inputId)}
|
|
84
|
-
<div class="input ${this.errorMsg.length > 0 ? 'error' : ''}">
|
|
85
|
-
${this.icon ? html`<pd-icon icon="${this.icon}" activeIcon @click="${this._iconClicked}"></pd-icon>` : ''}
|
|
86
|
-
<input
|
|
87
|
-
id="${inputId}"
|
|
88
|
-
name="${this.name || this.valueName || this.autoCompleteName}"
|
|
89
|
-
class="input-style ${this.gradient ? 'gradient' : ''}"
|
|
90
|
-
type="file"
|
|
91
|
-
maxlength="${this.maxlength}"
|
|
92
|
-
accept="${this.accept}"
|
|
93
|
-
?disabled="${this.disabled}"
|
|
94
|
-
@keyup="${this._onKeyUp}"
|
|
95
|
-
@blur="${this._onBlur}"
|
|
96
|
-
@change="${this._onChange}"
|
|
97
|
-
/>
|
|
98
|
-
</div>
|
|
99
|
-
${this._renderErrorMsg()}
|
|
100
|
-
`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_onKeyUp(e) {
|
|
104
|
-
super._onKeyUp(e);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
_iconClicked() {
|
|
108
|
-
this.dispatchEvent(new CustomEvent("input-icon-click"))
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
_onChange(e) {
|
|
112
|
-
// TODO
|
|
113
|
-
this.dispatchEvent(new CustomEvent("file-change"))
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
get files() {
|
|
117
|
-
const el = this.shadowRoot.getElementById(`${this.id}Input`);
|
|
118
|
-
return el ? el.files : undefined;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
}
|