Skip to content

Commit

Permalink
Add skeleton component
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed May 8, 2023
1 parent 8acbaf0 commit 5776248
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 24 deletions.
49 changes: 49 additions & 0 deletions src/components/VSkeleton.global.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<slot />
<span
v-if="isEmpty"
:class="class"
>
<span
v-for="line in lines"
:key="line"
class="inline-block w-full rounded-sm bg-gray-100 leading-5"
>
&zwnj;
</span>
</span>
</template>

<script setup>
import { useAttrs, useSlots, computed } from 'vue'
const props = defineProps({
class: {
type: String,
default: 'w-full'
},
lines: {
type: Number,
default: 1
}
})
const slots = useSlots()
const attrs = useAttrs()
const isEmpty = computed(() => {
const children = slots.default?.()
return isEmptyVNode(children)
})
function isEmptyVNode(children) {
if (!children) return true
const [firstNode] = children
let str = firstNode.children
return firstNode.el || str
}
</script>
19 changes: 6 additions & 13 deletions src/modules/otus/components/TaxaInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</h2>
<h1 class="text-xl dark:text-gray-100">
<span>
<span
<span
:title="taxon.short_status"
v-html="taxon.full_name_tag"
v-html="taxon.full_name_tag"
/>
<span
<span
v-if="!taxon.is_valid"
class="ml-1"
:class="statusStyle"
Expand Down Expand Up @@ -40,15 +40,8 @@ const props = defineProps({
}
})
const status = computed(() =>
props.taxon.cached_is_valid
? ''
: '&#10005;'
const status = computed(() => (props.taxon.cached_is_valid ? '' : '&#10005;'))
const statusStyle = computed(() =>
props.taxon.cached_is_valid ? '' : 'text-red-600'
)
const statusStyle = computed(() =>
props.taxon.cached_is_valid
? ''
: 'text-red-600'
)
</script>
30 changes: 19 additions & 11 deletions src/modules/otus/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
<div
class="flex flex-col-reverse md:flex-row justify-between items-start"
>
<Breadcrumb
v-if="isReady"
class="w-4/4 md:w-3/4"
:list="otu?.parents || {}"
:current="taxon"
/>
<VSkeleton class="w-4/4 md:w-3/4">
<Breadcrumb
v-if="isReady"
class="w-4/4 md:w-3/4"
:list="otu?.parents || {}"
:current="taxon"
/>
</VSkeleton>
<Autocomplete
class="print:hidden min-w-full mb-2 md:min-w-fit md:ml-2 md:mb-0 md:w-96"
url="/otus/autocomplete"
Expand All @@ -23,11 +25,16 @@
</div>

<div class="mt-8 flex justify-between middle">
<TaxaInfo
v-if="isReady"
:taxon="taxon"
:otu-id="otu.id"
/>
<VSkeleton
:lines="2"
class="w-96"
>
<TaxaInfo
v-if="isReady"
:taxon="taxon"
:otu-id="otu.id"
/>
</VSkeleton>
</div>

<TabMenu
Expand Down Expand Up @@ -67,6 +74,7 @@ import { useOtuStore } from '../store/store'
import Breadcrumb from '../components/Breadcrumb/Breadcrumb.vue'
import TaxaInfo from '../components/TaxaInfo.vue'
import { useHead, createHead } from 'unhead'
import VSkeletonGlobal from '@/components/VSkeleton.global.vue'
//import useChildrenRoutes from '../composables/useChildrenRoutes'
Expand Down

0 comments on commit 5776248

Please sign in to comment.