@progressive-development/pd-contact 0.0.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.
- package/.editorconfig +29 -0
- package/.storybook/main.js +3 -0
- package/.storybook/server.mjs +8 -0
- package/LICENSE +2 -0
- package/README.md +76 -0
- package/demo/index.html +29 -0
- package/index.js +1 -0
- package/package.json +66 -0
- package/pd-contact.js +3 -0
- package/src/PdContact.js +423 -0
- package/stories/index.stories.js +44 -0
- package/test/pd-contact.test.js +32 -0
- package/web-dev-server.config.mjs +27 -0
- package/web-test-runner.config.mjs +41 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[*]
|
|
9
|
+
|
|
10
|
+
# Change these settings to your own preference
|
|
11
|
+
indent_style = space
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
# We recommend you to keep these unchanged
|
|
15
|
+
end_of_line = lf
|
|
16
|
+
charset = utf-8
|
|
17
|
+
trim_trailing_whitespace = true
|
|
18
|
+
insert_final_newline = true
|
|
19
|
+
|
|
20
|
+
[*.md]
|
|
21
|
+
trim_trailing_whitespace = false
|
|
22
|
+
|
|
23
|
+
[*.json]
|
|
24
|
+
indent_size = 2
|
|
25
|
+
|
|
26
|
+
[*.{html,js,md}]
|
|
27
|
+
block_comment_start = /**
|
|
28
|
+
block_comment = *
|
|
29
|
+
block_comment_end = */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { storybookPlugin } from '@web/dev-server-storybook';
|
|
2
|
+
import baseConfig from '../web-dev-server.config.mjs';
|
|
3
|
+
|
|
4
|
+
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
5
|
+
...baseConfig,
|
|
6
|
+
open: '/',
|
|
7
|
+
plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
|
|
8
|
+
});
|
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# \<pd-contact>
|
|
2
|
+
|
|
3
|
+
This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i pd-contact
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script type="module">
|
|
15
|
+
import 'pd-contact/pd-contact.js';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<pd-contact></pd-contact>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Linting and formatting
|
|
22
|
+
|
|
23
|
+
To scan the project for linting and formatting errors, run
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm run lint
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To automatically fix linting and formatting errors, run
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run format
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Testing with Web Test Runner
|
|
36
|
+
|
|
37
|
+
To execute a single test run:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To run the tests in interactive watch mode run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run test:watch
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Demoing with Storybook
|
|
50
|
+
|
|
51
|
+
To run a local instance of Storybook for your component, run
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run storybook
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
To build a production version of Storybook, run
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm run storybook:build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## Tooling configs
|
|
65
|
+
|
|
66
|
+
For most of the tools, the configuration is in the `package.json` to minimize the amount of files in your project.
|
|
67
|
+
|
|
68
|
+
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
69
|
+
|
|
70
|
+
## Local Demo with `web-dev-server`
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm start
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
To run a local development server that serves the basic demo located in `demo/index.html`
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
}
|
|
9
|
+
</style>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="demo"></div>
|
|
13
|
+
|
|
14
|
+
<script type="module">
|
|
15
|
+
import { html, render } from 'lit';
|
|
16
|
+
import '../pd-contact.js';
|
|
17
|
+
|
|
18
|
+
const title = 'Hello owc World!';
|
|
19
|
+
render(
|
|
20
|
+
html`
|
|
21
|
+
<pd-contact .title=${title}>
|
|
22
|
+
some light-dom
|
|
23
|
+
</pd-contact>
|
|
24
|
+
`,
|
|
25
|
+
document.querySelector('#demo')
|
|
26
|
+
);
|
|
27
|
+
</script>
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PdContact } from './src/PdContact.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@progressive-development/pd-contact",
|
|
3
|
+
"description": "Progressive Development Contact component",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
5
|
+
"author": "PD Progressive Development",
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"module": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"analyze": "cem analyze --litelement",
|
|
11
|
+
"start": "web-dev-server",
|
|
12
|
+
"lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
|
|
13
|
+
"format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
|
|
14
|
+
"test": "web-test-runner --coverage",
|
|
15
|
+
"test:watch": "web-test-runner --watch",
|
|
16
|
+
"storybook": "npm run analyze -- --exclude dist && web-dev-server -c .storybook/server.mjs",
|
|
17
|
+
"storybook:build": "npm run analyze -- --exclude dist && build-storybook"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"lit": "^2.0.2",
|
|
21
|
+
"@progressive-development/pd-forms": "0.0.11"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@custom-elements-manifest/analyzer": "^0.4.17",
|
|
25
|
+
"@open-wc/eslint-config": "^4.3.0",
|
|
26
|
+
"@open-wc/testing": "next",
|
|
27
|
+
"@web/dev-server": "^0.1.25",
|
|
28
|
+
"@web/dev-server-storybook": "next",
|
|
29
|
+
"@web/test-runner": "^0.13.20",
|
|
30
|
+
"eslint": "^7.32.0",
|
|
31
|
+
"eslint-config-prettier": "^8.3.0",
|
|
32
|
+
"husky": "^4.3.8",
|
|
33
|
+
"lint-staged": "^10.5.4",
|
|
34
|
+
"prettier": "^2.4.1"
|
|
35
|
+
},
|
|
36
|
+
"customElements": "custom-elements.json",
|
|
37
|
+
"eslintConfig": {
|
|
38
|
+
"extends": [
|
|
39
|
+
"@open-wc",
|
|
40
|
+
"prettier"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"prettier": {
|
|
44
|
+
"singleQuote": true,
|
|
45
|
+
"arrowParens": "avoid"
|
|
46
|
+
},
|
|
47
|
+
"husky": {
|
|
48
|
+
"hooks": {
|
|
49
|
+
"pre-commit": "lint-staged"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"lint-staged": {
|
|
53
|
+
"*.js": [
|
|
54
|
+
"eslint --fix",
|
|
55
|
+
"prettier --write"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"pd",
|
|
60
|
+
"progressive",
|
|
61
|
+
"development",
|
|
62
|
+
"contact",
|
|
63
|
+
"form",
|
|
64
|
+
"view"
|
|
65
|
+
]
|
|
66
|
+
}
|
package/pd-contact.js
ADDED
package/src/PdContact.js
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { LitElement, html, css } from 'lit';
|
|
7
|
+
|
|
8
|
+
import '@progressive-development/pd-forms/PdCheckbox.js';
|
|
9
|
+
import '@progressive-development/pd-forms/PdFormContainer.js';
|
|
10
|
+
import '@progressive-development/pd-forms/PdFormRow.js';
|
|
11
|
+
import '@progressive-development/pd-forms/PdInput.js';
|
|
12
|
+
import '@progressive-development/pd-forms/PdRadioGroup.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An example element.
|
|
16
|
+
*
|
|
17
|
+
* @slot - This element has a slot
|
|
18
|
+
* @csspart button - The button
|
|
19
|
+
*/
|
|
20
|
+
export class PdContact extends LitElement {
|
|
21
|
+
static get styles() {
|
|
22
|
+
return css`
|
|
23
|
+
:host {
|
|
24
|
+
display: block;
|
|
25
|
+
|
|
26
|
+
--my-address-txt-color: var(--squi-addrress-txt-color, black);
|
|
27
|
+
--my-address-title-color: var(--squi-addrress-txt-color, #084c61);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.contact {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
address {
|
|
36
|
+
color: var(--my-address-txt-color);
|
|
37
|
+
line-height: 1.8;
|
|
38
|
+
font-style: normal;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
dl {
|
|
42
|
+
margin: 0;
|
|
43
|
+
padding: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
dt {
|
|
47
|
+
font-weight: bold;
|
|
48
|
+
padding-top: 10px;
|
|
49
|
+
/*color: var(--my-address-title-color);*/
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
dd {
|
|
53
|
+
font-weight: 400;
|
|
54
|
+
font-size: 1em;
|
|
55
|
+
margin: 0;
|
|
56
|
+
padding: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.contact-form {
|
|
60
|
+
--row-padding-top: 10px;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static get properties() {
|
|
66
|
+
return {
|
|
67
|
+
addressTitle: { type: String },
|
|
68
|
+
addressRef: { type: String },
|
|
69
|
+
/**
|
|
70
|
+
* address type, business (true) or private (false)
|
|
71
|
+
*/
|
|
72
|
+
business: { type: Boolean },
|
|
73
|
+
/**
|
|
74
|
+
* summary (true) or view (false) contact data
|
|
75
|
+
*/
|
|
76
|
+
summary: { type: Boolean },
|
|
77
|
+
contact: { type: Object },
|
|
78
|
+
match: { type: Object },
|
|
79
|
+
_errorMap: { type: Object },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
constructor() {
|
|
84
|
+
super();
|
|
85
|
+
this.addressTitle = 'Adres';
|
|
86
|
+
this.summary = false;
|
|
87
|
+
this.business = false;
|
|
88
|
+
this.match = {};
|
|
89
|
+
this._errorMap = new Map();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
firstUpdated() {
|
|
93
|
+
this.addEventListener('key-pressed', e => {
|
|
94
|
+
this._errorMap.set(e.detail.name, '');
|
|
95
|
+
super.requestUpdate();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render() {
|
|
100
|
+
return html`
|
|
101
|
+
<div class="contact">
|
|
102
|
+
${this.summary ? this._renderViewContact() : this._renderEditContact()}
|
|
103
|
+
</div>
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_renderEditContact() {
|
|
108
|
+
return html`
|
|
109
|
+
<squi-form-container>
|
|
110
|
+
<squi-form-row id="testFormId">
|
|
111
|
+
<squi-radio-group
|
|
112
|
+
class="quarter4"
|
|
113
|
+
label="Type*"
|
|
114
|
+
@checkbox-changed="${this._switchAddressType}"
|
|
115
|
+
style="--group-gap: 20px;"
|
|
116
|
+
>
|
|
117
|
+
<squi-checkbox value="true" valueName="private"
|
|
118
|
+
>particulier</squi-checkbox
|
|
119
|
+
>
|
|
120
|
+
<squi-checkbox valueName="business">onderneming</squi-checkbox>
|
|
121
|
+
</squi-radio-group>
|
|
122
|
+
</squi-form-row>
|
|
123
|
+
|
|
124
|
+
${this.business
|
|
125
|
+
? html`
|
|
126
|
+
<squi-form-row class="contact-form">
|
|
127
|
+
<squi-input
|
|
128
|
+
id="compNameId"
|
|
129
|
+
class="quarter2"
|
|
130
|
+
label="Naam onderneming*"
|
|
131
|
+
valueName="companyName"
|
|
132
|
+
errorMsg="${this._getErrorMsg('companyName')}"
|
|
133
|
+
></squi-input>
|
|
134
|
+
<squi-input
|
|
135
|
+
id="vatId"
|
|
136
|
+
class="quarter2"
|
|
137
|
+
label="Ondernemingsnr*"
|
|
138
|
+
valueName="vatNr"
|
|
139
|
+
errorMsg="${this._getErrorMsg('vatNr')}"
|
|
140
|
+
></squi-input>
|
|
141
|
+
</squi-form-row>
|
|
142
|
+
`
|
|
143
|
+
: html`
|
|
144
|
+
<squi-form-row class="contact-form">
|
|
145
|
+
<squi-input
|
|
146
|
+
id="firstNameId"
|
|
147
|
+
class="quarter2"
|
|
148
|
+
label="Voornaam*"
|
|
149
|
+
valueName="firstName"
|
|
150
|
+
errorMsg="${this._getErrorMsg('firstName')}"
|
|
151
|
+
></squi-input>
|
|
152
|
+
<squi-input
|
|
153
|
+
id="lastNameId"
|
|
154
|
+
class="quarter2"
|
|
155
|
+
label="Naam*"
|
|
156
|
+
valueName="lastName"
|
|
157
|
+
errorMsg="${this._getErrorMsg('lastName')}"
|
|
158
|
+
></squi-input>
|
|
159
|
+
</squi-form-row>
|
|
160
|
+
`}
|
|
161
|
+
<squi-form-row class="contact-form">
|
|
162
|
+
<squi-input
|
|
163
|
+
id="streetId"
|
|
164
|
+
class="quarter3"
|
|
165
|
+
label="Straat*"
|
|
166
|
+
valueName="street"
|
|
167
|
+
errorMsg="${this._getErrorMsg('street')}"
|
|
168
|
+
></squi-input>
|
|
169
|
+
<squi-input
|
|
170
|
+
id="streetNrId"
|
|
171
|
+
class="quarter1"
|
|
172
|
+
label="Nr*"
|
|
173
|
+
valueName="streetNr"
|
|
174
|
+
errorMsg="${this._getErrorMsg('streetNr')}"
|
|
175
|
+
></squi-input>
|
|
176
|
+
</squi-form-row>
|
|
177
|
+
<squi-form-row class="contact-form">
|
|
178
|
+
<squi-input
|
|
179
|
+
class="quarter4"
|
|
180
|
+
id="additionalHintId"
|
|
181
|
+
label="Extra informatie"
|
|
182
|
+
></squi-input>
|
|
183
|
+
</squi-form-row>
|
|
184
|
+
<squi-form-row class="contact-form">
|
|
185
|
+
${this.match && this.match.zip
|
|
186
|
+
? html`
|
|
187
|
+
<squi-input
|
|
188
|
+
readonly
|
|
189
|
+
id="zipId"
|
|
190
|
+
class="quarter2"
|
|
191
|
+
label="Postcode*"
|
|
192
|
+
key="zip"
|
|
193
|
+
valueName="zip"
|
|
194
|
+
value="${this.match ? this.match.zip || '' : ''}"
|
|
195
|
+
errorMsg="${this._getErrorMsg('zip')}"
|
|
196
|
+
></squi-input>
|
|
197
|
+
`
|
|
198
|
+
: html`
|
|
199
|
+
<squi-input
|
|
200
|
+
id="zipId"
|
|
201
|
+
class="quarter2"
|
|
202
|
+
label="Postcode*"
|
|
203
|
+
key="zip"
|
|
204
|
+
valueName="zip"
|
|
205
|
+
errorMsg="${this._getErrorMsg('zip')}"
|
|
206
|
+
></squi-input>
|
|
207
|
+
`}
|
|
208
|
+
<squi-input
|
|
209
|
+
id="cityId"
|
|
210
|
+
class="quarter2"
|
|
211
|
+
label="Plaats*"
|
|
212
|
+
valueName="city"
|
|
213
|
+
errorMsg="${this._getErrorMsg('city')}"
|
|
214
|
+
></squi-input>
|
|
215
|
+
</squi-form-row>
|
|
216
|
+
<squi-form-row class="contact-form">
|
|
217
|
+
<squi-input
|
|
218
|
+
id="phoneId"
|
|
219
|
+
class="quarter2"
|
|
220
|
+
label="Telefoon*"
|
|
221
|
+
key="phone"
|
|
222
|
+
valueName="phone1"
|
|
223
|
+
errorMsg="${this._getErrorMsg('phone1')}"
|
|
224
|
+
></squi-input>
|
|
225
|
+
<squi-input
|
|
226
|
+
id="mailId"
|
|
227
|
+
class="quarter2"
|
|
228
|
+
label="E-mail*"
|
|
229
|
+
key="mail"
|
|
230
|
+
valueName="email"
|
|
231
|
+
errorMsg="${this._getErrorMsg('email')}"
|
|
232
|
+
></squi-input>
|
|
233
|
+
</squi-form-row>
|
|
234
|
+
</squi-form-container>
|
|
235
|
+
`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_renderViewContact() {
|
|
239
|
+
return html`
|
|
240
|
+
<address>
|
|
241
|
+
<dl>
|
|
242
|
+
<dt>${this.addressTitle}</dt>
|
|
243
|
+
${this.contact
|
|
244
|
+
? html`
|
|
245
|
+
<dd>${this.contact.companyName}</dd>
|
|
246
|
+
<dd>${this.contact.vatNr}</dd>
|
|
247
|
+
<dd>${this._getFullName()}</dd>
|
|
248
|
+
<dd>${this._getFullStreet()}</dd>
|
|
249
|
+
<dd>${this._getFullLocation()}</dd>
|
|
250
|
+
<dd>${this.contact.country}</dd>
|
|
251
|
+
<dd>${this.contact.phone}</dd>
|
|
252
|
+
<dd>${this.contact.email}</dd>
|
|
253
|
+
|
|
254
|
+
${this.contact.btw
|
|
255
|
+
? html`<dt>BTW</dt>
|
|
256
|
+
<dd>${this.contact.btw}</dd>`
|
|
257
|
+
: ''}
|
|
258
|
+
${this.contact.kbc
|
|
259
|
+
? html`<dt>Bankgegevens</dt>
|
|
260
|
+
<dd>${this.contact.kbc}</dd>
|
|
261
|
+
<dd>${this.contact.bank}</dd>`
|
|
262
|
+
: ''}
|
|
263
|
+
`
|
|
264
|
+
: html`${this.addressRef || '--'}`}
|
|
265
|
+
</dl>
|
|
266
|
+
</address>
|
|
267
|
+
`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
_switchAddressType(e) {
|
|
271
|
+
this.business = e.detail.name === 'business';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
validateInput() {
|
|
275
|
+
const matchForValidate = this.match || {};
|
|
276
|
+
|
|
277
|
+
const companyName = this.business
|
|
278
|
+
? this.shadowRoot.getElementById('compNameId').value
|
|
279
|
+
: undefined;
|
|
280
|
+
const vatNr = this.business
|
|
281
|
+
? this.shadowRoot.getElementById('vatId').value
|
|
282
|
+
: undefined;
|
|
283
|
+
const firstName = this.business
|
|
284
|
+
? undefined
|
|
285
|
+
: this.shadowRoot.getElementById('firstNameId').value;
|
|
286
|
+
const lastName = this.business
|
|
287
|
+
? undefined
|
|
288
|
+
: this.shadowRoot.getElementById('lastNameId').value;
|
|
289
|
+
const street = this.shadowRoot.getElementById('streetId').value;
|
|
290
|
+
const streetNr = this.shadowRoot.getElementById('streetNrId').value;
|
|
291
|
+
const additionalHint =
|
|
292
|
+
this.shadowRoot.getElementById('additionalHintId').value;
|
|
293
|
+
const zip = this.shadowRoot.getElementById('zipId').value;
|
|
294
|
+
const city = this.shadowRoot.getElementById('cityId').value;
|
|
295
|
+
const phone1 = this.shadowRoot.getElementById('phoneId').value;
|
|
296
|
+
const email = this.shadowRoot.getElementById('mailId').value;
|
|
297
|
+
|
|
298
|
+
const newErrorMap = new Map();
|
|
299
|
+
|
|
300
|
+
const reqFieldFunc = (field, key, type, mustMatch) => {
|
|
301
|
+
if (!field || field === '') {
|
|
302
|
+
newErrorMap.set(
|
|
303
|
+
key,
|
|
304
|
+
type !== 'phone'
|
|
305
|
+
? 'Vul dit veld in.'
|
|
306
|
+
: 'Vul dit veld in. Gebruik +32 494 667085.'
|
|
307
|
+
);
|
|
308
|
+
} else if (mustMatch && field !== mustMatch) {
|
|
309
|
+
newErrorMap.set(key, `Not match ${mustMatch}`);
|
|
310
|
+
} else {
|
|
311
|
+
switch (type) {
|
|
312
|
+
case 'vat':
|
|
313
|
+
// eslint-disable-next-line no-restricted-globals
|
|
314
|
+
if (!newErrorMap.has(key) && !PdContact._vatIsValid(field)) {
|
|
315
|
+
newErrorMap.set(key, 'Formaat BE0123456789 vereist');
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
case 'number':
|
|
319
|
+
// eslint-disable-next-line no-restricted-globals
|
|
320
|
+
if (!newErrorMap.has(key) && isNaN(field)) {
|
|
321
|
+
newErrorMap.set(key, 'Alleen nummers toegestaan');
|
|
322
|
+
}
|
|
323
|
+
break;
|
|
324
|
+
case 'mail':
|
|
325
|
+
if (!newErrorMap.has(key) && !PdContact._mailIsValid(field)) {
|
|
326
|
+
newErrorMap.set(key, 'Ongeldig e-mailadres');
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
case 'phone':
|
|
330
|
+
if (!newErrorMap.has(key) && !PdContact._phoneIsValid(field)) {
|
|
331
|
+
newErrorMap.set(
|
|
332
|
+
key,
|
|
333
|
+
'Ongeldig telefoonnummer, gebruik +32 494 667085.'
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
default:
|
|
338
|
+
console.warn('Undefined field: ', type);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
if (this.business) {
|
|
344
|
+
reqFieldFunc(companyName, 'companyName');
|
|
345
|
+
reqFieldFunc(vatNr, 'vatNr', 'vat');
|
|
346
|
+
} else {
|
|
347
|
+
reqFieldFunc(firstName, 'firstName');
|
|
348
|
+
reqFieldFunc(lastName, 'lastName');
|
|
349
|
+
}
|
|
350
|
+
reqFieldFunc(street, 'street');
|
|
351
|
+
reqFieldFunc(streetNr, 'streetNr');
|
|
352
|
+
reqFieldFunc(zip, 'zip', 'number', matchForValidate.zip);
|
|
353
|
+
reqFieldFunc(city, 'city');
|
|
354
|
+
reqFieldFunc(phone1, 'phone1', 'phone');
|
|
355
|
+
reqFieldFunc(email, 'email', 'mail');
|
|
356
|
+
this._errorMap = newErrorMap;
|
|
357
|
+
|
|
358
|
+
return new Promise((resolve, reject) => {
|
|
359
|
+
if (newErrorMap.size > 0) {
|
|
360
|
+
reject();
|
|
361
|
+
} else {
|
|
362
|
+
this.contact = {
|
|
363
|
+
business: this.business,
|
|
364
|
+
companyName,
|
|
365
|
+
vatNr,
|
|
366
|
+
firstName,
|
|
367
|
+
lastName,
|
|
368
|
+
street,
|
|
369
|
+
streetNr,
|
|
370
|
+
additionalHint,
|
|
371
|
+
zip,
|
|
372
|
+
city,
|
|
373
|
+
phone1,
|
|
374
|
+
email,
|
|
375
|
+
};
|
|
376
|
+
resolve(this.contact);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
static _mailIsValid(email) {
|
|
382
|
+
const mValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
383
|
+
return mValid;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
static _vatIsValid(vat) {
|
|
387
|
+
const mValid = /^BE[0-9]{10}/.test(vat);
|
|
388
|
+
return mValid;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
static _phoneIsValid(nr) {
|
|
392
|
+
// Valid +49 830 9001 | 49 221 123 | 08912379
|
|
393
|
+
const mValid = /^\+?[0-9 ]{7,15}$/.test(nr);
|
|
394
|
+
return mValid;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
_getErrorMsg(itemId) {
|
|
398
|
+
return this._errorMap.get(itemId) || '';
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
_getFullName() {
|
|
402
|
+
return PdContact._getFullVal(this.contact.firstName, this.contact.lastName);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
_getFullStreet() {
|
|
406
|
+
return PdContact._getFullVal(this.contact.street, this.contact.streetNr);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
_getFullLocation() {
|
|
410
|
+
return PdContact._getFullVal(this.contact.zip, this.contact.city);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
static _getFullVal(val1, val2, elseStr) {
|
|
414
|
+
let fullVal = '';
|
|
415
|
+
if (val1) {
|
|
416
|
+
fullVal += val1;
|
|
417
|
+
}
|
|
418
|
+
if (val2) {
|
|
419
|
+
fullVal += ` ${val2}`;
|
|
420
|
+
}
|
|
421
|
+
return fullVal.length === 0 ? elseStr : fullVal;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import '../pd-contact.js';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'PdContact',
|
|
6
|
+
component: 'pd-contact',
|
|
7
|
+
argTypes: {
|
|
8
|
+
title: { control: 'text' },
|
|
9
|
+
counter: { control: 'number' },
|
|
10
|
+
textColor: { control: 'color' },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function Template({ title = 'Hello world', counter = 5, textColor, slot }) {
|
|
15
|
+
return html`
|
|
16
|
+
<pd-contact
|
|
17
|
+
style="--pd-contact-text-color: ${textColor || 'black'}"
|
|
18
|
+
.title=${title}
|
|
19
|
+
.counter=${counter}
|
|
20
|
+
>
|
|
21
|
+
${slot}
|
|
22
|
+
</pd-contact>
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Regular = Template.bind({});
|
|
27
|
+
|
|
28
|
+
export const CustomTitle = Template.bind({});
|
|
29
|
+
CustomTitle.args = {
|
|
30
|
+
title: 'My title',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const CustomCounter = Template.bind({});
|
|
34
|
+
CustomCounter.args = {
|
|
35
|
+
counter: 123456,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const SlottedContent = Template.bind({});
|
|
39
|
+
SlottedContent.args = {
|
|
40
|
+
slot: html`<p>Slotted content</p>`,
|
|
41
|
+
};
|
|
42
|
+
SlottedContent.argTypes = {
|
|
43
|
+
slot: { table: { disable: true } },
|
|
44
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { fixture, expect } from '@open-wc/testing';
|
|
3
|
+
|
|
4
|
+
import '../pd-contact.js';
|
|
5
|
+
|
|
6
|
+
describe('PdContact', () => {
|
|
7
|
+
it('has a default title "Hey there" and counter 5', async () => {
|
|
8
|
+
const el = await fixture(html`<pd-contact></pd-contact>`);
|
|
9
|
+
|
|
10
|
+
expect(el.title).to.equal('Hey there');
|
|
11
|
+
expect(el.counter).to.equal(5);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('increases the counter on button click', async () => {
|
|
15
|
+
const el = await fixture(html`<pd-contact></pd-contact>`);
|
|
16
|
+
el.shadowRoot.querySelector('button').click();
|
|
17
|
+
|
|
18
|
+
expect(el.counter).to.equal(6);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('can override the title via attribute', async () => {
|
|
22
|
+
const el = await fixture(html`<pd-contact title="attribute title"></pd-contact>`);
|
|
23
|
+
|
|
24
|
+
expect(el.title).to.equal('attribute title');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('passes the a11y audit', async () => {
|
|
28
|
+
const el = await fixture(html`<pd-contact></pd-contact>`);
|
|
29
|
+
|
|
30
|
+
await expect(el).shadowDom.to.be.accessible();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
|
|
2
|
+
|
|
3
|
+
/** Use Hot Module replacement by adding --hmr to the start command */
|
|
4
|
+
const hmr = process.argv.includes('--hmr');
|
|
5
|
+
|
|
6
|
+
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
7
|
+
open: '/demo/',
|
|
8
|
+
/** Use regular watch mode if HMR is not enabled. */
|
|
9
|
+
watch: !hmr,
|
|
10
|
+
/** Resolve bare module imports */
|
|
11
|
+
nodeResolve: {
|
|
12
|
+
exportConditions: ['browser', 'development'],
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
16
|
+
// esbuildTarget: 'auto'
|
|
17
|
+
|
|
18
|
+
/** Set appIndex to enable SPA routing */
|
|
19
|
+
// appIndex: 'demo/index.html',
|
|
20
|
+
|
|
21
|
+
plugins: [
|
|
22
|
+
/** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
|
|
23
|
+
// hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
|
|
24
|
+
],
|
|
25
|
+
|
|
26
|
+
// See documentation for all available options
|
|
27
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// import { playwrightLauncher } from '@web/test-runner-playwright';
|
|
2
|
+
|
|
3
|
+
const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
|
|
4
|
+
|
|
5
|
+
export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
|
|
6
|
+
/** Test files to run */
|
|
7
|
+
files: 'test/**/*.test.js',
|
|
8
|
+
|
|
9
|
+
/** Resolve bare module imports */
|
|
10
|
+
nodeResolve: {
|
|
11
|
+
exportConditions: ['browser', 'development'],
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
/** Filter out lit dev mode logs */
|
|
15
|
+
filterBrowserLogs(log) {
|
|
16
|
+
for (const arg of log.args) {
|
|
17
|
+
if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
25
|
+
// esbuildTarget: 'auto',
|
|
26
|
+
|
|
27
|
+
/** Amount of browsers to run concurrently */
|
|
28
|
+
// concurrentBrowsers: 2,
|
|
29
|
+
|
|
30
|
+
/** Amount of test files per browser to test concurrently */
|
|
31
|
+
// concurrency: 1,
|
|
32
|
+
|
|
33
|
+
/** Browsers to run tests on */
|
|
34
|
+
// browsers: [
|
|
35
|
+
// playwrightLauncher({ product: 'chromium' }),
|
|
36
|
+
// playwrightLauncher({ product: 'firefox' }),
|
|
37
|
+
// playwrightLauncher({ product: 'webkit' }),
|
|
38
|
+
// ],
|
|
39
|
+
|
|
40
|
+
// See documentation for all available options
|
|
41
|
+
});
|