UNPKG

@empathyco/x-components

Version:
189 lines (159 loc) • 6.31 kB
--- title: NextQueriesList --- # NextQueriesList Component that inserts groups of next queries in different positions of the injected search items list, based on the provided configuration. ## Props | Name | Description | Type | Default | | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------ | | <code>animation</code> | Animation component that will be used to animate the next queries groups. | <code>AnimationProp</code> | <code>'ul'</code> | | <code>offset</code> | The first index to insert a group of next queries at. | <code>number</code> | <code>24</code> | | <code>frequency</code> | The items cycle size to keep inserting next queries groups at. | <code>number</code> | <code>24</code> | | <code>maxNextQueriesPerGroup</code> | The maximum amount of next queries to add in a single group. | <code>number</code> | <code>4</code> | | <code>maxGroups</code> | The maximum number of groups to insert into the injected list items list. | <code>number</code> | <code></code> | | <code>showOnlyAfterOffset</code> | Determines if a group is added to the injected items list in case the number<br />of items is smaller than the offset. | <code>boolean</code> | <code>false</code> | ## Events This component emits no events. ## See it in action <!-- prettier-ignore-start --> :::warning Backend microservice required To use this component, the <b>QuerySignals</b> microservice must be implemented. ::: <!-- prettier-ignore-end --> Usually, this component is going to be used together with the `ResultsList` one. Next queries groups will be inserted between the results, guiding users to discover new searches directly from the results list. ```vue live <template> <div> <SearchInput /> <ResultsList> <NextQueriesList /> </ResultsList> </div> </template> <script> import { NextQueriesList } from '@empathyco/x-components/next-queries' import { ResultsList } from '@empathyco/x-components/search' import { SearchInput } from '@empathyco/x-components/search-box' export default { name: 'NextQueriesListDemo', components: { NextQueriesList, ResultsList, SearchInput, }, } </script> ``` ### Play with the index that next queries groups are inserted at The component allows to customise where are the next queries groups inserted. In the following example, the first group of next queries will be inserted at the index `48` (`offset`), and then a second group will be inserted at index `120` because of the `frequency` prop configured to `72`. Finally, a third group will be inserted at index `192`. Because `maxGroups` is configured to `3`, no more groups will be inserted. Each one of this groups will have up to `6` next queries (`maxNextQueriesPerGroup`). ```vue live <template> <div> <SearchInput /> <ResultsList> <NextQueriesList :offset="48" :frequency="72" :maxNextQueriesPerGroup="6" :maxGroups="3" /> </ResultsList> </div> </template> <script> import { NextQueriesList } from '@empathyco/x-components/next-queries' import { ResultsList } from '@empathyco/x-components/search' import { SearchInput } from '@empathyco/x-components/search-box' export default { name: 'NextQueriesListDemo', components: { NextQueriesList, ResultsList, SearchInput, }, } </script> ``` ### Showing/hiding first next queries group when no more items By default, the first next query group will be inserted when the total number of results is smaller than the offset, but this behavior can be deactivated by setting the `showOnlyAfterOffset` to `true`. ```vue live <template> <div> <SearchInput /> <ResultsList> <NextQueriesList :offset="48" :frequency="72" :maxNextQueriesPerGroup="1" :showOnlyAfterOffset="true" /> </ResultsList> </div> </template> <script> import { NextQueriesList } from '@empathyco/x-components/next-queries' import { ResultsList } from '@empathyco/x-components/search' import { SearchInput } from '@empathyco/x-components/search-box' export default { name: 'NextQueriesListDemo', components: { NextQueriesList, ResultsList, SearchInput, }, } </script> ``` ### Customise the layout of the component This component will render by default the `id` of each search item, both the injected, and for the groups of next queries generated, but the common case is to integrate it with another layout component, for example the `BaseGrid`. To do so, you can use the `default` slot ```vue <template> <div> <SearchInput /> <ResultsList> <NextQueriesList :offset="48" :frequency="72" :maxNextQueriesPerGroup="6" :maxGroups="3" #default="{ items }" > <BaseGrid :items="items" :animation="animation"> <template #next-queries-group="{ item }"> <span>NextQueriesGroup: {{ item.queries.join(', ') }}</span> </template> <template #result="{ item }"> <span>Result: {{ item.name }}</span> </template> <template #default="{ item }"> <span>Default: {{ item }}</span> </template> </BaseGrid> </NextQueriesList> </ResultsList> </div> </template> <script> import { NextQueriesList } from '@empathyco/x-components/next-queries' import { ResultsList } from '@empathyco/x-components/search' import { SearchInput } from '@empathyco/x-components/search-box' import { BaseGrid } from '@empathyco/x-components' export default { name: 'NextQueriesListDemo', components: { NextQueriesList, ResultsList, BaseGrid, SearchInput, }, } </script> ```