Examples
Basic
Preview
Code
<template>
<div class="w-250px flex flex-col space-y-3">
<NSkeleton
class="h-125px"
/>
<div class="space-y-2">
<NSkeleton class="h-4" />
<NSkeleton class="h-4 w-80%" />
</div>
</div>
</template>
Shape
Prop | Default | Type | Description |
---|---|---|---|
rounded | none | string | Change the shape of the skeleton. |
Preview
Code
<template>
<div class="space-y-4">
<!-- News feed skeleton item -->
<template v-for="i in 3" :key="i">
<div class="flex items-start space-x-4">
<NSkeleton
rounded="full"
class="h-10 w-10"
/>
<div class="flex-1 space-y-2">
<NSkeleton class="h-4 w-3/4" />
<NSkeleton class="h-4 w-1/2" />
</div>
</div>
</template>
</div>
</template>
Color
Prop | Default | Type | Description |
---|---|---|---|
skeleton | gray | string | Change the color of the skeleton. |
Preview
Code
<template>
<div class="w-250px">
<div class="flex items-end space-x-2">
<NSkeleton
rounded="b-full"
class="h-15 w-15"
/>
<div class="space-y-2">
<NSkeleton
skeleton="primary"
rounded="t-full"
class="h-15 w-15"
/>
<NSkeleton
rounded="l-full"
class="h-15 w-15"
/>
</div>
</div>
</div>
</template>
Slots
Name | Props | Description |
---|---|---|
default | - | The default slot. |
Presets
shortcuts/skeleton.ts
import type { RuleContext } from '@unocss/core'
import type { Theme } from '@unocss/preset-uno'
import { parseColor } from '@unocss/preset-mini/utils'
type SkeletonPrefix = 'skeleton'
export const staticSkeleton: Record<`${SkeletonPrefix}-${string}` | SkeletonPrefix, string> = {
// base
skeleton: 'skeleton-gray text-md animate-pulse rounded-md w-full h-0.5em bg-brand',
}
export const dynamicSkeleton = [
[/^skeleton-(.*)$/, ([, body]: string[], { theme }: RuleContext<Theme>) => {
const color = parseColor(body, theme)
if ((color?.cssColor?.type === 'rgb' || color?.cssColor?.type === 'rgba') && color.cssColor.components)
return `n-${body}-100 dark:n-${body}-800`
}],
]
export const skeleton = [
...dynamicSkeleton,
staticSkeleton,
]
Props
types/skeleton.ts
import type { HTMLAttributes } from 'vue'
interface Extensions { class?: HTMLAttributes['class'] }
export interface NSkeletonProps extends Extensions {
/**
* Allows you to add `UnaUI` skeleton preset properties,
* Think of it as a shortcut for adding options or variants to the preset if available.
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/skeleton.ts
* @example
* skeleton="green""
*/
skeleton?: HTMLAttributes['class']
/**
* Allows you to change the size of the skeleton.
*
* @default base|md
*
* @example
* size="sm" | size="2cm" | size="2rem" | size="2px"
*/
size?: HTMLAttributes['class']
/**
* Allows you to change the shape of the skeleton.
* @default rounded
*
* @example
* rounded="none" | rounded="sm" | rounded="md" | rounded="lg" | rounded="full"
*/
rounded?: HTMLAttributes['class']
/**
* `UnaUI` preset configuration
*
* @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/skeleton.ts
*/
una?: {
skeleton?: HTMLAttributes['class']
}
}
Components
Skeleton.vue
<script setup lang="ts">
import type { NSkeletonProps } from '../../types'
import { cn } from '../../utils'
const props = defineProps<NSkeletonProps>()
</script>
<template>
<div
:class="
cn(
'skeleton',
props.class,
props.una?.skeleton,
)
"
:skeleton
:size
:rounded
>
<slot />
</div>
</template>