@postnord/pn-marketweb-components 1.0.17 → 1.0.21

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 (78) hide show
  1. package/cjs/MarketWebContextService-420668a7.js +166 -0
  2. package/cjs/loader.cjs.js +1 -1
  3. package/cjs/pn-filter-checkbox.cjs.entry.js +67 -0
  4. package/cjs/pn-language-selector_9.cjs.entry.js +34 -11
  5. package/cjs/pn-mainnav-link.cjs.entry.js +1 -1
  6. package/cjs/{pn-mainnav-store-661b0b11.js → pn-mainnav-store-87a95686.js} +1 -0
  7. package/cjs/pn-market-web-components.cjs.js +1 -1
  8. package/cjs/pn-marketweb-sitefooter.cjs.entry.js +48 -6
  9. package/cjs/pn-marketweb-siteheader.cjs.entry.js +62 -9
  10. package/collection/collection-manifest.json +1 -0
  11. package/collection/components/input/pn-filter-checkbox/checkbox.stories.js +34 -0
  12. package/collection/components/input/pn-filter-checkbox/pn-filter-checkbox.css +73 -0
  13. package/collection/components/input/pn-filter-checkbox/pn-filter-checkbox.js +183 -0
  14. package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +75 -12
  15. package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.stories.js +16 -0
  16. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +8 -1
  17. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +172 -68
  18. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.stories.js +23 -12
  19. package/collection/components/navigation/pn-language-selector/pn-language-selector.js +28 -7
  20. package/collection/components/navigation/pn-mainnav/pn-mainnav-level.css +3 -0
  21. package/collection/components/navigation/pn-mainnav/pn-mainnav-level.js +5 -1
  22. package/collection/components/navigation/pn-mainnav/pn-mainnav-store.js +1 -0
  23. package/collection/components/navigation/pn-mainnav/pn-mainnav.js +1 -1
  24. package/collection/components/navigation/pn-site-selector/pn-site-selector.js +6 -6
  25. package/collection/globals/MarketWebContextService.js +163 -0
  26. package/custom-elements/index.d.ts +6 -0
  27. package/custom-elements/index.js +376 -32
  28. package/esm/MarketWebContextService-9a201388.js +164 -0
  29. package/esm/loader.js +1 -1
  30. package/esm/pn-filter-checkbox.entry.js +63 -0
  31. package/esm/pn-language-selector_9.entry.js +34 -11
  32. package/esm/pn-mainnav-link.entry.js +1 -1
  33. package/esm/{pn-mainnav-store-4b030e31.js → pn-mainnav-store-8e518460.js} +1 -0
  34. package/esm/pn-market-web-components.js +1 -1
  35. package/esm/pn-marketweb-sitefooter.entry.js +48 -6
  36. package/esm/pn-marketweb-siteheader.entry.js +63 -10
  37. package/esm-es5/MarketWebContextService-9a201388.js +1 -0
  38. package/esm-es5/loader.js +1 -1
  39. package/esm-es5/pn-filter-checkbox.entry.js +1 -0
  40. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  41. package/esm-es5/pn-mainnav-link.entry.js +1 -1
  42. package/esm-es5/pn-mainnav-store-8e518460.js +1 -0
  43. package/esm-es5/pn-market-web-components.js +1 -1
  44. package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
  45. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  46. package/package.json +2 -2
  47. package/pn-market-web-components/p-02eed66e.system.entry.js +1 -0
  48. package/pn-market-web-components/{p-facf4ecb.system.entry.js → p-251d44f2.system.entry.js} +1 -1
  49. package/pn-market-web-components/p-25bdf3f8.system.js +1 -1
  50. package/pn-market-web-components/p-2da203c9.system.entry.js +1 -0
  51. package/pn-market-web-components/p-363a27ff.entry.js +1 -0
  52. package/pn-market-web-components/p-582dbd9c.entry.js +1 -0
  53. package/pn-market-web-components/p-64dc840d.js +1 -0
  54. package/pn-market-web-components/p-86a9f853.system.js +1 -0
  55. package/pn-market-web-components/p-8c072330.entry.js +1 -0
  56. package/pn-market-web-components/p-8d62c46f.system.entry.js +1 -0
  57. package/pn-market-web-components/p-8dad5ed9.js +1 -0
  58. package/pn-market-web-components/p-a320fe58.system.js +1 -0
  59. package/pn-market-web-components/p-ae0e5fd8.entry.js +1 -0
  60. package/pn-market-web-components/{p-f7d60229.entry.js → p-e220ea83.entry.js} +1 -1
  61. package/pn-market-web-components/p-ecfabe25.system.entry.js +1 -0
  62. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  63. package/types/components/input/pn-filter-checkbox/pn-filter-checkbox.d.ts +22 -0
  64. package/types/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.d.ts +5 -0
  65. package/types/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.d.ts +8 -0
  66. package/types/components/navigation/pn-language-selector/pn-language-selector.d.ts +2 -0
  67. package/types/components/navigation/pn-mainnav/pn-mainnav-store.d.ts +2 -0
  68. package/types/components.d.ts +61 -0
  69. package/types/globals/MarketWebContextService.d.ts +51 -0
  70. package/esm-es5/pn-mainnav-store-4b030e31.js +0 -1
  71. package/pn-market-web-components/p-6b735c44.system.js +0 -1
  72. package/pn-market-web-components/p-a74e5481.js +0 -1
  73. package/pn-market-web-components/p-b80600a3.system.entry.js +0 -1
  74. package/pn-market-web-components/p-cc6e3bcb.entry.js +0 -1
  75. package/pn-market-web-components/p-d2da364d.system.entry.js +0 -1
  76. package/pn-market-web-components/p-ed135751.entry.js +0 -1
  77. package/pn-market-web-components/p-f55ad3f8.system.entry.js +0 -1
  78. package/pn-market-web-components/p-f5dddd2d.entry.js +0 -1
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-0404c97e.js');
6
+ const MarketWebContextService = require('./MarketWebContextService-420668a7.js');
6
7
 
7
8
  const translations = {
8
9
  'sv': {
@@ -57,13 +58,19 @@ const pnMarketwebSiteheaderCss = "body[data-siteheader-menuopen=true]{max-height
57
58
  let PnMarketwebSiteheader = class {
58
59
  constructor(hostRef) {
59
60
  index.registerInstance(this, hostRef);
61
+ this.changeLanguage = index.createEvent(this, "changeLanguage", 7);
62
+ this.changeMarket = index.createEvent(this, "changeMarket", 7);
60
63
  this.endpointPath = "/api/navigation/header";
64
+ // allowedLanguages = ["sv","da","fi","no","en"];
65
+ // allowedMarkets = ["se","dk","fi","no","com"];
61
66
  /** Specifies which market we want to show (se,dk,fi,no,com) */
62
- this.market = "se";
67
+ this.market = null; //se
63
68
  /** Specifies which language we want to show (sv,da,fi,no,en) */
64
- this.language = "sv";
69
+ this.language = null; //sv
70
+ /** Specifies which environment we're fetching data from. (production, preproduction, integration, localhost) */
71
+ this.environment = null; //sv
65
72
  /** Specifies which endpoint domain we should load from */
66
- this.endpoint = "";
73
+ this.endpoint = null;
67
74
  /** Hides the site selector if set to true*/
68
75
  this.hideSiteSelector = false;
69
76
  /** Hides the language selector if set to true*/
@@ -87,22 +94,64 @@ let PnMarketwebSiteheader = class {
87
94
  this.minimizeSearch = false;
88
95
  }
89
96
  componentWillLoad() {
90
- this.setTranslations();
91
- this.init();
97
+ this.setInitialValues().then(() => {
98
+ this.init();
99
+ });
100
+ }
101
+ async setInitialValues(href = window.location.href) {
102
+ var _a;
103
+ const marketWebContextService = new MarketWebContextService.MarketWebContextService(href);
104
+ if (this.market === null) {
105
+ const resolvedMarket = await marketWebContextService.getMarket();
106
+ this.market = resolvedMarket;
107
+ }
108
+ if (this.language === null) {
109
+ const resolvedMarket = await marketWebContextService.getLanguage();
110
+ this.language = resolvedMarket;
111
+ }
112
+ if (this.environment === null) {
113
+ this.environment = await marketWebContextService.getEnvironmentName();
114
+ }
115
+ if (this.endpoint === null && ((_a = this.environment) === null || _a === void 0 ? void 0 : _a.indexOf('local')) === -1) {
116
+ this.endpoint = await marketWebContextService.getEndpoint(this.environment);
117
+ }
118
+ if (this.endpoint === null) {
119
+ this.endpoint = "";
120
+ }
92
121
  }
122
+ // TODO
123
+ //* Expose market and language attributes when changed internally
124
+ //* Business logic to select market and language depending on domains / html tag.
125
+ //* Property to stop language change from changeing url, throw an event instead.
126
+ //* Fetch new data when langauge or market is changed
93
127
  async init() {
128
+ this.setTranslations();
94
129
  await this.fetchData();
95
130
  window.setTimeout(() => { this.checkMenuOverflow(); }, 50);
96
131
  }
97
132
  setTranslations() {
98
- if (translations[this.language]) {
133
+ if (this.language && translations[this.language]) {
99
134
  this.i18n = translations[this.language];
100
135
  }
101
136
  }
137
+ onLanguageChange() {
138
+ this.setTranslations();
139
+ this.changeLanguage.emit(this.language);
140
+ this.fetchData();
141
+ }
142
+ onMarketChange() {
143
+ this.changeMarket.emit(this.market);
144
+ this.fetchData();
145
+ }
102
146
  async fetchData() {
147
+ if (this.endpoint === null || !this.market || !this.language) {
148
+ // console.warn(`One or more values where not specified.\nEndpoint: ${this.endpoint}\nMarket: ${this.market}\nLanguage: ${this.language}`)
149
+ return;
150
+ }
103
151
  this.fetchingData = true;
104
152
  const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
105
- const response = await fetch(`${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`);
153
+ const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
154
+ const response = await fetch(fetchUrl);
106
155
  const data = await response.json();
107
156
  this.setStateFromData(data);
108
157
  }
@@ -173,7 +222,7 @@ let PnMarketwebSiteheader = class {
173
222
  }
174
223
  render() {
175
224
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
176
- return (index.h("header", null, index.h("div", { class: "siteheader-row" }, index.h("div", { class: "siteheader-topleft" }, index.h("slot", { name: "topleft" }), !this.hideSiteSelector &&
225
+ return (index.h(index.Host, { language: this.language, market: this.market, environment: this.environment }, index.h("header", null, index.h("div", { class: "siteheader-row" }, index.h("div", { class: "siteheader-topleft" }, index.h("slot", { name: "topleft" }), !this.hideSiteSelector &&
177
226
  index.h("pn-site-selector", { language: this.language, buttontext: (_b = (_a = this.siteSelector) === null || _a === void 0 ? void 0 : _a.currentSiteTitle) !== null && _b !== void 0 ? _b : 'postnord' }, (this.gotData && ((_c = this.siteSelector) === null || _c === void 0 ? void 0 : _c.currentSiteTitle)) &&
178
227
  index.h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_d = this.siteSelector) === null || _d === void 0 ? void 0 : _d.siteSelections)) && this.siteSelector.siteSelections.map((site) => index.h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.href, newwindow: site.openInNewWindow })))), index.h("div", { class: "siteheader-logocontainer" }, index.h("a", { href: (_f = (_e = this.siteDefinition) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : document.location.hostname, title: "Home", class: "siteheader-logolink" }, index.h("svg", { class: "siteheader-logo", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 141.73 26.65" }, index.h("path", { d: "M108.84,13.35c0,6.34-5.17,9-10,9S89,19.76,89,13.63c0-6.28,5.08-9,10-9S108.84,7.25,108.84,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.29,3.29,0,0,0,3.42,3.41A3.24,3.24,0,0,0,102.28,13.54Zm-83,0c0,4.83-3.32,8.82-8.49,8.82a6.54,6.54,0,0,1-4.65-1.57v5.86H0V5.16H6.17V6.8a6.43,6.43,0,0,1,5.11-2.18C16.41,4.62,19.31,8.58,19.31,13.54Zm-6.53,0A3.27,3.27,0,0,0,9.4,10,3.28,3.28,0,0,0,6,13.54,3.29,3.29,0,0,0,9.4,16.95,3.24,3.24,0,0,0,12.78,13.54Zm103.69,0.27c0-2.54,1.54-3.32,3.6-3.32a6.56,6.56,0,0,1,2.08.3L122.3,5.1a3.92,3.92,0,0,0-1.45-.18c-3.45,0-4.38,2.18-4.38,2.18V5.16H110.3V21.84h6.17v-8ZM141.73,0V21.84h-6.16V20.21a6.43,6.43,0,0,1-5.11,2.18c-5.14,0-8-4-8-8.91s3.32-8.82,8.49-8.82a6.54,6.54,0,0,1,4.65,1.57v-5Zm-6,13.48a3.28,3.28,0,0,0-3.41-3.41A3.24,3.24,0,0,0,129,13.47,3.4,3.4,0,1,0,135.75,13.47ZM81.35,4.62c-3.6,0-4.9,2.18-4.9,2.18V5.16H70.29V21.84h6.16V13.29c0-2.11.79-3.08,2.69-3.08s2.18,1.57,2.18,3.57v8.07h6.22V11.6C87.55,7,85.34,4.62,81.35,4.62ZM64.07,1.42H57.9V21.84h6.16V10.36H67l2.81-5.2H64.07V1.42ZM50.26,11.21c-2-.3-2.87-0.3-2.87-1.09s0.81-.94,2.42-0.94a16.15,16.15,0,0,1,5.11.91L56,5.41a24.56,24.56,0,0,0-6.13-.75c-5.89,0-9,2.27-9,5.89,0,2.81,1.66,4.47,6.53,5.11,2.06,0.27,2.81.39,2.81,1.15s-0.82,1-2.24,1a16.67,16.67,0,0,1-6-1.3L40.77,21.3a22.14,22.14,0,0,0,6.68,1c6.35,0,9.28-2.24,9.28-5.89C56.72,13.54,55.15,12,50.26,11.21ZM40.19,13.35c0,6.34-5.17,9-10,9s-9.82-2.6-9.82-8.73c0-6.28,5.08-9,10-9S40.19,7.25,40.19,13.35Zm-6.56.18a3.4,3.4,0,1,0-6.8,0,3.28,3.28,0,0,0,3.41,3.41A3.24,3.24,0,0,0,33.63,13.54Z", fill: "#00A0D6", transform: "translate(0 0)" })))), index.h("div", { class: "siteheader-topright" }, index.h("slot", { name: "toprightstart" }), (this.gotData && this.loginDialog && !this.hideLogin) && (index.h("pn-marketweb-siteheader-login", { loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })), (this.gotData && ((_g = this.languageSelector) === null || _g === void 0 ? void 0 : _g.languages)) && !this.hideLanguageSelector &&
179
228
  index.h("pn-language-selector", { value: this.language }, this.languageSelector.languages.map(language => index.h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))), index.h("slot", { name: "toprightend" }))), index.h("div", { class: "siteheader-row" }, index.h("div", { class: "siteheader-menu" }, index.h("pn-mainnav", { market: this.market, language: this.language, onMenuOpenChange: (e) => {
@@ -190,9 +239,13 @@ let PnMarketwebSiteheader = class {
190
239
  })), index.h("div", { slot: "footer", class: "siteheader-menu-footer" }, (this.gotData && this.loginDialog && !this.hideLogin) && (index.h("pn-marketweb-siteheader-login", { loginDialog: this.loginDialog, endpoint: this.endpoint, i18n: this.i18n })), (this.gotData && ((_h = this.languageSelector) === null || _h === void 0 ? void 0 : _h.languages)) && !this.hideLanguageSelector &&
191
240
  index.h("pn-language-selector", { value: this.language }, this.languageSelector.languages.map(language => index.h("pn-language-selector-option", { name: language.nativeName, code: language.twoLetterISOLanguageName, selected: language.isCurrent, url: this.getLanguageVersionUrl(language) }))), !this.hideSiteSelector &&
192
241
  index.h("pn-site-selector", { language: this.language }, (this.gotData && ((_j = this.siteSelector) === null || _j === void 0 ? void 0 : _j.currentSiteTitle)) &&
193
- index.h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_k = this.siteSelector) === null || _k === void 0 ? void 0 : _k.siteSelections)) && this.siteSelector.siteSelections.map((site) => index.h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.pageLink, newwindow: site.openInNewWindow })))), index.h("div", { slot: "top", class: "siteheader-menu-top" }, index.h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, i18n: this.i18n }))))), index.h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n }))));
242
+ index.h("pn-site-selector-item", { heading: this.siteSelector.currentSiteTitle, description: this.siteSelector.currentSiteDescription }), (this.gotData && ((_k = this.siteSelector) === null || _k === void 0 ? void 0 : _k.siteSelections)) && this.siteSelector.siteSelections.map((site) => index.h("pn-site-selector-item", { heading: site.linkText, description: site.linkDescription, url: site.pageLink, newwindow: site.openInNewWindow })))), index.h("div", { slot: "top", class: "siteheader-menu-top" }, index.h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, i18n: this.i18n }))))), index.h("pn-marketweb-siteheader-search", { search: this.search, "hide-search": this.hideSearch, "show-only-link": this.minimizeSearch, i18n: this.i18n })))));
194
243
  }
195
244
  get hostElement() { return index.getElement(this); }
245
+ static get watchers() { return {
246
+ "language": ["onLanguageChange"],
247
+ "market": ["onMarketChange"]
248
+ }; }
196
249
  };
197
250
  PnMarketwebSiteheader.style = pnMarketwebSiteheaderCss;
198
251
 
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "entries": [
3
3
  "./components/input/pn-choice-button/pn-choice-button.js",
4
+ "./components/input/pn-filter-checkbox/pn-filter-checkbox.js",
4
5
  "./components/input/pn-filter-search/pn-filter-search.js",
5
6
  "./components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js",
6
7
  "./components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js",
@@ -0,0 +1,34 @@
1
+ import readme from "./readme.md";
2
+
3
+ export default {
4
+ title: "input/Filter Checkbox",
5
+ parameters: {
6
+ notes: readme,
7
+ layout: 'centered'
8
+ }
9
+ };
10
+
11
+
12
+ const Template = ({ ...args }) => {
13
+ return `
14
+ <div style="display: flex; align-items: center;">
15
+ <form method="get" target="_blank">
16
+ <pn-filter-checkbox checkboxid="${args.checkboxid}" value="${args.value}" name="${args.name}" checked="${args.checked}" indeterminate="${args.indeterminate}" disabled="${args.disabled}"></pn-filter-checkbox>
17
+ <label style="margin-left: .5em;" for="${args.checkboxid}">${args.value}</label>
18
+
19
+ <br/><br/>
20
+ <pn-button type="submit">Submit</pn-button>
21
+ </form>
22
+ </div>
23
+ `;
24
+ };
25
+
26
+ export const Primary = Template.bind({})
27
+ Primary.args = {
28
+ disabled: false,
29
+ checked: false,
30
+ indeterminate: false,
31
+ checkboxid: 'test-id',
32
+ value: 'test value',
33
+ name: 'test-name',
34
+ };
@@ -0,0 +1,73 @@
1
+ :host {
2
+ display: inline-block;
3
+ user-select: none;
4
+ }
5
+ :host input {
6
+ opacity: 0;
7
+ position: absolute;
8
+ }
9
+ :host input[type=checkbox] + label.pn-checkbox {
10
+ width: 1.5em;
11
+ min-width: 1.5em;
12
+ height: 1.5em;
13
+ min-height: 1.5em;
14
+ background: #fff;
15
+ display: flex;
16
+ justify-content: center;
17
+ align-items: center;
18
+ position: relative;
19
+ border: 0.1rem solid #969087;
20
+ cursor: pointer;
21
+ border-radius: 0.4rem;
22
+ cursor: pointer;
23
+ transition-duration: 220ms;
24
+ transition-timing-function: cubic-bezier(0.79, 0.14, 0.15, 0.86);
25
+ transition-property: border, background, box-shadow;
26
+ }
27
+ :host input[type=checkbox] + label.pn-checkbox svg {
28
+ width: 80%;
29
+ fill: none;
30
+ }
31
+ :host input[type=checkbox] + label.pn-checkbox svg polyline {
32
+ stroke: #FFF;
33
+ transform-origin: 0 0;
34
+ stroke-linecap: round;
35
+ stroke-dasharray: 23;
36
+ stroke-dashoffset: 23;
37
+ transition-delay: none;
38
+ transition: stroke-dashoffset 180ms cubic-bezier(0.79, 0.14, 0.15, 0.86);
39
+ }
40
+ :host input[type=checkbox]:hover + label.pn-checkbox {
41
+ border: 0.1rem solid #005D92;
42
+ background: #E0F8FF;
43
+ }
44
+ :host input[type=checkbox]:checked + label.pn-checkbox, :host input[type=checkbox]:indeterminate + label.pn-checkbox {
45
+ background: #005D92;
46
+ border: 0.1rem solid #005D92;
47
+ }
48
+ :host input[type=checkbox]:checked + label.pn-checkbox svg polyline, :host input[type=checkbox]:indeterminate + label.pn-checkbox svg polyline {
49
+ transition-delay: 220ms;
50
+ }
51
+ :host input[type=checkbox]:checked + label.pn-checkbox svg polyline.checkmark-path {
52
+ stroke-dashoffset: 0;
53
+ }
54
+ :host input[type=checkbox]:indeterminate + label.pn-checkbox svg polyline.indeterminate-path {
55
+ stroke-dashoffset: 0;
56
+ }
57
+ :host input[type=checkbox]:focus + label.pn-checkbox, :host input[type=checkbox]:active + label.pn-checkbox {
58
+ box-shadow: 0 0 0 0.1rem white, 0 0 0 0.3rem #005D92;
59
+ }
60
+ :host input[type=checkbox]:disabled + label.pn-checkbox {
61
+ background-color: #D3CECB;
62
+ border: 0.1rem solid #969087;
63
+ cursor: not-allowed;
64
+ }
65
+ :host input[type=checkbox]:disabled + label.pn-checkbox svg polyline {
66
+ stroke: #969087;
67
+ }
68
+ :host input[type=checkbox]:disabled:checked + label.pn-checkbox {
69
+ border: 0.1rem solid transparent;
70
+ }
71
+ :host input[type=checkbox]:disabled:active + label.pn-checkbox {
72
+ box-shadow: none;
73
+ }
@@ -0,0 +1,183 @@
1
+ import { Component, Prop, h, Host, Element, Listen } from "@stencil/core";
2
+ export class PnFilterCheckbox {
3
+ constructor() {
4
+ this.disabled = false;
5
+ this.checked = false;
6
+ this.indeterminate = false;
7
+ }
8
+ handlechange() {
9
+ this.indeterminate = false;
10
+ }
11
+ componentDidLoad() {
12
+ this.checkAndSetIndeterminateState();
13
+ this.bindEvents();
14
+ }
15
+ componentDidUpdate() {
16
+ this.checkAndSetIndeterminateState();
17
+ }
18
+ bindEvents() {
19
+ const labels = document.querySelectorAll('label[for="' + this.checkboxid + '"]');
20
+ labels.forEach((label) => {
21
+ label.addEventListener('click', () => {
22
+ this.hostElement.shadowRoot.querySelector('label').click();
23
+ });
24
+ });
25
+ const checkboxInput = this.hostElement.shadowRoot.querySelector('input');
26
+ checkboxInput.addEventListener('change', this.onCheckboxChange.bind(this, checkboxInput));
27
+ }
28
+ onCheckboxChange(checkboxInput) {
29
+ let outsideInput = this.hostElement.querySelector("input.hidden-" + this.checkboxid);
30
+ if (outsideInput) {
31
+ outsideInput.value = (checkboxInput.checked) ? this.value : "";
32
+ }
33
+ }
34
+ checkAndSetIndeterminateState() {
35
+ let checkbox = this.hostElement.querySelector(`#${this.checkboxid}`);
36
+ if (checkbox) {
37
+ checkbox.indeterminate = this.indeterminate;
38
+ }
39
+ }
40
+ renderInputOutsideShadowRoot() {
41
+ var _a;
42
+ let input = this.hostElement.querySelector("input.hidden-" + this.checkboxid);
43
+ if (!input) {
44
+ input = this.hostElement.ownerDocument.createElement("input");
45
+ input.type = "hidden";
46
+ input.classList.add("hidden-" + this.checkboxid);
47
+ this.hostElement.appendChild(input);
48
+ }
49
+ input.name = (_a = this.name) !== null && _a !== void 0 ? _a : this.checkboxid;
50
+ }
51
+ render() {
52
+ this.renderInputOutsideShadowRoot();
53
+ return (h(Host, { checked: this.checked, id: this.checkboxid },
54
+ h("input", { type: "checkbox", id: this.checkboxid, value: this.value, name: this.name || this.checkboxid, disabled: this.disabled, checked: this.checked }),
55
+ h("label", { htmlFor: this.checkboxid, class: "pn-checkbox" },
56
+ h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none" },
57
+ h("polyline", { class: "checkmark-path", points: "4,12 9,17 20,6", "stroke-width": "3" }),
58
+ h("polyline", { class: "indeterminate-path", points: "4,12 20,12", "stroke-width": "3" })))));
59
+ }
60
+ static get is() { return "pn-filter-checkbox"; }
61
+ static get encapsulation() { return "shadow"; }
62
+ static get originalStyleUrls() { return {
63
+ "$": ["pn-filter-checkbox.scss"]
64
+ }; }
65
+ static get styleUrls() { return {
66
+ "$": ["pn-filter-checkbox.css"]
67
+ }; }
68
+ static get properties() { return {
69
+ "value": {
70
+ "type": "any",
71
+ "mutable": false,
72
+ "complexType": {
73
+ "original": "any",
74
+ "resolved": "any",
75
+ "references": {}
76
+ },
77
+ "required": false,
78
+ "optional": false,
79
+ "docs": {
80
+ "tags": [],
81
+ "text": "This will be emitted on change and input, like a native checkbox"
82
+ },
83
+ "attribute": "value",
84
+ "reflect": true
85
+ },
86
+ "name": {
87
+ "type": "string",
88
+ "mutable": false,
89
+ "complexType": {
90
+ "original": "string",
91
+ "resolved": "string",
92
+ "references": {}
93
+ },
94
+ "required": false,
95
+ "optional": false,
96
+ "docs": {
97
+ "tags": [],
98
+ "text": "The name of the checkbox group"
99
+ },
100
+ "attribute": "name",
101
+ "reflect": false
102
+ },
103
+ "checkboxid": {
104
+ "type": "string",
105
+ "mutable": false,
106
+ "complexType": {
107
+ "original": "string",
108
+ "resolved": "string",
109
+ "references": {}
110
+ },
111
+ "required": false,
112
+ "optional": false,
113
+ "docs": {
114
+ "tags": [],
115
+ "text": "The string you put here will be what you'd make the ID of a native radio button, you can't name props \"id\" because it's reserved\nso we went with the more descriptive name \"checkboxid\", if you want to create labels for your checkbox, you will bind it to this ID"
116
+ },
117
+ "attribute": "checkboxid",
118
+ "reflect": false
119
+ },
120
+ "disabled": {
121
+ "type": "boolean",
122
+ "mutable": false,
123
+ "complexType": {
124
+ "original": "boolean",
125
+ "resolved": "boolean",
126
+ "references": {}
127
+ },
128
+ "required": false,
129
+ "optional": true,
130
+ "docs": {
131
+ "tags": [],
132
+ "text": ""
133
+ },
134
+ "attribute": "disabled",
135
+ "reflect": false,
136
+ "defaultValue": "false"
137
+ },
138
+ "checked": {
139
+ "type": "boolean",
140
+ "mutable": false,
141
+ "complexType": {
142
+ "original": "boolean",
143
+ "resolved": "boolean",
144
+ "references": {}
145
+ },
146
+ "required": false,
147
+ "optional": true,
148
+ "docs": {
149
+ "tags": [],
150
+ "text": ""
151
+ },
152
+ "attribute": "checked",
153
+ "reflect": false,
154
+ "defaultValue": "false"
155
+ },
156
+ "indeterminate": {
157
+ "type": "boolean",
158
+ "mutable": true,
159
+ "complexType": {
160
+ "original": "boolean",
161
+ "resolved": "boolean",
162
+ "references": {}
163
+ },
164
+ "required": false,
165
+ "optional": true,
166
+ "docs": {
167
+ "tags": [],
168
+ "text": ""
169
+ },
170
+ "attribute": "indeterminate",
171
+ "reflect": false,
172
+ "defaultValue": "false"
173
+ }
174
+ }; }
175
+ static get elementRef() { return "hostElement"; }
176
+ static get listeners() { return [{
177
+ "name": "change",
178
+ "method": "handlechange",
179
+ "target": undefined,
180
+ "capture": false,
181
+ "passive": false
182
+ }]; }
183
+ }
@@ -1,5 +1,6 @@
1
- import { Component, Prop, h, State, Element, Host } from "@stencil/core";
1
+ import { Component, Prop, h, State, Element, Host, Watch } from "@stencil/core";
2
2
  import { translations } from "./translations";
3
+ import { MarketWebContextService } from "../../../globals/MarketWebContextService";
3
4
  export class PnMarketwebSiteheader {
4
5
  constructor() {
5
6
  this.endpointPath = "/api/footer/footer";
@@ -7,27 +8,64 @@ export class PnMarketwebSiteheader {
7
8
  this.market = "se";
8
9
  /** Specifies which language we want to show (sv,da,fi,no,en) */
9
10
  this.language = "sv";
11
+ /** Specifies which environment we're fetching data from. (production, preproduction, integration, localhost) */
12
+ this.environment = null; //sv
10
13
  /** Specifies which endpoint domain we should load from */
11
- this.endpoint = "";
14
+ this.endpoint = null;
12
15
  this.gotData = false;
13
16
  this.fetchingData = false;
14
17
  }
15
18
  componentWillLoad() {
16
- this.setTranslations();
17
- this.init();
19
+ this.setInitialValues().then(() => {
20
+ this.init();
21
+ });
22
+ }
23
+ async setInitialValues(href = window.location.href) {
24
+ var _a;
25
+ const marketWebContextService = new MarketWebContextService(href);
26
+ if (this.market === null) {
27
+ const resolvedMarket = await marketWebContextService.getMarket();
28
+ this.market = resolvedMarket;
29
+ }
30
+ if (this.language === null) {
31
+ const resolvedMarket = await marketWebContextService.getLanguage();
32
+ this.language = resolvedMarket;
33
+ }
34
+ if (this.environment === null) {
35
+ this.environment = await marketWebContextService.getEnvironmentName();
36
+ }
37
+ if (this.endpoint === null && ((_a = this.environment) === null || _a === void 0 ? void 0 : _a.indexOf('local')) === -1) {
38
+ this.endpoint = await marketWebContextService.getEndpoint(this.environment);
39
+ }
40
+ if (this.endpoint === null) {
41
+ this.endpoint = "";
42
+ }
18
43
  }
19
44
  async init() {
45
+ this.setTranslations();
20
46
  await this.fetchData();
21
47
  }
22
48
  setTranslations() {
23
- if (translations[this.language]) {
49
+ if (this.language && translations[this.language]) {
24
50
  this.i18n = translations[this.language];
25
51
  }
26
52
  }
53
+ onLanguageChange() {
54
+ this.setTranslations();
55
+ this.fetchData();
56
+ }
57
+ onMarketChange() {
58
+ this.fetchData();
59
+ }
27
60
  async fetchData() {
61
+ if (this.endpoint === null || !this.market || !this.language) {
62
+ // console.warn(`One or more values where not specified.\nEndpoint: ${this.endpoint}\nMarket: ${this.market}\nLanguage: ${this.language}`)
63
+ return;
64
+ }
28
65
  this.fetchingData = true;
29
66
  const endpointBase = (this.endpoint.lastIndexOf("/") === this.endpoint.length - 1) ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
30
- const response = await fetch(`${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`);
67
+ const fetchUrl = `${endpointBase}${this.endpointPath}?market=${this.market}&language=${this.language}`;
68
+ const response = await fetch(fetchUrl);
31
69
  const data = await response.json();
32
70
  this.setStateFromData(data);
33
71
  }
@@ -70,7 +108,7 @@ export class PnMarketwebSiteheader {
70
108
  }
71
109
  render() {
72
110
  var _a, _b, _c, _d, _e;
73
- return (h(Host, null,
111
+ return (h(Host, { language: this.language, market: this.market, environment: this.environment },
74
112
  h("pn-site-footer", { url: (_b = (_a = this.siteDefinition) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : "" },
75
113
  (this.gotData && ((_c = this.footerContent) === null || _c === void 0 ? void 0 : _c.columns)) ? this.footerContent.columns.map((column) => (h("pn-site-footer-col", null,
76
114
  h("h3", null, column.heading),
@@ -102,7 +140,7 @@ export class PnMarketwebSiteheader {
102
140
  static get properties() { return {
103
141
  "market": {
104
142
  "type": "string",
105
- "mutable": false,
143
+ "mutable": true,
106
144
  "complexType": {
107
145
  "original": "string",
108
146
  "resolved": "string",
@@ -115,12 +153,12 @@ export class PnMarketwebSiteheader {
115
153
  "text": "Specifies which market we want to show (se,dk,fi,no,com)"
116
154
  },
117
155
  "attribute": "market",
118
- "reflect": false,
156
+ "reflect": true,
119
157
  "defaultValue": "\"se\""
120
158
  },
121
159
  "language": {
122
160
  "type": "string",
123
- "mutable": false,
161
+ "mutable": true,
124
162
  "complexType": {
125
163
  "original": "string",
126
164
  "resolved": "string",
@@ -133,9 +171,27 @@ export class PnMarketwebSiteheader {
133
171
  "text": "Specifies which language we want to show (sv,da,fi,no,en)"
134
172
  },
135
173
  "attribute": "language",
136
- "reflect": false,
174
+ "reflect": true,
137
175
  "defaultValue": "\"sv\""
138
176
  },
177
+ "environment": {
178
+ "type": "string",
179
+ "mutable": true,
180
+ "complexType": {
181
+ "original": "string",
182
+ "resolved": "string",
183
+ "references": {}
184
+ },
185
+ "required": false,
186
+ "optional": false,
187
+ "docs": {
188
+ "tags": [],
189
+ "text": "Specifies which environment we're fetching data from. (production, preproduction, integration, localhost)"
190
+ },
191
+ "attribute": "environment",
192
+ "reflect": true,
193
+ "defaultValue": "null"
194
+ },
139
195
  "endpoint": {
140
196
  "type": "string",
141
197
  "mutable": false,
@@ -152,7 +208,7 @@ export class PnMarketwebSiteheader {
152
208
  },
153
209
  "attribute": "endpoint",
154
210
  "reflect": false,
155
- "defaultValue": "\"\""
211
+ "defaultValue": "null"
156
212
  }
157
213
  }; }
158
214
  static get states() { return {
@@ -163,4 +219,11 @@ export class PnMarketwebSiteheader {
163
219
  "fetchingData": {}
164
220
  }; }
165
221
  static get elementRef() { return "hostElement"; }
222
+ static get watchers() { return [{
223
+ "propName": "language",
224
+ "methodName": "onLanguageChange"
225
+ }, {
226
+ "propName": "market",
227
+ "methodName": "onMarketChange"
228
+ }]; }
166
229
  }
@@ -52,3 +52,19 @@ Primary.args = {
52
52
  language: 'sv',
53
53
  endpoint: 'https://com-integration.postnord.com'
54
54
  };
55
+
56
+
57
+ const MinimalOptionsTemplate = ({ ...args }) => {
58
+ return `
59
+ <pn-marketweb-sitefooter language="sv">
60
+ </pn-marketweb-sitefooter>
61
+ `;
62
+ };
63
+
64
+
65
+ export const MinimalOptions = MinimalOptionsTemplate.bind({});
66
+ MinimalOptionsTemplate.args = {
67
+ market : "",
68
+ language: '',
69
+ endpoint: ''
70
+ };
@@ -1,4 +1,4 @@
1
- import { Component, Prop, h, State, Element } from "@stencil/core";
1
+ import { Component, Prop, h, State, Element, Watch } from "@stencil/core";
2
2
  import { PNLoginManager } from "./pn-marketweb-siteheader-loginmanager";
3
3
  export class PnMarketwebSiteheaderLogin {
4
4
  constructor() {
@@ -147,4 +147,11 @@ export class PnMarketwebSiteheaderLogin {
147
147
  "toggleButtonText": {}
148
148
  }; }
149
149
  static get elementRef() { return "hostElement"; }
150
+ static get watchers() { return [{
151
+ "propName": "i18n",
152
+ "methodName": "init"
153
+ }, {
154
+ "propName": "loginDialog",
155
+ "methodName": "init"
156
+ }]; }
150
157
  }