Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Create Skeleton components (#392)
Krystle Salazar51e0771b30d1
diff --git a/nuxt.config.js b/nuxt.config.jsindex b62c92219..43dff437d 100644--- a/nuxt.config.js+++ b/nuxt.config.js@@ -134,6 +134,7 @@ export default {'~/components/MediaInfo','~/components/MetaSearch','~/components/MediaTag',+ '~/components/Skeleton',],},plugins: [diff --git a/src/components/Skeleton/AudioTrackSkeleton.vue b/src/components/Skeleton/AudioTrackSkeleton.vuenew file mode 100644index 000000000..eaf80ef41--- /dev/null+++ b/src/components/Skeleton/AudioTrackSkeleton.vue@@ -0,0 +1,64 @@+<template>+ <article class="flex flex-row w-full mb-14">+ <!-- Thumbnail skeleton -->+ <div+ class="flex-shrink-0 h-20 w-20 mr-4 bg-dark-charcoal-10 rounded shimmering"+ />++ <div class="flex flex-row gap-6 h-20 w-full">+ <!-- Track info skeleton -->+ <div class="flex-shrink-0 w-70">+ <div class="flex flex-col h-full justify-around">+ <div+ v-for="idx in 2"+ :key="idx"+ class="row-line bg-dark-charcoal-10 h-3 rounded shimmering"+ :style="{ width: `${getRandomSize()}px` }"+ />+ <div class="inline-flex space-x-1 gap-2">+ <div class="h-3 w-14 bg-dark-charcoal-10 rounded shimmering" />+ <div class="rounded-full h-3 w-3 bg-dark-charcoal-10 shimmering" />+ <div+ class="row-line h-3 w-30 bg-dark-charcoal-10 rounded shimmering"+ />+ </div>+ </div>+ </div>+ <!-- Waveform skeleton -->+ <div class="w-full bg-dark-charcoal-10 rounded shimmering" />+ </div>+ </article>+</template>++<script>+export default {+ name: 'AudioTrackSkeleton',+ methods: {+ getRandomSize(max = 250, min = 70) {+ return Math.floor(Math.random() * (max - min) + min)+ },+ },+}+</script>++<style scoped>+@keyframes shimmer {+ 0% {+ background-position: -1000px 0;+ }+ 100% {+ background-position: 1000px 0;+ }+}++.shimmering {+ animation: shimmer 3s infinite linear;+ background: linear-gradient(+ to right,+ theme('colors.dark-charcoal-10') 4%,+ theme('colors.dark-charcoal-20') 25%,+ theme('colors.dark-charcoal-10') 36%+ );+ background-size: 1000px 100%;+}+</style>diff --git a/src/components/Skeleton/GridSkeleton.vue b/src/components/Skeleton/GridSkeleton.vuenew file mode 100644index 000000000..a526df2e9--- /dev/null+++ b/src/components/Skeleton/GridSkeleton.vue@@ -0,0 +1,74 @@+<template>+ <section class="px-10 pb-16">+ <div+ v-if="isForTab == 'all'"+ class="grid gap-4 tab:grid-cols-2 desk:grid-cols-5"+ >+ <VBone v-for="idx in numElems" :key="idx" class="square" />+ </div>++ <div v-if="isForTab == 'image'" class="masonry">+ <VBone+ v-for="idx in numElems"+ :key="idx"+ class="mb-4"+ :style="{ height: `${getRandomSize()}px` }"+ />+ </div>++ <template v-if="isForTab == 'audio'">+ <AudioTrackSkeleton v-for="idx in numElems" :key="idx" />+ </template>+ </section>+</template>++<script>+/**+ * Display placeholder elements while waiting for the actual elements to be+ * loaded in the results views.+ */+export default {+ name: 'GridSkeleton',+ props: {+ isForTab: {+ type: String,+ default: 'image',+ validator: (val) => ['all', 'image', 'audio'].includes(val),+ },+ numElems: {+ type: Number,+ default: function () {+ if (this.isForTab === 'all') return 10+ if (this.isForTab === 'image') return 30+ return 8+ },+ },+ },+ setup() {+ function getRandomSize(max = 300, min = 100) {+ return Math.floor(Math.random() * (max - min) + min)+ }++ return { getRandomSize }+ },+}+</script>++<style lang="scss" scoped>+.square {+ aspect-ratio: 1 / 1;+}++.masonry {+ column-count: 2;+ column-gap: 1rem;++ @screen tab {+ column-count: 3;+ }++ @screen desk {+ column-count: 5;+ }+}+</style>diff --git a/src/components/Skeleton/VBone.vue b/src/components/Skeleton/VBone.vuenew file mode 100644index 000000000..d64685ae0--- /dev/null+++ b/src/components/Skeleton/VBone.vue@@ -0,0 +1,32 @@+<template>+ <div :class="['bg-dark-charcoal-10', shimmer ? 'shimmering' : '']" />+</template>++<script>+export default {+ name: 'VBone',+ props: { shimmer: { type: Boolean, default: true } },+}+</script>++<style scoped>+@keyframes shimmer {+ 0% {+ background-position: -1000px 0;+ }+ 100% {+ background-position: 1000px 0;+ }+}++.shimmering {+ animation: shimmer 3s infinite linear;+ background: linear-gradient(+ to right,+ theme('colors.dark-charcoal-10') 4%,+ theme('colors.dark-charcoal-20') 25%,+ theme('colors.dark-charcoal-10') 36%+ );+ background-size: 1000px 100%;+}+</style>diff --git a/src/components/Skeleton/meta/GridSkeleton.stories.mdx b/src/components/Skeleton/meta/GridSkeleton.stories.mdxnew file mode 100644index 000000000..322968fdf--- /dev/null+++ b/src/components/Skeleton/meta/GridSkeleton.stories.mdx@@ -0,0 +1,47 @@+import {+ ArgsTable,+ Canvas,+ Description,+ Meta,+ Story,+} from '@storybook/addon-docs'++import GridSkeleton from '~/components/Skeleton/GridSkeleton.vue'++<Meta title="Components/Skeleton" component={GridSkeleton} />++export const Template = (args, { argTypes }) => ({+ template: `<GridSkeleton v-bind="$props" />`,+ components: { GridSkeleton },+ props: Object.keys(argTypes),+})++# Skeleton++<Description of={GridSkeleton} />++<ArgsTable of={GridSkeleton} />++## Grid skeleton for "All" tab++<Canvas>+ <Story name="All tab" args={{ isForTab: 'all' }}>+ {Template.bind({})}+ </Story>+</Canvas>++## Grid skeleton for "Image" tab++<Canvas>+ <Story name="Image tab" args={{ isForTab: 'image' }}>+ {Template.bind({})}+ </Story>+</Canvas>++## List skeleton for "Audio" tab++<Canvas>+ <Story name="Audio tab" args={{ isForTab: 'audio' }}>+ {Template.bind({})}+ </Story>+</Canvas>diff --git a/tailwind.config.js b/tailwind.config.jsindex 4dcfedfeb..a2b7d78a7 100644--- a/tailwind.config.js+++ b/tailwind.config.js@@ -59,6 +59,7 @@ module.exports = {0: '0',1: '0.25rem',2: '0.50rem',+ 3: '0.75rem',4: '1.00rem',5: '1.25rem',6: '1.50rem',