@progressive-development/pd-contact 0.1.68 → 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 +10 -0
- package/dist/locales/be.js +20 -0
- package/dist/locales/de.js +20 -0
- package/dist/locales/en.js +20 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-checkbox.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-form-container.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-form-row.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-hover-box.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-input.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-radio-group.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseInputElement.js +86 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseUi.js +33 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseUiInput.js +229 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdCheckbox.js +230 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdFormContainer.js +167 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdFormRow.js +92 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdHoverBox.js +108 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdInput.js +79 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdRadioGroup.js +72 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/shared-input-field-styles.js +152 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/shared-input-styles.js +64 -0
- package/dist/node_modules/@progressive-development/pd-icon/pd-icon.js +4 -0
- package/dist/node_modules/@progressive-development/pd-icon/src/PdIcon.js +595 -0
- package/dist/node_modules/lit-html/directive.js +27 -0
- package/dist/node_modules/lit-html/directives/class-map.js +36 -0
- package/dist/node_modules/lit-html/lit-html.js +242 -0
- package/dist/pd-contact.js +2 -0
- package/dist/src/PdContact.js +616 -0
- package/package.json +46 -22
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/server.mjs +0 -8
- package/demo/index.html +0 -29
- package/index.js +0 -1
- package/pd-contact.js +0 -3
- package/src/PdContact.js +0 -618
- package/stories/index.stories.js +0 -78
- package/test/pd-contact.test.js +0 -32
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
package/src/PdContact.js
DELETED
|
@@ -1,618 +0,0 @@
|
|
|
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 { PDFontStyles } from '@progressive-development/pd-shared-styles';
|
|
9
|
-
|
|
10
|
-
import '@progressive-development/pd-icon/pd-icon.js';
|
|
11
|
-
|
|
12
|
-
import '@progressive-development/pd-forms/pd-checkbox.js';
|
|
13
|
-
import '@progressive-development/pd-forms/pd-form-container.js';
|
|
14
|
-
import '@progressive-development/pd-forms/pd-form-row.js';
|
|
15
|
-
import '@progressive-development/pd-forms/pd-input.js';
|
|
16
|
-
import '@progressive-development/pd-forms/pd-radio-group.js';
|
|
17
|
-
|
|
18
|
-
const countryPrefixes = {
|
|
19
|
-
de: "+49", // Deutschland
|
|
20
|
-
be: "+32", // Belgien
|
|
21
|
-
nl: "+31", // Niederland
|
|
22
|
-
fr: "+33", // Frankreich
|
|
23
|
-
es: "+34", // Spanien
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function transformPhone(phone, country) {
|
|
27
|
-
if (!phone || typeof phone !== "string") {
|
|
28
|
-
return ""; // Ungültige Eingabe zurücksetzen
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Hol das Länderpräfix basierend auf dem übergebenen Land
|
|
32
|
-
const countryPrefix = countryPrefixes[country];
|
|
33
|
-
if (!countryPrefix) {
|
|
34
|
-
throw new Error(`Unbekanntes Land: ${country}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Entferne alle Leerzeichen und Sonderzeichen (außer "+")
|
|
38
|
-
const cleanedPhone = phone.replace(/\s+/g, "").replace(/[^0-9+]/g, "");
|
|
39
|
-
|
|
40
|
-
// Prüfe, ob die Nummer mit "+" beginnt (internationale Nummer)
|
|
41
|
-
if (cleanedPhone.startsWith("+")) {
|
|
42
|
-
return cleanedPhone; // Nummer ist bereits international
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Prüfe, ob die Nummer mit "0" beginnt und füge das Ländercode-Präfix hinzu
|
|
46
|
-
if (cleanedPhone.startsWith("0")) {
|
|
47
|
-
return countryPrefix + cleanedPhone.slice(1); // "0" durch Präfix ersetzen
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Wenn die Nummer weder mit "+" noch "0" beginnt, ist sie ungültig
|
|
51
|
-
return "";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export class PdContact extends LitElement {
|
|
56
|
-
static get styles() {
|
|
57
|
-
return [
|
|
58
|
-
PDFontStyles,
|
|
59
|
-
css`
|
|
60
|
-
:host {
|
|
61
|
-
display: block;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.contact {
|
|
65
|
-
display: flex;
|
|
66
|
-
flex-direction: column;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
address {
|
|
70
|
-
color: var(--pd-contact-address-col, var(--pd-default-font-content-col));
|
|
71
|
-
line-height: 1.8;
|
|
72
|
-
font-style: normal;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
dl {
|
|
76
|
-
margin: 0;
|
|
77
|
-
padding: 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
dt {
|
|
81
|
-
font-weight: bold;
|
|
82
|
-
padding-top: 10px;
|
|
83
|
-
color: var(--pd-contact-address-title-col, var(--pd-default-font-title-col));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
dd {
|
|
87
|
-
font-weight: 400;
|
|
88
|
-
font-size: 1em;
|
|
89
|
-
margin: 0;
|
|
90
|
-
padding: 0;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
dd.larger {
|
|
94
|
-
padding-top: 3px;
|
|
95
|
-
padding-bottom: 5px;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.contact-form {
|
|
99
|
-
--row-padding-top: 10px;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.link-icon {
|
|
103
|
-
--pd-icon-bg-col-active: #859900;
|
|
104
|
-
--pd-icon-bg-col-hover: #859900;
|
|
105
|
-
--pd-icon-size: 14px;
|
|
106
|
-
--pd-icon-stroke-col-active: white;
|
|
107
|
-
--pd-icon-col-active: white;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.link-item {
|
|
111
|
-
display: flex;
|
|
112
|
-
align-items: center;
|
|
113
|
-
text-decoration: none;
|
|
114
|
-
color: var(--pd-default-font-link-col, inherit);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.link-item:hover {
|
|
118
|
-
color: var(--pd-default-font-link-col-hover, #451A46) ;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
`];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
static get properties() {
|
|
125
|
-
return {
|
|
126
|
-
|
|
127
|
-
addressTitle: { type: String },
|
|
128
|
-
addressRef: { type: String },
|
|
129
|
-
/**
|
|
130
|
-
* show (true) or not (false) tel number as link
|
|
131
|
-
*/
|
|
132
|
-
phoneMailLink: { type: Boolean },
|
|
133
|
-
/**
|
|
134
|
-
* summary (true) or view (false) contact data
|
|
135
|
-
*/
|
|
136
|
-
summary: { type: Boolean },
|
|
137
|
-
/**
|
|
138
|
-
* List with required contact fields, if not set use default (previous existing values to be consitent during update)
|
|
139
|
-
*/
|
|
140
|
-
requiredFields: { type: Array },
|
|
141
|
-
contact: { type: Object },
|
|
142
|
-
match: { type: Object },
|
|
143
|
-
/**
|
|
144
|
-
* address type, business (true) or private (false), refactor, ist state internal? => _business, state:true
|
|
145
|
-
*/
|
|
146
|
-
_business: { type: Boolean, state: true },
|
|
147
|
-
_errorMap: { type: Object },
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
constructor() {
|
|
152
|
-
super();
|
|
153
|
-
this.addressTitle = 'Adres';
|
|
154
|
-
this.requiredFields = [];
|
|
155
|
-
this.summary = false;
|
|
156
|
-
this.match = {};
|
|
157
|
-
this._business = false;
|
|
158
|
-
this._errorMap = new Map();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
update(changedProperties) {
|
|
162
|
-
if (changedProperties.has("contact") && this.contact) {
|
|
163
|
-
this._business = this.contact.business;
|
|
164
|
-
}
|
|
165
|
-
super.update(changedProperties);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
connectedCallback() {
|
|
169
|
-
super.connectedCallback();
|
|
170
|
-
// add validation event listener
|
|
171
|
-
this.addEventListener('validate-form', this._validateForm);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
disconnectedCallback() {
|
|
175
|
-
super.connectedCallback();
|
|
176
|
-
// add validation event listener
|
|
177
|
-
this.removeEventListener('validate-form', this._validateForm);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
firstUpdated() {
|
|
181
|
-
this.addEventListener('key-pressed', e => {
|
|
182
|
-
this._errorMap.set(e.detail.name, '');
|
|
183
|
-
super.requestUpdate();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// first validation if form is already filled (edit)
|
|
187
|
-
if (this.contact) {
|
|
188
|
-
const detail = {
|
|
189
|
-
errorMap: new Map()
|
|
190
|
-
}
|
|
191
|
-
this.shadowRoot?.getElementById("contactContainerId")?.dispatchEvent(
|
|
192
|
-
new CustomEvent("validate-form", {detail})
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
render() {
|
|
198
|
-
return html`
|
|
199
|
-
<div class="contact">
|
|
200
|
-
${this.summary ? this._renderViewContact() : this._renderEditContact()}
|
|
201
|
-
</div>
|
|
202
|
-
`;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
_renderEditContact() {
|
|
206
|
-
return html`
|
|
207
|
-
<pd-form-container id="contactContainerId" requiredFieldInfo>
|
|
208
|
-
<pd-form-row id="testFormId">
|
|
209
|
-
<pd-radio-group
|
|
210
|
-
class="quarter3"
|
|
211
|
-
label="Type"
|
|
212
|
-
required
|
|
213
|
-
value="${this._getRadioValue()}"
|
|
214
|
-
@field-change="${this._switchAddressType}"
|
|
215
|
-
style="--group-gap: 20px;"
|
|
216
|
-
>
|
|
217
|
-
<pd-checkbox value="${this.contact ? !this.contact.business : true}" valueName="private"
|
|
218
|
-
>Particulier</pd-checkbox
|
|
219
|
-
>
|
|
220
|
-
<pd-checkbox valueName="business" value="${this.contact ? this.contact.business : false}">Onderneming</pd-checkbox>
|
|
221
|
-
</pd-radio-group>
|
|
222
|
-
</pd-form-row>
|
|
223
|
-
|
|
224
|
-
${this._business
|
|
225
|
-
? html`
|
|
226
|
-
<pd-form-row class="contact-form">
|
|
227
|
-
<pd-input
|
|
228
|
-
id="compNameId"
|
|
229
|
-
class="quarter3"
|
|
230
|
-
label="Naam onderneming"
|
|
231
|
-
?required="${this._isRequired("companyName")}"
|
|
232
|
-
value="${this.contact ? this.contact.companyName : ""}"
|
|
233
|
-
valueName="companyName"
|
|
234
|
-
autoCompleteName="organization"
|
|
235
|
-
></pd-input>
|
|
236
|
-
</pd-form-row>
|
|
237
|
-
<pd-form-row class="contact-form">
|
|
238
|
-
<pd-input
|
|
239
|
-
id="vatId"
|
|
240
|
-
class="quarter3"
|
|
241
|
-
label="Ondernemingsnr"
|
|
242
|
-
?required="${this._isRequired("vatNr")}"
|
|
243
|
-
field-type="vat"
|
|
244
|
-
valueName="vatNr"
|
|
245
|
-
value="${this.contact ? this.contact.vatNr : ""}"
|
|
246
|
-
autoCompleteName="vat"
|
|
247
|
-
></pd-input>
|
|
248
|
-
</pd-form-row>
|
|
249
|
-
`
|
|
250
|
-
: html`
|
|
251
|
-
<pd-form-row class="contact-form">
|
|
252
|
-
<pd-input
|
|
253
|
-
id="firstNameId"
|
|
254
|
-
class="quarter3"
|
|
255
|
-
label="Voornaam"
|
|
256
|
-
valueName="firstName"
|
|
257
|
-
value="${this.contact ? this.contact.firstName : ""}"
|
|
258
|
-
autoCompleteName="given-name"
|
|
259
|
-
?required="${this._isRequired("firstName")}"
|
|
260
|
-
></pd-input>
|
|
261
|
-
</pd-form-row>
|
|
262
|
-
<pd-form-row class="contact-form">
|
|
263
|
-
<pd-input
|
|
264
|
-
id="lastNameId"
|
|
265
|
-
class="quarter3"
|
|
266
|
-
label="Naam"
|
|
267
|
-
valueName="lastName"
|
|
268
|
-
value="${this.contact ? this.contact.lastName : ""}"
|
|
269
|
-
autoCompleteName="family-name"
|
|
270
|
-
?required="${this._isRequired("lastName")}"
|
|
271
|
-
></pd-input>
|
|
272
|
-
</pd-form-row>
|
|
273
|
-
`}
|
|
274
|
-
<pd-form-row class="contact-form">
|
|
275
|
-
<pd-input
|
|
276
|
-
id="streetId"
|
|
277
|
-
class="quarter2"
|
|
278
|
-
label="Straat"
|
|
279
|
-
valueName="street"
|
|
280
|
-
value="${this.contact ? this.contact.street : ""}"
|
|
281
|
-
autoCompleteName="street-address"
|
|
282
|
-
?required="${this._isRequired("street")}"
|
|
283
|
-
></pd-input>
|
|
284
|
-
<pd-input
|
|
285
|
-
id="streetNrId"
|
|
286
|
-
class="quarter1"
|
|
287
|
-
label="Nr"
|
|
288
|
-
valueName="streetNr"
|
|
289
|
-
value="${this.contact ? this.contact.streetNr : ""}"
|
|
290
|
-
?required="${this._isRequired("streetNr")}"
|
|
291
|
-
></pd-input>
|
|
292
|
-
</pd-form-row>
|
|
293
|
-
<pd-form-row class="contact-form">
|
|
294
|
-
${this.match && this.match.zip
|
|
295
|
-
? html`
|
|
296
|
-
<pd-input
|
|
297
|
-
readonly
|
|
298
|
-
id="zipId"
|
|
299
|
-
class="quarter1"
|
|
300
|
-
label="Postcode"
|
|
301
|
-
valueName="zip"
|
|
302
|
-
value="${this.match ? this.match.zip || '' : ''}"
|
|
303
|
-
></pd-input>
|
|
304
|
-
`
|
|
305
|
-
: html`
|
|
306
|
-
<pd-input
|
|
307
|
-
id="zipId"
|
|
308
|
-
class="quarter1"
|
|
309
|
-
label="Postcode"
|
|
310
|
-
field-type="number"
|
|
311
|
-
valueName="zip"
|
|
312
|
-
value="${this.contact ? this.contact.zip : ""}"
|
|
313
|
-
autoCompleteName="postal-code"
|
|
314
|
-
?required="${this._isRequired("zip")}"
|
|
315
|
-
></pd-input>
|
|
316
|
-
`}
|
|
317
|
-
<pd-input
|
|
318
|
-
id="cityId"
|
|
319
|
-
class="quarter2"
|
|
320
|
-
label="Plaats"
|
|
321
|
-
valueName="city"
|
|
322
|
-
value="${this.contact ? this.contact.city : ""}"
|
|
323
|
-
autoCompleteName="locality"
|
|
324
|
-
?required="${this._isRequired("city")}"
|
|
325
|
-
></pd-input>
|
|
326
|
-
</pd-form-row>
|
|
327
|
-
<pd-form-row class="contact-form">
|
|
328
|
-
<pd-input
|
|
329
|
-
class="quarter3"
|
|
330
|
-
id="additionalHintId"
|
|
331
|
-
label="Extra informatie"
|
|
332
|
-
value="${this.contact ? this.contact.additionalHint : ""}"
|
|
333
|
-
></pd-input>
|
|
334
|
-
</pd-form-row>
|
|
335
|
-
<pd-form-row class="contact-form">
|
|
336
|
-
<pd-input
|
|
337
|
-
id="phoneId"
|
|
338
|
-
class="quarter3"
|
|
339
|
-
label="Telefoon"
|
|
340
|
-
name="phone"
|
|
341
|
-
valueName="phone1"
|
|
342
|
-
value="${this.contact ? this.contact.phone1 : ""}"
|
|
343
|
-
field-type="phone"
|
|
344
|
-
autoCompleteName="tel"
|
|
345
|
-
?required="${this._isRequired("phone1")}"
|
|
346
|
-
></pd-input>
|
|
347
|
-
</pd-form-row>
|
|
348
|
-
<pd-form-row class="contact-form">
|
|
349
|
-
<pd-input
|
|
350
|
-
id="mailId"
|
|
351
|
-
class="quarter3"
|
|
352
|
-
label="E-mail"
|
|
353
|
-
field-type="mail"
|
|
354
|
-
valueName="email"
|
|
355
|
-
value="${this.contact ? this.contact.email : ""}"
|
|
356
|
-
autoCompleteName="email"
|
|
357
|
-
?required="${this._isRequired("email")}"
|
|
358
|
-
></pd-input>
|
|
359
|
-
</pd-form-row>
|
|
360
|
-
</pd-form-container>
|
|
361
|
-
`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
_getRadioValue() {
|
|
365
|
-
if (this.contact) {
|
|
366
|
-
return this.contact.business ? "business" : "private";
|
|
367
|
-
}
|
|
368
|
-
return "private";
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
_renderViewContact() {
|
|
372
|
-
const trPhoneNr = transformPhone(this.contact.phone1, this.contact.country || "be");
|
|
373
|
-
return html`
|
|
374
|
-
<address>
|
|
375
|
-
<dl>
|
|
376
|
-
<dt>${this.addressTitle}</dt>
|
|
377
|
-
${this.contact
|
|
378
|
-
? html`
|
|
379
|
-
<dd>${this.contact.companyName}</dd>
|
|
380
|
-
<dd>${this.contact.vatNr}</dd>
|
|
381
|
-
<dd>${this._getFullName()}</dd>
|
|
382
|
-
<dd>${this._getFullStreet()}</dd>
|
|
383
|
-
<dd>${this._getFullLocation()}</dd>
|
|
384
|
-
${this.contact.additionalHint ? html`<dd>${this.contact.additionalHint}</dd>` : ''}
|
|
385
|
-
<dd>${this.contact.country}</dd>
|
|
386
|
-
|
|
387
|
-
${this.contact.phone1 ? html`
|
|
388
|
-
<dd class="larger">${this.phoneMailLink && trPhoneNr ? html`
|
|
389
|
-
<a href="${`tel:${trPhoneNr}`}"
|
|
390
|
-
aria-label="${`Phone call: ${this.contact.phone1}`}"
|
|
391
|
-
class="link-item">
|
|
392
|
-
<span style="margin-right: 8px;">${this.contact.phone1}</span>
|
|
393
|
-
<pd-icon activeIcon icon="phoneIcon" class="round link-icon"></pd-icon>
|
|
394
|
-
</a>
|
|
395
|
-
` : this.contact.phone1}</dd>
|
|
396
|
-
` : ''}
|
|
397
|
-
|
|
398
|
-
${this.contact.email ? html`
|
|
399
|
-
<dd class="larger">${this.phoneMailLink ? html`
|
|
400
|
-
<a href="${`mailto:${this.contact.email}`}"
|
|
401
|
-
aria-label="${`Send mail: ${this.contact.email}`}"
|
|
402
|
-
class="link-item">
|
|
403
|
-
<span style="margin-right: 8px;">${this.contact.email}</span>
|
|
404
|
-
<pd-icon activeIcon icon="mailIcon" class="round link-icon"></pd-icon>
|
|
405
|
-
</a>
|
|
406
|
-
` : this.contact.email}</dd>
|
|
407
|
-
` : ''}
|
|
408
|
-
|
|
409
|
-
${this.contact.btw
|
|
410
|
-
? html`<dt>BTW</dt>
|
|
411
|
-
<dd>${this.contact.btw}</dd>`
|
|
412
|
-
: ''}
|
|
413
|
-
${this.contact.kbc
|
|
414
|
-
? html`<dt>Bankgegevens</dt>
|
|
415
|
-
<dd>${this.contact.kbc}</dd>
|
|
416
|
-
<dd>${this.contact.bank}</dd>`
|
|
417
|
-
: ''}
|
|
418
|
-
`
|
|
419
|
-
: html`${this.addressRef || '--'}`}
|
|
420
|
-
</dl>
|
|
421
|
-
</address>
|
|
422
|
-
`;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
_switchAddressType(e) {
|
|
426
|
-
this._business = e.detail.name === 'business';
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
_isRequired(field) {
|
|
430
|
-
return this.requiredFields && this.requiredFields.length > 0 ?
|
|
431
|
-
this.requiredFields.includes(field) : false;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/*
|
|
435
|
-
validateInput() {
|
|
436
|
-
const matchForValidate = this.match || {};
|
|
437
|
-
|
|
438
|
-
const companyName = this.business
|
|
439
|
-
? this.shadowRoot.getElementById('compNameId').value
|
|
440
|
-
: undefined;
|
|
441
|
-
const vatNr = this.business
|
|
442
|
-
? this.shadowRoot.getElementById('vatId').value
|
|
443
|
-
: undefined;
|
|
444
|
-
const firstName = this.business
|
|
445
|
-
? undefined
|
|
446
|
-
: this.shadowRoot.getElementById('firstNameId').value;
|
|
447
|
-
const lastName = this.business
|
|
448
|
-
? undefined
|
|
449
|
-
: this.shadowRoot.getElementById('lastNameId').value;
|
|
450
|
-
const street = this.shadowRoot.getElementById('streetId').value;
|
|
451
|
-
const streetNr = this.shadowRoot.getElementById('streetNrId').value;
|
|
452
|
-
const additionalHint =
|
|
453
|
-
this.shadowRoot.getElementById('additionalHintId').value;
|
|
454
|
-
const zip = this.shadowRoot.getElementById('zipId').value;
|
|
455
|
-
const city = this.shadowRoot.getElementById('cityId').value;
|
|
456
|
-
const phone1 = this.shadowRoot.getElementById('phoneId').value;
|
|
457
|
-
const email = this.shadowRoot.getElementById('mailId').value;
|
|
458
|
-
|
|
459
|
-
const newErrorMap = new Map();
|
|
460
|
-
|
|
461
|
-
const reqFieldFunc = (field, key, type, mustMatch) => {
|
|
462
|
-
if (!field || field === '') {
|
|
463
|
-
newErrorMap.set(
|
|
464
|
-
key,
|
|
465
|
-
type !== 'phone'
|
|
466
|
-
? 'Vul dit veld in.'
|
|
467
|
-
: 'Vul dit veld in. Gebruik +32 494 667085.'
|
|
468
|
-
);
|
|
469
|
-
} else if (mustMatch && field !== mustMatch) {
|
|
470
|
-
newErrorMap.set(key, `Not match ${mustMatch}`);
|
|
471
|
-
} else {
|
|
472
|
-
switch (type) {
|
|
473
|
-
case 'vat':
|
|
474
|
-
// eslint-disable-next-line no-restricted-globals
|
|
475
|
-
if (!newErrorMap.has(key) && !PdContact._vatIsValid(field)) {
|
|
476
|
-
newErrorMap.set(key, 'Formaat BE0123456789 vereist');
|
|
477
|
-
}
|
|
478
|
-
break;
|
|
479
|
-
case 'number':
|
|
480
|
-
// eslint-disable-next-line no-restricted-globals
|
|
481
|
-
if (!newErrorMap.has(key) && isNaN(field)) {
|
|
482
|
-
newErrorMap.set(key, 'Alleen nummers toegestaan');
|
|
483
|
-
}
|
|
484
|
-
break;
|
|
485
|
-
case 'mail':
|
|
486
|
-
if (!newErrorMap.has(key) && !PdContact._mailIsValid(field)) {
|
|
487
|
-
newErrorMap.set(key, 'Ongeldig e-mailadres');
|
|
488
|
-
}
|
|
489
|
-
break;
|
|
490
|
-
case 'phone':
|
|
491
|
-
if (!newErrorMap.has(key) && !PdContact._phoneIsValid(field)) {
|
|
492
|
-
newErrorMap.set(
|
|
493
|
-
key,
|
|
494
|
-
'Ongeldig telefoonnummer, gebruik +32 494 667085.'
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
break;
|
|
498
|
-
default:
|
|
499
|
-
console.warn('Undefined field: ', type);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
if (this.business) {
|
|
505
|
-
reqFieldFunc(companyName, 'companyName');
|
|
506
|
-
reqFieldFunc(vatNr, 'vatNr', 'vat');
|
|
507
|
-
} else {
|
|
508
|
-
reqFieldFunc(firstName, 'firstName');
|
|
509
|
-
reqFieldFunc(lastName, 'lastName');
|
|
510
|
-
}
|
|
511
|
-
reqFieldFunc(street, 'street');
|
|
512
|
-
reqFieldFunc(streetNr, 'streetNr');
|
|
513
|
-
reqFieldFunc(zip, 'zip', 'number', matchForValidate.zip);
|
|
514
|
-
reqFieldFunc(city, 'city');
|
|
515
|
-
reqFieldFunc(phone1, 'phone1', 'phone');
|
|
516
|
-
reqFieldFunc(email, 'email', 'mail');
|
|
517
|
-
this._errorMap = newErrorMap;
|
|
518
|
-
|
|
519
|
-
return new Promise((resolve, reject) => {
|
|
520
|
-
if (newErrorMap.size > 0) {
|
|
521
|
-
reject();
|
|
522
|
-
} else {
|
|
523
|
-
this.contact = {
|
|
524
|
-
business: this.business,
|
|
525
|
-
companyName,
|
|
526
|
-
vatNr,
|
|
527
|
-
firstName,
|
|
528
|
-
lastName,
|
|
529
|
-
street,
|
|
530
|
-
streetNr,
|
|
531
|
-
additionalHint,
|
|
532
|
-
zip,
|
|
533
|
-
city,
|
|
534
|
-
phone1,
|
|
535
|
-
email,
|
|
536
|
-
};
|
|
537
|
-
resolve(this.contact);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
*/
|
|
542
|
-
|
|
543
|
-
_validateForm(e) {
|
|
544
|
-
if (e.detail && !e.detail.singleElement) {
|
|
545
|
-
this.shadowRoot.getElementById("contactContainerId").dispatchEvent(
|
|
546
|
-
new CustomEvent("validate-form", {
|
|
547
|
-
detail: e.detail
|
|
548
|
-
})
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
// set prepared form, if no validation error occured
|
|
552
|
-
if (e.detail.errorMap.size === 0 && e.detail.formData) {
|
|
553
|
-
e.detail.formData[this.id] = this._setFormData();
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
_setFormData() {
|
|
559
|
-
const companyName = this._business
|
|
560
|
-
? this.shadowRoot.getElementById('compNameId').value
|
|
561
|
-
: undefined;
|
|
562
|
-
const vatNr = this._business
|
|
563
|
-
? this.shadowRoot.getElementById('vatId').value
|
|
564
|
-
: undefined;
|
|
565
|
-
const firstName = this._business
|
|
566
|
-
? undefined
|
|
567
|
-
: this.shadowRoot.getElementById('firstNameId').value;
|
|
568
|
-
const lastName = this._business
|
|
569
|
-
? undefined
|
|
570
|
-
: this.shadowRoot.getElementById('lastNameId').value;
|
|
571
|
-
const street = this.shadowRoot.getElementById('streetId').value;
|
|
572
|
-
const streetNr = this.shadowRoot.getElementById('streetNrId').value;
|
|
573
|
-
const additionalHint =
|
|
574
|
-
this.shadowRoot.getElementById('additionalHintId').value;
|
|
575
|
-
const zip = this.shadowRoot.getElementById('zipId').value;
|
|
576
|
-
const city = this.shadowRoot.getElementById('cityId').value;
|
|
577
|
-
const phone1 = this.shadowRoot.getElementById('phoneId').value;
|
|
578
|
-
const email = this.shadowRoot.getElementById('mailId').value;
|
|
579
|
-
|
|
580
|
-
return {
|
|
581
|
-
business: this._business,
|
|
582
|
-
companyName,
|
|
583
|
-
vatNr,
|
|
584
|
-
firstName,
|
|
585
|
-
lastName,
|
|
586
|
-
street,
|
|
587
|
-
streetNr,
|
|
588
|
-
additionalHint,
|
|
589
|
-
zip,
|
|
590
|
-
city,
|
|
591
|
-
phone1,
|
|
592
|
-
email,
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
_getFullName() {
|
|
597
|
-
return PdContact._getFullVal(this.contact.firstName, this.contact.lastName);
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
_getFullStreet() {
|
|
601
|
-
return PdContact._getFullVal(this.contact.street, this.contact.streetNr);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
_getFullLocation() {
|
|
605
|
-
return PdContact._getFullVal(this.contact.zip, this.contact.city);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
static _getFullVal(val1, val2, elseStr) {
|
|
609
|
-
let fullVal = '';
|
|
610
|
-
if (val1) {
|
|
611
|
-
fullVal += val1;
|
|
612
|
-
}
|
|
613
|
-
if (val2) {
|
|
614
|
-
fullVal += ` ${val2}`;
|
|
615
|
-
}
|
|
616
|
-
return fullVal.length === 0 ? elseStr : fullVal;
|
|
617
|
-
}
|
|
618
|
-
}
|
package/stories/index.stories.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { html } from 'lit';
|
|
2
|
-
import '../pd-contact.js';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
title: 'PdContact/Contact',
|
|
6
|
-
component: 'pd-contact',
|
|
7
|
-
argTypes: {
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function Template() {
|
|
12
|
-
return html`
|
|
13
|
-
<h3>Edit Contact</h3>
|
|
14
|
-
<pd-contact></pd-contact>
|
|
15
|
-
`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function TemplateView({summary, phoneMailLink}) {
|
|
19
|
-
console.log(summary);
|
|
20
|
-
return html`
|
|
21
|
-
<h3>View Contact</h3>
|
|
22
|
-
<pd-contact ?summary="${summary}" ?phoneMailLink="${phoneMailLink}" .contact="${{
|
|
23
|
-
firstName: 'Peter',
|
|
24
|
-
lastName: 'Musterman',
|
|
25
|
-
street: 'Musterstrasse',
|
|
26
|
-
streetNr: '23b',
|
|
27
|
-
zip: '9040',
|
|
28
|
-
city: 'Gent',
|
|
29
|
-
phone1: '0221 992344234',
|
|
30
|
-
mobil: '0175/9923443',
|
|
31
|
-
email: 'peter@muster.be'
|
|
32
|
-
}}"></pd-contact>`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function TemplateViewBusiness({summary}) {
|
|
36
|
-
console.log(summary);
|
|
37
|
-
return html`
|
|
38
|
-
<h3>View Contact</h3>
|
|
39
|
-
<pd-contact ?summary="${summary}" .contact="${{
|
|
40
|
-
business: true,
|
|
41
|
-
companyName: 'PD Progressive Develpoment',
|
|
42
|
-
vatNr: "DE0123456789",
|
|
43
|
-
street: 'Musterstrasse',
|
|
44
|
-
streetNr: '23b',
|
|
45
|
-
zip: '9040',
|
|
46
|
-
city: 'Gent',
|
|
47
|
-
phone1: '0221 992344234',
|
|
48
|
-
mobil: '0175/9923443',
|
|
49
|
-
email: 'peter@muster.be'
|
|
50
|
-
}}"></pd-contact>`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const ContactForm = Template.bind({});
|
|
54
|
-
ContactForm.args = {
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const ContactView = TemplateView.bind({});
|
|
58
|
-
ContactView.args = {
|
|
59
|
-
summary: "true"
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const ContactViewPhone = TemplateView.bind({});
|
|
63
|
-
ContactViewPhone.args = {
|
|
64
|
-
summary: "true",
|
|
65
|
-
phoneMailLink: "true"
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const ContactPreparedForm = TemplateView.bind({});
|
|
69
|
-
ContactView.args = {
|
|
70
|
-
summary: "false"
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const ContactPreparedFormCompany = TemplateViewBusiness.bind({});
|
|
74
|
-
ContactView.args = {
|
|
75
|
-
summary: "false",
|
|
76
|
-
phoneCallLink: "false"
|
|
77
|
-
};
|
|
78
|
-
|