Skip to content

Commit

Permalink
refactor: use modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahdayan committed Sep 8, 2023
1 parent 33d25bf commit 97171a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"path": "packages/vue-instantsearch/vue3/umd/index.js",
"maxSize": "63.5 kB"
"maxSize": "63.25 kB"
},
{
"path": "packages/vue-instantsearch/vue2/cjs/index.js",
Expand Down
29 changes: 12 additions & 17 deletions packages/vue-instantsearch/src/components/Pagination.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="state" :class="suit()">
<slot
:refine="(page) => refine(page, $event)"
:refine="refine"
:createURL="state.createURL"
:current-refinement="state.currentRefinement"
:nb-hits="state.nbHits"
Expand All @@ -23,14 +23,14 @@
name="first"
:createURL="() => state.createURL(0)"
:is-first-page="state.isFirstPage"
:refine="() => refine(0, $event)"
:refine="() => refine(0)"
>
<template v-if="!state.isFirstPage">
<a
:class="suit('link')"
aria-label="First"
:href="state.createURL(0)"
@click.prevent="refine(0, $event)"
@click.exact.left.prevent="refine(0)"
>‹‹</a
>
</template>
Expand All @@ -51,14 +51,14 @@
name="previous"
:createURL="() => state.createURL(state.currentRefinement - 1)"
:is-first-page="state.isFirstPage"
:refine="() => refine(state.currentRefinement - 1, $event)"
:refine="() => refine(state.currentRefinement - 1)"
>
<template v-if="!state.isFirstPage">
<a
:class="suit('link')"
aria-label="Previous"
:href="state.createURL(state.currentRefinement - 1)"
@click.prevent="refine(state.currentRefinement - 1, $event)"
@click.exact.left.prevent="refine(state.currentRefinement - 1)"
>‹</a
>
</template>
Expand All @@ -83,13 +83,13 @@
:createURL="() => state.createURL(page)"
:is-first-page="state.isFirstPage"
:is-last-page="state.isLastPage"
:refine="() => refine(page, $event)"
:refine="() => refine(page)"
>
<a
:class="suit('link')"
:href="state.createURL(page)"
:aria-label="`Page ${page + 1}`"
@click.prevent="refine(page, $event)"
@click.exact.left.prevent="refine(page)"
>{{ page + 1 }}</a
>
</slot>
Expand All @@ -107,14 +107,14 @@
name="next"
:createURL="() => state.createURL(state.currentRefinement + 1)"
:is-last-page="state.isLastPage"
:refine="() => refine(state.currentRefinement + 1, $event)"
:refine="() => refine(state.currentRefinement + 1)"
>
<template v-if="!state.isLastPage">
<a
:class="suit('link')"
aria-label="Next"
:href="state.createURL(state.currentRefinement + 1)"
@click.prevent="refine(state.currentRefinement + 1, $event)"
@click.exact.left.prevent="refine(state.currentRefinement + 1)"
>›</a
>
</template>
Expand All @@ -135,14 +135,14 @@
name="last"
:createURL="() => state.createURL(state.nbPages - 1)"
:is-last-page="state.isLastPage"
:refine="() => refine(state.nbPages - 1, $event)"
:refine="() => refine(state.nbPages - 1)"
>
<template v-if="!state.isLastPage">
<a
:class="suit('link')"
aria-label="Last"
:href="state.createURL(state.nbPages - 1)"
@click.prevent="refine(state.nbPages - 1, $event)"
@click.exact.left.prevent="refine(state.nbPages - 1)"
>››</a
>
</template>
Expand All @@ -162,7 +162,6 @@ import { connectPagination } from 'instantsearch.js/es/connectors';
import { createPanelConsumerMixin } from '../mixins/panel';
import { createSuitMixin } from '../mixins/suit';
import { createWidgetMixin } from '../mixins/widget';
import { isModifierClick } from '../util/isModifierClick';
export default {
name: 'AisPagination',
Expand Down Expand Up @@ -220,11 +219,7 @@ export default {
},
emits: ['page-change'],
methods: {
refine(page, event) {
if (isModifierClick(event)) {
return;
}
refine(page) {
const p = Math.min(Math.max(page, 0), this.state.nbPages - 1);
this.state.refine(p);
// TODO: do this in a general way
Expand Down
11 changes: 0 additions & 11 deletions packages/vue-instantsearch/src/util/isModifierClick.js

This file was deleted.

0 comments on commit 97171a6

Please sign in to comment.