|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <header class="header"> |
| 4 | + <div class="header-wrapper wrapper"> |
| 5 | + <nav class="header-nav"> |
| 6 | + <a href="/">Home</a> |
| 7 | + </nav> |
| 8 | + <div id="autocomplete"></div> |
| 9 | + </div> |
| 10 | + </header> |
| 11 | + |
| 12 | + <ais-instant-search |
| 13 | + :search-client="searchClient" |
| 14 | + :index-name="indexName" |
| 15 | + :routing="routing" |
| 16 | + :middlewares="middlewares" |
| 17 | + > |
| 18 | + <ais-configure |
| 19 | + :attributes-to-snippet.camel="['name:7', 'description:15']" |
| 20 | + :snippet-ellipsis-text.camel="'…'" |
| 21 | + ></ais-configure> |
| 22 | + <div class="container wrapper"> |
| 23 | + <div> |
| 24 | + <ais-panel> |
| 25 | + <template v-slot:header>Categories</template> |
| 26 | + <ais-hierarchical-menu |
| 27 | + :attributes="[ |
| 28 | + 'hierarchicalCategories.lvl0', |
| 29 | + 'hierarchicalCategories.lvl1', |
| 30 | + ]" |
| 31 | + ></ais-hierarchical-menu> |
| 32 | + </ais-panel> |
| 33 | + </div> |
| 34 | + <div> |
| 35 | + <ais-search-box><template></template></ais-search-box> |
| 36 | + <ais-hits> |
| 37 | + <template v-slot:item="{ item }"> |
| 38 | + <article class="hit"> |
| 39 | + <div class="hit-image"> |
| 40 | + <img :src="item.image" :alt="item.name" /> |
| 41 | + </div> |
| 42 | + <div> |
| 43 | + <h1> |
| 44 | + <ais-snippet :hit="item" attribute="name" /> |
| 45 | + </h1> |
| 46 | + <div> |
| 47 | + By <strong>{{ item.brand }}</strong> in |
| 48 | + <strong>{{ item.categories[0] }}</strong> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + </article> |
| 52 | + </template> |
| 53 | + </ais-hits> |
| 54 | + <ais-pagination :show-first="false" :show-last="false" /> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + </ais-instant-search> |
| 58 | + </div> |
| 59 | +</template> |
| 60 | + |
| 61 | +<script> |
| 62 | +import { history as historyRouter } from 'instantsearch.js/es/lib/routers'; |
| 63 | +import { singleIndex as singleIndexMapping } from 'instantsearch.js/es/lib/stateMappings'; |
| 64 | +
|
| 65 | +import { autocompleteMiddleware } from './autocompleteMiddleware'; |
| 66 | +import { INSTANT_SEARCH_INDEX_NAME } from './constants'; |
| 67 | +import { searchClient } from './searchClient'; |
| 68 | +
|
| 69 | +export default { |
| 70 | + data() { |
| 71 | + return { |
| 72 | + searchClient, |
| 73 | + indexName: INSTANT_SEARCH_INDEX_NAME, |
| 74 | + routing: { |
| 75 | + router: historyRouter(), |
| 76 | + stateMapping: singleIndexMapping(INSTANT_SEARCH_INDEX_NAME), |
| 77 | + }, |
| 78 | + middlewares: [autocompleteMiddleware], |
| 79 | + }; |
| 80 | + }, |
| 81 | +}; |
| 82 | +</script> |
| 83 | + |
| 84 | +<style> |
| 85 | +* { |
| 86 | + box-sizing: border-box; |
| 87 | +} |
| 88 | +
|
| 89 | +body { |
| 90 | + margin: 0; |
| 91 | + padding: 0; |
| 92 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, |
| 93 | + Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; |
| 94 | + background-color: rgb(244, 244, 249); |
| 95 | + color: rgb(65, 65, 65); |
| 96 | +} |
| 97 | +
|
| 98 | +a { |
| 99 | + color: var(--aa-primary-color); |
| 100 | + text-decoration: none; |
| 101 | +} |
| 102 | +
|
| 103 | +.header { |
| 104 | + background: rgb(252 252 255 / 92%); |
| 105 | + box-shadow: 0 0 0 1px rgba(35, 38, 59, 0.05), |
| 106 | + 0 1px 3px 0 rgba(35, 38, 59, 0.15); |
| 107 | + padding: 0.5rem 0; |
| 108 | + position: fixed; |
| 109 | + top: 0; |
| 110 | + width: 100%; |
| 111 | +} |
| 112 | +
|
| 113 | +.header-wrapper { |
| 114 | + align-items: center; |
| 115 | + display: grid; |
| 116 | + grid-template-columns: 100px 1fr; |
| 117 | +} |
| 118 | +
|
| 119 | +.header-nav { |
| 120 | + font-weight: 500; |
| 121 | +} |
| 122 | +
|
| 123 | +.wrapper { |
| 124 | + margin: 0 auto; |
| 125 | + max-width: 1200px; |
| 126 | + padding: 0 1.5rem; |
| 127 | + width: 100%; |
| 128 | +} |
| 129 | +
|
| 130 | +.container { |
| 131 | + margin-top: 3.5rem; |
| 132 | + padding: 1.5rem; |
| 133 | + display: grid; |
| 134 | + gap: 1rem; |
| 135 | + grid-template-columns: 1fr 3fr; |
| 136 | +} |
| 137 | +
|
| 138 | +/* Autocomplete */ |
| 139 | +
|
| 140 | +.aa-Panel { |
| 141 | + position: fixed; |
| 142 | +} |
| 143 | +
|
| 144 | +/* InstantSearch */ |
| 145 | +
|
| 146 | +.ais-Hits-list { |
| 147 | + display: grid; |
| 148 | + gap: 1rem; |
| 149 | + grid-template-columns: 1fr 1fr 1fr; |
| 150 | +} |
| 151 | +
|
| 152 | +.ais-Hits-item { |
| 153 | + padding: 1rem !important; |
| 154 | +} |
| 155 | +
|
| 156 | +.hit { |
| 157 | + align-items: center; |
| 158 | + display: grid; |
| 159 | + gap: 1rem; |
| 160 | +} |
| 161 | +
|
| 162 | +.hit h1 { |
| 163 | + font-size: 1rem; |
| 164 | +} |
| 165 | +
|
| 166 | +.hit p { |
| 167 | + font-size: 0.8rem; |
| 168 | + opacity: 0.8; |
| 169 | +} |
| 170 | +
|
| 171 | +.hit-image { |
| 172 | + align-items: center; |
| 173 | + display: flex; |
| 174 | + height: 100px; |
| 175 | + justify-content: center; |
| 176 | +} |
| 177 | +
|
| 178 | +.hit-image img { |
| 179 | + max-height: 100%; |
| 180 | +} |
| 181 | +
|
| 182 | +.ais-HierarchicalMenu-item--selected.ais-HierarchicalMenu-item--parent |
| 183 | + > div:first-of-type |
| 184 | + .ais-HierarchicalMenu-label { |
| 185 | + font-weight: bold; |
| 186 | +} |
| 187 | +
|
| 188 | +.ais-HierarchicalMenu-item--selected:not(.ais-HierarchicalMenu-item--parent) |
| 189 | + .ais-HierarchicalMenu-label { |
| 190 | + font-weight: bold; |
| 191 | +} |
| 192 | +
|
| 193 | +.ais-Pagination { |
| 194 | + display: flex; |
| 195 | + justify-content: center; |
| 196 | + margin: 2rem 0; |
| 197 | +} |
| 198 | +</style> |
0 commit comments