@progressive-development/pd-contact 0.1.63 → 0.1.65
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 +3 -2
- package/src/PdContact.js +82 -21
- package/stories/index.stories.js +11 -3
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Progressive Development Contact component",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"author": "PD Progressive Development",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.65",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.js",
|
|
9
9
|
"scripts": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"storybook:build": "npm run analyze -- --exclude dist && build-storybook"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@progressive-development/pd-forms": "^0.2.
|
|
20
|
+
"@progressive-development/pd-forms": "^0.2.15",
|
|
21
|
+
"@progressive-development/pd-icon": "^0.1.21",
|
|
21
22
|
"@progressive-development/pd-shared-styles": "^0.1.1",
|
|
22
23
|
"lit": "^2.2.0"
|
|
23
24
|
},
|
package/src/PdContact.js
CHANGED
|
@@ -7,13 +7,51 @@
|
|
|
7
7
|
|
|
8
8
|
import { PDFontStyles } from '@progressive-development/pd-shared-styles';
|
|
9
9
|
|
|
10
|
+
import '@progressive-development/pd-icon/pd-icon.js';
|
|
11
|
+
|
|
10
12
|
import '@progressive-development/pd-forms/pd-checkbox.js';
|
|
11
13
|
import '@progressive-development/pd-forms/pd-form-container.js';
|
|
12
14
|
import '@progressive-development/pd-forms/pd-form-row.js';
|
|
13
15
|
import '@progressive-development/pd-forms/pd-input.js';
|
|
14
16
|
import '@progressive-development/pd-forms/pd-radio-group.js';
|
|
15
17
|
|
|
16
|
-
|
|
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
|
+
|
|
17
55
|
export class PdContact extends LitElement {
|
|
18
56
|
static get styles() {
|
|
19
57
|
return [
|
|
@@ -55,6 +93,10 @@
|
|
|
55
93
|
.contact-form {
|
|
56
94
|
--row-padding-top: 10px;
|
|
57
95
|
}
|
|
96
|
+
|
|
97
|
+
.phone-icon {
|
|
98
|
+
|
|
99
|
+
}
|
|
58
100
|
`];
|
|
59
101
|
}
|
|
60
102
|
|
|
@@ -63,6 +105,10 @@
|
|
|
63
105
|
|
|
64
106
|
addressTitle: { type: String },
|
|
65
107
|
addressRef: { type: String },
|
|
108
|
+
/**
|
|
109
|
+
* show (true) or not (false) tel number as link
|
|
110
|
+
*/
|
|
111
|
+
phoneCallLink: { type: Boolean },
|
|
66
112
|
/**
|
|
67
113
|
* summary (true) or view (false) contact data
|
|
68
114
|
*/
|
|
@@ -140,7 +186,7 @@
|
|
|
140
186
|
<pd-form-container id="contactContainerId" requiredFieldInfo>
|
|
141
187
|
<pd-form-row id="testFormId">
|
|
142
188
|
<pd-radio-group
|
|
143
|
-
class="
|
|
189
|
+
class="quarter3"
|
|
144
190
|
label="Type"
|
|
145
191
|
required
|
|
146
192
|
value="${this._getRadioValue()}"
|
|
@@ -159,16 +205,18 @@
|
|
|
159
205
|
<pd-form-row class="contact-form">
|
|
160
206
|
<pd-input
|
|
161
207
|
id="compNameId"
|
|
162
|
-
class="
|
|
208
|
+
class="quarter3"
|
|
163
209
|
label="Naam onderneming"
|
|
164
210
|
?required="${this._isRequired("companyName")}"
|
|
165
211
|
value="${this.contact ? this.contact.companyName : ""}"
|
|
166
212
|
valueName="companyName"
|
|
167
213
|
autoCompleteName="organization"
|
|
168
214
|
></pd-input>
|
|
215
|
+
</pd-form-row>
|
|
216
|
+
<pd-form-row class="contact-form">
|
|
169
217
|
<pd-input
|
|
170
218
|
id="vatId"
|
|
171
|
-
class="
|
|
219
|
+
class="quarter3"
|
|
172
220
|
label="Ondernemingsnr"
|
|
173
221
|
?required="${this._isRequired("vatNr")}"
|
|
174
222
|
field-type="vat"
|
|
@@ -182,16 +230,18 @@
|
|
|
182
230
|
<pd-form-row class="contact-form">
|
|
183
231
|
<pd-input
|
|
184
232
|
id="firstNameId"
|
|
185
|
-
class="
|
|
233
|
+
class="quarter3"
|
|
186
234
|
label="Voornaam"
|
|
187
235
|
valueName="firstName"
|
|
188
236
|
value="${this.contact ? this.contact.firstName : ""}"
|
|
189
237
|
autoCompleteName="given-name"
|
|
190
238
|
?required="${this._isRequired("firstName")}"
|
|
191
239
|
></pd-input>
|
|
240
|
+
</pd-form-row>
|
|
241
|
+
<pd-form-row class="contact-form">
|
|
192
242
|
<pd-input
|
|
193
243
|
id="lastNameId"
|
|
194
|
-
class="
|
|
244
|
+
class="quarter3"
|
|
195
245
|
label="Naam"
|
|
196
246
|
valueName="lastName"
|
|
197
247
|
value="${this.contact ? this.contact.lastName : ""}"
|
|
@@ -203,7 +253,7 @@
|
|
|
203
253
|
<pd-form-row class="contact-form">
|
|
204
254
|
<pd-input
|
|
205
255
|
id="streetId"
|
|
206
|
-
class="
|
|
256
|
+
class="quarter2"
|
|
207
257
|
label="Straat"
|
|
208
258
|
valueName="street"
|
|
209
259
|
value="${this.contact ? this.contact.street : ""}"
|
|
@@ -218,22 +268,14 @@
|
|
|
218
268
|
value="${this.contact ? this.contact.streetNr : ""}"
|
|
219
269
|
?required="${this._isRequired("streetNr")}"
|
|
220
270
|
></pd-input>
|
|
221
|
-
</pd-form-row>
|
|
222
|
-
<pd-form-row class="contact-form">
|
|
223
|
-
<pd-input
|
|
224
|
-
class="quarter4"
|
|
225
|
-
id="additionalHintId"
|
|
226
|
-
label="Extra informatie"
|
|
227
|
-
value="${this.contact ? this.contact.additionalHint : ""}"
|
|
228
|
-
></pd-input>
|
|
229
|
-
</pd-form-row>
|
|
271
|
+
</pd-form-row>
|
|
230
272
|
<pd-form-row class="contact-form">
|
|
231
273
|
${this.match && this.match.zip
|
|
232
274
|
? html`
|
|
233
275
|
<pd-input
|
|
234
276
|
readonly
|
|
235
277
|
id="zipId"
|
|
236
|
-
class="
|
|
278
|
+
class="quarter1"
|
|
237
279
|
label="Postcode"
|
|
238
280
|
valueName="zip"
|
|
239
281
|
value="${this.match ? this.match.zip || '' : ''}"
|
|
@@ -242,7 +284,7 @@
|
|
|
242
284
|
: html`
|
|
243
285
|
<pd-input
|
|
244
286
|
id="zipId"
|
|
245
|
-
class="
|
|
287
|
+
class="quarter1"
|
|
246
288
|
label="Postcode"
|
|
247
289
|
field-type="number"
|
|
248
290
|
valueName="zip"
|
|
@@ -261,10 +303,18 @@
|
|
|
261
303
|
?required="${this._isRequired("city")}"
|
|
262
304
|
></pd-input>
|
|
263
305
|
</pd-form-row>
|
|
306
|
+
<pd-form-row class="contact-form">
|
|
307
|
+
<pd-input
|
|
308
|
+
class="quarter3"
|
|
309
|
+
id="additionalHintId"
|
|
310
|
+
label="Extra informatie"
|
|
311
|
+
value="${this.contact ? this.contact.additionalHint : ""}"
|
|
312
|
+
></pd-input>
|
|
313
|
+
</pd-form-row>
|
|
264
314
|
<pd-form-row class="contact-form">
|
|
265
315
|
<pd-input
|
|
266
316
|
id="phoneId"
|
|
267
|
-
class="
|
|
317
|
+
class="quarter3"
|
|
268
318
|
label="Telefoon"
|
|
269
319
|
name="phone"
|
|
270
320
|
valueName="phone1"
|
|
@@ -273,9 +323,11 @@
|
|
|
273
323
|
autoCompleteName="tel"
|
|
274
324
|
?required="${this._isRequired("phone1")}"
|
|
275
325
|
></pd-input>
|
|
326
|
+
</pd-form-row>
|
|
327
|
+
<pd-form-row class="contact-form">
|
|
276
328
|
<pd-input
|
|
277
329
|
id="mailId"
|
|
278
|
-
class="
|
|
330
|
+
class="quarter3"
|
|
279
331
|
label="E-mail"
|
|
280
332
|
field-type="mail"
|
|
281
333
|
valueName="email"
|
|
@@ -296,6 +348,7 @@
|
|
|
296
348
|
}
|
|
297
349
|
|
|
298
350
|
_renderViewContact() {
|
|
351
|
+
const trPhoneNr = transformPhone(this.contact.phone1, this.contact.country || "de");
|
|
299
352
|
return html`
|
|
300
353
|
<address>
|
|
301
354
|
<dl>
|
|
@@ -307,8 +360,16 @@
|
|
|
307
360
|
<dd>${this._getFullName()}</dd>
|
|
308
361
|
<dd>${this._getFullStreet()}</dd>
|
|
309
362
|
<dd>${this._getFullLocation()}</dd>
|
|
363
|
+
${this.contact.additionalHint ? html`<dd>${this.contact.additionalHint}</dd>` : ''}
|
|
310
364
|
<dd>${this.contact.country}</dd>
|
|
311
|
-
<dd>${this.
|
|
365
|
+
<dd>${this.phoneCallLink && trPhoneNr ? html`
|
|
366
|
+
<a href="${`tel:${trPhoneNr}`}"
|
|
367
|
+
aria-label="${`Phone call: ${this.contact.phone1}`}"
|
|
368
|
+
style="display: flex; align-items: center; text-decoration: none; color: inherit;">
|
|
369
|
+
<span style="margin-right: 8px;">${this.contact.phone1}</span>
|
|
370
|
+
<pd-icon icon="phoneIcon" class="round small phone-icon"></pd-icon>
|
|
371
|
+
</a>
|
|
372
|
+
` : this.contact.phone1}</dd>
|
|
312
373
|
<dd>${this.contact.email}</dd>
|
|
313
374
|
|
|
314
375
|
${this.contact.btw
|
package/stories/index.stories.js
CHANGED
|
@@ -15,11 +15,11 @@ function Template() {
|
|
|
15
15
|
`;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function TemplateView({summary}) {
|
|
18
|
+
function TemplateView({summary, phoneCallLink}) {
|
|
19
19
|
console.log(summary);
|
|
20
20
|
return html`
|
|
21
21
|
<h3>View Contact</h3>
|
|
22
|
-
<pd-contact ?summary="${summary}" .contact="${{
|
|
22
|
+
<pd-contact ?summary="${summary}" ?phoneCallLink="${phoneCallLink}" .contact="${{
|
|
23
23
|
firstName: 'Peter',
|
|
24
24
|
lastName: 'Musterman',
|
|
25
25
|
street: 'Musterstrasse',
|
|
@@ -59,6 +59,12 @@ ContactView.args = {
|
|
|
59
59
|
summary: "true"
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
export const ContactViewPhone = TemplateView.bind({});
|
|
63
|
+
ContactViewPhone.args = {
|
|
64
|
+
summary: "true",
|
|
65
|
+
phoneCallLink: "true"
|
|
66
|
+
};
|
|
67
|
+
|
|
62
68
|
export const ContactPreparedForm = TemplateView.bind({});
|
|
63
69
|
ContactView.args = {
|
|
64
70
|
summary: "false"
|
|
@@ -66,5 +72,7 @@ ContactView.args = {
|
|
|
66
72
|
|
|
67
73
|
export const ContactPreparedFormCompany = TemplateViewBusiness.bind({});
|
|
68
74
|
ContactView.args = {
|
|
69
|
-
summary: "false"
|
|
75
|
+
summary: "false",
|
|
76
|
+
phoneCallLink: "false"
|
|
70
77
|
};
|
|
78
|
+
|