@salla.sa/twilight-components 1.0.20 → 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.
@@ -1,123 +0,0 @@
1
- import { r as registerInstance, h, g as getElement } from './index-799f93d3.js';
2
- import { H as Helper } from './Helper-d07ebbc7.js';
3
-
4
- const sallaLoginCss = "salla-verify{display:block}";
5
-
6
- const SallaLogin = class {
7
- constructor(hostRef) {
8
- registerInstance(this, hostRef);
9
- this.regType = 'sms';
10
- this.isLoginByMail = true;
11
- this.loginTypeTitle = salla.lang.get('blocks.header.select_login_way');
12
- this.loginText = salla.lang.get('blocks.header.login');
13
- this.smsLabel = salla.lang.get('blocks.header.sms');
14
- this.mobileLabel = salla.lang.get('common.elements.mobile');
15
- this.emailLabel = salla.lang.get('common.elements.email');
16
- this.enterText = salla.lang.get('blocks.header.enter');
17
- this.bySMSText = salla.lang.get('blocks.header.login_by_sms');
18
- this.byEmailText = salla.lang.get('blocks.header.login_by_email');
19
- this.backText = salla.lang.get('common.elements.back');
20
- this.title = this.host.title || salla.lang.get('blocks.header.login');
21
- this.host.removeAttribute('title');
22
- salla.auth.event.onVerificationFailed(() => {
23
- //
24
- });
25
- }
26
- /**
27
- * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
28
- */
29
- onVerified(event) {
30
- if (!event.detail.case) {
31
- console.log('verified but without case!');
32
- return;
33
- }
34
- if (event.detail.case === "new_customer") {
35
- return this.showTab(this.tab5);
36
- }
37
- //TODO::It looks that is this workaround🤔
38
- if (salla.auth.event.getTypeActionOnVerified() !== 'redirect') {
39
- return;
40
- }
41
- if (event.redirect_url) {
42
- return window.location.href = event.redirect_url;
43
- }
44
- window.location.reload();
45
- }
46
- onbackClicked() {
47
- this.regType == 'sms' ? this.showTab(this.tab2) : this.showTab(this.tab3);
48
- }
49
- async show() {
50
- this.showTab(this.isLoginByMail ? this.tab1 : this.tab2);
51
- return this.modal.show();
52
- }
53
- showTab(tab) {
54
- [this.tab1, this.tab2, this.tab3, this.tab4, this.tab5].map(el => Helper.toggleElement(el, 'visible', 'hidden', () => el == tab));
55
- setTimeout(() => { [this.tab1, this.tab2, this.tab3, this.tab4, this.tab5].map(el => Helper.toggleElement(el, 's-login-active', 's-login-unactive', () => el == tab)); }, 200);
56
- setTimeout(() => { this.host.querySelector('.s-login-wrapper').setAttribute('style', 'height:' + (tab === null || tab === void 0 ? void 0 : tab.scrollHeight) + 'px'); });
57
- if ([this.tab2, this.tab3].includes(tab)) {
58
- this.regType = tab === this.tab2 ? 'sms' : 'email';
59
- }
60
- let isRegistrationTab = tab == this.tab5;
61
- this.modal.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
62
- if (!isRegistrationTab) {
63
- Helper.toggleElement(this.regMobileBlock, 's-hidden', 's-block', () => this.regType === 'sms')
64
- .toggleElement(this.regEmailBlock, 's-hidden', 's-block', () => this.regType === 'email');
65
- }
66
- return this;
67
- }
68
- loginByEmail() {
69
- if (!Helper.isValidEmail(this.email.value)) {
70
- this.email.classList.add('s-has-error');
71
- this.email.nextElementSibling['innerText'] = '* ' + salla.lang.get('common.elements.email_is_valid');
72
- return;
73
- }
74
- this.email.nextElementSibling['innerText'] = '';
75
- this.email.classList.remove('s-has-error');
76
- salla.auth.api.login({ type: 'email', email: this.email.value })
77
- .then(() => this.showTab(this.tab4))
78
- .then(() => (this.tab4.by = 'email') && (this.tab4.url = 'auth/email/verify'))
79
- .then(() => this.tab4.show({ email: this.email.value }));
80
- }
81
- loginBySMS() {
82
- if (this.mobile.value.length < 6) {
83
- this.mobile.classList.add('s-has-error');
84
- this.mobile.nextElementSibling['innerText'] = '* ' + salla.lang.get('mobile_app.strings.incorrect_mobile');
85
- return;
86
- }
87
- this.mobile.nextElementSibling['innerText'] = '';
88
- this.mobile.classList.remove('s-has-error');
89
- salla.auth.api.login({ type: 'sms', mobile: this.mobile.value })
90
- .then(() => this.showTab(this.tab4))
91
- .then(() => (this.tab4.by = 'sms') && (this.tab4.url = 'auth/mobile/verify'))
92
- .then(() => this.tab4.show({ mobile: this.mobile.value, country_code: 'SA' }));
93
- }
94
- //TODO:: if it's enter, go submit
95
- typing({ target }) {
96
- target.type === 'tel' && salla.helpers.digitsOnly(target);
97
- target.classList.remove('s-has-error');
98
- target.nextElementSibling.innerText = '';
99
- }
100
- newUser() {
101
- this.tab4.getCode()
102
- .then(code => salla.auth.api.register({
103
- first_name: this.firstName.value,
104
- last_name: this.lastName.value,
105
- phone: this.regMobile.value || this.mobile.value,
106
- email: this.regEmail.value || this.email.value,
107
- country_code: '',
108
- country_key: '',
109
- code: code,
110
- verified_by: this.regType,
111
- }));
112
- }
113
- render() {
114
- return (h("salla-modal", { id: "salla-login", title: this.title, ref: modal => this.modal = modal, width: "xs" }, h("div", { class: "s-login-wrapper" }, this.isLoginByMail ?
115
- h("div", { class: "s-login-tab", ref: tab => this.tab1 = tab }, h("p", { class: "s-login-sub-title" }, this.loginTypeTitle), h("a", { href: "#", class: "s-login-main-btn", onClick: () => this.showTab(this.tab2) }, h("i", { class: "s-login-main-btn-icon sicon-phone" }), h("span", { class: "s-login-main-btn-text" }, this.smsLabel), h("i", { class: "main-btn-arrow sicon-keyboard_arrow_left" })), h("a", { href: "#", class: "s-login-main-btn", onClick: () => this.showTab(this.tab3) }, h("i", { class: "s-login-main-btn-icon sicon-mail" }), h("span", { class: "s-login-main-btn-text" }, this.emailLabel), h("i", { class: "main-btn-arrow sicon-keyboard_arrow_left" })))
116
- : '', h("div", { class: "s-login-tab", ref: tab => this.tab2 = tab }, h("label", { class: "s-login-label" }, this.mobileLabel), h("salla-tel-input", null), h("input", { onChange: () => this.loginBySMS(), type: "tel", ref: el => this.mobile = el, onInput: this.typing, placeholder: "5xx xxx xxx", class: "s-login-input tel-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginBySMS() }, this.enterText), this.isLoginByMail ? h("a", { href: "#", onClick: () => this.showTab(this.tab3), class: "s-login-link" }, this.byEmailText) : ''), this.isLoginByMail ?
117
- h("div", { class: "s-login-tab", ref: tab => this.tab3 = tab }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { onChange: () => this.loginByEmail(), type: "email", ref: el => this.email = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginByEmail() }, this.enterText), h("a", { href: "#", onClick: () => this.showTab(this.tab2), class: "s-login-link" }, this.bySMSText)) : '', h("salla-verify", { "without-modal": true, ref: tab => this.tab4 = tab, autoReload: false, "back-text": this.backText }), h("div", { ref: tab => this.tab5 = tab }, h("label", { class: "s-login-label" }, salla.lang.get('blocks.header.your_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.firstName = el, placeholder: salla.lang.get('pages.profile.first_name') }), h("label", { class: "s-login-label" }, salla.lang.get('pages.profile.last_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.lastName = el, placeholder: salla.lang.get('pages.profile.last_name') }), h("div", { ref: el => this.regMobileBlock = el }, h("label", { class: "s-login-label" }, this.mobileLabel), h("input", { type: "tel", ref: el => this.regMobile = el, onInput: this.typing, placeholder: "5xx xxx xxx", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" })), h("div", { ref: el => this.regEmailBlock = el }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { type: "email", ref: el => this.regEmail = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" })), h("salla-button", { wide: true, onClick: () => this.newUser() }, salla.lang.get('blocks.header.register'))))));
118
- }
119
- get host() { return getElement(this); }
120
- };
121
- SallaLogin.style = sallaLoginCss;
122
-
123
- export { SallaLogin as S };
@@ -1,79 +0,0 @@
1
- import { r as registerInstance, h, e as Host, g as getElement } from './index-799f93d3.js';
2
- import { H as Helper } from './Helper-d07ebbc7.js';
3
-
4
- const SallaSearch = class {
5
- constructor(hostRef) {
6
- registerInstance(this, hostRef);
7
- var _a, _b;
8
- this.results = [];
9
- /**
10
- * Override search placeholder.
11
- */
12
- this.placeholder = salla.lang.get('blocks.header.search_placeholder');
13
- /**
14
- * Override no results error message.
15
- */
16
- this.noResultsText = salla.lang.get('common.elements.no_options');
17
- Helper.setHost(this.host);
18
- this.buttonSlot = ((_a = Helper.getElement('[slot="button"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<i class="sicon-search"></i>';
19
- this.productSlot = ((_b = Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.getDefaultProductSlot();
20
- }
21
- onModalClose() {
22
- Helper.getElement('.s-search-input').value = '';
23
- this.results = [];
24
- this.afterSearching();
25
- }
26
- getDefaultProductSlot() {
27
- return '<a target="_blank" href={url} class="s-search-product-image-container">' +
28
- ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
29
- '</a>' +
30
- '<div class="s-search-product-details">' +
31
- ' <div class="s-search-product-name">{name}</div> <div class="s-search-product-price">{price}</div>' +
32
- '</div>';
33
- }
34
- //todo:: reset data when closing
35
- search(e) {
36
- Helper.hideElement(this.noResults);
37
- if (e.target.value.length === 0) {
38
- this.results = [];
39
- this.afterSearching();
40
- return;
41
- }
42
- if (e.target.value.length <= 2) {
43
- return;
44
- }
45
- //run loading spinner or stop it
46
- Helper.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => true);
47
- salla.search.api.search(e.target.value)
48
- .then(response => this.results = response.results)
49
- .catch(err => err !== 'Query Same As Previous!' ? this.results = [] : null)
50
- .finally(() => this.afterSearching(/*isEmpty*/ false));
51
- }
52
- afterSearching(isEmpty = true) {
53
- this.noResults.style.display = isEmpty || this.results.length > 0 ? 'none' : 'block';
54
- Helper.toggleElement(this.container, 's-search-container-open', 'no-results', () => this.results.length)
55
- .toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => false); //stop searching anime
56
- salla.search.api.previousQuery = ''; //avoid having error 'Query Same As Previous' after reopen modal;
57
- }
58
- render() {
59
- var _a;
60
- return (h(Host, { class: "s-search" }, h("button", { onClick: () => this.modal.show(), class: "s-search-button", innerHTML: this.buttonSlot }), h("salla-modal", { ref: modal => this.modal = modal }, h("div", { class: "s-search-container", slot: "body", ref: container => this.container = container }, h("input", { class: "s-search-input", type: "text", placeholder: this.placeholder, onInput: e => this.search(e) }), h("span", { class: "s-search-icon" }, h("i", { class: "sicon-search", ref: el => this.searchIcon = el })), h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
61
- _a.map(item => {
62
- var _a;
63
- return h("div", { class: "s-search-product", innerHTML: this.productSlot
64
- .replace(/\{name\}/g, item.title)
65
- .replace(/\{price\}/g, (_a = item.price) === null || _a === void 0 ? void 0 : _a.after) //todo:: get discounted price too
66
- .replace(/\{url\}/g, item.url)
67
- .replace(/\{image\}/g, item.thumb) });
68
- }), h("p", { ref: el => this.noResults = el, class: "s-search-no-results" }, this.noResultsText))))));
69
- }
70
- /**
71
- * Run it one time after load
72
- */
73
- componentDidLoad() {
74
- this.afterSearching();
75
- }
76
- get host() { return getElement(this); }
77
- };
78
-
79
- export { SallaSearch as S };