Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Update search types popover for the new homepage and header (#2071)
Olga Bulatec0793365da6
diff --git a/src/assets/icons/item-indicator.svg b/src/assets/icons/item-indicator.svgnew file mode 100644index 000000000..c2e29332e--- /dev/null+++ b/src/assets/icons/item-indicator.svg@@ -0,0 +1,5 @@+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+ <g id="icon">+ <path fill-rule="evenodd" clip-rule="evenodd" d="M17.9291 7.97825L10.7308 17.6591L6.2145 14.3009L7.10952 13.0972L10.4221 15.5603L16.7253 7.08322L17.9291 7.97825Z" fill="currentColor"/>+ </g>+</svg>diff --git a/src/components/VContentSwitcher/VSearchTypeItem.vue b/src/components/VContentSwitcher/VSearchTypeItem.vueindex e4a294cbd..44079b038 100644--- a/src/components/VContentSwitcher/VSearchTypeItem.vue+++ b/src/components/VContentSwitcher/VSearchTypeItem.vue@@ -3,7 +3,8 @@:selected="selected":is-first="isFirst":as="component"- class="h-16 text-base lg:h-12"+ class="label-regular"+ :size="size"v-bind="{ href }"@click.native="$emit('click', item)">diff --git a/src/components/VContentSwitcher/VSearchTypePopover.vue b/src/components/VContentSwitcher/VSearchTypePopover.vueindex 8b68f6675..8fbec66ae 100644--- a/src/components/VContentSwitcher/VSearchTypePopover.vue+++ b/src/components/VContentSwitcher/VSearchTypePopover.vue@@ -14,16 +14,16 @@</template><VSearchTypesid="content-switcher-popover"- class="min-w-[262px] pt-2"+ class="w-[260px] pt-2"size="small"- :use-links="true"+ :use-links="placement === 'header'"@select="closePopover"/></VPopover></template><script lang="ts">-import { defineComponent, ref } from "@nuxtjs/composition-api"+import { defineComponent, PropType, ref } from "@nuxtjs/composition-api"import VPopover from "~/components/VPopover/VPopover.vue"import VSearchTypeButton from "~/components/VContentSwitcher/VSearchTypeButton.vue"@@ -38,6 +38,12 @@ export default defineComponent({VSearchTypeButton,VSearchTypes,},+ props: {+ placement: {+ type: String as PropType<"header" | "searchbar">,+ default: "header",+ },+ },setup() {const contentMenuPopover = ref<InstanceType<typeof VPopover> | null>(null)diff --git a/src/components/VContentSwitcher/VSearchTypes.vue b/src/components/VContentSwitcher/VSearchTypes.vueindex 7be6b69bf..d9a9a9459 100644--- a/src/components/VContentSwitcher/VSearchTypes.vue+++ b/src/components/VContentSwitcher/VSearchTypes.vue@@ -4,22 +4,24 @@:size="size":bordered="bordered"type="radiogroup"- class="z-10 min-w-[262px] max-w-full"+ class="z-10"+ :class="{ 'w-[260px]': size === 'small' }"><divv-for="(category, index) in contentTypeGroups":key="index"- class="flex flex-col lg:gap-y-1"+ class="flex flex-col":class="{'mt-2': index > 0,'border-t border-dark-charcoal-20 bg-dark-charcoal-06':index > 0 && !bordered,+ 'gap-1': size === 'small',}"><h4v-if="index !== 0":class="bordered ? 'ps-0' : 'ps-6'"- class="pt-6 pb-4 text-sr font-semibold uppercase pe-6"+ class="category pt-6 pb-4 uppercase pe-6">{{ $t(`search-type.${category.heading}`) }}</h4>@@ -57,13 +59,18 @@ import { defineEvent } from "~/types/emits"import VItemGroup from "~/components/VItemGroup/VItemGroup.vue"import VSearchTypeItem from "~/components/VContentSwitcher/VSearchTypeItem.vue"+type ContentTypeGroup = {+ heading: string+ items: SearchType[]+}+export default defineComponent({name: "VSearchTypes",components: { VItemGroup, VSearchTypeItem },props: {/**- * 'Small' size for mobile screens,- * 'medium' size for larger screens.+ * 'Small' size is used in the popover,+ * 'medium' size is used in the mobile modal.*/size: {type: String as PropType<"small" | "medium">,@@ -86,18 +93,18 @@ export default defineComponent({const isActive = (item: SearchType) => item === content.activeType.value- const contentTypeGroups = computed(() => {- const base = [+ const contentTypeGroups = computed<ContentTypeGroup[]>(() => {+ const base: ContentTypeGroup[] = [{heading: "heading",items: content.types,},]- if (content.additionalTypes.value.length && props.useLinks) {+ if (content.additionalTypes.value.length) {base.push({heading: "additional",- items: content.additionalTypes.value,+ items: [...content.additionalTypes.value],})}diff --git a/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx b/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdxindex 46a0187d7..0ab0a9965 100644--- a/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx+++ b/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx@@ -7,6 +7,7 @@ import {} from "@storybook/addon-docs"import VSearchTypePopover from "~/components/VContentSwitcher/VSearchTypePopover.vue"+import { useFeatureFlagStore } from "~/stores/feature-flag"<Metatitle="Components/VContentSwitcher/VSearchTypePopover"@@ -15,6 +16,12 @@ import VSearchTypePopover from "~/components/VContentSwitcher/VSearchTypePopoverselect: {action: "select",},+ additionalTypes: {+ control: { type: "boolean" },+ },+ }}+ args={{+ additionalTypes: false,}}/>@@ -22,6 +29,11 @@ export const Template = (args) => ({template: `<VSearchTypePopover active-item="image" v-bind="args" v-on="args"/>`,components: { VSearchTypePopover },setup() {+ const featureFlagStore = useFeatureFlagStore()+ featureFlagStore.toggleFeature(+ "external_sources",+ args.additionalTypes ? "on" : "off"+ )return { args }},})diff --git a/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx b/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdxindex 84175870f..4750ceefd 100644--- a/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx+++ b/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx@@ -7,32 +7,39 @@ import {} from "@storybook/addon-docs"import VSearchTypes from "~/components/VContentSwitcher/VSearchTypes.vue"+import { useFeatureFlagStore } from "~/stores/feature-flag"<Metatitle="Components/VContentSwitcher/VSearchTypes"components={VSearchTypes}argTypes={{- select: {- action: "select",- },size: {- control: {- type: "select",- options: ["small", "medium"],- },+ options: ["small", "medium"],+ control: { type: "select" },},useLinks: {- control: {- type: "boolean",- },+ control: { type: "boolean" },+ },+ additionalTypes: {+ control: { type: "boolean" },},}}+ args={{+ size: "medium",+ useLinks: false,+ additionalTypes: false,+ }}/>export const Template = (args) => ({- template: `<VSearchTypes active-item="image" v-bind="args" v-on="args"/>`,+ template: `<VSearchTypes v-bind="args" v-on="args"/>`,components: { VSearchTypes },setup() {+ const featureFlagStore = useFeatureFlagStore()+ featureFlagStore.toggleFeature(+ "external_sources",+ args.additionalTypes ? "on" : "off"+ )return { args }},})diff --git a/src/components/VItemGroup/VItem.vue b/src/components/VItemGroup/VItem.vueindex 7184ce906..9ac73300e 100644--- a/src/components/VItemGroup/VItem.vue+++ b/src/components/VItemGroup/VItem.vue@@ -18,7 +18,7 @@<VButtondata-item-group-item:as="as"- class="group relative flex min-w-full justify-between py-2 px-6 hover:bg-dark-charcoal-10 focus:z-10 lg:px-2"+ class="group relative flex min-w-full justify-between py-2 hover:bg-dark-charcoal-10 focus:z-10":class="[$style[`${contextProps.direction}-button`],$style[`${contextProps.size}-button`],@@ -54,8 +54,9 @@contextProps.direction === 'vertical' &&contextProps.showCheck"- class="absolute end-2 lg:end-5"- :icon-path="checkmark"+ class="absolute end-2"+ :class="contextProps.size === 'small' ? 'end-3' : 'end-6'"+ :icon-path="itemIndicator"/></VButton></div>@@ -82,7 +83,7 @@ import VButton from "~/components/VButton.vue"import VIcon from "~/components/VIcon/VIcon.vue"import { VPopoverContentContextKey } from "~/components/VPopover/VPopoverContent.vue"-import checkmark from "~/assets/icons/checkmark.svg"+import itemIndicator from "~/assets/icons/item-indicator.svg"export default defineComponent({name: "VItem",@@ -165,7 +166,7 @@ export default defineComponent({})return {- checkmark,+ itemIndicator,contextProps,isInPopover,isFocused,@@ -205,7 +206,7 @@ export default defineComponent({}.has-check .vertical-content {- @apply pe-8 lg:pe-8;+ @apply pe-8;}.vertical-popover-item {@@ -243,4 +244,10 @@ export default defineComponent({.horizontal-popover-item:last-of-type {@apply pe-2;}+.small-button {+ @apply p-3;+}+.medium-button {+ @apply px-6 py-5;+}</style>diff --git a/src/composables/use-search-type.ts b/src/composables/use-search-type.tsindex e3784f3a0..24ebfc837 100644--- a/src/composables/use-search-type.ts+++ b/src/composables/use-search-type.ts@@ -14,6 +14,8 @@ import {import { useSearchStore } from "~/stores/search"import { useFeatureFlagStore } from "~/stores/feature-flag"+import { useI18n } from "~/composables/use-i18n"+import allIcon from "~/assets/icons/all-content.svg"import audioIcon from "~/assets/icons/audio-content.svg"import imageIcon from "~/assets/icons/image-content.svg"@@ -28,7 +30,16 @@ const icons = {[MODEL_3D]: model3dIcon,} as const+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",+} as const+export default function useSearchType() {+ const i18n = useI18n()const activeType = computed(() => useSearchStore().searchType)const previousSearchType = ref(activeType.value)@@ -46,13 +57,22 @@ export default function useSearchType() {previousSearchType.value = searchType}+ const getSearchTypeProps = (searchType?: SearchType) => {+ const type = searchType ?? activeType.value+ return {+ label: i18n.t(labels[type]).toString(),+ icon: icons[type],+ searchType: type,+ }+ }+return {setActiveType,activeType,+ getSearchTypeProps,types: searchTypes,icons,+ labels,additionalTypes,}}--export type UseSearchTypeReturn = ReturnType<typeof useSearchType>