@progressive-development/pd-contact 0.1.64 → 0.1.66

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": "Progressive Development Contact component",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.1.64",
6
+ "version": "0.1.66",
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.14",
20
+ "@progressive-development/pd-forms": "^0.2.16",
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
  */
@@ -302,6 +348,7 @@
302
348
  }
303
349
 
304
350
  _renderViewContact() {
351
+ const trPhoneNr = transformPhone(this.contact.phone1, this.contact.country || "de");
305
352
  return html`
306
353
  <address>
307
354
  <dl>
@@ -313,8 +360,16 @@
313
360
  <dd>${this._getFullName()}</dd>
314
361
  <dd>${this._getFullStreet()}</dd>
315
362
  <dd>${this._getFullLocation()}</dd>
363
+ ${this.contact.additionalHint ? html`<dd>${this.contact.additionalHint}</dd>` : ''}
316
364
  <dd>${this.contact.country}</dd>
317
- <dd>${this.contact.phone1}</dd>
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>
318
373
  <dd>${this.contact.email}</dd>
319
374
 
320
375
  ${this.contact.btw
@@ -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
+