feat(Skeleton): new component

This commit is contained in:
Benjamin Canac
2024-03-12 18:22:55 +01:00
parent 4b3a9855ac
commit e2fb25309f
7 changed files with 58 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ useHead({
}
})
const components = ['avatar', 'badge', 'button', 'collapsible', 'kbd', 'popover', 'tooltip']
const components = ['avatar', 'badge', 'button', 'collapsible', 'kbd', 'popover', 'skeleton', 'tooltip']
</script>
<template>

View File

@@ -0,0 +1,10 @@
<template>
<div class="flex items-center gap-4">
<USkeleton class="h-12 w-12 rounded-full" />
<div class="space-y-2">
<USkeleton class="h-4 w-[250px]" />
<USkeleton class="h-4 w-[200px]" />
</div>
</div>
</template>

View File

@@ -0,0 +1,25 @@
<script lang="ts">
import { tv } from 'tailwind-variants'
import type { AppConfig } from '@nuxt/schema'
import _appConfig from '#build/app.config'
import theme from '#build/ui/skeleton'
const appConfig = _appConfig as AppConfig & { ui: { skeleton: Partial<typeof theme> } }
const skeleton = tv({ extend: tv(theme), ...(appConfig.ui?.skeleton || {}) })
export interface SkeletonProps {
as?: string
class?: any
}
</script>
<script setup lang="ts">
const props = withDefaults(defineProps<SkeletonProps>(), { as: 'div' })
</script>
<template>
<component :is="as" :class="skeleton({ class: props.class })">
<slot />
</component>
</template>

View File

@@ -7,4 +7,5 @@ export { default as container } from './container'
export { default as icons } from './icons'
export { default as kbd } from './kbd'
export { default as popover } from './popover'
export { default as skeleton } from './skeleton'
export { default as tooltip } from './tooltip'

3
src/theme/skeleton.ts Normal file
View File

@@ -0,0 +1,3 @@
export default {
base: 'animate-pulse rounded-md bg-gray-50 dark:bg-gray-800'
}

View File

@@ -0,0 +1,13 @@
import { describe, it, expect } from 'vitest'
import Skeleton, { type SkeletonProps } from '../../src/runtime/components/Skeleton.vue'
import ComponentRender from '../component-render'
describe('Skeleton', () => {
it.each([
['basic case', {}],
['with class', { props: { class: 'rounded-full size-12' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: SkeletonProps, slots?: any }) => {
const html = await ComponentRender(nameOrHtml, options, Skeleton)
expect(html).toMatchSnapshot()
})
})

View File

@@ -0,0 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Skeleton > renders basic case correctly 1`] = `"<div class="animate-pulse rounded-md bg-gray-50 dark:bg-gray-800"></div>"`;
exports[`Skeleton > renders with class correctly 1`] = `"<div class="animate-pulse bg-gray-50 dark:bg-gray-800 rounded-full size-12"></div>"`;