Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix audio button rounding and global audio not closing (#1453)
Olga Bulat01b733a97c0b
diff --git a/src/components/VAudioTrack/VGlobalAudioTrack.vue b/src/components/VAudioTrack/VGlobalAudioTrack.vueindex 14df8a274..360719ad9 100644--- a/src/components/VAudioTrack/VGlobalAudioTrack.vue+++ b/src/components/VAudioTrack/VGlobalAudioTrack.vue@@ -1,10 +1,6 @@<template>- <div- class="audio-track"- :aria-label="$t('audio-track.aria-label').toString()"- role="region"- >- <VGlobalLayout :audio="audio" size="m">+ <div class="audio-track" :aria-label="ariaLabel" role="region">+ <VGlobalLayout :audio="audio"><template #controller="waveformProps"><VWaveformv-bind="waveformProps"@@ -75,6 +71,10 @@ export default defineComponent({const activeMediaStore = useActiveMediaStore()const activeAudio = useActiveAudio()+ const ariaLabel = computed(() =>+ i18n.t('audio-track.aria-label', { title: props.audio.title }).toString()+ )+const status = ref<AudioStatus>('paused')const currentTime = ref(0)const duration = defaultRef(() => {@@ -209,6 +209,7 @@ export default defineComponent({currentTime,duration,+ ariaLabel,}},})diff --git a/src/components/VAudioTrack/VPlayPause.vue b/src/components/VAudioTrack/VPlayPause.vueindex e91e064f9..7227dbc0b 100644--- a/src/components/VAudioTrack/VPlayPause.vue+++ b/src/components/VAudioTrack/VPlayPause.vue@@ -5,7 +5,7 @@class="play-pause flex-shrink-0 bg-dark-charcoal border-dark-charcoal text-white disabled:opacity-70 focus-visible:border-pink focus-visible:outline-none focus-visible:shadow-ring":icon-props="{ iconPath: icon }":aria-label="$t(label)"- :button-props="{ variant: 'plain-dangerous' }"+ :button-props="buttonProps"@click.stop.prevent="handleClick"/></template>@@ -16,6 +16,7 @@ import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'import type { AudioLayout, AudioStatus } from '~/constants/audio'import VIconButton from '~/components/VIconButton/VIconButton.vue'+import type { ButtonConnections, ButtonVariant } from '~/components/VButton.vue'import playIcon from '~/assets/icons/play.svg'import pauseIcon from '~/assets/icons/pause.svg'@@ -25,12 +26,21 @@ const statusVerbMap = {playing: 'pause',paused: 'play',played: 'replay',-}+} as const+const statusIconMap = {playing: pauseIcon,paused: playIcon,played: replayIcon,-}+} as const++const layoutConnectionsMap: Record<AudioLayout, ButtonConnections> = {+ row: 'end',+ global: 'all',+ box: 'none',+ full: 'none',+} as const+/*** Displays the control for switching between the playing and paused states of* a media file.@@ -69,12 +79,24 @@ export default defineComponent({* Get the button icon based on the current status of the player.*/const icon = computed(() => statusIconMap[props.status])++ /**+ * Sets the button variant to `plain-dangerous` to manually handle focus states.+ * Sets the connections (none-rounded corners) for the button based on the layout.+ */+ const buttonProps = computed(() => {+ const variant = 'plain-dangerous' as ButtonVariant++ return { variant, connections: layoutConnectionsMap[props.layout] }+ })+const handleClick = () => {emit('toggle', isPlaying.value ? 'paused' : 'playing')}return {label,icon,+ buttonProps,handleClick,}diff --git a/src/components/VAudioTrack/layouts/VGlobalLayout.vue b/src/components/VAudioTrack/layouts/VGlobalLayout.vueindex ed99cc178..29f3fae4e 100644--- a/src/components/VAudioTrack/layouts/VGlobalLayout.vue+++ b/src/components/VAudioTrack/layouts/VGlobalLayout.vue@@ -2,7 +2,7 @@<div class="global-track flex flex-row w-full"><div class="flex-shrink-0"><VAudioThumbnail :audio="audio" />- <slot name="play-pause" size="medium" />+ <slot name="play-pause" size="medium" layout="global" /></div><div class="relative flex-grow">diff --git a/src/components/VAudioTrack/layouts/VRowLayout.vue b/src/components/VAudioTrack/layouts/VRowLayout.vueindex cfc0f1d15..d512ef555 100644--- a/src/components/VAudioTrack/layouts/VRowLayout.vue+++ b/src/components/VAudioTrack/layouts/VRowLayout.vue@@ -9,7 +9,7 @@><VAudioThumbnail :audio="audio" /><div v-show="isSmall" class="absolute bottom-0 rtl:left-0 ltr:right-0">- <slot name="play-pause" size="tiny" />+ <slot name="play-pause" size="tiny" layout="row" /></div></div>@@ -71,7 +71,11 @@'flex-grow': isMedium,}">- <slot name="play-pause" :size="isLarge ? 'medium' : 'large'" />+ <slot+ name="play-pause"+ :size="isLarge ? 'medium' : 'large'"+ :layout="'row'"+ /><slotname="controller":features="features"diff --git a/src/components/VButton.vue b/src/components/VButton.vueindex 4768cdd5c..6b6919b6f 100644--- a/src/components/VButton.vue+++ b/src/components/VButton.vue@@ -6,6 +6,7 @@:class="[$style.button,$style[variant],+ isConnected && $style[`connection-${connections}`],isActive && $style[`${variant}-pressed`],$style[`size-${size}`],isPlainDangerous ? '' : 'focus-visible:ring focus-visible:ring-pink',@@ -55,17 +56,17 @@ export const buttonVariants = ['plain-dangerous','full',] as const-export type ButtonVariant = typeof buttonVariants[number]export const buttonSizes = ['large', 'medium', 'small', 'disabled'] as const-export type ButtonSize = typeof buttonSizes[number]export const buttonTypes = ['button', 'submit', 'reset'] as const-export type ButtonType = typeof buttonTypes[number]+export const buttonConnections = ['start', 'end', 'none', 'all'] as const+export type ButtonConnections = typeof buttonConnections[number]+export type ButtonProps = ProperlyExtractPropTypes<NonNullable<typeof VButton['props']>>@@ -169,6 +170,17 @@ const VButton = defineComponent({type: String as PropType<ButtonType>,default: 'button',},+ /**+ * Whether the button is connected to another control and needs to have no rounded+ * borders at that edge.+ * `all` means that the button is not rounded.+ *+ * @default 'none'+ */+ connections: {+ type: String as PropType<ButtonConnections>,+ default: 'none',+ },},setup(props, { attrs }) {const propsRef = toRefs(props)@@ -180,6 +192,8 @@ const VButton = defineComponent({const typeRef = ref<ButtonType | undefined>(propsRef.type.value)const supportsDisabledAttributeRef = ref(true)+ const isConnected = computed(() => props.connections !== 'none')+const isActive = computed(() => {return (propsRef.pressed.value ||@@ -237,6 +251,7 @@ const VButton = defineComponent({ariaDisabledRef,typeRef,isActive,+ isConnected,isPlainDangerous,}},@@ -322,4 +337,14 @@ a.button {.full-pressed {@apply w-full font-semibold bg-dark-charcoal-06 text-dark-charcoal;}++.connection-start {+ @apply rounded-s-none;+}+.connection-end {+ @apply rounded-e-none;+}+.connection-all {+ @apply rounded-none;+}</style>diff --git a/src/components/VGlobalAudioSection/VGlobalAudioSection.vue b/src/components/VGlobalAudioSection/VGlobalAudioSection.vueindex 6fc9bbc30..5759ccdad 100644--- a/src/components/VGlobalAudioSection/VGlobalAudioSection.vue+++ b/src/components/VGlobalAudioSection/VGlobalAudioSection.vue@@ -1,9 +1,9 @@<template><div class="global-audio sticky sm:hidden bottom-0">- <VGlobalAudioTrack v-if="audio" layout="global" :audio="audio" />+ <VGlobalAudioTrack v-if="audio" :audio="audio" /><VIconButtonv-if="audio"- class="absolute top-0 rtl:left-0 ltr:right-0 border-none z-10"+ class="absolute top-0 rtl:left-0 ltr:right-0 border-none z-20":icon-props="{ iconPath: icons.closeIcon }"@click="handleClose"/>diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.potindex 10063ed75..ce2e702e2 100644--- a/src/locales/po-files/openverse.pot+++ b/src/locales/po-files/openverse.pot@@ -4,7 +4,7 @@ msgid ""msgstr """Project-Id-Version: Openverse \n""Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"-"POT-Creation-Date: 2022-05-17T14:35:39+00:00\n"+"POT-Creation-Date: 2022-05-17T14:42:04+00:00\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"@@ -252,7 +252,7 @@ msgctxt "audio-track.creator"msgid "by ###creator###"msgstr ""-#: src/components/VAudioTrack/layouts/VRowLayout.vue:128+#: src/components/VAudioTrack/layouts/VRowLayout.vue:132msgctxt "audio-track.messages.blink_seek_disabled"msgid "Seeking for Jamendo tracks is limited to Firefox and Safari."msgstr ""