@salla.sa/twilight-components 1.0.16 → 1.0.17

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 (93) hide show
  1. package/dist/cjs/Helper-8852feaa.js +23 -0
  2. package/dist/cjs/index-0b5b5867.js +1656 -0
  3. package/dist/cjs/index.cjs.js +13 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/salla-branches.cjs.entry.js +92 -0
  6. package/dist/cjs/salla-button_4.cjs.entry.js +299 -0
  7. package/dist/cjs/salla-localization.cjs.entry.js +80 -0
  8. package/dist/cjs/salla-login-342876b9.js +118 -0
  9. package/dist/cjs/salla-offer.cjs.entry.js +25 -0
  10. package/dist/cjs/salla-product-availability.cjs.entry.js +75 -0
  11. package/dist/cjs/salla-rating.cjs.entry.js +300 -0
  12. package/dist/cjs/salla-search-28da4616.js +81 -0
  13. package/dist/cjs/salla-search.cjs.entry.js +11 -0
  14. package/dist/cjs/twilight-components.cjs.js +19 -0
  15. package/dist/collection/Helpers/Helper.js +19 -0
  16. package/dist/collection/collection-manifest.json +21 -0
  17. package/dist/collection/components/generate-summary.js +35 -0
  18. package/dist/collection/components/salla-branches/salla-branches.css +12 -0
  19. package/dist/collection/components/salla-branches/salla-branches.js +233 -0
  20. package/dist/collection/components/salla-button/salla-button.css +3 -0
  21. package/dist/collection/components/salla-button/salla-button.js +246 -0
  22. package/dist/collection/components/salla-localization/salla-localization.js +206 -0
  23. package/dist/collection/components/salla-login/salla-login.js +348 -0
  24. package/dist/collection/components/salla-modal/salla-modal.js +459 -0
  25. package/dist/collection/components/salla-offer/salla-offer.js +40 -0
  26. package/dist/collection/components/salla-product-availability/salla-product-availability.js +331 -0
  27. package/dist/collection/components/salla-rating/salla-rating.css +7 -0
  28. package/dist/collection/components/salla-rating/salla-rating.js +483 -0
  29. package/dist/collection/components/salla-search/salla-search.js +132 -0
  30. package/dist/collection/components/salla-verify/salla-verify.js +238 -0
  31. package/dist/collection/index.js +2 -0
  32. package/dist/collection/interfaces/colors.js +1 -0
  33. package/dist/collection/interfaces/index.js +2 -0
  34. package/dist/collection/interfaces/ratio.js +1 -0
  35. package/dist/collection/plugins/tailwind-theme/generator.js +62 -0
  36. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  37. package/dist/{twilight-components → esm}/Helper-81ac9a8c.js +0 -0
  38. package/dist/esm/index-8b97d225.js +1628 -0
  39. package/dist/esm/index.js +4 -0
  40. package/dist/esm/loader.js +17 -0
  41. package/dist/esm/polyfills/core-js.js +11 -0
  42. package/dist/esm/polyfills/css-shim.js +1 -0
  43. package/dist/esm/polyfills/dom.js +79 -0
  44. package/dist/esm/polyfills/es5-html-element.js +1 -0
  45. package/dist/esm/polyfills/index.js +34 -0
  46. package/dist/esm/polyfills/system.js +6 -0
  47. package/dist/{twilight-components → esm}/salla-branches.entry.js +6 -6
  48. package/dist/esm/salla-button_4.entry.js +292 -0
  49. package/dist/esm/salla-localization.entry.js +76 -0
  50. package/dist/esm/salla-login-32d25ffa.js +116 -0
  51. package/dist/esm/salla-offer.entry.js +21 -0
  52. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +2 -2
  53. package/dist/{twilight-components → esm}/salla-rating.entry.js +73 -70
  54. package/dist/{twilight-components/salla-search-5338c0a1.js → esm/salla-search-f552c487.js} +1 -1
  55. package/dist/esm/salla-search.entry.js +3 -0
  56. package/dist/esm/twilight-components.js +17 -0
  57. package/dist/index.cjs.js +1 -0
  58. package/dist/index.js +1 -0
  59. package/dist/twilight-components/index.esm.js +1 -4
  60. package/dist/twilight-components/p-33990e49.entry.js +1 -0
  61. package/dist/twilight-components/p-36683152.js +1 -0
  62. package/dist/twilight-components/p-3cfede65.entry.js +1 -0
  63. package/dist/twilight-components/p-648661c8.entry.js +1 -0
  64. package/dist/twilight-components/p-93c3ac79.js +1 -0
  65. package/dist/twilight-components/p-9bc28e0c.js +1 -0
  66. package/dist/twilight-components/p-a923a51e.entry.js +1 -0
  67. package/dist/twilight-components/p-bc278b0e.entry.js +1 -0
  68. package/dist/twilight-components/p-cb1c59a2.js +1 -0
  69. package/dist/twilight-components/p-fa04c4b6.entry.js +1 -0
  70. package/dist/twilight-components/p-fa2f0e64.entry.js +1 -0
  71. package/dist/twilight-components/twilight-components.css +1 -3
  72. package/dist/twilight-components/twilight-components.esm.js +1 -125
  73. package/dist/types/components/salla-button/salla-button.d.ts +3 -2
  74. package/dist/types/components/salla-localization/salla-localization.d.ts +8 -0
  75. package/dist/types/components/salla-login/salla-login.d.ts +39 -0
  76. package/dist/types/components/salla-modal/salla-modal.d.ts +12 -4
  77. package/dist/types/components/salla-offer/salla-offer.d.ts +8 -0
  78. package/dist/types/components/salla-rating/salla-rating.d.ts +17 -2
  79. package/dist/types/components/salla-verify/salla-verify.d.ts +16 -6
  80. package/dist/types/components.d.ts +94 -8
  81. package/package.json +2 -1
  82. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  83. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  84. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  85. package/dist/twilight-components/index-8966d27f.js +0 -3010
  86. package/dist/twilight-components/salla-button.entry.js +0 -73
  87. package/dist/twilight-components/salla-localization.entry.js +0 -73
  88. package/dist/twilight-components/salla-login-4d620368.js +0 -12
  89. package/dist/twilight-components/salla-login.entry.js +0 -2
  90. package/dist/twilight-components/salla-modal.entry.js +0 -91
  91. package/dist/twilight-components/salla-search.entry.js +0 -3
  92. package/dist/twilight-components/salla-verify.entry.js +0 -92
  93. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -0,0 +1,233 @@
1
+ import { Component, h, Prop, Method, State, Element } from "@stencil/core";
2
+ let engine = require('store/src/store-engine');
3
+ let storages = require('store/storages/sessionStorage');
4
+ let sessionStore = engine.createStore(storages);
5
+ export class SallaBranches {
6
+ constructor() {
7
+ this.open = false;
8
+ this.isOpenedBefore = sessionStore.get("branch-choosed-before");
9
+ this.displayAs = 'default';
10
+ this.browseProductsFrom = 'all';
11
+ this.branches = [
12
+ { id: 1, name: 'فرع الرياض', open: true, available: true, limited: false, tag: 'متوفر' },
13
+ { id: 2, name: 'فرع جدة', open: false, available: false, limited: false, tag: 'غير متوفر' },
14
+ { id: 3, name: 'فرع مكة', open: true, available: true, limited: false, tag: 'متوفر' },
15
+ { id: 4, name: 'فرع المدينة', open: true, available: true, limited: false, tag: 'متوفر' },
16
+ { id: 5, name: 'فرع جازان', open: true, available: true, limited: true, tag: 'الكمية محدودة' }
17
+ ];
18
+ this.current = 1;
19
+ this.currentBranch = (prop) => {
20
+ return this.branches.filter((el) => el.id == this.current)[0][prop];
21
+ };
22
+ this.statusColor = (branch = null) => {
23
+ return branch ?
24
+ branch.limited ? 's-branches-color-red' : branch.available ? 's-branches-color-green' : 's-branches-color-gray'
25
+ :
26
+ this.currentBranch('limited') ? 's-branches-color-red' : this.currentBranch('available') ? 's-branches-color-green' : 's-branches-color-gray';
27
+ };
28
+ this.isChoiceable = () => {
29
+ return (this.browseProductsFrom !== 'all' && this.position == 'single') || this.position == 'header';
30
+ };
31
+ this.formTitle = () => {
32
+ return this.isChoiceable() ?
33
+ 'توفر المنتج في الفروع الآخرى'
34
+ : 'التسوق من فرع آخر';
35
+ };
36
+ salla.event.on('branches::show', () => this.show());
37
+ }
38
+ async show() {
39
+ return this.modal.show();
40
+ }
41
+ async hide() {
42
+ return this.modal.hide();
43
+ }
44
+ handelChange(event) {
45
+ this.selected = event.target.value;
46
+ }
47
+ handleSubmit() {
48
+ this.btn.load().then(() => {
49
+ setTimeout(() => location.reload(), 2000);
50
+ });
51
+ sessionStore.set("branch-choosed-before", true);
52
+ this.show();
53
+ setTimeout(() => {
54
+ this.current = this.selected;
55
+ }, 300);
56
+ }
57
+ render() {
58
+ return (h("salla-modal", { icon: "sicon-store-alt", title: "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636", "sub-title": "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646", "sub-title-first": true, "is-closable": !this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true', ref: modal => this.modal = modal, "modal-width": "sm", id: "s-branches-modal", class: "hidden" },
59
+ h("h4", { class: "s-branches-title" }, this.formTitle()),
60
+ this.branches.length <= 5 ?
61
+ h("div", { class: "s-branches-space-v" }, this.branches.map((branch) => h("div", { class: "s-branches-input-wrap" },
62
+ h("input", { id: this.position + '_branch_' + branch.id, disabled: !branch.open && this.isChoiceable(), name: "lang", type: "radio", value: branch.id, onChange: (event) => this.handelChange(event), class: {
63
+ 's-branches-input': true,
64
+ 'opacity-50': !branch.open,
65
+ 'hidden': !this.isChoiceable()
66
+ }, checked: this.current == branch.id }),
67
+ h("label", { htmlFor: this.position + '_branch_' + branch.id, class: {
68
+ 's-branches-label': true,
69
+ 's-branches-clickable': this.isChoiceable()
70
+ } },
71
+ h("span", { class: { 's-branches-is-closed': !branch.open } }, branch.name),
72
+ this.isChoiceable() ?
73
+ h("small", { class: "s-branches-closed-badge" }, branch.open ? '' : 'مُغلق')
74
+ :
75
+ h("span", { class: this.statusColor(branch) }, branch.tag)))))
76
+ :
77
+ h("select", { class: "s-branches-select", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id },
78
+ branch.name,
79
+ " ",
80
+ branch.open ? '' : '- مُغلق')))),
81
+ this.isChoiceable() ?
82
+ h("slot", { name: "footer" },
83
+ h("salla-button", { ref: btn => this.btn = btn, onClick: () => this.handleSubmit(), class: "s-branches-submit", wide: true }, salla.lang.get('common.elements.ok')))
84
+ : ''));
85
+ }
86
+ componentDidRender() {
87
+ if (!this.isOpenedBefore && this.displayAs == 'popup') {
88
+ this.show();
89
+ }
90
+ }
91
+ static get is() { return "salla-branches"; }
92
+ static get originalStyleUrls() { return {
93
+ "$": ["salla-branches.scss"]
94
+ }; }
95
+ static get styleUrls() { return {
96
+ "$": ["salla-branches.css"]
97
+ }; }
98
+ static get properties() { return {
99
+ "position": {
100
+ "type": "string",
101
+ "mutable": false,
102
+ "complexType": {
103
+ "original": "string",
104
+ "resolved": "string",
105
+ "references": {}
106
+ },
107
+ "required": false,
108
+ "optional": false,
109
+ "docs": {
110
+ "tags": [],
111
+ "text": ""
112
+ },
113
+ "attribute": "position",
114
+ "reflect": false
115
+ },
116
+ "displayAs": {
117
+ "type": "string",
118
+ "mutable": false,
119
+ "complexType": {
120
+ "original": "string",
121
+ "resolved": "string",
122
+ "references": {}
123
+ },
124
+ "required": false,
125
+ "optional": false,
126
+ "docs": {
127
+ "tags": [],
128
+ "text": ""
129
+ },
130
+ "attribute": "display-as",
131
+ "reflect": false,
132
+ "defaultValue": "'default'"
133
+ },
134
+ "browseProductsFrom": {
135
+ "type": "string",
136
+ "mutable": false,
137
+ "complexType": {
138
+ "original": "string",
139
+ "resolved": "string",
140
+ "references": {}
141
+ },
142
+ "required": false,
143
+ "optional": false,
144
+ "docs": {
145
+ "tags": [],
146
+ "text": ""
147
+ },
148
+ "attribute": "browse-products-from",
149
+ "reflect": false,
150
+ "defaultValue": "'all'"
151
+ },
152
+ "branches": {
153
+ "type": "unknown",
154
+ "mutable": false,
155
+ "complexType": {
156
+ "original": "any[]",
157
+ "resolved": "any[]",
158
+ "references": {}
159
+ },
160
+ "required": false,
161
+ "optional": false,
162
+ "docs": {
163
+ "tags": [],
164
+ "text": ""
165
+ },
166
+ "defaultValue": "[\n {id: 1, name: '\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 2, name: '\u0641\u0631\u0639 \u062C\u062F\u0629', open: false, available: false, limited: false, tag: '\u063A\u064A\u0631 \u0645\u062A\u0648\u0641\u0631'},\n {id: 3, name: '\u0641\u0631\u0639 \u0645\u0643\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 4, name: '\u0641\u0631\u0639 \u0627\u0644\u0645\u062F\u064A\u0646\u0629', open: true, available: true, limited: false, tag: '\u0645\u062A\u0648\u0641\u0631'},\n {id: 5, name: '\u0641\u0631\u0639 \u062C\u0627\u0632\u0627\u0646', open: true, available: true, limited: true, tag: '\u0627\u0644\u0643\u0645\u064A\u0629 \u0645\u062D\u062F\u0648\u062F\u0629'}\n ]"
167
+ },
168
+ "current": {
169
+ "type": "number",
170
+ "mutable": true,
171
+ "complexType": {
172
+ "original": "number",
173
+ "resolved": "number",
174
+ "references": {}
175
+ },
176
+ "required": false,
177
+ "optional": false,
178
+ "docs": {
179
+ "tags": [],
180
+ "text": ""
181
+ },
182
+ "attribute": "current",
183
+ "reflect": false,
184
+ "defaultValue": "1"
185
+ }
186
+ }; }
187
+ static get states() { return {
188
+ "open": {},
189
+ "selected": {},
190
+ "isOpenedBefore": {}
191
+ }; }
192
+ static get methods() { return {
193
+ "show": {
194
+ "complexType": {
195
+ "signature": "() => Promise<HTMLElement>",
196
+ "parameters": [],
197
+ "references": {
198
+ "Promise": {
199
+ "location": "global"
200
+ },
201
+ "HTMLElement": {
202
+ "location": "global"
203
+ }
204
+ },
205
+ "return": "Promise<HTMLElement>"
206
+ },
207
+ "docs": {
208
+ "text": "",
209
+ "tags": []
210
+ }
211
+ },
212
+ "hide": {
213
+ "complexType": {
214
+ "signature": "() => Promise<HTMLElement>",
215
+ "parameters": [],
216
+ "references": {
217
+ "Promise": {
218
+ "location": "global"
219
+ },
220
+ "HTMLElement": {
221
+ "location": "global"
222
+ }
223
+ },
224
+ "return": "Promise<HTMLElement>"
225
+ },
226
+ "docs": {
227
+ "text": "",
228
+ "tags": []
229
+ }
230
+ }
231
+ }; }
232
+ static get elementRef() { return "host"; }
233
+ }
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,246 @@
1
+ import { Component, Element, h, Method, Prop, Watch, Host } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaButton {
4
+ constructor() {
5
+ this.btnStyle = 'primary';
6
+ this.loading = false;
7
+ this.disabled = false;
8
+ this.loaderPosition = 'before';
9
+ this.wide = false;
10
+ this.hostAttributes = {};
11
+ //============= Initiate Button Attributes =============//
12
+ for (let i = 0; i < this.host.attributes.length; i++) {
13
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
14
+ }
15
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
16
+ this.hostAttributes.class += ' s-button-btn btn--has-loading'
17
+ + ' s-button-' + this.btnStyle
18
+ + (this.wide ? ' s-button-wide ' : '')
19
+ + ' loader-' + this.loaderPosition
20
+ + (this.loaderPosition == 'before' ? ' s-button-loader-after' : '');
21
+ delete this.hostAttributes['btn-style'];
22
+ delete this.hostAttributes['id'];
23
+ if (this.wide) {
24
+ this.host.classList.add('s-button-wide');
25
+ }
26
+ }
27
+ async load() {
28
+ if (this.loaderPosition == 'center')
29
+ this.text.classList.add('s-button-hide');
30
+ this.host.setAttribute('loading', '');
31
+ return this.host;
32
+ }
33
+ async stop() {
34
+ this.host.removeAttribute('loading');
35
+ return this.host;
36
+ }
37
+ async disable() {
38
+ this.host.setAttribute('disabled', '');
39
+ }
40
+ async enable() {
41
+ this.host.removeAttribute('disabled');
42
+ }
43
+ handleVisible(newKind, oldKind) {
44
+ //todo::use united styles
45
+ this.btn.classList.remove('btn-' + oldKind);
46
+ this.btn.classList.add('btn-' + newKind);
47
+ }
48
+ handleLoading(newVal) {
49
+ //todo::use united styles
50
+ Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
51
+ }
52
+ render() {
53
+ return (
54
+ //TODO:: use HOST then fake button behaviours
55
+ h(Host, { class: "s-button-host-tag" },
56
+ h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes),
57
+ h("span", { class: "s-button-text", ref: el => this.text = el },
58
+ h("slot", null)),
59
+ this.loading ? h("span", { class: {
60
+ //todo::use united styles
61
+ 's-button-loader': true,
62
+ 's-button-loader-start': this.loaderPosition === 'start',
63
+ 's-button-loader-end': this.loaderPosition === 'end',
64
+ 's-button-loader-center': this.loaderPosition === 'center',
65
+ } }) : '')));
66
+ }
67
+ static get is() { return "salla-button"; }
68
+ static get originalStyleUrls() { return {
69
+ "$": ["salla-button.css"]
70
+ }; }
71
+ static get styleUrls() { return {
72
+ "$": ["salla-button.css"]
73
+ }; }
74
+ static get properties() { return {
75
+ "btnStyle": {
76
+ "type": "string",
77
+ "mutable": false,
78
+ "complexType": {
79
+ "original": "'primary' | 'outline' | 'outline-primary' | 'danger'",
80
+ "resolved": "\"danger\" | \"outline\" | \"outline-primary\" | \"primary\"",
81
+ "references": {}
82
+ },
83
+ "required": false,
84
+ "optional": false,
85
+ "docs": {
86
+ "tags": [],
87
+ "text": ""
88
+ },
89
+ "attribute": "btn-style",
90
+ "reflect": true,
91
+ "defaultValue": "'primary'"
92
+ },
93
+ "loading": {
94
+ "type": "boolean",
95
+ "mutable": false,
96
+ "complexType": {
97
+ "original": "boolean",
98
+ "resolved": "boolean",
99
+ "references": {}
100
+ },
101
+ "required": false,
102
+ "optional": false,
103
+ "docs": {
104
+ "tags": [],
105
+ "text": ""
106
+ },
107
+ "attribute": "loading",
108
+ "reflect": true,
109
+ "defaultValue": "false"
110
+ },
111
+ "disabled": {
112
+ "type": "boolean",
113
+ "mutable": false,
114
+ "complexType": {
115
+ "original": "boolean",
116
+ "resolved": "boolean",
117
+ "references": {}
118
+ },
119
+ "required": false,
120
+ "optional": false,
121
+ "docs": {
122
+ "tags": [],
123
+ "text": ""
124
+ },
125
+ "attribute": "disabled",
126
+ "reflect": true,
127
+ "defaultValue": "false"
128
+ },
129
+ "loaderPosition": {
130
+ "type": "string",
131
+ "mutable": false,
132
+ "complexType": {
133
+ "original": "'start' | 'end' | 'center' | 'before'",
134
+ "resolved": "\"before\" | \"center\" | \"end\" | \"start\"",
135
+ "references": {}
136
+ },
137
+ "required": false,
138
+ "optional": false,
139
+ "docs": {
140
+ "tags": [],
141
+ "text": ""
142
+ },
143
+ "attribute": "loader-position",
144
+ "reflect": false,
145
+ "defaultValue": "'before'"
146
+ },
147
+ "wide": {
148
+ "type": "boolean",
149
+ "mutable": false,
150
+ "complexType": {
151
+ "original": "boolean",
152
+ "resolved": "boolean",
153
+ "references": {}
154
+ },
155
+ "required": false,
156
+ "optional": false,
157
+ "docs": {
158
+ "tags": [],
159
+ "text": ""
160
+ },
161
+ "attribute": "wide",
162
+ "reflect": false,
163
+ "defaultValue": "false"
164
+ }
165
+ }; }
166
+ static get methods() { return {
167
+ "load": {
168
+ "complexType": {
169
+ "signature": "() => Promise<HTMLElement>",
170
+ "parameters": [],
171
+ "references": {
172
+ "Promise": {
173
+ "location": "global"
174
+ },
175
+ "HTMLElement": {
176
+ "location": "global"
177
+ }
178
+ },
179
+ "return": "Promise<HTMLElement>"
180
+ },
181
+ "docs": {
182
+ "text": "",
183
+ "tags": []
184
+ }
185
+ },
186
+ "stop": {
187
+ "complexType": {
188
+ "signature": "() => Promise<HTMLElement>",
189
+ "parameters": [],
190
+ "references": {
191
+ "Promise": {
192
+ "location": "global"
193
+ },
194
+ "HTMLElement": {
195
+ "location": "global"
196
+ }
197
+ },
198
+ "return": "Promise<HTMLElement>"
199
+ },
200
+ "docs": {
201
+ "text": "",
202
+ "tags": []
203
+ }
204
+ },
205
+ "disable": {
206
+ "complexType": {
207
+ "signature": "() => Promise<void>",
208
+ "parameters": [],
209
+ "references": {
210
+ "Promise": {
211
+ "location": "global"
212
+ }
213
+ },
214
+ "return": "Promise<void>"
215
+ },
216
+ "docs": {
217
+ "text": "",
218
+ "tags": []
219
+ }
220
+ },
221
+ "enable": {
222
+ "complexType": {
223
+ "signature": "() => Promise<void>",
224
+ "parameters": [],
225
+ "references": {
226
+ "Promise": {
227
+ "location": "global"
228
+ }
229
+ },
230
+ "return": "Promise<void>"
231
+ },
232
+ "docs": {
233
+ "text": "",
234
+ "tags": []
235
+ }
236
+ }
237
+ }; }
238
+ static get elementRef() { return "host"; }
239
+ static get watchers() { return [{
240
+ "propName": "btnStyle",
241
+ "methodName": "handleVisible"
242
+ }, {
243
+ "propName": "loading",
244
+ "methodName": "handleLoading"
245
+ }]; }
246
+ }
@@ -0,0 +1,206 @@
1
+ import { Component, Element, h, Method, Prop } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ /**
4
+ * @slot header - The top of the modal.
5
+ * @slot footer - Replaces the bottom button.
6
+ * @slot language - Replaces language label, has replaceable props `{name}`, `{code}`, `{country_code}`.
7
+ * @slot currency - Replaces currency label, has replaceable props `{name}`, `{code}`, `{country_code}`.
8
+ */
9
+ export class SallaLocalization {
10
+ constructor() {
11
+ var _a, _b;
12
+ this.language = salla.config.language || {};
13
+ this.currency = salla.config.currency || {};
14
+ this.languagesTitle = salla.lang.get('common.titles.language');
15
+ this.currenciesTitle = salla.lang.get('common.titles.currency');
16
+ this.ok = salla.lang.get('common.elements.ok');
17
+ Helper.setHost(this.host);
18
+ salla.event.on('localization::show', () => this.show());
19
+ /**
20
+ * letting developer to insert his own slot like:
21
+ * <salla-localization>
22
+ * <div slot="language">...{name}....</div>
23
+ * <div slot="currency">...{name}....</div>
24
+ * </salla-localization>
25
+ * Because scoped templates not supported in stencil );
26
+ * we made a workaround to pass language & currency attributes, then replace names in rendering
27
+ */
28
+ this.languageSlot = ((_a = Helper.getElement('[slot="language"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<label class="s-localization-label" for="lang-{code}"><span>{name}</span><div class="s-localization-flag flag iti__flag iti__{country_code}"></div></label>';
29
+ this.currencySlot = ((_b = Helper.getElement('[slot="currency"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<label class="s-localization-label" for="currency-{code}"><span>{name}</span><small class="s-localization-currency">{code}</small></label>';
30
+ }
31
+ async show() {
32
+ return this.modal.show();
33
+ }
34
+ async hide() {
35
+ return this.modal.hide();
36
+ }
37
+ onChangeCurrency(event) {
38
+ this.currency = salla.config.currencies.filter(currency => currency.code == event.target.value)[0];
39
+ }
40
+ onChangeLanguage(event) {
41
+ this.language = salla.config.languages.filter(lang => lang.code == event.target.value)[0];
42
+ }
43
+ async submit() {
44
+ let url;
45
+ console.log('this.currency.code::::', this.currency, this.currency.code);
46
+ this.btn.load()
47
+ .then(() => (this.currency.code === salla.config.currency.code) || ((url = window.location.href) && salla.currency.api.change(this.currency.code)))
48
+ .then(() => (this.language.code === salla.config.language.code) || (url = this.language.url))
49
+ .then(() => this.btn.stop())
50
+ .then(() => this.hide())
51
+ .then(() => url && (window.location.href = url));
52
+ }
53
+ render() {
54
+ return (h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal, "modal-width": "xs" },
55
+ h("div", { slot: "header" },
56
+ h("slot", { name: "header" })),
57
+ h("div", { class: "s-localization-inner" },
58
+ salla.config.languages ?
59
+ h("div", { class: "s-localization-section" },
60
+ h("label", { class: "s-localization-title" }, this.languagesTitle),
61
+ h("div", { class: "s-localization-section-inner" }, salla.config.languages.length < 6 ?
62
+ salla.config.languages.map(lang => h("div", { class: "s-localization-item" },
63
+ h("input", { class: "s-localization-input", type: "radio", checked: this.language.code == lang.code, onChange: () => this.language = lang, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }),
64
+ h("div", { id: "language-slot", innerHTML: this.languageSlot
65
+ .replace(/\{name\}/g, lang.name)
66
+ .replace(/\{code\}/g, lang.code)
67
+ .replace(/\{country_code\}/g, lang.country_code) }))) :
68
+ h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeLanguage(e) }, salla.config.languages.map(lang => h("option", { value: lang.code, selected: this.language.code == lang.code }, lang.name)))))
69
+ : '',
70
+ salla.config.currencies ?
71
+ h("div", { class: "s-localization-section" },
72
+ h("label", { class: "s-localization-title" }, this.currenciesTitle),
73
+ h("div", { class: "s-localization-section-inner" }, salla.config.currencies.length < 6 ?
74
+ salla.config.currencies.map(currency => h("div", { class: "s-localization-item" },
75
+ h("input", { class: "s-localization-input", type: "radio", name: "currency", checked: this.currency.code == currency.code, onChange: () => this.currency = currency, id: 'currency-' + currency.code, value: currency.code }),
76
+ h("div", { id: "currency-slot", innerHTML: this.currencySlot
77
+ .replace(/\{name\}/g, currency.name)
78
+ .replace(/\{code\}/g, currency.code)
79
+ .replace(/\{country_code\}/g, currency.country_code) }))) :
80
+ h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, salla.config.currencies.map(currency => h("option", { value: currency.code, selected: this.currency.code == currency.code }, currency.name)))))
81
+ : ''),
82
+ h("slot", { name: "footer" },
83
+ h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.ok))));
84
+ }
85
+ /**
86
+ * to reduce dom levels we will move slot data into the parent dom
87
+ */
88
+ componentDidRender() {
89
+ this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
90
+ this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
91
+ }
92
+ static get is() { return "salla-localization"; }
93
+ static get properties() { return {
94
+ "languagesTitle": {
95
+ "type": "string",
96
+ "mutable": false,
97
+ "complexType": {
98
+ "original": "string",
99
+ "resolved": "string",
100
+ "references": {}
101
+ },
102
+ "required": false,
103
+ "optional": false,
104
+ "docs": {
105
+ "tags": [],
106
+ "text": ""
107
+ },
108
+ "attribute": "languages-title",
109
+ "reflect": false,
110
+ "defaultValue": "salla.lang.get('common.titles.language')"
111
+ },
112
+ "currenciesTitle": {
113
+ "type": "string",
114
+ "mutable": false,
115
+ "complexType": {
116
+ "original": "string",
117
+ "resolved": "string",
118
+ "references": {}
119
+ },
120
+ "required": false,
121
+ "optional": false,
122
+ "docs": {
123
+ "tags": [],
124
+ "text": ""
125
+ },
126
+ "attribute": "currencies-title",
127
+ "reflect": false,
128
+ "defaultValue": "salla.lang.get('common.titles.currency')"
129
+ },
130
+ "ok": {
131
+ "type": "string",
132
+ "mutable": false,
133
+ "complexType": {
134
+ "original": "string",
135
+ "resolved": "string",
136
+ "references": {}
137
+ },
138
+ "required": false,
139
+ "optional": false,
140
+ "docs": {
141
+ "tags": [],
142
+ "text": ""
143
+ },
144
+ "attribute": "ok",
145
+ "reflect": false,
146
+ "defaultValue": "salla.lang.get('common.elements.ok')"
147
+ }
148
+ }; }
149
+ static get methods() { return {
150
+ "show": {
151
+ "complexType": {
152
+ "signature": "() => Promise<HTMLElement>",
153
+ "parameters": [],
154
+ "references": {
155
+ "Promise": {
156
+ "location": "global"
157
+ },
158
+ "HTMLElement": {
159
+ "location": "global"
160
+ }
161
+ },
162
+ "return": "Promise<HTMLElement>"
163
+ },
164
+ "docs": {
165
+ "text": "",
166
+ "tags": []
167
+ }
168
+ },
169
+ "hide": {
170
+ "complexType": {
171
+ "signature": "() => Promise<HTMLElement>",
172
+ "parameters": [],
173
+ "references": {
174
+ "Promise": {
175
+ "location": "global"
176
+ },
177
+ "HTMLElement": {
178
+ "location": "global"
179
+ }
180
+ },
181
+ "return": "Promise<HTMLElement>"
182
+ },
183
+ "docs": {
184
+ "text": "",
185
+ "tags": []
186
+ }
187
+ },
188
+ "submit": {
189
+ "complexType": {
190
+ "signature": "() => Promise<void>",
191
+ "parameters": [],
192
+ "references": {
193
+ "Promise": {
194
+ "location": "global"
195
+ }
196
+ },
197
+ "return": "Promise<void>"
198
+ },
199
+ "docs": {
200
+ "text": "",
201
+ "tags": []
202
+ }
203
+ }
204
+ }; }
205
+ static get elementRef() { return "host"; }
206
+ }