Skip to content

Instantly share code, notes, and snippets.

@dietergoetelen
Created August 13, 2021 11:53
Show Gist options
  • Save dietergoetelen/9c16d7b5cdba73beaf2d6b9c983d5ccf to your computer and use it in GitHub Desktop.
Save dietergoetelen/9c16d7b5cdba73beaf2d6b9c983d5ccf to your computer and use it in GitHub Desktop.
Content placeholder component in #vue3
<template>
<div class="content-placeholder gap-1 animate-pulse">
<div v-for="template of templates" :key="template" class="bg-gray-300" :style="{gridArea: template}" />
</div>
</template>
<script lang="ts" setup>
const props = defineProps<{
template: Array<Array<string>>
rows: string
columns: string
}>()
const cssGridTemplate = computed(() => props.template.map(template => `"${template.join(' ')}"`).join('\n'))
const templates = computed(() => Array.from(new Set(props.template.flat())))
const rows = computed(() => props.rows)
const columns = computed(() => props.columns)
</script>
<style scoped>
.content-placeholder {
display: grid;
grid-template-areas: v-bind(cssGridTemplate);
grid-template-columns: v-bind(columns);
grid-template-rows: v-bind(rows);
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment