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

Commit 908542f

Browse files
authored
Update the Filters button (#1861)
Update the VFilterButton
1 parent 6de7e20 commit 908542f

23 files changed

+99
-76
lines changed

src/components/VHeader/VFilterButton.vue

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
<template>
22
<VButton
33
id="filter-button"
4-
:variant="variant"
4+
:variant="filtersAreApplied ? 'action-menu-muted' : 'action-menu'"
55
size="disabled"
6-
class="align-center flex-shrink-0 gap-2 self-center py-2 font-semibold focus-visible:border-tx focus-visible:ring focus-visible:ring-pink"
7-
:class="
8-
filtersAreApplied
9-
? 'flex-shrink-0 px-3'
10-
: 'h-10 w-10 px-0 md:h-auto md:w-auto md:px-3'
11-
"
6+
class="align-center label-regular h-12 w-12 gap-2 self-center xl:w-auto xl:ps-3"
7+
:class="[filtersAreApplied ? 'xl:pe-3' : 'xl:pe-4']"
128
:pressed="pressed"
139
:disabled="disabled"
1410
aria-controls="filters"
15-
:aria-label="mdMinLabel"
11+
:aria-label="xlMinLabel"
1612
@click="$emit('toggle')"
1713
@keydown.tab.exact="$emit('tab', $event)"
1814
>
1915
<VIcon
2016
:class="filtersAreApplied ? 'hidden' : 'block'"
2117
:icon-path="filterIcon"
2218
/>
23-
<span class="hidden md:inline-block">{{ mdMinLabel }}</span>
24-
<span class="md:hidden" :class="!filtersAreApplied && 'hidden'">{{
25-
smMaxLabel
19+
<span class="hidden xl:inline-block">{{ xlMinLabel }}</span>
20+
<span class="xl:hidden" :class="{ hidden: !filtersAreApplied }">{{
21+
lgMaxLabel
2622
}}</span>
2723
</VButton>
2824
</template>
2925

3026
<script lang="ts">
31-
import { computed, defineComponent, inject, ref } from '@nuxtjs/composition-api'
27+
import { computed, defineComponent } from '@nuxtjs/composition-api'
3228
3329
import { useSearchStore } from '~/stores/search'
3430
import { defineEvent } from '~/types/emits'
35-
import type { ButtonVariant } from '~/types/button'
3631
import { useI18n } from '~/composables/use-i18n'
3732
3833
import VButton from '~/components/VButton.vue'
@@ -63,55 +58,28 @@ export default defineComponent({
6358
setup() {
6459
const i18n = useI18n()
6560
const searchStore = useSearchStore()
66-
const isMinScreenMd = inject('isMinScreenMd', ref(false))
67-
const isHeaderScrolled = inject('isHeaderScrolled', ref(false))
6861
const filterCount = computed(() => searchStore.appliedFilterCount)
6962
const filtersAreApplied = computed(() => filterCount.value > 0)
7063
71-
/**
72-
* Determine the visual style of the button
73-
* based on the viewport, the application of filters, and scrolling.
74-
*/
75-
const variant = computed(() => {
76-
// Show the bordered state by default, unless below md
77-
let value: ButtonVariant = isMinScreenMd.value
78-
? 'action-menu-bordered'
79-
: 'action-menu'
80-
81-
if (isHeaderScrolled.value) {
82-
value = 'action-menu'
83-
}
84-
if (filtersAreApplied.value) {
85-
value = 'action-menu-muted'
86-
}
87-
return value
88-
})
89-
9064
/**
9165
* This label's verbosity makes it useful for the aria-label
9266
* where it is also used, especially on mobile where the
9367
* label would just be the number of applied filters, and therefore
9468
* basically useless as far as a label is concerned!
9569
*/
96-
const mdMinLabel = computed(() =>
70+
const xlMinLabel = computed(() =>
9771
filtersAreApplied.value
9872
? i18n.tc('header.filter-button.with-count', filterCount.value)
9973
: i18n.t('header.filter-button.simple')
10074
)
101-
102-
const smMaxLabel = computed(() =>
103-
isHeaderScrolled.value
104-
? filterCount.value
105-
: i18n.tc('header.filter-button.with-count', filterCount.value)
75+
const lgMaxLabel = computed(() =>
76+
filtersAreApplied ? filterCount.value : ''
10677
)
10778
10879
return {
109-
filterCount,
11080
filterIcon,
111-
mdMinLabel,
112-
smMaxLabel,
113-
variant,
114-
isHeaderScrolled,
81+
xlMinLabel,
82+
lgMaxLabel,
11583
filtersAreApplied,
11684
}
11785
},

src/components/VHeader/meta/VFilterButton.stories.mdx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Meta,
66
Story,
77
} from '@storybook/addon-docs'
8-
import { provide, ref } from '@nuxtjs/composition-api'
98
import VFilterButton from '~/components/VHeader/VFilterButton.vue'
109
import { useSearchStore } from '~/stores/search'
1110
import { filterData, mediaFilterKeys } from '~/constants/filters'
@@ -21,23 +20,24 @@ import { IMAGE } from '~/constants/media'
2120
appliedFilters: {
2221
type: 'number',
2322
},
24-
scrolled: {
25-
type: 'boolean',
23+
toggle: {
24+
action: 'toggle',
2625
},
27-
isMinMd: {
28-
type: 'boolean',
26+
tab: {
27+
action: 'tab',
2928
},
3029
}}
3130
/>
3231

3332
export const Template = (args, { argTypes }) => ({
34-
template: `<VFilterButton v-bind="args" />`,
33+
template: `<VFilterButton v-bind="args" v-on="args" />`,
3534
components: { VFilterButton },
3635
props: Object.keys(argTypes),
3736
setup() {
3837
const searchStore = useSearchStore()
3938
searchStore.setSearchType(IMAGE)
4039
function applyNFilters(filterCount) {
40+
searchStore.clearFilters()
4141
const filterTypes = [...mediaFilterKeys[IMAGE]]
4242
let filterIdx = 0
4343
// Skip license type filters as they can disable license filters
@@ -56,12 +56,6 @@ export const Template = (args, { argTypes }) => ({
5656
}
5757
}
5858
applyNFilters(args.appliedFilters)
59-
if (args.scrolled) {
60-
provide('isHeaderScrolled', ref(true))
61-
}
62-
if (args.isMinMd) {
63-
provide('isMinScreenMd', ref(true))
64-
}
6559
return { args }
6660
},
6761
})
@@ -78,15 +72,24 @@ the field receives an input. It also emits the `search` event when the search
7872
button is clicked.
7973

8074
<Canvas>
81-
<Story name="Default">{Template.bind({})}</Story>
75+
<Story
76+
name="Default"
77+
parameters={{
78+
viewport: {
79+
defaultViewport: 'lg',
80+
},
81+
}}
82+
>
83+
{Template.bind({})}
84+
</Story>
8285
</Canvas>
8386

8487
<Canvas>
8588
<Story
86-
name="Mobile Scrolled"
89+
name="With text label"
8790
parameters={{
8891
viewport: {
89-
defaultViewport: 'iphonex',
92+
defaultViewport: 'xl',
9093
},
9194
}}
9295
>
File renamed without changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { test } from '@playwright/test'
2+
3+
import breakpoints from '~~/test/playwright/utils/breakpoints'
4+
import { makeGotoWithArgs } from '~~/test/storybook/utils/args'
5+
6+
const gotoWithArgs = makeGotoWithArgs(
7+
'components-vheaderold-vfilterbuttonold--default-story'
8+
)
9+
10+
test.describe.configure({ mode: 'parallel' })
11+
12+
test.describe('VFilterButtonOld', () => {
13+
breakpoints.describeMd(({ expectSnapshot }) => {
14+
test('no filters applied', async ({ page }) => {
15+
await gotoWithArgs(page, { isMinMd: true })
16+
await expectSnapshot('filter-button-old-at-rest', page)
17+
})
18+
19+
test('no filters pressed', async ({ page }) => {
20+
await gotoWithArgs(page, { isMinMd: true, pressed: true })
21+
await expectSnapshot('filter-button-old-pressed', page)
22+
})
23+
24+
test('filters applied', async ({ page }) => {
25+
await gotoWithArgs(page, { isMinMd: true, appliedFilters: 2 })
26+
await expectSnapshot('filter-button-old-2-filters', page)
27+
})
28+
29+
test('filters applied and pressed', async ({ page }) => {
30+
await gotoWithArgs(page, {
31+
isMinMd: true,
32+
appliedFilters: 2,
33+
pressed: true,
34+
})
35+
await expectSnapshot('filter-button-old-2-filters-pressed', page)
36+
})
37+
})
38+
39+
breakpoints.describeXs(({ expectSnapshot }) => {
40+
test('no filters applied and not scrolled', async ({ page }) => {
41+
await gotoWithArgs(page)
42+
await expectSnapshot('filter-button-old-no-filters-not-scrolled', page)
43+
})
44+
45+
test('no filters but scrolled', async ({ page }) => {
46+
await gotoWithArgs(page, { scrolled: true })
47+
await expectSnapshot('filter-button-old-no-filters-scrolled', page)
48+
})
49+
50+
test('2 filters not scrolled', async ({ page }) => {
51+
await gotoWithArgs(page, { appliedFilters: 2 })
52+
await expectSnapshot('filter-button-old-2-filters-not-scrolled', page)
53+
})
54+
55+
test('2 filters and scrolled', async ({ page }) => {
56+
await gotoWithArgs(page, { appliedFilters: 2, scrolled: true })
57+
await expectSnapshot('filter-button-old-2-filters-scrolled', page)
58+
})
59+
})
60+
})
5.33 KB
Loading
4.12 KB
Loading
5.39 KB
Loading
5.17 KB
Loading

0 commit comments

Comments
 (0)