Skip to content

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

Create a global audio player (amongst many smaller improvements) (#399)

Dhruv Bhanushaliaf5841274503
diff --git a/src/assets/icons/close.svg b/src/assets/icons/close.svg
new file mode 100644
index 000000000..b4c834c83
--- /dev/null
+++ b/src/assets/icons/close.svg
@@ -0,0 +1,5 @@
+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <g id="icon" fill="currentColor">
+ <path d="M12 13.0607L15.7123 16.773L16.773 15.7123L13.0607 12L16.773 8.28772L15.7123 7.22706L12 10.9394L8.2877 7.22705L7.22704 8.28771L10.9394 12L7.22704 15.7123L8.2877 16.773L12 13.0607Z"/>
+ </g>
+</svg>
diff --git a/src/components/AudioTrack/AudioController.vue b/src/components/AudioTrack/AudioController.vue
index 819ecdd86..8ce996493 100644
--- a/src/components/AudioTrack/AudioController.vue
+++ b/src/components/AudioTrack/AudioController.vue
@@ -1,7 +1,7 @@
<template>
<div class="audio-controller">
<Waveform
- :class="waveformClasses"
+ v-bind="waveformProps"
:message="message ? $t(`audio-track.messages.${message}`) : null"
:current-time="currentTime"
:duration="duration"
@@ -27,11 +27,14 @@
</template>
<script>
-import Waveform from '~/components/AudioTrack/Waveform'
import { computed, ref, useStore, watch } from '@nuxtjs/composition-api'
+
+import Waveform from '~/components/AudioTrack/Waveform'
+
+import { ACTIVE } from '~/constants/store-modules.js'
import {
+ PAUSE_ACTIVE_MEDIA_ITEM,
SET_ACTIVE_MEDIA_ITEM,
- UNSET_ACTIVE_MEDIA_ITEM,
} from '~/constants/mutation-types'
/**
@@ -64,10 +67,10 @@ export default {
validator: (val) => ['playing', 'paused', 'played'].includes(val),
},
/**
- * the CSS classes to apply on the waveform; This can take any form
- * acceptable to Vue class bindings.
+ * the Vue props to pass to the waveform; This can take any form acceptable
+ * to Vue bindings.
*/
- waveformClasses: {},
+ waveformProps: {},
},
setup(props, { emit }) {
const store = useStore()
@@ -88,23 +91,25 @@ export default {
if (!audioEl.value) return
if (prevStatus === 'played' && status === 'playing') {
- // If going from played to playing, then reset the time to the beginning. Let the regular logic handle actually triggering the playing of the audio
+ // If going from played to playing, then reset the time to the beginning.
+ // Let the regular logic handle actually triggering the playing of the audio
audioEl.value.currentTime = 0
}
switch (status) {
case 'playing':
audioEl.value.play()
- store.commit(SET_ACTIVE_MEDIA_ITEM, {
+ store.commit(`${ACTIVE}/${SET_ACTIVE_MEDIA_ITEM}`, {
type: 'audio',
id: props.audio.id,
})
window.requestAnimationFrame(updateTimeLoop)
break
case 'paused':
+ case 'played': // Note that played media shows as paused in the store
audioEl.value.pause()
if (isActiveTrack.value) {
- store.commit(UNSET_ACTIVE_MEDIA_ITEM)
+ store.commit(`${ACTIVE}/${PAUSE_ACTIVE_MEDIA_ITEM}`)
}
break
}
diff --git a/src/components/AudioTrack/AudioTrack.vue b/src/components/AudioTrack/AudioTrack.vue
index deae52c72..7bd013d1b 100644
--- a/src/components/AudioTrack/AudioTrack.vue
+++ b/src/components/AudioTrack/AudioTrack.vue
@@ -16,7 +16,7 @@
v-bind="controllerProps"
:audio="audio"
@ready="handleReady"
- @finished="status = 'played'"
+ @finished="handleFinished"
@seeked="handleSeeked"
/>
</template>
@@ -40,6 +40,7 @@ import AudioController from '~/components/AudioTrack/AudioController.vue'
import Full from '~/components/AudioTrack/layouts/Full.vue'
import Row from '~/components/AudioTrack/layouts/Row.vue'
+import Global from '~/components/AudioTrack/layouts/Global.vue'
/**
* Displays the waveform and basic information about the track, along with
@@ -47,7 +48,15 @@ import Row from '~/components/AudioTrack/layouts/Row.vue'
*/
export default {
name: 'AudioTrack',
- components: { AudioController, PlayPause, Full, Row },
+ components: {
+ AudioController,
+ PlayPause,
+
+ // Layouts
+ Full,
+ Row,
+ Global,
+ },
props: {
/**
* the information about the track, typically from a track's detail endpoint
@@ -63,7 +72,7 @@ export default {
layout: {
type: String,
default: 'full',
- validator: (val) => ['full', 'box', 'row'].includes(val),
+ validator: (val) => ['full', 'box', 'row', 'global'].includes(val),
},
/**
* the size of the component; Both 'box' and 'row' layouts offer multiple
@@ -94,6 +103,9 @@ export default {
status.value = 'paused'
}
}
+ const handleFinished = () => {
+ status.value = 'played'
+ }
/* Metadata readiness */
@@ -107,12 +119,14 @@ export default {
const layoutMappings = {
full: 'Full',
row: 'Row',
+ global: 'Global',
}
const layoutComponent = computed(() => layoutMappings[props.layout])
return {
status,
handleSeeked,
+ handleFinished,
isReady,
handleReady,
diff --git a/src/components/AudioTrack/PlayPause.vue b/src/components/AudioTrack/PlayPause.vue
index 1efbdcc99..c0c01388a 100644
--- a/src/components/AudioTrack/PlayPause.vue
+++ b/src/components/AudioTrack/PlayPause.vue
@@ -4,72 +4,67 @@
class="play-pause flex-shrink-0 flex items-center justify-center bg-dark-charcoal text-white transition-shadow duration-100 ease-linear disabled:opacity-70 focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink"
@click="handleClick"
>
- <span class="sr-only">{{ label }}</span>
- <svg
- class="h-8 w-8"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 24 24"
- aria-hidden="true"
- focusable="false"
- >
- <use :href="`${icon}#icon`" />
- </svg>
+ <span class="sr-only">{{ $t(label) }}</span>
+ <VIcon :icon-path="icon" />
</button>
</template>
<script>
+import VIcon from '~/components/VIcon/VIcon.vue'
+
import playIcon from '~/assets/icons/play.svg'
import pauseIcon from '~/assets/icons/pause.svg'
import replayIcon from '~/assets/icons/replay.svg'
-/**
- * @param {'playing' | 'paused' | 'played'} status
- */
-const getLabelFromStatus = (status) => {
- switch (status) {
- case 'playing':
- return 'play-pause.pause'
- case 'paused':
- return 'play-pause.play'
- case 'played':
- return 'play-pause.replay'
- }
-}
-
-const STATUS_TO_ICON = {
- playing: pauseIcon,
- paused: playIcon,
- played: replayIcon,
-}
-
/**
* Displays the control for switching between the playing and paused states of
* a media file.
*/
export default {
name: 'PlayPause',
+ components: { VIcon },
model: {
prop: 'status',
event: 'toggle',
},
props: {
/**
- * the playing/paused status of the audio
+ * the current play status of the audio
*/
status: {
type: String,
validator: (val) => ['playing', 'paused', 'played'].includes(val),
},
},
+ data() {
+ return {
+ statusVerbMap: {
+ playing: 'pause',
+ paused: 'play',
+ played: 'replay',
+ },
+ statusIconMap: {
+ playing: pauseIcon,
+ paused: playIcon,
+ played: replayIcon,
+ },
+ }
+ },
computed: {
isPlaying() {
return this.status === 'playing'
},
+ /**
+ * Get the button label based on the current status of the player.
+ */
label() {
- return this.$t(getLabelFromStatus(this.status))
+ return `play-pause.${this.statusVerbMap[this.status]}`
},
+ /**
+ * Get the button icon based on the current status of the player.
+ */
icon() {
- return STATUS_TO_ICON[this.status]
+ return this.statusIconMap[this.status]
},
},
methods: {
diff --git a/src/components/AudioTrack/Waveform.vue b/src/components/AudioTrack/Waveform.vue
index 15ee4aeb9..c1bc2cb8d 100644
--- a/src/components/AudioTrack/Waveform.vue
+++ b/src/components/AudioTrack/Waveform.vue
@@ -1,7 +1,8 @@
<template>
<div
ref="el"
- class="waveform relative bg-dark-charcoal-04 overflow-hidden focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink"
+ class="waveform relative bg-dark-charcoal-06 overflow-hidden focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink"
+ :style="{ '--unusable-height': `${Math.floor((1 - usableFrac) * 100)}%` }"
tabIndex="0"
role="slider"
:aria-label="$t('waveform.label')"
@@ -19,8 +20,9 @@
@keydown.home.prevent="handlePosKeys(0)"
@keydown.end.prevent="handlePosKeys(1)"
>
+ <!-- Progress bar -->
<svg
- class="w-full h-full"
+ class="absolute inset-0 w-full h-full"
xmlns="http://www.w3.org/2000/svg"
:viewBox="viewBox"
preserveAspectRatio="none"
@@ -33,13 +35,23 @@
:width="progressBarWidth"
height="100%"
/>
+ </svg>
+
+ <!-- Bars -->
+ <svg
+ class="bars absolute bottom-0 w-full"
+ :style="{ '--usable-height': `${Math.floor(usableFrac * 100)}%` }"
+ xmlns="http://www.w3.org/2000/svg"
+ :viewBox="viewBox"
+ preserveAspectRatio="none"
+ >
<rect
v-for="(peak, index) in normalizedPeaks"
:key="index"
class="transform origin-bottom transition-transform duration-500"
:class="[
isReady ? 'scale-y-100' : 'scale-y-0',
- index <= seekIndex ? 'fill-black' : 'fill-dark-charcoal-20',
+ index <= seekIndex ? 'fill-black' : 'fill-dark-charcoal-20-alpha',
]"
:x="spaceBefore(index)"
:y="spaceAbove(index)"
@@ -73,7 +85,7 @@
class="progress timestamp z-10 transform"
:class="[
...(isProgressTimestampCutoff
- ? ['bg-dark-charcoal-04-opaque']
+ ? ['bg-dark-charcoal-06']
: ['bg-yellow', '-translate-x-full']),
]"
:style="{ '--progress-time-left': `${progressBarWidth}px` }"
@@ -91,7 +103,7 @@
</div>
<div
v-if="showDuration"
- class="duration timestamp right-0 bg-dark-charcoal-04-opaque"
+ class="duration timestamp right-0 bg-dark-charcoal-06"
>
{{ timeFmt(duration) }}
</div>
@@ -100,7 +112,7 @@
<!-- Message overlay -->
<div
v-else
- class="absolute inset-x-0 inset-y-0 flex items-center justify-center loading font-bold text-xs"
+ class="absolute inset-0 flex items-center justify-center loading font-bold text-xs"
>
{{ message }}
</div>
@@ -161,6 +173,14 @@ export default {
type: Boolean,
default: false,
},
+ /**
+ * the fraction of the waveform height to use for the bars and timestamp;
+ * The remaining space can be used to place other elements.
+ */
+ usableFrac: {
+ type: Number,
+ default: 1,
+ },
},
setup(props, { emit }) {
/* Utils */
@@ -244,17 +264,9 @@ export default {
/* SVG drawing */
- /**
- * the fraction of space to reserve for the timestamps above the bars; The
- * `viewBox` height of the waveform will be 1 + `timestampSpace`.
- */
- const timestampSpace = 0.33 // % of bar height
- const viewBoxHeight = 1 + timestampSpace
- const viewBox = computed(
- () => `0 0 ${waveformWidth.value} ${viewBoxHeight}`
- )
+ const viewBox = computed(() => `0 0 ${waveformWidth.value} 1`)
const spaceBefore = (index) => index * barWidth + (index + 1) * barGap
- const spaceAbove = (index) => viewBoxHeight - normalizedPeaks.value[index]
+ const spaceAbove = (index) => 1 - normalizedPeaks.value[index]
/* Progress bar */
@@ -425,7 +437,12 @@ export default {
<style scoped lang="css">
.timestamp {
- @apply absolute top-1 font-bold text-xs px-1 pointer-events-none;
+ @apply absolute font-bold text-xs px-1 pointer-events-none;
+ top: calc(var(--unusable-height) + theme('spacing[0.5]'));
+}
+
+.bars {
+ height: calc(var(--usable-height) - 1rem - 2 * theme('spacing[0.5]'));
}
.progress {
@@ -436,12 +453,11 @@ export default {
left: var(--seek-time-left);
}
-.bg-dark-charcoal-04-opaque {
- /* opaque equivalent of dark-charcoal-04 on top of white */
- background-color: rgb(247, 246, 247);
-}
-
.waveform:focus-visible .focus-indicator {
display: flex;
}
+
+.fill-dark-charcoal-20-alpha {
+ fill: rgba(48, 39, 46, 0.2);
+}
</style>
diff --git a/src/components/AudioTrack/layouts/Full.vue b/src/components/AudioTrack/layouts/Full.vue
index f5b8171c9..4abe57cc1 100644
--- a/src/components/AudioTrack/layouts/Full.vue
+++ b/src/components/AudioTrack/layouts/Full.vue
@@ -34,8 +34,13 @@
</template>
<script>
+import DownloadButton from '~/components/DownloadButton.vue'
+
export default {
name: 'Full',
+ components: {
+ DownloadButton,
+ },
props: ['audio'],
setup() {
/**
diff --git a/src/components/AudioTrack/layouts/Global.vue b/src/components/AudioTrack/layouts/Global.vue
new file mode 100644
index 000000000..5eb56f5fb
--- /dev/null
+++ b/src/components/AudioTrack/layouts/Global.vue
@@ -0,0 +1,43 @@
+<template>
+ <div class="global-track flex flex-row w-full">
+ <div class="flex-shrink-0">
+ <AudioThumbnail :audio="audio" />
+ <slot name="play-pause" />
+ </div>
+
+ <div class="relative flex-grow">
+ <div
+ class="absolute inset-x-0 z-10 top-4 px-4 flex flex-row items-center justify-between"
+ >
+ <p class="text-sr font-semibold">{{ audio.title }}</p>
+ </div>
+
+ <slot name="controller" :waveform-props="{ 'usable-frac': 0.5 }" />
+ </div>
+ </div>
+</template>
+
+<script>
+import AudioThumbnail from '~/components/AudioThumbnail/AudioThumbnail.vue'
+
+export default {
+ name: 'Global',
+ components: { AudioThumbnail },
+ props: ['audio'],
+}
+</script>
+
+<style>
+.global-track .play-pause,
+.global-track .thumbnail {
+ @apply h-14 w-14;
+}
+
+.global-track .audio-controller {
+ @apply absolute inset-0;
+}
+
+.global-track .waveform {
+ @apply h-full;
+}
+</style>
diff --git a/src/components/AudioTrack/layouts/Row.vue b/src/components/AudioTrack/layouts/Row.vue
index 508caf919..1c9e74009 100644
--- a/src/components/AudioTrack/layouts/Row.vue
+++ b/src/components/AudioTrack/layouts/Row.vue
@@ -1,34 +1,47 @@
<template>
<article class="row-track flex flex-row" :class="`size-${size}`">
- <div class="flex-shrink-0" :class="isSmall ? 'w-20 me-4' : 'w-30 me-6'">
+ <div
+ class="relative flex-shrink-0 rounded-sm overflow-hidden"
+ :class="isLarge ? 'w-30 me-6' : 'w-20 me-4'"
+ >
<AudioThumbnail :audio="audio" />
+ <div v-if="isSmall" class="absolute bottom-0 end-0">
+ <slot name="play-pause" />
+ </div>
</div>
+
<div
- class="flex"
- :class="isSmall ? 'flex-row gap-8' : 'flex-col justify-between'"
+ class="flex-grow"
+ :class="{
+ 'flex flex-row gap-8': isMedium,
+ 'flex flex-col justify-between': isLarge,
+ }"
>
- <div class="flex-shrink-0" :class="isSmall ? 'w-70' : ''">
+ <div class="flex-shrink-0" :class="{ 'w-70': isMedium }">
<NuxtLink
:to="localePath(`/audio/${audio.id}`)"
- class="font-heading font-semibold text-2xl"
+ class="font-heading font-semibold text-dark-charcoal hover:text-dark-charcoal"
+ :class="{
+ 'text-2xl': isMedium || isLarge,
+ 'leading-snug': isSmall,
+ }"
>{{ audio.title }}</NuxtLink
>
<div
- class="flex leading-snug text-dark-charcoal-70 mt-2"
- :class="
- isSmall ? 'flex-col gap-2' : 'flex-row items-center justify-between'
- "
+ class="flex text-dark-charcoal-70 mt-2"
+ :class="{
+ 'text-sr': isSmall,
+ 'leading-snug': isMedium || isLarge,
+ 'flex-col gap-2': isSmall || isMedium,
+ 'flex-row items-center justify-between': isLarge,
+ }"
>
<div class="part-a">
- <i18n
- tag="span"
- class="font-semibold leading-snug"
- path="audio-track.creator"
- >
+ <i18n tag="span" class="font-semibold" path="audio-track.creator">
<template #creator>{{ audio.creator }}</template>
</i18n>
- <span v-if="!isSmall">
+ <span v-if="isSmall || isLarge">
{{ $t('interpunct') }} {{ timeFmt(audio.duration) }}
<template v-if="audio.category">
{{ $t('interpunct') }}
@@ -38,18 +51,25 @@
</div>
<div class="part-b inline-flex space-x-1">
- <div v-if="isSmall">
+ <div v-if="isMedium">
{{ timeFmt(audio.duration) }} {{ $t('interpunct') }}
<template v-if="audio.category">
{{ $t(`audio-categories.${audio.category}`) }}
{{ $t('interpunct') }}
</template>
</div>
- <License class="inline" :license="audio.license" />
+ <License :license="audio.license" />
</div>
</div>
</div>
- <div class="flex flex-row">
+
+ <div
+ class="flex flex-row"
+ :class="{
+ hidden: isSmall,
+ 'flex-grow': isMedium,
+ }"
+ >
<slot name="play-pause" />
<slot name="controller" />
</div>
@@ -84,10 +104,15 @@ export default {
}
const isSmall = computed(() => props.size === 's')
+ const isMedium = computed(() => props.size === 'm')
+ const isLarge = computed(() => props.size === 'l')
return {
timeFmt,
+
isSmall,
+ isMedium,
+ isLarge,
}
},
}
@@ -98,31 +123,27 @@ export default {
@apply rounded-ts-sm rounded-bs-sm flex-shrink-0;
}
+.row-track .audio-controller {
+ @apply flex-grow;
+}
+
.row-track .waveform {
@apply rounded-te-sm rounded-be-sm;
}
-.row-track.size-s .play-pause {
+.row-track.size-m .play-pause {
@apply h-20 w-20;
}
-.row-track.size-s .waveform {
+.row-track.size-m .waveform {
@apply h-20;
}
-.row-track.size-s .thumbnail {
- @apply rounded-ts-sm rounded-bs-sm overflow-hidden;
-}
-
-.row-track.size-m .play-pause {
+.row-track.size-l .play-pause {
@apply h-14 w-14;
}
-.row-track.size-m .waveform {
+.row-track.size-l .waveform {
@apply h-14;
}
-
-.row-track.size-m .thumbnail {
- @apply rounded-sm overflow-hidden;
-}
</style>
diff --git a/src/components/AudioTrack/meta/AudioTrack.stories.mdx b/src/components/AudioTrack/meta/AudioTrack.stories.mdx
index b5286af30..bba33b7b3 100644
--- a/src/components/AudioTrack/meta/AudioTrack.stories.mdx
+++ b/src/components/AudioTrack/meta/AudioTrack.stories.mdx
@@ -24,7 +24,7 @@ import wavWaveform from './wav-waveform.json'
},
layout: {
defaultValue: 'full',
- options: ['full', 'box', 'row'],
+ options: ['full', 'box', 'row', 'global'],
control: 'select',
},
size: {
@@ -48,6 +48,8 @@ export const commonAttrs = () => ({
creator: 'Wolfgang Amadeus Mozart',
creatorUrl: 'https://en.wikipedia.org/wiki/Wolfgang_Amadeus_Mozart',
category: 'music',
+ thumbnail:
+ 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/Croce-Mozart-Detail.jpg/370px-Croce-Mozart-Detail.jpg',
})
export const formatExamples = {
@@ -105,14 +107,26 @@ export const Template = (args, { argTypes }) => ({
<ArgsTable of={AudioTrack} />
-<Canvas>
- <Story name="Default">{Template.bind({})}</Story>
-</Canvas>
+**Audio thumbnail:** "Mozart Family" by
+[Johann Nepomuk della Croce](https://en.wikipedia.org/wiki/Johann_Nepomuk_della_Croce)
+(Public Domain)
-The component can also be rendered in a multiple different layouts, by
+## Layouts
+
+The component can be rendered in a multiple different layouts, by
specifying a `layout`. The layout can further be customised by the `size` and
`aspect` props.
+### Full (default)
+
+<Canvas>
+ <Story name="Full">{Template.bind({})}</Story>
+</Canvas>
+
+### Row
+
+**Sizes:** S (small) and M (medium) and L (large)
+
<Canvas>
<Story
name="Row (small)"
@@ -123,6 +137,9 @@ specifying a `layout`. The layout can further be customised by the `size` and
>
{Template.bind({})}
</Story>
+</Canvas>
+
+<Canvas>
<Story
name="Row (medium)"
args={{
@@ -134,6 +151,31 @@ specifying a `layout`. The layout can further be customised by the `size` and
</Story>
</Canvas>
+<Canvas>
+ <Story
+ name="Row (large)"
+ args={{
+ layout: 'row',
+ size: 'l',
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
+
+### Global
+
+<Canvas>
+ <Story
+ name="Global"
+ args={{
+ layout: 'global',
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
+
## Other formats
The component is capable of playing audio in many formats, but this largely
diff --git a/src/components/AudioTrack/meta/PlayPause.stories.mdx b/src/components/AudioTrack/meta/PlayPause.stories.mdx
index 6ac2f74bb..bc2f1ec76 100644
--- a/src/components/AudioTrack/meta/PlayPause.stories.mdx
+++ b/src/components/AudioTrack/meta/PlayPause.stories.mdx
@@ -47,7 +47,11 @@ of `h-*` and `w-*` classes are needed.
</Canvas>
The recommended way to use it is with `v-model` mapping to a `String` that can
-either be `'playing'` or `'paused'`.
+either be `'playing'`, `'paused'` or `'played'`.
+
+It should be noted that both paused and played states change to playing when
+toggled whereas the playing state toggles to paused. The played state can only
+be achieved by playing till the end of a track.
export const vModelTemplate = () => ({
template: `
@@ -59,7 +63,7 @@ export const vModelTemplate = () => ({
components: { PlayPause },
data() {
return {
- status: 'paused',
+ status: 'played',
}
},
})
diff --git a/src/components/AudioTrack/meta/Waveform.stories.mdx b/src/components/AudioTrack/meta/Waveform.stories.mdx
index 947ef9fe5..c69eb5fd9 100644
--- a/src/components/AudioTrack/meta/Waveform.stories.mdx
+++ b/src/components/AudioTrack/meta/Waveform.stories.mdx
@@ -85,6 +85,28 @@ The waveform always takes the height and width of its container.
Thus the `barWidth` and `barGap` will be maintained even in the case of
horizontal scaling.
+## Usable area
+
+To leave some blank space at the top, for overlaying your own stuff, you can
+pass a number less than 1 as the `usableFrac` prop. Note that the usable area
+contains both the bars and the timestamps so the actual bar height is less than
+`usableFrac`.
+
+<Canvas>
+ <Story
+ name="With blank space"
+ args={{
+ peaks: [0.5, 1, 0.5, 0, 0.5],
+ currentTime: 2,
+ duration: 10,
+ showDuration: true,
+ usableFrac: 0.5,
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
+
## Message state
The waveform bars are set to zero height when the `message` prop is passed. They
diff --git a/src/components/License/License.vue b/src/components/License/License.vue
index c209c1e9b..f7abf3c2b 100644
--- a/src/components/License/License.vue
+++ b/src/components/License/License.vue
@@ -1,27 +1,19 @@
<template>
- <div class="license text-dark-charcoal-70 flex gap-2">
+ <div class="license text-dark-charcoal-70 flex flex-row items-center gap-2">
<div class="flex gap-1">
- <svg
+ <VIcon
v-if="isCC"
- class="h-5 w-5 inline"
- viewBox="0 0 30 30"
- xmlns="http://www.w3.org/2000/svg"
- aria-hidden="true"
- focusable="false"
- >
- <use :href="`${ccLogo}#icon`" />
- </svg>
- <svg
+ class="icon"
+ view-box="0 0 30 30"
+ :icon-path="ccLogo"
+ />
+ <VIcon
v-for="(name, index) in icons"
:key="index"
- class="h-5 w-5 inline"
- viewBox="0 0 30 30"
- xmlns="http://www.w3.org/2000/svg"
- aria-hidden="true"
- focusable="false"
- >
- <use :href="`${svgs[name]}#icon`" />
- </svg>
+ class="icon"
+ view-box="0 0 30 30"
+ :icon-path="svgs[name]"
+ />
</div>
<span class="name">
{{ $t(`license-names.${license}`) }}
@@ -30,12 +22,15 @@
</template>
<script>
+import { computed } from '@nuxtjs/composition-api'
+
+import VIcon from '~/components/VIcon/VIcon.vue'
+
import {
ALL_LICENCES,
CC_LICENSES,
LICENSE_ICON_MAPPING,
} from '~/constants/license.js'
-import { computed } from '@nuxtjs/composition-api'
import by from '~/assets/licenses/by.svg'
import cc0 from '~/assets/licenses/cc0.svg'
@@ -51,6 +46,7 @@ import sa from '~/assets/licenses/sa.svg'
*/
export default {
name: 'License',
+ components: { VIcon },
props: {
/**
* the slug of the license
@@ -85,3 +81,10 @@ export default {
},
}
</script>
+
+<style scoped>
+.icon {
+ height: 1.1667em;
+ width: 1.1667em;
+}
+</style>
diff --git a/src/components/VIcon/VIcon.vue b/src/components/VIcon/VIcon.vue
new file mode 100644
index 000000000..1c5298ec6
--- /dev/null
+++ b/src/components/VIcon/VIcon.vue
@@ -0,0 +1,45 @@
+<template>
+ <svg
+ class="v-icon h-6 w-6"
+ xmlns="http://www.w3.org/2000/svg"
+ :viewBox="viewBox"
+ aria-hidden="true"
+ focusable="false"
+ >
+ <use :href="`${iconPath}#${gId}`" />
+ </svg>
+</template>
+
+<script>
+/**
+ * Displays the given icon in a 24px × 24px square.
+ */
+export default {
+ name: 'VIcon',
+ props: {
+ /**
+ *
+ */
+ viewBox: {
+ type: String,
+ default: '0 0 24 24',
+ },
+ /**
+ * the path to the icon SVG; In a bundled application like Openverse,
+ * importing an SVG should give us the path to the file.
+ */
+ iconPath: {
+ type: String,
+ required: true,
+ },
+ /**
+ * the ID of the `g` element to import from the icon; This element should
+ * ideally have the `id` as "icon" and the `fill` as `currentColor`.
+ */
+ gId: {
+ type: String,
+ default: 'icon',
+ },
+ },
+}
+</script>
diff --git a/src/components/VIcon/meta/VIcon.stories.mdx b/src/components/VIcon/meta/VIcon.stories.mdx
new file mode 100644
index 000000000..dc1823353
--- /dev/null
+++ b/src/components/VIcon/meta/VIcon.stories.mdx
@@ -0,0 +1,54 @@
+import {
+ ArgsTable,
+ Canvas,
+ Description,
+ Meta,
+ Story,
+} from '@storybook/addon-docs'
+
+import VIcon from '~/components/VIcon/VIcon.vue'
+
+import replayIcon from '~/assets/icons/replay.svg'
+
+<Meta title="Components/VIcon" component={VIcon} />
+
+export const Template = (args, { argTypes }) => ({
+ template: `<VIcon v-bind="$props" />`,
+ components: { VIcon },
+ props: Object.keys(argTypes),
+})
+
+# Icon
+
+<Description of={VIcon} />
+
+<ArgsTable of={VIcon} />
+
+To display the icon, the path to the SVG must be specified. When using a bundler
+like Webpack, importing an SVG (with the right loaders) will give the path to
+that SVG.
+
+```js
+import iconSvg from '~/path/to/icon' // contains the URL path to the SVG
+```
+
+You can then pass this imported value as the `iconPath` prop.
+
+```html
+<VIcon :iconPath="iconSvg" />
+```
+
+<Canvas>
+ <Story
+ name="Default"
+ args={{
+ iconPath: replayIcon,
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
+
+Each icon SVG must have a `<g>` element right below the top-level `<svg>`
+element. This element should have the `id` attribute equal to `"icon"`. If not,
+pass the attribute value as the `gId` prop.
diff --git a/src/constants/mutation-types.js b/src/constants/mutation-types.js
index 16fa56263..7940d5810 100644
--- a/src/constants/mutation-types.js
+++ b/src/constants/mutation-types.js
@@ -30,7 +30,8 @@ export const SET_REFERRED = 'SET_REFERRED'
export const SET_SEARCH_TYPE = 'SET_SEARCH_TYPE'
export const UPDATE_FILTERS = 'UPDATE_FILTERS'
export const SET_ACTIVE_MEDIA_ITEM = 'SET_ACTIVE_MEDIA_ITEM'
-export const UNSET_ACTIVE_MEDIA_ITEM = 'UNSET_ACTIVE_MEDIA_ITEM'
+export const PAUSE_ACTIVE_MEDIA_ITEM = 'PAUSE_ACTIVE_MEDIA_ITEM'
+export const EJECT_ACTIVE_MEDIA_ITEM = 'EJECT_ACTIVE_MEDIA_ITEM'
export const RESET_MEDIA = 'RESET_MEDIA'
export const REPLACE_FILTERS = 'REPLACE_FILTERS'
export const REPLACE_QUERY = 'REPLACE_QUERY'
diff --git a/src/constants/store-modules.js b/src/constants/store-modules.js
index 2e3a92309..5a2f94d9c 100644
--- a/src/constants/store-modules.js
+++ b/src/constants/store-modules.js
@@ -1,5 +1,6 @@
export const RELATED = 'related'
export const ABTEST = 'abtest'
+export const ACTIVE = 'active'
export const ATTRIBUTION = 'attribution'
export const PROVIDER = 'provider'
export const NAV = 'nav'
diff --git a/src/locales/en.json b/src/locales/en.json
index 145d870a4..a31697fa6 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -618,7 +618,8 @@
},
"play-pause": {
"play": "Play",
- "pause": "Pause"
+ "pause": "Pause",
+ "replay": "Replay"
},
"audio-categories": {
"title": "Audio Category",
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index e1e36a046..734d8e4b5 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: 2021-10-21T17:13:21+00:00\n"
+"POT-Creation-Date: 2021-11-05T09:58:32+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -105,6 +105,10 @@ msgctxt "play-pause.pause"
msgid "Pause"
msgstr ""
+msgctxt "play-pause.replay"
+msgid "Replay"
+msgstr ""
+
#: src/components/AudioTrack/AudioTrack.vue:4
msgctxt "audio-track.aria-label"
msgid "Audio Player"
@@ -142,13 +146,13 @@ msgctxt "audio-thumbnail.alt"
msgid "Cover art for \"###title###\" by ###creator###"
msgstr ""
-#: src/components/AudioTrack/Waveform.vue:7
+#: src/components/AudioTrack/Waveform.vue:8
msgctxt "waveform.label"
msgid "Audio seek bar"
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/AudioTrack/Waveform.vue:420
+#: src/components/AudioTrack/Waveform.vue:432
msgctxt "waveform.current-time"
msgid "###time### seconds"
msgstr ""
@@ -272,7 +276,7 @@ msgctxt "photo-details.creator"
msgid "by ###name###"
msgstr ""
-#: src/components/ImageDetails/PhotoDetails.vue:151
+#: src/components/ImageDetails/PhotoDetails.vue:150
msgctxt "photo-details.weblink"
msgid "Go to image's website"
msgstr ""
@@ -613,12 +617,12 @@ msgctxt "browse-page.all-no-results"
msgid "No results"
msgstr ""
-#: src/components/AudioResultsList.vue:80
+#: src/components/AudioResultsList.vue:77
msgctxt "browse-page.audio-no-results"
msgid "No audio results"
msgstr ""
-#: src/components/SearchGridManualLoad.vue:124
+#: src/components/SearchGridManualLoad.vue:109
msgctxt "browse-page.image-no-results"
msgid "No image results"
msgstr ""
@@ -631,7 +635,7 @@ msgstr[0] ""
msgstr[1] ""
#. Do not translate words between ### ###.
-#: src/components/AudioResultsList.vue:86
+#: src/components/AudioResultsList.vue:83
msgctxt "browse-page.audio-result-count"
msgid "###localeCount### audio result"
msgid_plural "###localeCount### audio results"
@@ -639,7 +643,7 @@ msgstr[0] ""
msgstr[1] ""
#. Do not translate words between ### ###.
-#: src/components/SearchGridManualLoad.vue:130
+#: src/components/SearchGridManualLoad.vue:115
msgctxt "browse-page.image-result-count"
msgid "###localeCount### image result"
msgid_plural "###localeCount### image results"
@@ -654,7 +658,7 @@ msgstr[0] ""
msgstr[1] ""
#. Do not translate words between ### ###.
-#: src/components/AudioResultsList.vue:83
+#: src/components/AudioResultsList.vue:80
msgctxt "browse-page.audio-result-count-more"
msgid "Over ###localeCount### audio results"
msgid_plural "Over ###localeCount### audio results"
@@ -662,7 +666,7 @@ msgstr[0] ""
msgstr[1] ""
#. Do not translate words between ### ###.
-#: src/components/SearchGridManualLoad.vue:127
+#: src/components/SearchGridManualLoad.vue:112
msgctxt "browse-page.image-result-count-more"
msgid "Over ###localeCount### image results"
msgid_plural "Over ###localeCount### image results"
@@ -773,7 +777,7 @@ msgid "This work is marked as being in the public domain."
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/SearchGridForm.vue:81
+#: src/components/SearchGridForm.vue:82
msgctxt "browse-page.search-form.placeholder"
msgid "Search all ###type###"
msgstr ""
@@ -1103,13 +1107,13 @@ msgid "An error occurred"
msgstr ""
#. Do not translate words between ### ###.
-#: src/pages/photos/_id.vue:66
+#: src/pages/photos/_id.vue:58
msgctxt "error.image-not-found"
msgid "Couldn't find image with id ###id###"
msgstr ""
#. Do not translate words between ### ###.
-#: src/pages/audio/_id.vue:79
+#: src/pages/audio/_id.vue:74
msgctxt "error.media-not-found"
msgid "Couldn't find ###mediaType### with id ###id###"
msgstr ""
@@ -1946,7 +1950,7 @@ msgctxt "header.extension-nav-item"
msgid "Web extension"
msgstr ""
-#: src/components/EmbeddedNavSection.vue:141
+#: src/components/EmbeddedNavSection.vue:143
msgctxt "header.placeholder"
msgid "Search all content"
msgstr ""
diff --git a/src/store/active.js b/src/store/active.js
index 128e85511..2638c289f 100644
--- a/src/store/active.js
+++ b/src/store/active.js
@@ -1,6 +1,7 @@
import {
SET_ACTIVE_MEDIA_ITEM,
- UNSET_ACTIVE_MEDIA_ITEM,
+ PAUSE_ACTIVE_MEDIA_ITEM,
+ EJECT_ACTIVE_MEDIA_ITEM,
} from '~/constants/mutation-types'
/**
@@ -10,6 +11,7 @@ import {
const state = () => ({
type: null,
id: null,
+ status: 'ejected', // can be 'playing' or 'paused' as well
})
const mutations = {
@@ -19,18 +21,28 @@ const mutations = {
* @param {object} payload
* @param {'image' | 'audio' | null} payload.type - the nature of the active media item
* @param {string} payload.id - the ID of the active media item
+ * @param {'ejected' | 'playing' | 'paused'} payload.status - the status of the active media item
*/
- [SET_ACTIVE_MEDIA_ITEM](_state, { type, id }) {
+ [SET_ACTIVE_MEDIA_ITEM](_state, { type, id, status = 'playing' }) {
_state.type = type
_state.id = id
+ _state.status = status
},
/**
- * Clear the active media item.
+ * Pause the active media item.
* @param {import('./types').ActiveMediaState} _state
*/
- [UNSET_ACTIVE_MEDIA_ITEM](_state) {
+ [PAUSE_ACTIVE_MEDIA_ITEM](_state) {
+ _state.status = 'paused'
+ },
+ /**
+ * Eject, and unset, the active media item.
+ * @param {import('./types').ActiveMediaState} _state
+ */
+ [EJECT_ACTIVE_MEDIA_ITEM](_state) {
_state.type = null
_state.id = null
+ _state.status = 'ejected'
},
}
diff --git a/src/store/types.d.ts b/src/store/types.d.ts
index 2ab11e21e..8c3ced50e 100644
--- a/src/store/types.d.ts
+++ b/src/store/types.d.ts
@@ -60,4 +60,5 @@ export type ImageDetail = {
export interface ActiveMediaState {
type: 'image' | 'audio' | null
id: string | null
+ status: 'ejected' | 'playing' | 'paused' // 'ejected' means player is closed
}
diff --git a/tailwind.config.js b/tailwind.config.js
index a2b7d78a7..c15c4a48a 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -28,18 +28,17 @@ module.exports = {
white: 'white',
// WordPress
- 'admin-gray': '#DCDCDE',
+ 'admin-gray': '#dcdcde',
// Dark Charcoal
- 'dark-charcoal-04': 'rgba(48, 39, 46, 0.04)', // This is a legacy opacity-based color. We should avoid it if possible
- 'dark-charcoal-06': '#F3F2F2',
- 'dark-charcoal-10': '#EAE9EA',
- 'dark-charcoal-20': '#D6D4D5',
- 'dark-charcoal-30': '#C1BEC0',
- 'dark-charcoal-40': '#ACA9AB',
+ 'dark-charcoal-06': '#f3f2f2',
+ 'dark-charcoal-10': '#eae9ea',
+ 'dark-charcoal-20': '#d6d4d5',
+ 'dark-charcoal-30': '#c1bec0',
+ 'dark-charcoal-40': '#aca9ab',
'dark-charcoal-50': '#989397',
- 'dark-charcoal-60': '#837D82',
- 'dark-charcoal-70': '#6E686D',
+ 'dark-charcoal-60': '#837d82',
+ 'dark-charcoal-70': '#6e686d',
'dark-charcoal-80': '#595258',
// Special keywords
@@ -57,6 +56,7 @@ module.exports = {
// Indexed by multiples of baseline (~ `0.25rem`)
0: '0',
+ 0.5: '0.125rem',
1: '0.25rem',
2: '0.50rem',
3: '0.75rem',