Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix VSearchTypes spacings (#1903)

Olga Bulatf470fc40ab40
diff --git a/src/components/VContentSwitcher/VSearchTypeItem.vue b/src/components/VContentSwitcher/VSearchTypeItem.vue
index 0ff65f733..667124a00 100644
--- a/src/components/VContentSwitcher/VSearchTypeItem.vue
+++ b/src/components/VContentSwitcher/VSearchTypeItem.vue
@@ -1,66 +1,113 @@
<template>
<VItem
- class="md:mb-1"
:selected="selected"
- :is-first="itemId === 0"
- v-bind="component"
+ :is-first="isFirst"
+ :as="component"
+ class="h-16 text-base lg:h-12"
+ v-bind="{ href }"
@click.native="$emit('click', item)"
>
- <div class="flex w-full flex-row items-center gap-2 py-2 text-base">
- <VIcon :icon-path="icon" />
- <span class="font-semibold">{{ $t(`search-type.${item}`) }}</span>
- <VPill v-if="isBeta" class="ms-auto">{{
- $t('search-type.status-beta')
- }}</VPill>
- </div>
+ <VIcon :icon-path="icon" />
+ <span>{{ $t(`search-type.${item}`) }}</span>
+ <VPill v-if="isBeta" class="ms-auto">{{
+ $t('search-type.status-beta')
+ }}</VPill>
</VItem>
</template>
-<script>
-import { computed, useContext, defineComponent } from '@nuxtjs/composition-api'
+<script lang="ts">
+import {
+ computed,
+ useContext,
+ defineComponent,
+ PropType,
+} from '@nuxtjs/composition-api'
-import { ALL_MEDIA, BETA, contentStatus } from '~/constants/media'
-import { useSearchStore } from '~/stores/search'
+import { BETA, contentStatus, searchPath, SearchType } from '~/constants/media'
+import { isSearchTypeSupported, useSearchStore } from '~/stores/search'
import VIcon from '~/components/VIcon/VIcon.vue'
import VItem from '~/components/VItemGroup/VItem.vue'
import VPill from '~/components/VPill.vue'
-/** @typedef {import('@nuxtjs/composition-api').ExtractPropTypes<typeof propTypes>} Props */
-const propTypes = {
- item: { type: String, required: true },
- itemId: { type: Number, required: true },
- selected: { type: Boolean, default: false },
- icon: { type: String, required: true },
- useLinks: { type: Boolean, default: true },
-}
+import type { Dictionary } from 'vue-router/types/router'
+
export default defineComponent({
name: 'VSearchTypeItem',
components: { VIcon, VItem, VPill },
- props: propTypes,
+ props: {
+ /**
+ * The search type to render.
+ */
+ item: {
+ type: String as PropType<SearchType>,
+ required: true,
+ },
+ /**
+ * Used for correctly handling keyboard navigation in VItem.
+ */
+ isFirst: {
+ type: Boolean,
+ default: false,
+ },
+ /**
+ * Whether the item is selected.
+ */
+ selected: {
+ type: Boolean,
+ default: false,
+ },
+ /**
+ * The icon used for the search type.
+ */
+ icon: {
+ type: String,
+ required: true,
+ },
+ /**
+ * Whether to use a `/search/image/?<query>` link or a button.
+ */
+ useLinks: {
+ type: Boolean,
+ default: true,
+ },
+ /**
+ * 'Small' size for larger screens,
+ * 'medium' size for mobile screens.
+ */
+ size: {
+ type: String as PropType<'small' | 'medium'>,
+ default: 'small',
+ },
+ },
setup(props) {
const { app } = useContext()
const searchStore = useSearchStore()
+ /**
+ * Currently, there are no Beta search types, so TS raises an error saying
+ * that this condition will always return false.
+ */
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-expect-error
const isBeta = computed(() => contentStatus[props.item] === BETA)
+ const href = computed(() => {
+ if (!props.useLinks || !isSearchTypeSupported(props.item)) {
+ return undefined
+ }
+ const query = searchStore.computeQueryParams(props.item)
+ const path = searchPath(props.item)
+ return app.localePath({ path, query: query as Dictionary<string> })
+ })
+
/**
* The query sets the filters that are applicable for the specific search type.
*/
- const component = computed(() => {
- if (!props.useLinks) {
- return {}
- }
- return {
- as: 'VLink',
- href: app.localePath({
- path: `/search/${props.item === ALL_MEDIA ? '' : props.item}`,
- query: searchStore.computeQueryParams(props.item),
- }),
- }
- })
+ const component = computed(() => (props.useLinks ? 'VLink' : undefined))
return {
component,
+ href,
isBeta,
}
},
diff --git a/src/components/VContentSwitcher/VSearchTypePopover.vue b/src/components/VContentSwitcher/VSearchTypePopover.vue
index 40de652bf..778aacebb 100644
--- a/src/components/VContentSwitcher/VSearchTypePopover.vue
+++ b/src/components/VContentSwitcher/VSearchTypePopover.vue
@@ -14,7 +14,8 @@
</template>
<VSearchTypes
id="content-switcher-popover"
- size="medium"
+ class="min-w-[262px] pt-2"
+ size="small"
:use-links="true"
@select="closePopover"
/>
diff --git a/src/components/VContentSwitcher/VSearchTypes.vue b/src/components/VContentSwitcher/VSearchTypes.vue
index 3b009d2e1..666dfcf96 100644
--- a/src/components/VContentSwitcher/VSearchTypes.vue
+++ b/src/components/VContentSwitcher/VSearchTypes.vue
@@ -4,11 +4,12 @@
:size="size"
:bordered="bordered"
type="radiogroup"
- class="z-10 max-w-full"
+ class="z-10 min-w-[262px] max-w-full"
>
<div
v-for="(category, index) in contentTypeGroups"
:key="index"
+ class="flex flex-col lg:gap-y-1"
:class="{
'mt-2': index > 0,
'border-t border-dark-charcoal-20 bg-dark-charcoal-06':
@@ -25,11 +26,17 @@
<VSearchTypeItem
v-for="(item, idx) in category.items"
:key="item"
- class="md:mb-1"
:item="item"
- :item-id="idx"
+ :is-first="index === 0 && idx === 0"
+ :size="size"
:icon="content.icons[item]"
:use-links="useLinks"
+ :class="{
+ 'mb-2':
+ idx === category.items.length - 1 &&
+ ((contentTypeGroups.length > 1 && index !== 0) ||
+ contentTypeGroups.length === 1),
+ }"
:selected="isActive(item)"
@click="selectItem(item)"
/>
@@ -63,7 +70,7 @@ export default defineComponent({
default: 'small',
},
/**
- * Whether to use buttons for search type selection, or links to the specific search type search for the items.
+ * Whether to use buttons for search type selection, or links to the specific search type search pages.
*/
useLinks: {
type: Boolean,
@@ -75,7 +82,7 @@ export default defineComponent({
},
setup(props, { emit }) {
const content = useSearchType()
- const bordered = computed(() => props.size === 'small')
+ const bordered = computed(() => props.size === 'medium')
const isActive = (item: SearchType) => item === content.activeType.value
diff --git a/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx b/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
index 13d4ac67e..7ccb8c9a0 100644
--- a/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
+++ b/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
@@ -6,12 +6,10 @@ import {
Story,
} from '@storybook/addon-docs'
-import { ref } from '@nuxtjs/composition-api'
-
import VSearchTypePopover from '~/components/VContentSwitcher/VSearchTypePopover.vue'
<Meta
- title="Components/VSearchTypePopover"
+ title="Components/VContentSwitcher/VSearchTypePopover"
components={VSearchTypePopover}
argTypes={{
select: {
@@ -39,27 +37,3 @@ export const Template = (args) => ({
{Template.bind({})}
</Story>
</Canvas>
-
-## v-model
-
-The recommended way to use it is with `v-model` mapping to a `String`.
-
-export const vModelTemplate = () => ({
- template: `
- <div>
- {{ item }}
- <VSearchTypePopover v-model="item"/>
- </div>
- `,
- components: { VSearchTypePopover },
- setup() {
- const item = ref('all')
- return { item }
- },
-})
-
-<Canvas>
- <Story height="480px" name="v-model">
- {vModelTemplate.bind({})}
- </Story>
-</Canvas>
diff --git a/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx b/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx
new file mode 100644
index 000000000..e2f22b834
--- /dev/null
+++ b/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx
@@ -0,0 +1,50 @@
+import {
+ ArgsTable,
+ Canvas,
+ Description,
+ Meta,
+ Story,
+} from '@storybook/addon-docs'
+
+import VSearchTypes from '~/components/VContentSwitcher/VSearchTypes.vue'
+
+<Meta
+ title="Components/VContentSwitcher/VSearchTypes"
+ components={VSearchTypes}
+ argTypes={{
+ select: {
+ action: 'select',
+ },
+ size: {
+ control: {
+ type: 'select',
+ options: ['small', 'medium'],
+ },
+ },
+ useLinks: {
+ control: {
+ type: 'boolean',
+ },
+ },
+ }}
+/>
+
+export const Template = (args) => ({
+ template: `<VSearchTypes active-item="image" v-bind="args" v-on="args"/>`,
+ components: { VSearchTypes },
+ setup() {
+ return { args }
+ },
+})
+
+# VSearchTypes
+
+<Description of={VSearchTypes} />
+
+<ArgsTable of={VSearchTypes} />
+
+<Canvas>
+ <Story height="480px" name="Default">
+ {Template.bind({})}
+ </Story>
+</Canvas>
diff --git a/src/components/VHeader/VHeaderMobile/VContentSettingsModal.vue b/src/components/VHeader/VHeaderMobile/VContentSettingsModal.vue
index 9032484ae..e842ad11e 100644
--- a/src/components/VHeader/VHeaderMobile/VContentSettingsModal.vue
+++ b/src/components/VHeader/VHeaderMobile/VContentSettingsModal.vue
@@ -37,7 +37,7 @@
/>
</template>
<VTabPanel id="content-settings">
- <VSearchTypes size="small" :use-links="true" />
+ <VSearchTypes size="medium" :use-links="true" />
</VTabPanel>
<VTabPanel id="filters">
<VSearchGridFilter
diff --git a/src/components/VItemGroup/VItem.vue b/src/components/VItemGroup/VItem.vue
index 14f2e8785..f4a15ea2e 100644
--- a/src/components/VItemGroup/VItem.vue
+++ b/src/components/VItemGroup/VItem.vue
@@ -8,15 +8,17 @@
}`]: contextProps.bordered,
'bg-dark-charcoal-10': selected && contextProps.bordered,
'px-2': isInPopover,
+ 'hover:bg-dark-charcoal-10': !isInPopover,
[$style[`${contextProps.direction}-popover-item`]]: isInPopover,
}"
>
<VButton
data-item-group-item
:as="as"
- class="group relative flex min-w-full justify-between px-2 py-2 hover:bg-dark-charcoal-10 focus:z-10"
+ 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="[
$style[`${contextProps.direction}-button`],
+ $style[`${contextProps.size}-button`],
selected && 'bg-dark-charcoal-10 ring-offset-dark-charcoal-10',
as === 'VLink' && 'text-dark-charcoal',
]"
@@ -35,14 +37,14 @@
@click.native="$emit('click')"
>
<div
- class="my-0 flex-grow whitespace-nowrap rounded-sm px-2"
+ class="flex w-full flex-grow gap-x-2 whitespace-nowrap rounded-sm"
:class="[$style[`${contextProps.direction}-content`]]"
>
<slot name="default" />
</div>
<VIcon
- v-if="!isInPopover && selected && contextProps.direction === 'vertical'"
- class="absolute end-5"
+ v-if="selected && contextProps.direction === 'vertical'"
+ class="absolute end-2 lg:end-5"
:icon-path="checkmark"
/>
</VButton>
@@ -163,7 +165,6 @@ export default defineComponent({
},
})
</script>
-
<style module>
.button:focus {
@apply z-10;
@@ -190,17 +191,13 @@ export default defineComponent({
}
.vertical-content {
- @apply flex flex-row items-center;
+ @apply flex flex-row items-center pe-8 lg:pe-8;
}
.vertical-popover-item {
@apply pb-0;
}
-.vertical-popover-item:last-of-type {
- @apply pb-2;
-}
-
.horizontal-button {
@apply w-max;
}
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts b/test/storybook/visual-regression/v-search-types.spec.ts
new file mode 100644
index 000000000..201238388
--- /dev/null
+++ b/test/storybook/visual-regression/v-search-types.spec.ts
@@ -0,0 +1,49 @@
+import { test } from '@playwright/test'
+
+import breakpoints from '~~/test/playwright/utils/breakpoints'
+
+const defaultUrl =
+ '/iframe.html?id=components-vcontentswitcher-vsearchtypes--default-story'
+
+const audioButtonLocator = 'text=images'
+
+test.describe('VSearchTypes', () => {
+ breakpoints.describeMd(({ expectSnapshot }) => {
+ test.beforeEach(async ({ page }) => {
+ await page.goto(`${defaultUrl}&args=size%3Amedium`)
+ })
+ test('medium resting', async ({ page }) => {
+ await expectSnapshot('v-search-types-medium-at-rest', page)
+ })
+
+ test('medium images hovered', async ({ page }) => {
+ await page.hover(audioButtonLocator)
+ await expectSnapshot('v-search-types-medium-images-hovered', page)
+ })
+
+ test('medium focused', async ({ page }) => {
+ await page.keyboard.press('Tab')
+ await expectSnapshot('v-search-types-medium-focused', page)
+ })
+ })
+
+ breakpoints.describeXl(({ expectSnapshot }) => {
+ test.beforeEach(async ({ page }) => {
+ await page.goto(`${defaultUrl}&args=size%3Asmall`)
+ })
+
+ test('small resting', async ({ page }) => {
+ await expectSnapshot('v-search-types-small-at-rest', page)
+ })
+
+ test('small images hovered', async ({ page }) => {
+ await page.hover(audioButtonLocator)
+ await expectSnapshot('v-search-types-small-images-hovered', page)
+ })
+
+ test('small focused', async ({ page }) => {
+ await page.keyboard.press('Tab')
+ await expectSnapshot('v-search-types-small-focused', page)
+ })
+ })
+})
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-at-rest-md-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-at-rest-md-linux.png
new file mode 100644
index 000000000..ce5363d34
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-at-rest-md-linux.png differ
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-focused-md-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-focused-md-linux.png
new file mode 100644
index 000000000..6ad2278b6
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-focused-md-linux.png differ
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-images-hovered-md-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-images-hovered-md-linux.png
new file mode 100644
index 000000000..bef7a753c
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-medium-images-hovered-md-linux.png differ
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-at-rest-xl-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-at-rest-xl-linux.png
new file mode 100644
index 000000000..f1f1e877b
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-at-rest-xl-linux.png differ
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-focused-xl-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-focused-xl-linux.png
new file mode 100644
index 000000000..a43d8fb14
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-focused-xl-linux.png differ
diff --git a/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-images-hovered-xl-linux.png b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-images-hovered-xl-linux.png
new file mode 100644
index 000000000..2a69b89f5
Binary files /dev/null and b/test/storybook/visual-regression/v-search-types.spec.ts-snapshots/v-search-types-small-images-hovered-xl-linux.png differ
diff --git a/tsconfig.json b/tsconfig.json
index e1005c00a..801d262f5 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -76,6 +76,7 @@
"src/components/VAllResultsGrid/VImageCellSquare.vue",
"src/components/VContentReport/VReportDescForm.vue",
"src/components/VContentSwitcher/VSearchTypeButton.vue",
+ "src/components/VContentSwitcher/VSearchTypeItem.vue",
"src/components/VContentSwitcher/VSearchTypeRadio.vue",
"src/components/VContentSwitcherOld/VSearchTypeButton.vue",
"src/components/VErrorSection/VErrorImage.vue",