@salla.sa/twilight-components 1.6.2 → 1.6.3

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 (67) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/salla-button_24.cjs.entry.js +10087 -0
  3. package/dist/cjs/twilight-components.cjs.js +1 -1
  4. package/dist/collection/components/salla-login-modal/salla-login-modal.js +3 -4
  5. package/dist/collection/components/salla-verify/salla-verify.js +1 -1
  6. package/dist/components/salla-login-modal.js +3 -4
  7. package/dist/components/salla-verify2.js +1 -1
  8. package/dist/esm/loader.js +1 -1
  9. package/dist/esm/salla-button_24.entry.js +10060 -0
  10. package/dist/esm/twilight-components.js +1 -1
  11. package/dist/twilight-components/p-30b2c5b0.entry.js +4 -0
  12. package/dist/twilight-components/twilight-components.esm.js +1 -1
  13. package/package.json +9 -3
  14. package/dist/cjs/Helper-8ae6a805.js +0 -28
  15. package/dist/cjs/arrow-right-3d137e4c.js +0 -13
  16. package/dist/cjs/cancel-ae668d91.js +0 -13
  17. package/dist/cjs/check-circle2-1aac98d1.js +0 -13
  18. package/dist/cjs/mail-2db058ee.js +0 -13
  19. package/dist/cjs/salla-button_10.cjs.entry.js +0 -2584
  20. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +0 -93
  21. package/dist/cjs/salla-list-tile_2.cjs.entry.js +0 -80
  22. package/dist/cjs/salla-loyalty.cjs.entry.js +0 -229
  23. package/dist/cjs/salla-product-availability.cjs.entry.js +0 -128
  24. package/dist/cjs/salla-product-size-guide.cjs.entry.js +0 -52
  25. package/dist/cjs/salla-quantity-input.cjs.entry.js +0 -101
  26. package/dist/cjs/salla-rating-modal.cjs.entry.js +0 -169
  27. package/dist/cjs/salla-rating-stars.cjs.entry.js +0 -83
  28. package/dist/cjs/salla-social-share.cjs.entry.js +0 -1447
  29. package/dist/cjs/salla-swiper.cjs.entry.js +0 -5023
  30. package/dist/cjs/salla-tab-content_3.cjs.entry.js +0 -159
  31. package/dist/cjs/star2-8288e6e1.js +0 -13
  32. package/dist/esm/Helper-e1d414a5.js +0 -26
  33. package/dist/esm/arrow-right-1c3e04f2.js +0 -11
  34. package/dist/esm/cancel-41a92070.js +0 -11
  35. package/dist/esm/check-circle2-f6e5f685.js +0 -11
  36. package/dist/esm/mail-9d5204c6.js +0 -11
  37. package/dist/esm/salla-button_10.entry.js +0 -2571
  38. package/dist/esm/salla-infinite-scroll.entry.js +0 -89
  39. package/dist/esm/salla-list-tile_2.entry.js +0 -75
  40. package/dist/esm/salla-loyalty.entry.js +0 -225
  41. package/dist/esm/salla-product-availability.entry.js +0 -124
  42. package/dist/esm/salla-product-size-guide.entry.js +0 -48
  43. package/dist/esm/salla-quantity-input.entry.js +0 -97
  44. package/dist/esm/salla-rating-modal.entry.js +0 -165
  45. package/dist/esm/salla-rating-stars.entry.js +0 -79
  46. package/dist/esm/salla-social-share.entry.js +0 -1443
  47. package/dist/esm/salla-swiper.entry.js +0 -5019
  48. package/dist/esm/salla-tab-content_3.entry.js +0 -153
  49. package/dist/esm/star2-b134fc74.js +0 -11
  50. package/dist/twilight-components/p-0d498694.entry.js +0 -4
  51. package/dist/twilight-components/p-14f0ff17.entry.js +0 -4
  52. package/dist/twilight-components/p-335abbbb.entry.js +0 -4
  53. package/dist/twilight-components/p-4cafb11b.entry.js +0 -4
  54. package/dist/twilight-components/p-5e63e308.entry.js +0 -4
  55. package/dist/twilight-components/p-648e74e5.entry.js +0 -4
  56. package/dist/twilight-components/p-6a3adf55.entry.js +0 -4
  57. package/dist/twilight-components/p-6da4bb74.entry.js +0 -4
  58. package/dist/twilight-components/p-897b2018.js +0 -4
  59. package/dist/twilight-components/p-93708e1e.js +0 -4
  60. package/dist/twilight-components/p-9d236cf4.entry.js +0 -4
  61. package/dist/twilight-components/p-9d2ca9c8.js +0 -4
  62. package/dist/twilight-components/p-af7d5660.js +0 -4
  63. package/dist/twilight-components/p-bdbd2386.entry.js +0 -4
  64. package/dist/twilight-components/p-cac3db69.entry.js +0 -4
  65. package/dist/twilight-components/p-d914a212.js +0 -4
  66. package/dist/twilight-components/p-dace8e6d.js +0 -4
  67. package/dist/twilight-components/p-f9253fda.entry.js +0 -4
@@ -1,97 +0,0 @@
1
- /*!
2
- * Crafted with ❤ by Salla
3
- */
4
- import { r as registerInstance, h, H as Host, g as getElement } from './index-4e30ffd0.js';
5
- import { H as Helper } from './Helper-e1d414a5.js';
6
-
7
- const Add = `<!-- Generated by IcoMoon.io -->
8
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
9
- <title>add</title>
10
- <path d="M26.667 14.667h-9.333v-9.333c0-0.736-0.597-1.333-1.333-1.333s-1.333 0.597-1.333 1.333v9.333h-9.333c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333h9.333v9.333c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-9.333h9.333c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333z"></path>
11
- </svg>
12
- `;
13
-
14
- const Minus = `<!-- Generated by IcoMoon.io -->
15
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
16
- <title>minus</title>
17
- <path d="M26.667 14.667h-21.333c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333h21.333c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333z"></path>
18
- </svg>
19
- `;
20
-
21
- const sallaQuantityInputCss = "";
22
-
23
- const SallaQuantityInput = class {
24
- constructor(hostRef) {
25
- registerInstance(this, hostRef);
26
- this.hostAttributes = {};
27
- this.hasIncrementSlot = false;
28
- this.hasDecrementSlot = false;
29
- this.didLoaded = false;
30
- this.quantity = 1;
31
- }
32
- /**
33
- * Workaround to fire change event for the input.
34
- */
35
- watchPropHandler() {
36
- if (!this.didLoaded) {
37
- return;
38
- }
39
- Helper.debounce(() => salla.document.event.fireEvent(this.textInput, 'change', { 'bubbles': true }));
40
- }
41
- componentWillLoad() {
42
- this.quantity = parseInt(this.host.getAttribute('value')) || 1;
43
- this.hasIncrementSlot = !!this.host.querySelector('[slot="increment-button"]');
44
- this.hasDecrementSlot = !!this.host.querySelector('[slot="decrement-button"]');
45
- }
46
- componentDidLoad() {
47
- this.didLoaded = true;
48
- this.textInput.addEventListener('input', (event) => salla.helpers.inputDigitsOnly(event.target));
49
- }
50
- getInputAttributes() {
51
- for (let i = 0; i < this.host.attributes.length; i++) {
52
- if (!['id', 'value', 'min', 'class'].includes(this.host.attributes[i].name)) {
53
- this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
54
- }
55
- }
56
- return this.hostAttributes;
57
- }
58
- /**
59
- * decrease quantity by one.
60
- * @return HTMLSallaQuantityInputElement
61
- */
62
- async decrease() {
63
- return this.setValue(this.quantity - 1);
64
- }
65
- /**
66
- * increase quantity by one.
67
- * @return HTMLSallaQuantityInputElement
68
- */
69
- async increase() {
70
- return this.setValue(Number(this.quantity) + 1);
71
- }
72
- /**
73
- * set quantity by one.
74
- * @return HTMLSallaQuantityInputElement
75
- */
76
- async setValue(value) {
77
- let maxQuantity = parseInt(this.host.getAttribute('max'));
78
- if (maxQuantity && value > maxQuantity) {
79
- value = maxQuantity;
80
- }
81
- if (value <= 1) {
82
- value = 1;
83
- }
84
- this.quantity = value;
85
- return this.host;
86
- }
87
- render() {
88
- return (h(Host, { class: "s-quantity-input" }, h("div", { class: "s-quantity-input-container" }, h("button", { onClick: () => this.increase(), class: "s-quantity-input-increase-button s-quantity-input-button", type: "button" }, !this.hasIncrementSlot ? h("span", { innerHTML: Add }) : '', h("slot", { name: "increment-button" })), h("input", Object.assign({ class: "s-quantity-input-input" }, this.getInputAttributes(), { ref: (el) => this.textInput = el, onInput: (event) => this.setValue(event.target.value), min: "1", value: this.quantity })), h("button", { class: "s-quantity-input-decrease-button s-quantity-input-button", onClick: () => this.decrease(), type: "button" }, !this.hasDecrementSlot ? h("span", { innerHTML: Minus }) : '', h("slot", { name: "decrement-button" })))));
89
- }
90
- get host() { return getElement(this); }
91
- static get watchers() { return {
92
- "quantity": ["watchPropHandler"]
93
- }; }
94
- };
95
- SallaQuantityInput.style = sallaQuantityInputCss;
96
-
97
- export { SallaQuantityInput as salla_quantity_input };
@@ -1,165 +0,0 @@
1
- /*!
2
- * Crafted with ❤ by Salla
3
- */
4
- import { r as registerInstance, h, H as Host, g as getElement } from './index-4e30ffd0.js';
5
- import { H as Helper } from './Helper-e1d414a5.js';
6
- import { C as CheckCircle2 } from './check-circle2-f6e5f685.js';
7
-
8
- const ShippingFast = `<!-- Generated by IcoMoon.io -->
9
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
10
- <title>shipping-fast</title>
11
- <path d="M10.667 14.667c0-0.737-0.597-1.333-1.333-1.333h-8c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333h8c0.736 0 1.333-0.596 1.333-1.333zM9.333 18.667c-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333 5.333-2.392 5.333-5.333-2.392-5.333-5.333-5.333zM9.333 26.667c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667zM1.333 10.667h5.333c0.736 0 1.333-0.596 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333zM31.123 13.103l-3.147-3.935c-1.273-1.589-3.171-2.501-5.205-2.501h-1.437c0-2.205-1.795-4-4-4h-13.333c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333h13.333c0.735 0 1.333 0.597 1.333 1.333v1.333c0 0.248 0.087 0.468 0.204 0.667-0.117 0.199-0.204 0.419-0.204 0.667v5.333c0 0.737 0.597 1.333 1.333 1.333h9.333v6.667h-1.333c-0.063 0-0.117 0.028-0.179 0.036-0.583-2.313-2.664-4.036-5.155-4.036-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333c2.491 0 4.572-1.723 5.155-4.036 0.061 0.008 0.116 0.036 0.179 0.036h2.667c0.736 0 1.333-0.596 1.333-1.333v-8.399c0-0.905-0.311-1.792-0.877-2.499zM21.333 13.333v-4h1.437c1.221 0 2.36 0.547 3.124 1.501l1.997 2.499zM22.667 26.667c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667z"></path>
12
- </svg>
13
- `;
14
-
15
- const sallaRatingModalCss = "";
16
-
17
- const SallaRatingModal = class {
18
- constructor(hostRef) {
19
- registerInstance(this, hostRef);
20
- this.stepsCount = 0;
21
- this.currentIndex = 0;
22
- this.submitted = [];
23
- /**
24
- * The order id, to rate on its products & shipping
25
- */
26
- this.orderId = salla.config.get('page.id');
27
- this.translationLoaded = false;
28
- Helper.setHost(document);
29
- salla.event.on('rating::open', () => this.open());
30
- salla.lang.onLoaded(() => {
31
- this.translationLoaded = true;
32
- });
33
- }
34
- /**
35
- * Show the rating modal
36
- */
37
- async open() {
38
- return this.modal.open()
39
- .then(() => this.order || salla.rating.api.order(this.orderId).then(res => this.order = res.data))
40
- .then(() => this.modal.setTitle(salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.order.id + ')</span>'))
41
- .then(() => this.modal.stopLoading())
42
- .then(() => this.stepsCount = [this.order.testimonials_enabled, this.order.products_enabled, this.order.shipping_enabled].filter(enabled => enabled).length)
43
- .then(() => setTimeout(() => this.handleWizard(), 100));
44
- }
45
- /**
46
- * Show the rating modal
47
- */
48
- async close() {
49
- return this.modal.close();
50
- }
51
- // handle wizard
52
- handleWizard() {
53
- this.steps = this.modal.querySelectorAll(".s-rating-modal-step");
54
- this.dots = this.modal.querySelectorAll(".s-rating-modal-step-dot");
55
- this.showActiveStep();
56
- }
57
- showActiveStep(current = null) {
58
- var _a;
59
- this.currentTab = current || this.steps[this.currentIndex];
60
- Helper.toggleClassIf('.s-rating-modal-step-dot', 's-rating-modal-bg-gray', 's-rating-modal-bg-primary', dot => dot != this.dots[this.currentIndex])
61
- .toggleClassIf('.s-rating-modal-step', 's-rating-modal-active', 's-rating-modal-hidden', tab => tab == this.currentTab);
62
- if (this.currentIndex != 0) {
63
- // the animation
64
- Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-unactive', 's-rating-modal-hidden', () => true);
65
- setTimeout(() => Helper.toggleElementClassIf(this.currentTab, 's-rating-modal-active', 's-rating-modal-unactive', () => true), 300);
66
- }
67
- // Btn text
68
- let nextType = (_a = this.steps[this.currentIndex + 1]) === null || _a === void 0 ? void 0 : _a.dataset.type;
69
- this.nextBtn.setText(nextType ? salla.lang.get('pages.rating.rate') + ' ' + salla.lang.get('pages.rating.' + nextType)
70
- : salla.lang.get('pages.rating.send_ratings'));
71
- setTimeout(() => { var _a; return this.body.setAttribute('style', 'height:' + ((_a = this.currentTab) === null || _a === void 0 ? void 0 : _a.scrollHeight) + 'px'); });
72
- }
73
- previousTab() {
74
- this.currentIndex > 0 && this.currentIndex--;
75
- Helper.toggleElementClassIf(this.backBtn, 's-rating-modal-unvisiable', 'block', () => this.currentIndex == 0);
76
- this.showActiveStep();
77
- }
78
- submit() {
79
- this.submittedBefore() || this.validate();
80
- salla.config.canLeave = false;
81
- this.nextBtn.load()
82
- .then(() => this.submittedBefore() || this.sendFeedback())
83
- .then(() => this.currentTab.querySelectorAll('[name],.s-rating-modal-btn-star').forEach(el => el.setAttribute('disabled', '')))
84
- .then(() => this.currentIndex < this.stepsCount && this.currentIndex++)
85
- .then(() => this.showActiveStep())
86
- .then(() => Helper.toggleClassIf('#prev-btn', 'block', 's-rating-modal-unvisiable', () => true))
87
- .finally(() => {
88
- this.nextBtn.stop();
89
- salla.config.canLeave = true;
90
- this.currentIndex == this.stepsCount && this.showThankYou();
91
- this.modal.isClosable = false;
92
- });
93
- }
94
- submittedBefore() {
95
- return this.submitted.includes(this.currentIndex);
96
- }
97
- validate(rating = null, type = null) {
98
- if (!rating && this.currentTab.dataset.type == 'products') {
99
- return this.currentTab.querySelectorAll('.rating-outer-form').forEach(rating => this.validate(rating, 'product'));
100
- }
101
- rating = rating || this.currentTab;
102
- let stars = rating.querySelector('.rating_hidden_input').value;
103
- let comment = rating.querySelector('.s-rating-modal-comment');
104
- let validationMessage = rating.querySelector('.s-rating-modal-validation-msg');
105
- if (stars && comment.value && comment.value.length > 3) {
106
- comment.classList.remove('s-has-error');
107
- validationMessage.innerHTML = '';
108
- return;
109
- }
110
- type = type || rating['dataset'].type;
111
- Helper.toggleElementClassIf(comment, 'save', 's-has-error', el => el.value.length > 3);
112
- throw validationMessage.innerHTML = stars
113
- ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + comment.getAttribute('placeholder'))
114
- : salla.lang.get(`pages.rating.rate_${type}_stars`).replace(' (:item)', '');
115
- }
116
- sendFeedback() {
117
- let data = {};
118
- this.currentTab.querySelectorAll('[name]').forEach((input) => {
119
- //decode names like `<input name="jamal[inner]" value="hi">` to be {name:jamal, value: {inner:"hi"}}
120
- let inputData = salla.helpers.inputData(input.name, input.value, data);
121
- data[inputData.name] = inputData.value;
122
- });
123
- if (Object.keys(data).length == 0) {
124
- return;
125
- }
126
- data['order_id'] = this.orderId;
127
- data['type'] = this.currentTab.dataset.type;
128
- this.submitted.push(this.currentIndex);
129
- return salla.rating.api[this.currentTab.dataset.type](data);
130
- }
131
- showThankYou() {
132
- let seconds = 10;
133
- let timeToClose = setInterval(() => {
134
- this.thanksTime.innerHTML = '00:0' + (seconds--);
135
- if (seconds > 0) {
136
- return;
137
- }
138
- clearInterval(timeToClose);
139
- this.thanksTime.remove();
140
- this.close().then(() => window.location.reload());
141
- }, 1000);
142
- this.modal.querySelector('.s-rating-modal-footer').classList.add('s-rating-modal-unvisiable');
143
- this.showActiveStep(this.thanksTab);
144
- }
145
- render() {
146
- return (h(Host, { class: "s-rating" }, h("salla-modal", { isLoading: true, width: "md", ref: modal => this.modal = modal }, this.order
147
- ? [h("div", { class: "s-rating-modal-wrapper", ref: el => this.body = el }, this.order.testimonials_enabled ?
148
- h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "store" }, h("div", { class: "s-rating-modal-rounded-icon" }, h("img", { src: salla.config.get('store.logo', 'https://assets.salla.sa/cp/assets/images/logo-new.png'), alt: "store name", class: "s-rating-modal-store-logo" })), h("h2", { class: "s-rating-modal-title" }, salla.lang.get('pages.rating.rate_the_store')), h("div", { class: "s-rating-modal-stars-company" }, h("salla-rating-stars", { size: "large" })), h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_store_rate') }), h("small", { class: "s-rating-modal-validation-msg" }))
149
- : '', this.order.products_enabled
150
- ? h("section", { class: "s-rating-modal-step s-rating-modal-hidden", "data-type": "products" }, this.order.products.map((item, index) => h("div", { class: "rating-outer-form s-rating-modal-product", "data-stars-error": salla.lang.get('pages.rating.rate_product_stars') }, h("div", { class: "s-rating-modal-product-img-wrap" }, h("img", { src: item.product.thumbnail, alt: item.product.name, class: "s-rating-modal-product-img" })), h("div", { class: "s-rating-modal-product-details" }, h("h3", { class: "s-rating-modal-product-title" }, " ", item.product.name), h("div", { class: "s-rating-modal-stars-product" }, h("salla-rating-stars", { size: "small", name: `products[${index}][rating]` })), h("input", { type: "hidden", name: `products[${index}][product_id]`, value: item.product.id }), h("textarea", { placeholder: salla.lang.get('pages.rating.write_product_rate'), name: `products[${index}][comment]`, class: "s-rating-modal-comment" }), h("small", { class: "s-rating-modal-validation-msg" })))))
151
- : '', this.order.shipping_enabled
152
- ? h("div", { class: "rating-outer-form s-rating-modal-step-wrap s-rating-modal-step s-rating-modal-hidden", "data-type": "shipping" }, h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.company.id }), this.order.shipping.company.logo
153
- ? h("div", { class: "s-rating-modal-rounded-icon" }, h("img", { src: this.order.shipping.company.logo, class: "s-rating-modal-shipping-logo", alt: this.order.shipping.company.name }))
154
- : h("span", { class: "s-rating-modal-icon", innerHTML: ShippingFast }), h("div", { class: "s-rating-modal-title" }, " ", salla.lang.get('pages.rating.rate_shipping') + ' ' + this.order.shipping.company.name), h("div", { class: "s-rating-modal-stars-company" }, h("salla-rating-stars", { size: "large" })), h("textarea", { name: "comment", class: "s-rating-modal-comment", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }), h("small", { class: "s-rating-modal-validation-msg" }))
155
- : '', h("div", { class: "s-rating-modal-thanks s-rating-modal-hidden", ref: el => this.thanksTab = el }, h("span", { class: "s-rating-modal-icon", innerHTML: CheckCircle2 }), h("h3", { class: "s-rating-modal-thanks-title" }, salla.lang.get('pages.rating.thanks')), h("div", { class: "s-rating-modal-thanks-msg", innerHTML: this.order.thanks_message }), h("time", { class: "s-rating-modal-thanks-time", ref: el => this.thanksTime = el }))), h("div", { class: "s-rating-modal-footer" }, h("button", { ref: el => this.backBtn = el, onClick: () => this.previousTab(), class: "s-rating-modal-btn s-rating-modal-unvisiable" }, salla.lang.get('common.elements.back')), this.stepsCount > 1 ? h("ul", { class: "s-rating-modal-dots" }, [0, 1, 2].slice(0, this.stepsCount).map(() => h("li", { class: 's-rating-modal-bg-gray s-rating-modal-step-dot' }))) : '', h("salla-button", { "loader-position": 'center', ref: el => this.nextBtn = el, onClick: () => this.submit() }, salla.lang.get('common.elements.next'))),]
156
- : '')));
157
- }
158
- componentDidLoad() {
159
- salla.event.dispatch('rating::ready', this);
160
- }
161
- get host() { return getElement(this); }
162
- };
163
- SallaRatingModal.style = sallaRatingModalCss;
164
-
165
- export { SallaRatingModal as salla_rating_modal };
@@ -1,79 +0,0 @@
1
- /*!
2
- * Crafted with ❤ by Salla
3
- */
4
- import { r as registerInstance, h, H as Host, g as getElement } from './index-4e30ffd0.js';
5
- import { H as Helper } from './Helper-e1d414a5.js';
6
- import { S as Star2 } from './star2-b134fc74.js';
7
-
8
- const sallaRatingStarsCss = "";
9
-
10
- const SallaRatingStars = class {
11
- constructor(hostRef) {
12
- registerInstance(this, hostRef);
13
- /**
14
- * Sets input name.
15
- */
16
- this.name = 'rating';
17
- /**
18
- * Sets the height and width of the component. Defaults to medium.
19
- */
20
- this.size = 'medium';
21
- }
22
- initiateRating() {
23
- this.host.addEventListener('click', () => {
24
- if (!this.startsElem)
25
- return;
26
- // Get the selected star - activeElement is not supported in safari
27
- let activeStars = this.startsElem.querySelectorAll('.s-rating-stars-hovered');
28
- let selected = activeStars[activeStars.length - 1];
29
- if (!selected)
30
- return;
31
- let selectedIndex = selected.getAttribute('data-star');
32
- this.startsElem.querySelector('.rating_hidden_input').value = selectedIndex;
33
- // Loop through each star, and add or remove the `.selected` class to toggle highlighting
34
- this.startsElem.querySelectorAll('.s-rating-stars-btn-star')
35
- .forEach((star, index) => Helper.toggleElementClassIf(star, 's-rating-stars-selected', 's-rating-stars-unselected', () => index < parseInt(selectedIndex)));
36
- // update aria-pressed attr status
37
- this.startsElem.querySelectorAll('[aria-pressed]').forEach(star => star.removeAttribute('aria-pressed'));
38
- selected.setAttribute('aria-pressed', 'true');
39
- });
40
- }
41
- highlightSelectedStars() {
42
- var _a, _b;
43
- let hoveredClass = 's-rating-stars-hovered', stars = (_a = this.startsElem) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.s-rating-stars-btn-star');
44
- stars === null || stars === void 0 ? void 0 : stars.forEach((star, index) => {
45
- star.addEventListener('mouseover', () => {
46
- for (let i = 0; i <= index; i++) {
47
- stars[i].classList.add(hoveredClass);
48
- }
49
- });
50
- star.addEventListener('mouseout', () => star.classList.remove(hoveredClass));
51
- });
52
- (_b = this.startsElem) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseout', () => stars.forEach(star => star.classList.remove(hoveredClass)));
53
- }
54
- createStars(n) {
55
- let stars = [];
56
- for (let i = 0; i < 5; i++) {
57
- stars.push(h("span", { class: {
58
- 's-rating-stars-btn-star': true,
59
- ['s-rating-stars-' + this.size]: true,
60
- 's-rating-stars-selected': i < n
61
- }, innerHTML: Star2 }));
62
- }
63
- return stars;
64
- }
65
- render() {
66
- return (h(Host, null, this.value ?
67
- h("div", { class: "s-rating-stars-wrapper" }, " ", this.createStars(this.value), " ")
68
- :
69
- h("div", { class: "s-rating-stars-element", ref: (el) => this.startsElem = el }, h("input", { type: "hidden", class: "rating_hidden_input", name: this.name, value: "" }), [1, 2, 3, 4, 5].map(star => h("button", { class: `s-rating-stars-btn-star s-rating-stars-` + this.size, "data-star": star }, h("span", { innerHTML: Star2 }))))));
70
- }
71
- componentDidLoad() {
72
- this.initiateRating();
73
- this.highlightSelectedStars();
74
- }
75
- get host() { return getElement(this); }
76
- };
77
- SallaRatingStars.style = sallaRatingStarsCss;
78
-
79
- export { SallaRatingStars as salla_rating_stars };