@progressive-development/pd-forms 0.2.7 → 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
@@ -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.2.7",
6
+ "version": "0.2.9",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
@@ -0,0 +1,3 @@
1
+ import { PdInputFile } from './src/PdInputFile.js';
2
+
3
+ window.customElements.define('pd-input-file', PdInputFile);
@@ -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:
@@ -49,6 +49,7 @@ import '../pd-hover-box.js';
49
49
  export const INPUT_TYPE_AREA = 5;
50
50
  export const INPUT_TYPE_CHECK_GROUP = 6;
51
51
  export const INPUT_TYPE_DATE = 7;
52
+ export const INPUT_TYPE_FILE = 8;
52
53
 
53
54
  /**
54
55
  * Specific key codes for input events.
@@ -12,7 +12,7 @@
12
12
  import { html, css } from 'lit';
13
13
  import { msg } from '@lit/localize';
14
14
 
15
- import { INPUT_TYPE_RANGE } from './PdBaseUiInput.js';
15
+ import { INPUT_TYPE_RANGE, INPUT_TYPE_SELECT } from './PdBaseUiInput.js';
16
16
 
17
17
  import { PdBaseUI } from './PdBaseUi.js';
18
18
 
@@ -114,7 +114,7 @@ export class PdFormContainer extends PdBaseUI {
114
114
  reqEl.forEach(el => {
115
115
  const tmpEl = el;
116
116
  if (!el.value || el.value === "" || el.value === "false" ||
117
- (el._inputType === INPUT_TYPE_RANGE && el.value === '0')) {
117
+ (el._inputType === INPUT_TYPE_RANGE && el.value === '0') || (el._inputType === INPUT_TYPE_SELECT && el.value === 'UNDEF')) {
118
118
  const erMsg = el.requiredMsg || msg('Eingabe erforderlich',{desc: '#pd.form.field.required#'});
119
119
  if (!e.detail.singleElement || e.detail.singleElement === el) {
120
120
  tmpEl.errorMsg = erMsg;
package/src/PdInput.js CHANGED
@@ -85,7 +85,7 @@ export class PdInput extends PdBaseInputElement {
85
85
  return html`
86
86
  ${this._renderLabel(inputId)}
87
87
  <div class="input ${this.errorMsg.length > 0 ? 'error' : ''}">
88
- ${this.icon ? html`<pd-icon icon="${this.icon}" @click="${this._iconClicked}"></pd-icon>` : ''}
88
+ ${this.icon ? html`<pd-icon icon="${this.icon}" activeIcon @click="${this._iconClicked}"></pd-icon>` : ''}
89
89
  <input
90
90
  id="${inputId}"
91
91
  name="${this.name || this.valueName || this.autoCompleteName}"
@@ -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
+ }
@@ -37,7 +37,7 @@ export const SharedInputFieldStyles = css`
37
37
  }
38
38
 
39
39
  :host([icon-left]) .input > input {
40
- padding-left: calc((var(--pd-input-field-height, 2rem) * 0.85) + 5px);
40
+ padding-left: calc(var(--pd-input-field-height, 2rem) + 5px);
41
41
  }
42
42
 
43
43
  :host([icon-right]) .input pd-icon {
@@ -46,7 +46,7 @@ export const SharedInputFieldStyles = css`
46
46
  }
47
47
 
48
48
  :host([icon-right]) .input > input {
49
- padding-right: calc((var(--pd-input-field-height, 2rem) * 0.85) + 5px);
49
+ padding-right: calc(var(--pd-input-field-height, 2rem) + 5px);
50
50
  }
51
51
 
52
52
  /* relative hack => see comment above in .input class, do it only for icon fiels relative for the moment*/
@@ -60,10 +60,10 @@ export const SharedInputFieldStyles = css`
60
60
  pd-icon {
61
61
  display: none;
62
62
  position: absolute;
63
- top: 5px;
64
- --pd-icon-size: calc(var(--pd-input-field-height, 2rem) * 0.85);
65
- --pd-icon-fill-color: var(--squi-input-icon-fill-color, currentcolor);
66
- --pd-icon-stroke-color: var(--squi-input-icon-stroke-color, none);
63
+ --pd-icon-size: var(--pd-input-icon-size, calc(var(--pd-input-field-height, 2rem) * 0.9));
64
+ --pd-icon-col-active: var(--pd-input-icon-color, #edf7fd);
65
+ --pd-icon-stroke-col-active: var(--pd-input-icon-stroke-color, var(--pd-default-color));
66
+ top: 2px;
67
67
  }
68
68
 
69
69
  pd-icon:hover {
@@ -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
+ };
@@ -1,6 +1,6 @@
1
1
  import { html } from 'lit';
2
2
  import '../../pd-input.js';
3
- import { ICON_CAMERA } from '@progressive-development/pd-icon/src/PdIcon.js';
3
+ import { ICON_CAMERA, ICON_DATE } from '@progressive-development/pd-icon/src/PdIcon.js';
4
4
 
5
5
  export default {
6
6
  title: 'PdForms/Input',
@@ -99,7 +99,7 @@ function Template({
99
99
  id="testRightTextId"
100
100
  text-right
101
101
  icon-right
102
- icon="${ICON_CAMERA}"
102
+ icon="${ICON_DATE}"
103
103
  value="Right Text"
104
104
  ></pd-input>
105
105
 
@@ -108,7 +108,7 @@ function Template({
108
108
  icon-right
109
109
  id="testIconId"
110
110
  value="Input value"
111
- icon="${ICON_CAMERA}"
111
+ icon="${ICON_DATE}"
112
112
  ></pd-input>
113
113
 
114
114
  <h3>Big Input with left Icon</h3>
@@ -117,7 +117,7 @@ function Template({
117
117
  icon-left
118
118
  id="testIcon2Id"
119
119
  value="Input value"
120
- icon="${ICON_CAMERA}"
120
+ icon="${ICON_DATE}"
121
121
  ></pd-input>
122
122
 
123
123
  <h3>Input with max lenth and size</h3>