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

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Sep 27, 2022
1 parent 7c88312 commit 55a8ac7
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 133 deletions.
1 change: 1 addition & 0 deletions src/components/VContentSwitcher/VMobileMenuModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<VSearchTypeButton
:a11y-props="a11yProps"
:visible="visible"
:active-item="activeItem"
aria-controls="content-switcher-modal"
/>
</template>
Expand Down
95 changes: 67 additions & 28 deletions src/components/VContentSwitcher/VSearchTypeButton.vue
Original file line number Diff line number Diff line change
@@ -1,69 +1,108 @@
<template>
<VButton
class="flex h-12 w-12 flex-row xl:w-auto xl:px-2 xl:ps-3"
variant="action-menu"
class="flex flex-row py-2 text-sr font-semibold md:text-base"
:class="[
sizeClasses,
isHeaderScrolled ? 'max-w-[10rem] sm:max-w-[20rem] md:max-w-[16rem]' : '',
]"
:variant="buttonVariant"
size="disabled"
:aria-label="buttonLabel"
v-bind="a11yProps"
@click="$emit('click')"
>
<VIcon :icon-path="icon" />
<span
class="label-regular hidden truncate xl:block xl:ms-2 xl:text-start"
class="md:block md:truncate md:ms-2 md:text-start"
:class="isHeaderScrolled ? 'hidden' : 'block truncate ms-2 text-start'"
>{{ buttonLabel }}</span
>
<VIcon class="hidden xl:block xl:ms-2" :icon-path="caretDownIcon" />
<VIcon
class="hidden text-dark-charcoal-40 md:block md:ms-2"
:icon-path="caretDownIcon"
/>
</VButton>
</template>
<script lang="ts">
import { computed, defineComponent } from '@nuxtjs/composition-api'
import {
computed,
defineComponent,
inject,
PropType,
ref,
} from '@nuxtjs/composition-api'
import { ALL_MEDIA, AUDIO, IMAGE, MODEL_3D, VIDEO } from '~/constants/media'
import { ALL_MEDIA, SearchType } from '~/constants/media'
import useSearchType from '~/composables/use-search-type'
import { useI18n } from '~/composables/use-i18n'
import { isMinScreen } from '~/composables/use-media-query'
import VIcon from '~/components/VIcon/VIcon.vue'
import VButton from '~/components/VButton.vue'
import caretDownIcon from '~/assets/icons/caret-down.svg'
const labels = {
[ALL_MEDIA]: 'search-type.all',
[IMAGE]: 'search-type.image',
[AUDIO]: 'search-type.audio',
[VIDEO]: 'search-type.video',
[MODEL_3D]: 'search-type.model-3d',
}
/**
* This is the search type button that appears in the header, not on the homepage.
*/
export default defineComponent({
name: 'VSearchTypeButton',
components: { VButton, VIcon },
props: {
a11yProps: {
type: Object,
default: () => ({
'aria-expanded': false,
'aria-haspopup': 'dialog',
}),
required: true,
},
activeItem: {
type: String as PropType<SearchType>,
default: ALL_MEDIA,
},
type: {
type: String as PropType<'header' | 'searchbar'>,
default: 'header',
},
},
setup() {
setup(props) {
const i18n = useI18n()
const { icons, activeType } = useSearchType()
const activeItem = computed(() => activeType.value)
const isHeaderScrolled = inject('isHeaderScrolled', ref(null))
const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })
const buttonLabel = computed(() => i18n.t(labels[activeItem.value]))
const { icons, activeType: activeItem } = useSearchType()
const isIconButton = computed(
() => isHeaderScrolled?.value && !isMinScreenMd.value
)
const sizeClasses = computed(() => {
if (props.type === 'searchbar') {
return 'h-12 px-2'
} else if (isIconButton.value) {
return 'w-10 h-10'
} else {
/**
When there is a caret down icon (on 'md' screens), paddings are balanced,
without it, paddings need to be adjusted.
*/
return 'ps-2 pe-3 md:px-2'
}
})
const icon = computed(() => icons[activeItem.value])
const buttonVariant = computed(() => {
if (props.type === 'searchbar') {
return 'action-menu'
} else {
return isMinScreenMd.value && !isHeaderScrolled?.value
? 'tertiary'
: 'action-menu'
}
})
const buttonLabel = computed(() => {
return i18n.t(`search-type.${props.activeItem}`)
})
return {
buttonVariant,
sizeClasses,
buttonLabel,
caretDownIcon,
icon,
isHeaderScrolled,
isMinScreenMd,
icon: computed(() => icons[activeItem.value]),
}
},
})
Expand Down
102 changes: 0 additions & 102 deletions src/components/VContentSwitcher/meta/VSearchTypeButton.stories.mdx

This file was deleted.

4 changes: 1 addition & 3 deletions src/composables/use-search-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const icons = {
[IMAGE]: imageIcon,
[VIDEO]: videoIcon,
[MODEL_3D]: model3dIcon,
} as const
}

export default function useSearchType() {
const activeType = computed(() => useSearchStore().searchType)
Expand Down Expand Up @@ -54,5 +54,3 @@ export default function useSearchType() {
additionalTypes,
}
}

export type UseSearchTypeReturn = ReturnType<typeof useSearchType>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 55a8ac7

Please sign in to comment.