@progressive-development/pd-forms 0.2.8 → 0.2.9
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
package/pd-input-file.js
ADDED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
INPUT_TYPE_SELECT,
|
|
27
27
|
INPUT_TYPE_TEXT,
|
|
28
28
|
INPUT_TYPE_DATE,
|
|
29
|
+
INPUT_TYPE_FILE
|
|
29
30
|
} from './PdBaseUiInput.js';
|
|
30
31
|
|
|
31
32
|
import { SharedInputFieldStyles } from './shared-input-field-styles.js';
|
|
@@ -92,6 +93,7 @@ export class PdBaseInputElement extends PdBaseUIInput {
|
|
|
92
93
|
return 'textarea';
|
|
93
94
|
case INPUT_TYPE_SELECT:
|
|
94
95
|
return 'select';
|
|
96
|
+
case INPUT_TYPE_FILE:
|
|
95
97
|
case INPUT_TYPE_TEXT:
|
|
96
98
|
return 'input';
|
|
97
99
|
case INPUT_TYPE_DATE:
|
package/src/PdBaseUiInput.js
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
|
|
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
|
+
}
|
|
@@ -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-input-file.js';
|
|
5
6
|
import '../../pd-range.js';
|
|
6
7
|
|
|
7
8
|
export default {
|
|
@@ -24,7 +25,7 @@ function Template() {
|
|
|
24
25
|
<pd-form-container id="testFormContainerId" requiredFieldInfo>
|
|
25
26
|
<pd-form-row>
|
|
26
27
|
<pd-input class="quarter2" id="test1Id" label="Label 1" required autoCompleteName="email"></pd-input>
|
|
27
|
-
<pd-input class="quarter2" id="test2Id" label="Label 2" required></pd-input>
|
|
28
|
+
<pd-input-file class="quarter2" id="test2Id" label="Label 2" required></pd-input-file>
|
|
28
29
|
</pd-form-row>
|
|
29
30
|
<pd-form-row>
|
|
30
31
|
<pd-input class="quarter4" id="test3Id" label="Label 3" required></pd-input>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import '../../pd-input-file.js';
|
|
3
|
+
import { ICON_DATE } from '@progressive-development/pd-icon/src/PdIcon.js';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'PdForms/InputFile',
|
|
7
|
+
component: 'pd-input-file',
|
|
8
|
+
argTypes: {
|
|
9
|
+
primaryColor: { control: 'color' },
|
|
10
|
+
secondaryColor: { control: 'color' },
|
|
11
|
+
textColor: { control: 'color' },
|
|
12
|
+
highlightColor: { control: 'color' },
|
|
13
|
+
errorColor: { control: 'color' },
|
|
14
|
+
errorBackgroundColor: { control: 'color' },
|
|
15
|
+
borderRadius: { control: 'text' },
|
|
16
|
+
displayFont: { control: 'text' },
|
|
17
|
+
fontSize: { control: 'text' },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function Template({
|
|
22
|
+
primaryColor,
|
|
23
|
+
secondaryColor,
|
|
24
|
+
textColor,
|
|
25
|
+
highlightColor,
|
|
26
|
+
errorColor,
|
|
27
|
+
errorBackgroundColor,
|
|
28
|
+
borderRadius,
|
|
29
|
+
displayFont,
|
|
30
|
+
fontSize,
|
|
31
|
+
accept
|
|
32
|
+
}) {
|
|
33
|
+
let style = '';
|
|
34
|
+
if (primaryColor) {
|
|
35
|
+
style += `--squi-primary-color:${primaryColor};`;
|
|
36
|
+
}
|
|
37
|
+
if (secondaryColor) {
|
|
38
|
+
style += `--squi-secondary-color:${secondaryColor};`;
|
|
39
|
+
}
|
|
40
|
+
if (textColor) {
|
|
41
|
+
style += `--squi-text-color:${textColor};`;
|
|
42
|
+
}
|
|
43
|
+
if (highlightColor) {
|
|
44
|
+
style += `--squi-highlight-color:${highlightColor};`;
|
|
45
|
+
}
|
|
46
|
+
if (errorColor) {
|
|
47
|
+
style += `--squi-error-color:${errorColor};`;
|
|
48
|
+
}
|
|
49
|
+
if (errorBackgroundColor) {
|
|
50
|
+
style += `--squi-error-background-color:${errorBackgroundColor};`;
|
|
51
|
+
}
|
|
52
|
+
if (borderRadius) {
|
|
53
|
+
style += `--squi-border-radius:${borderRadius};`;
|
|
54
|
+
}
|
|
55
|
+
if (displayFont) {
|
|
56
|
+
style += `--squi-display-font:${displayFont};`;
|
|
57
|
+
}
|
|
58
|
+
if (fontSize) {
|
|
59
|
+
style += `--squi-font-size:${fontSize};`;
|
|
60
|
+
}
|
|
61
|
+
return html`
|
|
62
|
+
<h3>Default Input</h3>
|
|
63
|
+
<pd-input-file id="test1Id" style="${style}"></pd-input-file>
|
|
64
|
+
|
|
65
|
+
<h3>Input with Icon</h3>
|
|
66
|
+
<pd-input-file
|
|
67
|
+
icon-right
|
|
68
|
+
id="testIconId"
|
|
69
|
+
icon="${ICON_DATE}"
|
|
70
|
+
></pd-input-file>
|
|
71
|
+
|
|
72
|
+
<h3>Input with left Icon</h3>
|
|
73
|
+
<pd-input-file
|
|
74
|
+
icon-left
|
|
75
|
+
id="testIcon2Id"
|
|
76
|
+
icon="${ICON_DATE}"
|
|
77
|
+
></pd-input-file>
|
|
78
|
+
|
|
79
|
+
<h3>Input with max lenth</h3>
|
|
80
|
+
<pd-input-file
|
|
81
|
+
id="test5Id"
|
|
82
|
+
maxlength="4"
|
|
83
|
+
></pd-input-file>
|
|
84
|
+
|
|
85
|
+
<h3>Input with accept</h3>
|
|
86
|
+
<pd-input-file
|
|
87
|
+
id="test5Id"
|
|
88
|
+
maxlength="4"
|
|
89
|
+
accept="${accept}"
|
|
90
|
+
></pd-input-file>
|
|
91
|
+
|
|
92
|
+
<h3>Input with label</h3>
|
|
93
|
+
<pd-input-file
|
|
94
|
+
id="test6Id"
|
|
95
|
+
label="Input Label 1"
|
|
96
|
+
></pd-input-file>
|
|
97
|
+
|
|
98
|
+
<h3>Input with label - disabled</h3>
|
|
99
|
+
<pd-input-file
|
|
100
|
+
id="test7Id"
|
|
101
|
+
label="Input Label 1"
|
|
102
|
+
disabled
|
|
103
|
+
></pd-input-file>
|
|
104
|
+
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const InputFile = Template.bind({});
|
|
109
|
+
InputFile.args = {
|
|
110
|
+
accept: "text/*"
|
|
111
|
+
};
|