@postnord/pn-marketweb-components 2.3.6 → 2.3.8

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.
Files changed (42) hide show
  1. package/cjs/loader.cjs.js +1 -1
  2. package/cjs/pn-animated-tile.cjs.entry.js +2 -2
  3. package/cjs/pn-market-web-components.cjs.js +1 -1
  4. package/cjs/pn-multi-formfield.cjs.entry.js +253 -0
  5. package/collection/collection-manifest.json +1 -1
  6. package/collection/components/animation/pn-animated-tile/pn-animated-tile.css +54 -20
  7. package/collection/components/animation/pn-animated-tile/pn-animated-tile.js +2 -2
  8. package/collection/components/layout-components/pn-multi-formfield/multi-formfield.stories.js +55 -0
  9. package/collection/components/layout-components/pn-multi-formfield/pn-multi-formfield.css +4 -0
  10. package/collection/components/layout-components/pn-multi-formfield/pn-multi-formfield.js +267 -0
  11. package/collection/components/layout-components/pn-multi-formfield/types.js +1 -0
  12. package/custom-elements/index.d.ts +4 -4
  13. package/custom-elements/index.js +303 -83
  14. package/esm/loader.js +1 -1
  15. package/esm/pn-animated-tile.entry.js +2 -2
  16. package/esm/pn-market-web-components.js +1 -1
  17. package/esm/pn-multi-formfield.entry.js +249 -0
  18. package/esm-es5/loader.js +1 -1
  19. package/esm-es5/pn-animated-tile.entry.js +1 -1
  20. package/esm-es5/pn-market-web-components.js +1 -1
  21. package/esm-es5/pn-multi-formfield.entry.js +1 -0
  22. package/package.json +2 -1
  23. package/pn-market-web-components/p-070f1309.system.entry.js +1 -0
  24. package/pn-market-web-components/p-468025b2.system.entry.js +1 -0
  25. package/pn-market-web-components/p-5776275b.entry.js +1 -0
  26. package/pn-market-web-components/p-67887512.system.js +1 -1
  27. package/pn-market-web-components/p-96e6d92c.entry.js +1 -0
  28. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  29. package/types/components/layout-components/pn-multi-formfield/pn-multi-formfield.d.ts +36 -0
  30. package/types/components/layout-components/pn-multi-formfield/types.d.ts +4 -0
  31. package/types/components.d.ts +17 -9
  32. package/cjs/pn-multi-input.cjs.entry.js +0 -32
  33. package/collection/components/layout-components/pn-multi-input/multi-input.stories.js +0 -22
  34. package/collection/components/layout-components/pn-multi-input/pn-multi-input.css +0 -0
  35. package/collection/components/layout-components/pn-multi-input/pn-multi-input.js +0 -31
  36. package/esm/pn-multi-input.entry.js +0 -28
  37. package/esm-es5/pn-multi-input.entry.js +0 -1
  38. package/pn-market-web-components/p-7cab2106.system.entry.js +0 -1
  39. package/pn-market-web-components/p-97aafcf4.entry.js +0 -1
  40. package/pn-market-web-components/p-b66743b3.system.entry.js +0 -1
  41. package/pn-market-web-components/p-d74172bc.entry.js +0 -1
  42. package/types/components/layout-components/pn-multi-input/pn-multi-input.d.ts +0 -8
@@ -19,8 +19,8 @@ export class PnAnimatedTile {
19
19
  h("div", { class: `pn-animated-tile__content cat-animate ${this.transitionClassName}` },
20
20
  h("slot", { name: "side-a" }),
21
21
  h("slot", { name: "side-b" })),
22
- h("div", { class: `pn-animated-tile__toggle cat-animate toggle ${this.animateIcon}` },
23
- h("pn-icon", { symbol: "plus", onClick: this.onClickHandler })))));
22
+ h("button", { class: `pn-animated-tile__toggle cat-animate toggle ${this.animateIcon}`, onClick: this.onClickHandler },
23
+ h("pn-icon", { symbol: "plus" })))));
24
24
  }
25
25
  static get is() { return "pn-animated-tile"; }
26
26
  static get originalStyleUrls() { return {
@@ -0,0 +1,55 @@
1
+ import readme from "./readme.md";
2
+
3
+ export default {
4
+ title: "Input/Multi-FormField",
5
+ parameters: {
6
+ notes: readme,
7
+ },
8
+ argTypes: {
9
+ formFieldClassName: "",
10
+ formFieldOuterParentClassName: "",
11
+ },
12
+ };
13
+
14
+ const Template = ({ ...args }) => {
15
+ return `
16
+ <pn-multi-formfield
17
+ formfieldclassname=${args.formFieldClassName}
18
+ formfieldouterparentclassname=${args.formFieldOuterParentClassName}
19
+ >
20
+ <div class="formelement">
21
+ <div>
22
+ <label class="Form__Element__Caption" for="e4752967-52ef-4315-88e7-acefd54667bd">Text</label>
23
+ <input
24
+ type="text"
25
+ name="__field_91506"
26
+ id="e4752967-52ef-4315-88e7-acefd54667bd"
27
+ class="FormTextbox__Input form-control"
28
+ />
29
+ </div>
30
+ </div>
31
+ <div class="formelement">
32
+ <div>
33
+ <label class="form-group-text form-label" for="0e58dbc8-ef3b-4647-85e6-1d24483e8fe9">Selection</label>
34
+ <select
35
+ class="form-control native-select"
36
+ name="__field_90429"
37
+ id="0e58dbc8-ef3b-4647-85e6-1d24483e8fe9"
38
+ data-f-datainput=""
39
+ >
40
+ <option disabled="disabled" selected='"selected"' value="">-- Choose an option --</option>
41
+ <option value="All" data-f-datainput="">All</option>
42
+ <option value="Legoland" data-f-datainput="">Legoland</option>
43
+ </select>
44
+ </div>
45
+ </div>
46
+ <textarea type="text" class="hiddenValue" cols="70" rows="10"></textarea>
47
+ </pn-multi-formfield>
48
+ `;
49
+ };
50
+
51
+ export const Primary = Template.bind({});
52
+ Primary.args = {
53
+ formFieldClassName: "form-control",
54
+ formFieldOuterParentClassName: "formelement",
55
+ };
@@ -0,0 +1,4 @@
1
+ .pn-multi-formfield {
2
+ display: flex;
3
+ flex-direction: row;
4
+ }
@@ -0,0 +1,267 @@
1
+ import { Component, Element, Host, h, State, Prop, Event } from "@stencil/core";
2
+ import { debounce } from "debounce";
3
+ import { v4 as uuidv4 } from "uuid";
4
+ export class PnMultiFormField {
5
+ constructor() {
6
+ this.containerElm = null;
7
+ this.slotElm = null;
8
+ this.formFields = null;
9
+ this.formFieldTypes = ["input", "textarea", "select"];
10
+ this.additionalRowStartIndex = 2;
11
+ this.formRow = [];
12
+ this.formValues = [];
13
+ this.elementToCopy = null;
14
+ this.fieldsPerRowCount = 0;
15
+ this.newRowStartIndex = 2;
16
+ this.originalLabelNames = [];
17
+ this.value = [];
18
+ this.formFieldClassName = "form-control";
19
+ this.formFieldOuterParentClassName = "formelement";
20
+ this.formFieldEvent = (e) => {
21
+ if (e.target.matches(`.${this.formFieldClassName}`)) {
22
+ ["change", "keyup"].forEach((eventName) => {
23
+ const debouncedAddValue = debounce(this.updateValues.bind(this, e.target), 1000);
24
+ e.target.addEventListener(eventName, debouncedAddValue);
25
+ });
26
+ }
27
+ };
28
+ }
29
+ generateUniqueId() {
30
+ return uuidv4();
31
+ }
32
+ componentDidLoad() {
33
+ this.init();
34
+ }
35
+ async init() {
36
+ this.addEventHandlers();
37
+ this.setDefaultValues();
38
+ }
39
+ addEventHandlers() {
40
+ this.hostElement.addEventListener("click", this.formFieldEvent);
41
+ }
42
+ setDefaultValues() {
43
+ var _a;
44
+ const labelElms = (_a = this.containerElm) === null || _a === void 0 ? void 0 : _a.querySelectorAll("label");
45
+ if (labelElms) {
46
+ this.fieldsPerRowCount = labelElms.length;
47
+ this.originalLabelNames = [...labelElms].map((label) => label.innerHTML);
48
+ const emptyValues = this.originalLabelNames.map((label) => {
49
+ const obj = { Name: label, Value: "" };
50
+ return obj;
51
+ });
52
+ this.formValues = [...emptyValues];
53
+ this.setHiddenValue();
54
+ }
55
+ }
56
+ setHiddenValue() {
57
+ var _a;
58
+ const hiddenField = (_a = this.hostElement) === null || _a === void 0 ? void 0 : _a.querySelector(".hiddenValue");
59
+ if (hiddenField) {
60
+ hiddenField.value = JSON.stringify(this.formValues);
61
+ }
62
+ }
63
+ updateValues(field, e) {
64
+ var _a;
65
+ e.preventDefault();
66
+ const slotElm = field.closest(".pn-multi-formfield-slot");
67
+ const isSlotParent = !!slotElm;
68
+ let containerElm = isSlotParent ? slotElm : field.closest(".generated-parent");
69
+ if (containerElm) {
70
+ const formFields = (_a = [...containerElm === null || containerElm === void 0 ? void 0 : containerElm.querySelectorAll(`.${this.formFieldClassName}`)]) === null || _a === void 0 ? void 0 : _a.filter((x) => this.formFieldTypes.includes(x.nodeName.toLowerCase()));
71
+ formFields === null || formFields === void 0 ? void 0 : formFields.map((elm) => {
72
+ const fieldElm = elm;
73
+ const closestLabelElm = fieldElm.closest("div").querySelector("label");
74
+ const label = (closestLabelElm === null || closestLabelElm === void 0 ? void 0 : closestLabelElm.dataset.label) || (closestLabelElm === null || closestLabelElm === void 0 ? void 0 : closestLabelElm.innerHTML);
75
+ const newItem = { Name: label, Value: fieldElm.value };
76
+ this.setFormValues(newItem);
77
+ });
78
+ }
79
+ this.setHiddenValue();
80
+ }
81
+ setFormValues(obj) {
82
+ const item = this.formValues.find((item) => item.Name === obj.Name);
83
+ if (item === undefined) {
84
+ this.formValues.push(obj);
85
+ }
86
+ if (item !== undefined) {
87
+ item.Value = obj.Value;
88
+ }
89
+ this.formValues = [...this.formValues];
90
+ this.value = this.formValues;
91
+ this.changed.emit(this.formValues);
92
+ }
93
+ addRow(e) {
94
+ if (e.type === "click") {
95
+ this.addFormElements();
96
+ }
97
+ }
98
+ addFormElements() {
99
+ if (!this.elementToCopy) {
100
+ const elm = this.hostElement.querySelector(".pn-multi-formfield");
101
+ const clone = elm.cloneNode(true);
102
+ this.elementToCopy = clone;
103
+ }
104
+ const setFormElements = [
105
+ ...this.elementToCopy.querySelectorAll(`.${this.formFieldOuterParentClassName}`),
106
+ ].map((elm) => {
107
+ const labelElm = elm.querySelector("label");
108
+ const fieldElm = elm.querySelector(`.${this.formFieldClassName}`);
109
+ const newId = this.generateUniqueId();
110
+ labelElm.dataset.label = `${labelElm.innerText} ${this.newRowStartIndex}`;
111
+ labelElm.setAttribute("for", newId);
112
+ fieldElm.setAttribute("id", newId);
113
+ fieldElm.setAttribute("name", `__${newId}`);
114
+ return elm;
115
+ });
116
+ this.newRowStartIndex++;
117
+ const parentId = this.generateUniqueId();
118
+ const parentElm = document.createElement("div");
119
+ parentElm.setAttribute("id", parentId);
120
+ parentElm.setAttribute("class", "generated-parent");
121
+ setFormElements.map((clone) => {
122
+ parentElm.innerHTML += clone.innerHTML;
123
+ });
124
+ parentElm.appendChild(this.createDeleteButton());
125
+ this.containerElm.appendChild(parentElm);
126
+ }
127
+ createDeleteButton() {
128
+ const buttonElm = document.createElement("pn-button");
129
+ buttonElm.onclick = (e) => this.deleteRow(e);
130
+ buttonElm.setAttribute("icon-only", "true");
131
+ buttonElm.setAttribute("icon", "minus");
132
+ buttonElm.setAttribute("appearance", "warning");
133
+ buttonElm.appendChild(document.createTextNode(`X`));
134
+ return buttonElm;
135
+ }
136
+ deleteRow(e) {
137
+ e.preventDefault();
138
+ const targetElm = e.currentTarget;
139
+ const parentElm = targetElm.parentElement;
140
+ const allFieldElms = parentElm.querySelectorAll(`.${this.formFieldClassName}`);
141
+ allFieldElms.forEach((elm) => {
142
+ elm.remove();
143
+ });
144
+ parentElm.remove();
145
+ this.newRowStartIndex--;
146
+ this.formValues = [...this.formValues.slice(0, this.fieldsPerRowCount)];
147
+ const allGeneratedElms = [...this.containerElm.querySelectorAll(".generated-parent")];
148
+ allGeneratedElms.map((elm, index) => {
149
+ const allLabelElms = [...elm.querySelectorAll("label")];
150
+ allLabelElms.map((labelElm) => {
151
+ const labelParts = this.getLabelParts(labelElm.dataset.label);
152
+ labelElm.dataset.label = this.getLabelName(labelParts[0], index);
153
+ const associatedField = labelElm.parentElement.querySelector(`.${this.formFieldClassName}`);
154
+ const updateItem = { Name: labelElm.dataset.label, Value: associatedField.value };
155
+ this.setFormValues(updateItem);
156
+ });
157
+ });
158
+ this.setHiddenValue();
159
+ }
160
+ getLabelParts(label) {
161
+ const part1 = label.substring(0, label.lastIndexOf(" "));
162
+ const part2 = label.substring(label.lastIndexOf(" ") + 1);
163
+ const parts = [part1, part2];
164
+ return parts;
165
+ }
166
+ getLabelName(name, index) {
167
+ return `${name} ${index + this.additionalRowStartIndex}`;
168
+ }
169
+ render() {
170
+ return (h(Host, null,
171
+ h("div", { ref: (el) => (this.containerElm = el), class: "pn-multi-formfield" },
172
+ h("div", { ref: (el) => (this.slotElm = el), class: "pn-multi-formfield-slot" },
173
+ h("slot", null))),
174
+ h("pn-button", { "icon-only": "true", "aria-label": "Add", icon: "plus", onClick: (e) => this.addRow(e) }, "+")));
175
+ }
176
+ static get is() { return "pn-multi-formfield"; }
177
+ static get originalStyleUrls() { return {
178
+ "$": ["pn-multi-formfield.scss"]
179
+ }; }
180
+ static get styleUrls() { return {
181
+ "$": ["pn-multi-formfield.css"]
182
+ }; }
183
+ static get properties() { return {
184
+ "value": {
185
+ "type": "unknown",
186
+ "mutable": true,
187
+ "complexType": {
188
+ "original": "FormValue[]",
189
+ "resolved": "FormValue[]",
190
+ "references": {
191
+ "FormValue": {
192
+ "location": "import",
193
+ "path": "./types"
194
+ }
195
+ }
196
+ },
197
+ "required": false,
198
+ "optional": false,
199
+ "docs": {
200
+ "tags": [],
201
+ "text": ""
202
+ },
203
+ "defaultValue": "[]"
204
+ },
205
+ "formFieldClassName": {
206
+ "type": "string",
207
+ "mutable": false,
208
+ "complexType": {
209
+ "original": "string",
210
+ "resolved": "string",
211
+ "references": {}
212
+ },
213
+ "required": false,
214
+ "optional": false,
215
+ "docs": {
216
+ "tags": [],
217
+ "text": ""
218
+ },
219
+ "attribute": "form-field-class-name",
220
+ "reflect": false,
221
+ "defaultValue": "\"form-control\""
222
+ },
223
+ "formFieldOuterParentClassName": {
224
+ "type": "string",
225
+ "mutable": false,
226
+ "complexType": {
227
+ "original": "string",
228
+ "resolved": "string",
229
+ "references": {}
230
+ },
231
+ "required": false,
232
+ "optional": false,
233
+ "docs": {
234
+ "tags": [],
235
+ "text": ""
236
+ },
237
+ "attribute": "form-field-outer-parent-class-name",
238
+ "reflect": false,
239
+ "defaultValue": "\"formelement\""
240
+ }
241
+ }; }
242
+ static get states() { return {
243
+ "formRow": {},
244
+ "formValues": {},
245
+ "elementToCopy": {},
246
+ "fieldsPerRowCount": {},
247
+ "newRowStartIndex": {},
248
+ "originalLabelNames": {}
249
+ }; }
250
+ static get events() { return [{
251
+ "method": "changed",
252
+ "name": "changed",
253
+ "bubbles": true,
254
+ "cancelable": true,
255
+ "composed": true,
256
+ "docs": {
257
+ "tags": [],
258
+ "text": ""
259
+ },
260
+ "complexType": {
261
+ "original": "any",
262
+ "resolved": "any",
263
+ "references": {}
264
+ }
265
+ }]; }
266
+ static get elementRef() { return "hostElement"; }
267
+ }
@@ -200,10 +200,10 @@ export const PnMarketwebSiteheaderUnifiedLogin: {
200
200
  new (): PnMarketwebSiteheaderUnifiedLogin;
201
201
  };
202
202
 
203
- interface PnMultiInput extends Components.PnMultiInput, HTMLElement {}
204
- export const PnMultiInput: {
205
- prototype: PnMultiInput;
206
- new (): PnMultiInput;
203
+ interface PnMultiFormfield extends Components.PnMultiFormfield, HTMLElement {}
204
+ export const PnMultiFormfield: {
205
+ prototype: PnMultiFormfield;
206
+ new (): PnMultiFormfield;
207
207
  };
208
208
 
209
209
  interface PnParcelTracker extends Components.PnParcelTracker, HTMLElement {}