Skip to content

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

Update VSearchBarButton to use VButton instead of VIconButton (#2724)

Olga Bulat470b88202564
diff --git a/frontend/src/components/VButton.vue b/frontend/src/components/VButton.vue
index 1119646fd..a8244289a 100644
--- a/frontend/src/components/VButton.vue
+++ b/frontend/src/components/VButton.vue
@@ -12,6 +12,7 @@
[$style[`connection-${connections}`]]: isConnected,
[$style[`icon-start-${size}`]]: hasIconStart,
[$style[`icon-end-${size}`]]: hasIconEnd,
+ [$style[`icon-only`]]: iconOnly,
'gap-x-2':
(hasIconEnd || hasIconStart) && (size == 'medium' || size == 'large'),
'gap-x-1': (hasIconEnd || hasIconStart) && size == 'small',
@@ -292,7 +293,7 @@ export default VButton
@apply h-8 px-2 py-0;
}
.size-small-icon-only {
- @apply h-8 w-8 p-0;
+ @apply h-8 w-8;
}
.icon-start-small {
@apply ps-1;
@@ -305,7 +306,7 @@ export default VButton
@apply h-10 px-3 py-0;
}
.size-medium-icon-only {
- @apply h-10 w-10 p-0;
+ @apply h-10 w-10;
}
.icon-start-medium {
@apply ps-2;
@@ -318,7 +319,7 @@ export default VButton
@apply h-12 px-5 py-0;
}
.size-large-icon-only {
- @apply h-12 w-12 p-0;
+ @apply h-12 w-12;
}
.icon-start-large {
@apply ps-4;
@@ -326,6 +327,9 @@ export default VButton
.icon-end-large {
@apply pe-4;
}
+.icon-only {
+ @apply flex-none;
+}
a.button {
@apply no-underline hover:no-underline;
@@ -367,6 +371,9 @@ a.button {
.transparent-dark {
@apply border-tx bg-tx text-dark-charcoal hover:bg-dark-charcoal hover:text-white;
}
+.transparent-dark-pressed {
+ @apply border-tx bg-dark-charcoal text-white hover:border-dark-charcoal-90;
+}
.dropdown-label {
@apply border-dark-charcoal-20 bg-white text-dark-charcoal hover:border-tx hover:bg-dark-charcoal hover:text-white;
diff --git a/frontend/src/components/VHeader/VHeaderDesktop.vue b/frontend/src/components/VHeader/VHeaderDesktop.vue
index c41f1d469..eb5fed7f0 100644
--- a/frontend/src/components/VHeader/VHeaderDesktop.vue
+++ b/frontend/src/components/VHeader/VHeaderDesktop.vue
@@ -15,7 +15,7 @@
v-show="searchTerm !== ''"
icon="close-small"
:label="$t('browsePage.searchForm.clear')"
- inner-area-classes="bg-white hover:bg-dark-charcoal-10"
+ variant="filled-white"
class="hidden group-focus-within:flex"
@click="clearSearchTerm"
/>
diff --git a/frontend/src/components/VHeader/VHeaderInternal.vue b/frontend/src/components/VHeader/VHeaderInternal.vue
index 2ce2770e4..36d5038dc 100644
--- a/frontend/src/components/VHeader/VHeaderInternal.vue
+++ b/frontend/src/components/VHeader/VHeaderInternal.vue
@@ -12,14 +12,14 @@
/>
</nav>
<div class="flex lg:hidden">
- <VOldIconButton
+ <VIconButton
id="menu-button"
ref="menuButtonRef"
+ variant="transparent-dark"
+ size="large"
:icon-props="{ name: 'menu' }"
:label="$t('header.aria.menu')"
v-bind="triggerA11yProps"
- class="border-tx hover:bg-dark-charcoal hover:text-white"
- :class="{ 'bg-dark-charcoal text-white': isModalVisible }"
@click="onTriggerClick"
/>
<template v-if="triggerElement">
@@ -94,27 +94,30 @@ import { useUiStore } from "~/stores/ui"
import VCloseButton from "~/components/VCloseButton.vue"
import VHomeLink from "~/components/VHeader/VHomeLink.vue"
-import VOldIconButton from "~/components/VIconButton/VOldIconButton.vue"
import VPageLinks from "~/components/VHeader/VPageLinks.vue"
import VModalContent from "~/components/VModal/VModalContent.vue"
import VPopoverContent from "~/components/VPopover/VPopoverContent.vue"
import VWordPressLink from "~/components/VHeader/VWordPressLink.vue"
+import VIconButton from "~/components/VIconButton/VIconButton.vue"
export default defineComponent({
name: "VHeaderInternal",
components: {
+ VIconButton,
VCloseButton,
VModalContent,
VPopoverContent,
VHomeLink,
- VOldIconButton,
VPageLinks,
VWordPressLink,
},
setup(_, { emit }) {
- const menuButtonRef = ref<InstanceType<typeof VOldIconButton> | null>(null)
+ const menuButtonRef = ref<{ $el: HTMLElement } | null>(null)
const nodeRef = ref<HTMLElement | null>(null)
- const modalContentRef = ref<InstanceType<typeof VModalContent> | null>(null)
+ const modalContentRef = ref<{
+ $el: HTMLElement
+ deactivateFocusTrap: () => void
+ } | null>(null)
const uiStore = useUiStore()
diff --git a/frontend/src/components/VHeader/VHeaderMobile/VContentSettingsButton.vue b/frontend/src/components/VHeader/VHeaderMobile/VContentSettingsButton.vue
index 38e51ebd8..7fa1e080b 100644
--- a/frontend/src/components/VHeader/VHeaderMobile/VContentSettingsButton.vue
+++ b/frontend/src/components/VHeader/VHeaderMobile/VContentSettingsButton.vue
@@ -10,13 +10,13 @@
aria-haspopup="dialog"
:aria-expanded="isPressed"
aria-controls="content-settings-modal"
- inner-area-classes="bg-white hover:bg-dark-charcoal hover:text-white"
+ variant="filled-white"
v-on="$listeners"
>
<template #notification>
<span
v-if="appliedFilterCount"
- class="absolute right-[-2px] top-[-2px] h-[8px] w-[8px] rounded bg-pink"
+ class="absolute right-[-0.1875rem] top-[-0.1875rem] h-[0.5rem] w-[0.5rem] rounded bg-pink"
/>
</template>
</VSearchBarButton>
diff --git a/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue b/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue
index 66e676c05..bcdcfa2e4 100644
--- a/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue
+++ b/frontend/src/components/VHeader/VHeaderMobile/VHeaderMobile.vue
@@ -30,10 +30,9 @@
<VSearchBarButton
v-show="searchBarIsActive"
icon="chevron-left"
- :inner-size="8"
:label="$t('header.backButton')"
:rtl-flip="true"
- inner-area-classes="bg-dark-charcoal-10 hover:bg-dark-charcoal hover:text-white"
+ variant="filled-gray"
@click="handleBack"
/>
</slot>
diff --git a/frontend/src/components/VHeader/VHeaderMobile/VSearchBarButton.vue b/frontend/src/components/VHeader/VHeaderMobile/VSearchBarButton.vue
index fc4405e3a..0d89db8bb 100644
--- a/frontend/src/components/VHeader/VHeaderMobile/VSearchBarButton.vue
+++ b/frontend/src/components/VHeader/VHeaderMobile/VSearchBarButton.vue
@@ -1,32 +1,31 @@
<template>
- <VOldIconButton
- class="border-tx bg-tx"
- :label="label"
- :button-props="{ variant: 'plain--avoid' }"
+ <VButton
+ :aria-label="label"
+ size="large"
+ variant="plain--avoid"
+ icon-only
v-on="$listeners"
>
- <template #default="{ iconSize }">
- <span
- class="relative flex flex-shrink-0 flex-grow-0 items-center justify-center rounded-sm group-focus-visible/button:ring group-focus-visible/button:ring-pink group-active/button:ring group-active/button:ring-pink"
- :class="[`h-${innerSize} w-${innerSize}`, innerAreaClasses]"
- >
- <VIcon
- :name="icon"
- :rtl-flip="rtlFlip"
- class="pointer-events-none"
- :size="iconSize"
- />
- <!-- @slot The element that can show a notification label for the button, can be absolutely positioned -->
- <slot name="notification" />
- </span>
- </template>
- </VOldIconButton>
+ <span
+ class="relative flex h-8 w-8 flex-none items-center justify-center rounded-sm border border-tx group-focus-visible/button:ring group-focus-visible/button:ring-pink group-active/button:ring group-active/button:ring-pink"
+ :class="variant"
+ >
+ <VIcon
+ :name="icon"
+ :rtl-flip="rtlFlip"
+ class="pointer-events-none"
+ :size="6"
+ />
+ <!-- @slot The element that can show a notification label for the button, can be absolutely positioned -->
+ <slot name="notification" />
+ </span>
+ </VButton>
</template>
<script lang="ts">
import { defineComponent, PropType } from "vue"
+import VButton from "~/components/VButton.vue"
import VIcon from "~/components/VIcon/VIcon.vue"
-import VOldIconButton from "~/components/VIconButton/VOldIconButton.vue"
import type { TranslateResult } from "vue-i18n"
@@ -38,30 +37,15 @@ import type { TranslateResult } from "vue-i18n"
*/
export default defineComponent({
name: "VSearchBarButton",
- components: { VIcon, VOldIconButton },
+ components: { VIcon, VButton },
props: {
/**
- * The path for the icon.
+ * The name of the icon.
*/
icon: {
type: String,
required: true,
},
- /**
- * The size of the inner area that has a different color,
- * sometimes only when interactive.
- */
- innerSize: {
- type: Number as PropType<6 | 8>,
- default: 8,
- },
- /**
- * The classes to apply to the inner area for styling resting/hover states.
- */
- innerAreaClasses: {
- type: String,
- default: "",
- },
/**
* Whether the icon should be flipped when the page is in RTL mode.
*/
@@ -76,6 +60,36 @@ export default defineComponent({
type: [String, Object] as PropType<string | TranslateResult>,
required: true,
},
+ /**
+ * The style of the inner area, matches the variants of VButton component.
+ */
+ variant: {
+ type: String as PropType<
+ "transparent-dark" | "transparent-gray" | "filled-white" | "filled-gray"
+ >,
+ default: "transparent-dark",
+ },
},
})
</script>
+
+<style scoped>
+.transparent-dark {
+ @apply border-tx bg-tx text-dark-charcoal hover:text-white group-hover/button:bg-dark-charcoal;
+}
+.transparent-gray {
+ @apply border-tx bg-tx text-dark-charcoal group-hover/button:bg-dark-charcoal group-hover/button:bg-opacity-10;
+}
+.filled-white {
+ @apply border-tx bg-white text-dark-charcoal group-hover/button:bg-dark-charcoal group-hover/button:text-white;
+}
+
+.filled-gray {
+ @apply border-tx bg-dark-charcoal-10 text-dark-charcoal group-hover/button:bg-dark-charcoal group-hover/button:text-white;
+}
+
+.filled-white,
+.filled-gray {
+ @apply group-focus-visible/button:border-white;
+}
+</style>
diff --git a/frontend/src/components/VHeader/meta/VSearchBarButton.stories.mdx b/frontend/src/components/VHeader/meta/VSearchBarButton.stories.mdx
index 1c6c897c9..10598f46c 100644
--- a/frontend/src/components/VHeader/meta/VSearchBarButton.stories.mdx
+++ b/frontend/src/components/VHeader/meta/VSearchBarButton.stories.mdx
@@ -12,28 +12,28 @@ import VSearchBarButton from "~/components/VHeader/VHeaderMobile/VSearchBarButto
title="Components/VHeader/VHeaderMobile/VSearchBarButton"
component={VSearchBarButton}
argTypes={{
- iconPath: {
+ icon: {
control: {
type: "select",
- options: ["close-small", "chevron-left", "source"],
default: "close-small",
},
- },
- innerSize: {
- control: {
- type: "select",
- options: [6, 8],
- },
+ options: ["close-small", "chevron-left", "source"],
},
rtlFlip: {
control: {
type: "boolean",
},
},
- innerAreaClasses: {
+ variant: {
control: {
- type: "text",
+ type: "select",
},
+ options: [
+ "filled-white",
+ "filled-gray",
+ "transparent-gray",
+ "transparent-dark",
+ ],
},
click: {
action: "click",
@@ -42,7 +42,7 @@ import VSearchBarButton from "~/components/VHeader/VHeaderMobile/VSearchBarButto
/>
export const Template = (args) => ({
- template: `<div class="bg-white"><VSearchBarButton label="VSearchBarButton" v-bind="args" v-on="args" /></div>`,
+ template: `<div class="wrapper border-dark-charcoal-10 inline-flex justify-start p-2"><VSearchBarButton label="VSearchBarButton" v-bind="args" v-on="args" /></div>`,
components: { VSearchBarButton },
setup() {
if (!args.icon) {
@@ -59,12 +59,21 @@ export const Template = (args) => ({
<ArgsTable of={VSearchBarButton} />
<Canvas>
- <Story name="Default">{Template.bind({})}</Story>
+ <Story
+ name="Default"
+ args={{
+ icon: "close-small",
+ label: "VSearchBarButton",
+ variant: "filled-white",
+ }}
+ >
+ {Template.bind({})}
+ </Story>
</Canvas>
export const contentSettingsTemplate = (args) => ({
template: `
- <div class="bg-dark-charcoal-10 rounded-sm flex justify-end">
+ <div class="wrapper rounded-sm inline-flex justify-end bg-dark-charcoal-10">
<VContentSettingsButton label="VContentSettingsButton" :are-filters-selected="true" v-bind="args" />
</div>
`,
@@ -92,18 +101,17 @@ export const activeButtonsTemplate = (args) => ({
template: `<div class="wrapper rounded-sm bg-white flex justify-between ring ring-pink">
<VSearchBarButton
icon="chevron-left"
- :inner-size="8"
:label="$t('header.back-button')"
- inner-area-classes="hover:bg-dark-charcoal hover:text-white"
+ variant="filled-gray"
:rtl-flip="true"
/>
<VSearchBarButton
icon="close-small"
:label="$t('browsePage.searchForm.clear')"
- inner-area-classes="bg-white hover:bg-dark-charcoal-10"
+ variant="transparent-gray"
/>
</div>`,
- components: { VContentSettingsButton },
+ components: { VContentSettingsButton, VSearchBarButton },
setup() {
return { args }
},