Skeleton
A placeholder to show while content is loading.
Demo
Related Theme
This requires the following theme to be installed:
Component
vue
<script lang="ts">
import theme from '@/ui/theme/skeleton'
import { Primitive } from 'reka-ui'
import { tv } from 'tailwind-variants'
import { computed } from 'vue'
const skeleton = tv(theme)
export interface SkeletonProps {
as?: any
class?: any
}
</script>
<script setup lang="ts">
const props = defineProps<SkeletonProps>()
const ui = computed(() => skeleton({ class: props.class }))
</script>
<template>
<Primitive :as="as" :class="ui">
<slot />
</Primitive>
</template>vue
<script lang="ts">
import theme from '@/UI/Theme/skeleton'
import { Primitive } from 'reka-ui'
import { tv } from 'tailwind-variants'
import { computed } from 'vue'
const skeleton = tv(theme)
export interface SkeletonProps {
as?: any
class?: any
}
</script>
<script setup lang="ts">
const props = defineProps<SkeletonProps>()
const ui = computed(() => skeleton({ class: props.class }))
</script>
<template>
<Primitive :as="as" :class="ui">
<slot />
</Primitive>
</template>Theme
ts
export default {
base: '',
}View Nuxt UI theme
ts
export default {
base: 'animate-pulse rounded-md bg-elevated',
}Test
To test this component, you can use the following test file:
ts
import type { RenderOptions } from '@testing-library/vue'
import Skeleton from '@/ui/components/Skeleton.vue'
import { render, screen } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'
describe('skeleton', () => {
it.each<[string, RenderOptions<typeof Skeleton>]>([
// Props
['with as', { props: { as: 'span' } }],
['with class', { props: { class: 'rounded-full size-12' } }],
])('renders %s correctly', (name, options) => {
render(Skeleton, {
attrs: {
'data-testid': 'skeleton',
},
...options,
})
expect(screen.getByTestId('skeleton')).toMatchSnapshot()
})
})ts
import type { RenderOptions } from '@testing-library/vue'
import Skeleton from '@/UI/Components/Skeleton.vue'
import { render, screen } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'
describe('skeleton', () => {
it.each<[string, RenderOptions<typeof Skeleton>]>([
// Props
['with as', { props: { as: 'span' } }],
['with class', { props: { class: 'rounded-full size-12' } }],
])('renders %s correctly', (name, options) => {
render(Skeleton, {
attrs: {
'data-testid': 'skeleton',
},
...options,
})
expect(screen.getByTestId('skeleton')).toMatchSnapshot()
})
})