Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit da5eadc

Browse files
committed
Predictive Search UI Component
1 parent 658f847 commit da5eadc

File tree

9 files changed

+1168
-1
lines changed

9 files changed

+1168
-1
lines changed

Diff for: packages/theme-predictive-search-component/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Description
2+
3+
A component that controls the state of a predictive search UI.
4+
5+
## Example
6+
7+
```js
8+
const predictivesearch = new PredictiveSearch({
9+
selectors: {
10+
input: '[data-predictive-search-input="header"]',
11+
reset: '[data-predictive-search-reset="header"]',
12+
result: '[data-predictive-search-result="header"]'
13+
},
14+
resultTemplateFct: data => {
15+
return `
16+
<div class="predictive-search">
17+
<ul class="predictive-search__list">
18+
${products.map(
19+
product => `
20+
<li>
21+
<img src="${product.image}" alt="${product.title}" />
22+
<span>${produtc.title}</span>
23+
</li>
24+
`
25+
)}
26+
</ul>
27+
</div>
28+
`;
29+
},
30+
onInputFocus: nodes => {
31+
// You can get a reference to active target
32+
console.log(nodes.input.id); //-> input
33+
console.log(nodes.submit.id); //-> submit
34+
console.log(nodes.result.id); //-> result
35+
},
36+
onInputKeyup: nodes => {
37+
return true; // This will allow the event callback to execute
38+
},
39+
onInputBlur: nodes => {
40+
return false; // This will prevent the event callback to execute
41+
},
42+
onInputClear: nodes => {},
43+
onBeforeKill: nodes => {},
44+
onBeforeOpen: nodes => {},
45+
onOpen: nodes => {},
46+
onBeforeClose: nodes => {},
47+
onClose: nodes => {},
48+
onKill: nodes => {}
49+
});
50+
51+
// Public methods
52+
predictivesearch.open();
53+
predictivesearch.close();
54+
predictivesearch.kill();
55+
```
56+
57+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"query": "The Calling",
3+
"resources": {
4+
"results": {
5+
"products": [
6+
{
7+
"title": "The Calling",
8+
"body": "<p>The Calling</p>",
9+
"handle": "calling",
10+
"image": "https://cdn.shopify.com/...",
11+
"url": "/products/calling?variant_id=1",
12+
"price": "3099",
13+
"variants": [
14+
{
15+
"title": "Large / Angry Dolphin",
16+
"url": "https://www.evil-bikes.com/products/calling",
17+
"image": "https://cdn.shopify.com/...",
18+
"price": "3099",
19+
"compare_at_price": "4099"
20+
}
21+
]
22+
}
23+
]
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"query": "The Following",
3+
"resources": {
4+
"results": {
5+
"products": [
6+
{
7+
"title": "The Following",
8+
"body": "<p>The Following</p>",
9+
"handle": "following",
10+
"image": "https://cdn.shopify.com/...",
11+
"url": "/products/following?variant_id=1",
12+
"price": "3099.00",
13+
"variants": [
14+
{
15+
"title": "Large / Angry Dolphin",
16+
"url": "https://www.evil-bikes.com/products/following",
17+
"image": "https://cdn.shopify.com/...",
18+
"price": "3099.00",
19+
"compare_at_price": "4099.00"
20+
}
21+
]
22+
}
23+
]
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"plugin:shopify/esnext",
5+
"plugin:shopify/node",
6+
"plugin:shopify/prettier"
7+
],
8+
"env": {
9+
"browser": true,
10+
"jest": true
11+
},
12+
"globals": {
13+
"page": true
14+
},
15+
"rules": {
16+
"shopify/strict-component-boundaries": "off",
17+
"babel/object-curly-spacing": 0
18+
}
19+
}

0 commit comments

Comments
 (0)