) {
- event.stopPropagation();
- this.bindings.store.state.activeProductChild = event.detail.child;
- this.suggestionManager.forceUpdate();
- }
-
private registerSearchboxSuggestionEvents() {
this.searchBoxSuggestionEventsQueue.forEach((evt) => {
this.suggestionManager.registerSuggestionsFromEvent(
@@ -310,7 +304,7 @@ export class AtomicCommerceSearchBox
this.searchBoxSuggestionEventsQueue = [];
}
- @Watch('redirectionUrl')
+ @watch('redirectionUrl')
watchRedirectionUrl() {
this.updateRedirectionUrl();
}
@@ -326,7 +320,7 @@ export class AtomicCommerceSearchBox
getSearchBoxValue: () => this.searchBoxState.value,
getSuggestionTimeout: () => this.suggestionTimeout,
getSuggestionDelay: () => this.suggestionDelay,
- getHost: () => this.host,
+ getHost: () => this,
getLogger: () => this.bindings.engine.logger,
});
this.suggestionManager.initializeSuggestions(this.suggestionBindings);
@@ -401,7 +395,7 @@ export class AtomicCommerceSearchBox
};
}
- private updateBreakpoints = once(() => updateBreakpoints(this.host));
+ private updateBreakpoints = once(() => updateBreakpoints(this));
private async onInput(value: string) {
this.updateQueryWithoutQuerySuggestionTrigger(value);
@@ -506,31 +500,31 @@ export class AtomicCommerceSearchBox
const isButton = item.onSelect || item.query;
if (!isButton) {
- return (
-
- );
+ return html`${simpleSearchSuggestion({
+ props: {
+ i18n: this.bindings.i18n,
+ id,
+ suggestion: item,
+ isSelected,
+ side,
+ index,
+ lastIndex,
+ isDoubleList: this.suggestionManager.isDoubleList,
+ },
+ })}`;
}
- return (
- {
+ return html`${buttonSearchSuggestion({
+ props: {
+ i18n: this.bindings.i18n,
+ id,
+ suggestion: item,
+ isSelected,
+ side,
+ index,
+ lastIndex,
+ isDoubleList: this.suggestionManager.isDoubleList,
+ onClick: (e: Event) => {
this.suggestionManager.onSuggestionClick(item, e);
if (item.key === 'recent-query-clear') {
return;
@@ -538,12 +532,12 @@ export class AtomicCommerceSearchBox
this.isExpanded = false;
this.triggerTextAreaChange(item.query ?? '');
- }}
- onMouseOver={() => {
+ },
+ onMouseOver: () => {
this.suggestionManager.onSuggestionMouseOver(item, side, id);
- }}
- >
- );
+ },
+ },
+ })}`;
}
private renderPanel(
@@ -556,22 +550,20 @@ export class AtomicCommerceSearchBox
return null;
}
- return (
- {
- if (e.target === getRef()) {
- e.preventDefault();
- }
- }}
- >
- {elements.map((suggestion, index) =>
- this.renderSuggestion(suggestion, index, elements.length - 1, side)
- )}
-
- );
+ return html`)}
+ class="flex grow basis-1/2 flex-col"
+ @mousedown=${(e: MouseEvent) => {
+ if (e.target === getRef()) {
+ e.preventDefault();
+ }
+ }}
+ >
+ ${elements.map((suggestion, index) =>
+ this.renderSuggestion(suggestion, index, elements.length - 1, side)
+ )}
+
`;
}
private renderSuggestions() {
@@ -579,49 +571,61 @@ export class AtomicCommerceSearchBox
return null;
}
- return (
-
- );
- }
+ const part = `suggestions-wrapper ${
+ this.suggestionManager.isDoubleList
+ ? 'suggestions-double-list'
+ : 'suggestions-single-list'
+ }`;
+
+ const isVisible =
+ this.suggestionManager.hasSuggestions &&
+ this.isExpanded &&
+ !this.isSearchDisabledForEndUser(this.searchBoxState.value);
+
+ const classes = {
+ 'bg-background': true,
+ 'border-neutral': true,
+ absolute: true,
+ 'top-full': true,
+ 'left-0': true,
+ 'z-10': true,
+ flex: true,
+ 'w-full': true,
+ 'rounded-md': true,
+ border: true,
+ hidden: !isVisible,
+ };
- private renderTextBox = (searchLabel: string) => {
+ return html``;
+ }
+ private renderTextBox(searchLabel: string) {
const props = {
loading: this.searchBoxState.isLoading,
- bindings: this.bindings,
+ i18n: this.bindings.i18n,
value: this.searchBoxState.value,
title: searchLabel,
ariaLabel: searchLabel,
@@ -641,28 +645,30 @@ export class AtomicCommerceSearchBox
},
};
- return (
- (this.textAreaRef = el as HTMLTextAreaElement)}
- {...props}
- onClear={() => {
+ return html`${searchBoxTextArea({
+ props: {
+ textAreaRef: this.textAreaRef,
+ ref: (el) => {
+ this.textAreaRef = el as HTMLTextAreaElement;
+ },
+ ...props,
+ onClear: () => {
props.onClear();
this.triggerTextAreaChange('');
- }}
- />
- );
- };
+ },
+ },
+ })}`;
+ }
private renderAbsolutePositionSpacer() {
- return (
-
- );
+ //style 0.875 rem to replace py-3.5 that does not work.. Is there a better solution ?
+ return html``;
}
private isSearchDisabledForEndUser(queryValue?: string) {
@@ -728,11 +734,12 @@ export class AtomicCommerceSearchBox
);
}
- public render() {
+ @bindingGuard()
+ @errorGuard()
+ render() {
this.updateBreakpoints();
const searchLabel = this.getSearchInputLabel(this.minimumQueryLength);
- const Submit = SubmitButton;
const isDisabled = this.isSearchDisabledForEndUser(
this.searchBoxState.value
);
@@ -740,40 +747,48 @@ export class AtomicCommerceSearchBox
this.registerSearchboxSuggestionEvents();
}
- return (
-
- {this.renderAbsolutePositionSpacer()}
- {[
- {
- if (!isFocusingOut(event)) {
- return;
- }
+ return html`
+ ${this.renderAbsolutePositionSpacer()}
+ ${wrapper({
+ props: {
+ disabled: isDisabled,
+ onFocusout: (event) => {
+ if (!isFocusingOut(event)) {
+ return;
+ }
+ this.suggestionManager.clearSuggestions();
+ this.isExpanded = false;
+ },
+ },
+ })(
+ html`${this.renderTextBox(searchLabel)}
+ ${submitButton({
+ props: {
+ i18n: this.bindings.i18n,
+ disabled: isDisabled,
+ onClick: () => {
+ this.searchBox.submit();
this.suggestionManager.clearSuggestions();
- this.isExpanded = false;
- }}
- >
- {this.renderTextBox(searchLabel)}
- {
- this.searchBox.submit();
- this.suggestionManager.clearSuggestions();
- }}
- title={searchLabel}
- />
- {this.renderSuggestions()}
- ,
- !this.suggestionManager.suggestions.length && (
+ },
+ title: searchLabel,
+ },
+ })}
+ ${this.renderSuggestions()}`
+ )}
+ ${this.suggestionManager.suggestions.length === 0
+ ? html`
- ),
- ]}
-
- );
+ `
+ : nothing}
+ `;
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ 'atomic-commerce-search-box': AtomicCommerceSearchBox;
}
}
diff --git a/packages/atomic/src/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.tw.css b/packages/atomic/src/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.tw.css
new file mode 100644
index 00000000000..1225171962f
--- /dev/null
+++ b/packages/atomic/src/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.tw.css
@@ -0,0 +1 @@
+@import '../../search/atomic-search-box/atomic-search-box.pcss';
diff --git a/packages/atomic/src/components/commerce/index.ts b/packages/atomic/src/components/commerce/index.ts
index 6606ec9ae26..f8e3894620b 100644
--- a/packages/atomic/src/components/commerce/index.ts
+++ b/packages/atomic/src/components/commerce/index.ts
@@ -1,2 +1,5 @@
// Auto-generated file
-export {};
+export {AtomicCommerceSearchBox} from './atomic-commerce-search-box/atomic-commerce-search-box.js';
+export {AtomicCommerceSearchBoxInstantProducts} from './atomic-commerce-search-box-instant-products/atomic-commerce-search-box-instant-products.js';
+export {AtomicCommerceSearchBoxQuerySuggestions} from './atomic-commerce-search-box-query-suggestions/atomic-commerce-search-box-query-suggestions.js';
+export {AtomicCommerceSearchBoxRecentQueries} from './atomic-commerce-search-box-recent-queries/atomic-commerce-search-box-recent-queries.js';
diff --git a/packages/atomic/src/components/commerce/lazy-index.ts b/packages/atomic/src/components/commerce/lazy-index.ts
index eb708f85099..57463e0fd69 100644
--- a/packages/atomic/src/components/commerce/lazy-index.ts
+++ b/packages/atomic/src/components/commerce/lazy-index.ts
@@ -1,4 +1,19 @@
// Auto-generated file
-export default {} as Record Promise>;
+export default {
+ 'atomic-commerce-search-box': async () =>
+ await import('./atomic-commerce-search-box/atomic-commerce-search-box.js'),
+ 'atomic-commerce-search-box-instant-products': async () =>
+ await import(
+ './atomic-commerce-search-box-instant-products/atomic-commerce-search-box-instant-products.js'
+ ),
+ 'atomic-commerce-search-box-query-suggestions': async () =>
+ await import(
+ './atomic-commerce-search-box-query-suggestions/atomic-commerce-search-box-query-suggestions.js'
+ ),
+ 'atomic-commerce-search-box-recent-queries': async () =>
+ await import(
+ './atomic-commerce-search-box-recent-queries/atomic-commerce-search-box-recent-queries.js'
+ ),
+} as Record Promise>;
export type * from './index.js';