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

Commit

Permalink
Refactor SearchTypePopover desktop header (#1842)
Browse files Browse the repository at this point in the history
* Refactor SearchTypePopover and filter button for desktop header

* Make VSearchTypes handle type selection

* Update src/components/VHeader/VHeaderFilter.vue

* Fix the logo size

* Revert changes to the VSearchTypeButton
  • Loading branch information
obulat authored Sep 29, 2022
1 parent 5e82520 commit 38acffa
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 74 deletions.
68 changes: 9 additions & 59 deletions src/components/VContentSwitcher/VSearchTypePopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,19 @@
<VSearchTypeButton
:a11y-props="a11yProps"
aria-controls="content-switcher-popover"
:active-item="activeItem"
:class="{
'!border-tx': isInSearchBar,
'!bg-white group-hover:!border-dark-charcoal-20 group-hover:focus:!border-tx':
isInSearchBar && !a11yProps['aria-expanded'],
}"
:type="placement"
/>
</template>
<VSearchTypes
id="content-switcher-popover"
size="medium"
:active-item="activeItem"
:use-links="placement === 'header'"
@select="selectItem"
:use-links="true"
@select="closePopover"
/>
</VPopover>
</template>

<script lang="ts">
import {
computed,
defineComponent,
PropType,
ref,
} from '@nuxtjs/composition-api'
import type { SearchType } from '~/constants/media'
import { defineEvent } from '~/types/emits'
import { defineComponent, ref } from '@nuxtjs/composition-api'
import VPopover from '~/components/VPopover/VPopover.vue'
import VSearchTypeButton from '~/components/VContentSwitcher/VSearchTypeButton.vue'
Expand All @@ -49,55 +33,21 @@ import checkIcon from '~/assets/icons/checkmark.svg'
export default defineComponent({
name: 'VSearchTypePopover',
components: {
VSearchTypeButton,
VPopover,
VSearchTypeButton,
VSearchTypes,
},
model: {
prop: 'activeItem',
event: 'select',
},
props: {
activeItem: {
type: String as PropType<SearchType>,
required: true,
},
placement: {
type: String as PropType<'header' | 'searchbar'>,
default: 'header',
},
},
emits: {
select: defineEvent<SearchType>(),
},
setup(props, { emit }) {
const contentMenuPopover = ref<HTMLElement | null>(null)
/**
* When in the searchbar, content switcher button has a border when the
* search bar group is hovered on.
*/
const isInSearchBar = computed(() => props.placement === 'searchbar')
/**
* Only the contentMenuPopover needs to be closed programmatically
*/
const closeMenu = () => {
if (contentMenuPopover.value) {
contentMenuPopover.value.close()
}
}
setup() {
const contentMenuPopover = ref<InstanceType<typeof VPopover> | null>(null)
const selectItem = (item: SearchType) => {
emit('select', item)
const closePopover = () => {
contentMenuPopover.value?.close()
}
return {
checkIcon,
selectItem,
closePopover,
contentMenuPopover,
isInSearchBar,
closeMenu,
}
},
})
Expand Down
30 changes: 19 additions & 11 deletions src/components/VContentSwitcher/VSearchTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@
:item-id="idx"
:icon="content.icons[item]"
:use-links="useLinks"
:selected="item === activeItem"
@click="handleClick(item)"
:selected="isActive(item)"
@click="selectItem(item)"
/>
</div>
</VItemGroup>
</template>
<script lang="ts">
import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'
import {
computed,
defineComponent,
type PropType,
} from '@nuxtjs/composition-api'
import type { SearchType } from '~/constants/media'
import useSearchType from '~/composables/use-search-type'
import type { SearchType } from '~/constants/media'
import { defineEvent } from '~/types/emits'
import VItemGroup from '~/components/VItemGroup/VItemGroup.vue'
Expand All @@ -57,10 +61,9 @@ export default defineComponent({
type: String as PropType<'small' | 'medium'>,
default: 'small',
},
activeItem: {
type: String as PropType<SearchType>,
required: true,
},
/**
* Whether to use buttons for search type selection, or links to the specific search type search for the items.
*/
useLinks: {
type: Boolean,
default: true,
Expand All @@ -71,6 +74,9 @@ export default defineComponent({
},
setup(props, { emit }) {
const content = useSearchType()
const bordered = computed(() => props.size === 'small')
const isActive = (item: SearchType) => item === content.activeType.value
const contentTypeGroups = computed(() => {
const base = [
Expand All @@ -90,15 +96,17 @@ export default defineComponent({
return base
})
const bordered = computed(() => props.size === 'small')
const handleClick = (item) => {
const selectItem = (item: SearchType) => {
content.setActiveType(item)
emit('select', item)
}
return {
content,
contentTypeGroups,
isActive,
bordered,
handleClick,
selectItem,
}
},
})
Expand Down
Loading

0 comments on commit 38acffa

Please sign in to comment.