mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(Skeleton): new component
This commit is contained in:
@@ -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>
|
||||
|
||||
10
playground/pages/skeleton.vue
Normal file
10
playground/pages/skeleton.vue
Normal 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>
|
||||
25
src/runtime/components/Skeleton.vue
Normal file
25
src/runtime/components/Skeleton.vue
Normal 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>
|
||||
@@ -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
3
src/theme/skeleton.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
base: 'animate-pulse rounded-md bg-gray-50 dark:bg-gray-800'
|
||||
}
|
||||
13
test/components/Skeleton.spec.ts
Normal file
13
test/components/Skeleton.spec.ts
Normal 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()
|
||||
})
|
||||
})
|
||||
5
test/components/__snapshots__/Skeleton.spec.ts.snap
Normal file
5
test/components/__snapshots__/Skeleton.spec.ts.snap
Normal 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>"`;
|
||||
Reference in New Issue
Block a user