Skip to content

Commit

Permalink
Add Live Search Widgets (EDS Delivery) (#18)
Browse files Browse the repository at this point in the history
* Add PLP and search widget

* Add autocomplete widget

* Use EDS delivered widgets

* Fix linting

* Fix linting

* Add urlKey to route function

* Update widget version

* Fix PLP widget config

* Fix CLS

* Fix CLS

* Fix SaaS environment for LS autocomplete

* search.js latest from elsie-base-design branch

* add to cart

* Optimize add to cart and enable list view

* latest widgets update from elsie-base-design

* Style fixes

---------

Co-authored-by: Kathleen Tynan <[email protected]>
  • Loading branch information
herzog31 and kathleentynan authored Feb 26, 2024
1 parent 5eca7a0 commit c79f666
Show file tree
Hide file tree
Showing 12 changed files with 1,147 additions and 973 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
helix-importer-ui
scripts/preact.js
scripts/htm.js
tools/picker
tools/picker
scripts/widgets
8 changes: 7 additions & 1 deletion blocks/header/header.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* stylelint-disable selector-class-pattern */

/* header and nav layout */
header .nav-wrapper {
background-color: var(--background-color);
Expand Down Expand Up @@ -314,6 +316,10 @@ header .nav-search-input input {
padding: 5px;
}

header .nav-search-input .search_autocomplete .popover-container {
width: 100%;
}

@media (width >= 1024px) {
header .nav-search-input {
left: unset;
Expand All @@ -323,4 +329,4 @@ header .nav-search-input input {
header .nav-search-input input {
min-width: 400px;
}
}
}
10 changes: 8 additions & 2 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ export default async function decorate(block) {
});

// Search
const searchInput = document.createRange().createContextualFragment('<div class="nav-search-input hidden"><form action="/search" method="GET"><input type="search" name="q" placeholder="Search" /></form></div>');
const searchInput = document.createRange().createContextualFragment(`<div class="nav-search-input hidden">
<form id="search_mini_form" action="/search" method="GET">
<input id="search" type="search" name="q" placeholder="Search" />
<div id="search_autocomplete" class="search-autocomplete"></div>
</form>
</div>`);
document.body.querySelector('header').append(searchInput);

const searchButton = document.createRange().createContextualFragment('<button type="button" class="nav-search-button">Search</button>');
navTools.append(searchButton);
navTools.querySelector('.nav-search-button').addEventListener('click', () => {
navTools.querySelector('.nav-search-button').addEventListener('click', async () => {
await import('./searchbar.js');
document.querySelector('header .nav-search-input').classList.toggle('hidden');
});

Expand Down
48 changes: 48 additions & 0 deletions blocks/header/searchbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { loadScript } from '../../scripts/aem.js';
import { getConfigValue } from '../../scripts/configs.js';

(async () => {
const widgetProd = '/scripts/widgets/LiveSearchAutocomplete.js';
await loadScript(widgetProd);

const storeDetails = {
environmentId: await getConfigValue('commerce-environment-id'),
environmentType: (await getConfigValue('commerce-environment-id')).includes('sandbox') ? 'testing' : '',
apiKey: await getConfigValue('commerce-x-api-key'),
websiteCode: await getConfigValue('commerce-website-code'),
storeCode: await getConfigValue('commerce-store-code'),
storeViewCode: await getConfigValue('commerce-store-view-code'),
config: {
pageSize: 8,
perPageConfig: {
pageSizeOptions: '12,24,36',
defaultPageSizeOption: '24',
},
minQueryLength: '2',
currencySymbol: '$',
currencyRate: '1',
displayOutOfStock: true,
allowAllProducts: false,
},
context: {
customerGroup: await getConfigValue('commerce-customer-group'),
},
route: ({ sku }) => `/products/missing-url-key/${sku}`, // TODO: We need urlKey as parameter as well!
searchRoute: {
route: '/search',
query: 'q',
},
};

await new Promise((resolve) => {
const interval = setInterval(() => {
if (window.LiveSearchAutocomplete) {
clearInterval(interval);
resolve();
}
}, 200);
});

// eslint-disable-next-line no-new
new window.LiveSearchAutocomplete(storeDetails);
})();
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c79f666

Please sign in to comment.