본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Empty

원문 보기 위키 갱신

Empty (빈 상태)

Empty 컴포넌트는 보여줄 콘텐츠가 없을 때 플레이스홀더 상태를 표시하는 컴포넌트예요. 데이터가 없을 때 안내 문구와 함께 사용자에게 다음 행동을 제안할 수 있어요.

출처: Nuxt UI

본문

사용법 (Usage)

Empty 컴포넌트를 사용해 보여줄 콘텐츠가 없을 때 플레이스홀더 상태를 표시하세요.

<template>
  <u-empty :actions="[
    {
      icon: 'i-lucide-plus',
      label: 'Create new'
    },
    {
      icon: 'i-lucide-refresh-cw',
      label: 'Refresh',
      color: 'neutral',
      variant: 'subtle'
    }
  ]" description="It looks like you haven't added any projects. Create one to get started." icon="i-lucide-file" title="No projects found" />
</template>

타이틀 (Title)

title prop으로 빈 상태의 제목을 설정할 수 있어요.

<template>
  <UEmpty title="No projects found" />
</template>

설명 (Description)

description prop으로 빈 상태의 설명을 설정할 수 있어요.

<template>
  <UEmpty title="No projects found" description="It looks like you haven't added any projects. Create one to get started." />
</template>

아이콘 (Icon)

icon prop으로 빈 상태의 아이콘을 설정할 수 있어요.

<template>
  <UEmpty icon="i-lucide-file" title="No projects found" description="It looks like you haven't added any projects. Create one to get started." />
</template>

아바타 (Avatar)

avatar prop으로 빈 상태의 아바타를 설정할 수 있어요.

<template>
  <UEmpty :avatar="{
  src: 'https://github.com/nuxt.png'
}" title="No projects found" description="It looks like you haven't added any projects. Create one to get started." />
</template>

로딩 (Loading) 4.10+

loading prop으로 아이콘 대신 로딩 아이콘을 표시할 수 있어요. 레이아웃은 동일하게 유지되므로 레이아웃 이동 없이 로딩 상태와 빈 상태를 전환할 수 있어요.

<template>
  <UEmpty icon="i-lucide-file" loading title="Loading projects" description="Please wait while we fetch your projects." />
</template>

로딩 아이콘 (Loading Icon) 4.10+

loading-icon prop으로 로딩 아이콘을 커스터마이즈할 수 있어요. 기본값은 i-lucide-loader-circle이에요.

<template>
  <UEmpty icon="i-lucide-file" loading loading-icon="i-lucide-loader" title="Loading projects" description="Please wait while we fetch your projects." />
</template>

Nuxt:

[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme

이 아이콘은 app.config.ts의 ui.icons.loading 키에서 전역으로 커스터마이즈할 수 있어요.

Vue:

[!TIP] See: /docs/getting-started/integrations/icons/vue#theme

이 아이콘은 vite.config.ts의 ui.icons.loading 키에서 전역으로 커스터마이즈할 수 있어요.

액션 (Actions)

actions prop으로 빈 상태에 Button 액션을 추가할 수 있어요.

<template>
  <UEmpty icon="i-lucide-file" title="No projects found" description="It looks like you haven't added any projects. Create one to get started." :actions="[
  {
    icon: 'i-lucide-plus',
    label: 'Create new'
  },
  {
    icon: 'i-lucide-refresh-cw',
    label: 'Refresh',
    color: 'neutral',
    variant: 'subtle'
  }
]" />
</template>

변형 (Variant)

variant prop으로 빈 상태의 변형을 변경할 수 있어요.

<template>
  <UEmpty variant="naked" icon="i-lucide-bell" title="No notifications" description="You're all caught up. New notifications will appear here." :actions="[
  {
    icon: 'i-lucide-refresh-cw',
    label: 'Refresh',
    color: 'neutral',
    variant: 'subtle'
  }
]" />
</template>

크기 (Size)

size prop으로 빈 상태의 크기를 변경할 수 있어요.

<template>
  <UEmpty size="xl" icon="i-lucide-bell" title="No notifications" description="You're all caught up. New notifications will appear here." :actions="[
  {
    icon: 'i-lucide-refresh-cw',
    label: 'Refresh',
    color: 'neutral',
    variant: 'subtle'
  }
]" />
</template>

예제 (Examples)

슬롯 사용 (With slots)

사용 가능한 슬롯을 사용해 더 복잡한 빈 상태를 만들 수 있어요.

<script setup lang="ts">
import type { UserProps } from '@nuxt/ui'

const members: UserProps[] = [
  {
    name: 'Daniel Roe',
    description: 'danielroe',
    to: 'https://github.com/danielroe',
    target: '_blank',
    avatar: {
      src: 'https://github.com/danielroe.png',
      alt: 'danielroe',
      loading: 'lazy' as const
    }
  },
  {
    name: 'Pooya Parsa',
    description: 'pi0',
    to: 'https://github.com/pi0',
    target: '_blank',
    avatar: {
      src: 'https://github.com/pi0.png',
      alt: 'pi0',
      loading: 'lazy' as const
    }
  },
  {
    name: 'Sébastien Chopin',
    description: 'atinux',
    to: 'https://github.com/atinux',
    target: '_blank',
    avatar: {
      src: 'https://github.com/atinux.png',
      alt: 'atinux',
      loading: 'lazy' as const
    }
  },
  {
    name: 'Benjamin Canac',
    description: 'benjamincanac',
    to: 'https://github.com/benjamincanac',
    target: '_blank',
    avatar: {
      src: 'https://github.com/benjamincanac.png',
      alt: 'benjamincanac',
      loading: 'lazy' as const
    }
  }
]
</script>

<template>
  <UEmpty
    title="No team members"
    description="Invite your team to collaborate on this project."
    variant="naked"
    :actions="[{
      label: 'Invite members',
      icon: 'i-lucide-user-plus',
      color: 'neutral'
    }]"
  >
    <template #leading>
      <UAvatarGroup size="xl">
        <UAvatar src="https://github.com/nuxt.png" alt="Nuxt" loading="lazy" />
        <UAvatar src="https://github.com/unjs.png" alt="Unjs" loading="lazy" />
      </UAvatarGroup>
    </template>

    <template #footer>
      <USeparator class="my-4" />

      <div class="grid grid-cols-2 gap-4">
        <UPageCard
          v-for="(member, index) in members"
          :key="index"
          :to="member.to"
          :ui="{ container: 'sm:p-4' }"
        >
          <UUser
            :avatar="member.avatar"
            :name="member.name"
            :description="member.description"
            :ui="{ name: 'truncate' }"
          />
        </UPageCard>
      </div>
    </template>
  </UEmpty>
</template>

API

Props (속성)

/**
 * Props for the Empty component
 */
interface EmptyProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * The icon displayed above the title.
   */
  icon?: any;
  avatar?: AvatarProps | undefined;
  /**
   * When `true`, the loading icon will be displayed.
   */
  loading?: boolean | undefined;
  /**
   * The icon when the `loading` prop is `true`.
   * @default appConfig.ui.icons.loading
   */
  loadingIcon?: any;
  title?: string | undefined;
  description?: string | undefined;
  /**
   * Display a list of Button in the body.
   */
  actions?: ButtonProps[] | undefined;
  /**
   * @default 'outline'
   */
  variant?: "outline" | "solid" | "soft" | "subtle" | "naked" | undefined;
  /**
   * @default 'md'
   */
  size?: "md" | "xs" | "sm" | "lg" | "xl" | undefined;
  ui?: { root?: SlotClass; header?: SlotClass; avatar?: SlotClass; title?: SlotClass; description?: SlotClass; body?: SlotClass; actions?: SlotClass; footer?: SlotClass; } | undefined;
}

Slots (슬롯)

/**
 * Slots for the Empty component
 */
interface EmptySlots {
  header(): any;
  leading(): any;
  title(): any;
  description(): any;
  body(): any;
  actions(): any;
  footer(): any;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    empty: {
      slots: {
        root: 'relative flex flex-col items-center justify-center gap-4 rounded-lg p-4 sm:p-6 lg:p-8 min-w-0',
        header: 'flex flex-col items-center gap-2 max-w-sm text-center',
        avatar: 'shrink-0 mb-2',
        title: 'text-highlighted text-pretty font-medium',
        description: 'text-balance text-center',
        body: 'flex flex-col items-center gap-4 max-w-sm',
        actions: 'flex flex-wrap justify-center gap-2 shrink-0',
        footer: 'flex flex-col items-center gap-2 max-w-sm'
      },
      variants: {
        size: {
          xs: {
            avatar: 'size-8 text-base',
            title: 'text-sm',
            description: 'text-xs'
          },
          sm: {
            avatar: 'size-9 text-lg',
            title: 'text-sm',
            description: 'text-xs'
          },
          md: {
            avatar: 'size-10 text-xl',
            title: 'text-base',
            description: 'text-sm'
          },
          lg: {
            avatar: 'size-11 text-[22px]',
            title: 'text-base',
            description: 'text-sm'
          },
          xl: {
            avatar: 'size-12 text-2xl',
            title: 'text-lg',
            description: 'text-base'
          }
        },
        variant: {
          solid: {
            root: 'bg-inverted',
            title: 'text-inverted',
            description: 'text-dimmed'
          },
          outline: {
            root: 'bg-default ring ring-default',
            description: 'text-muted'
          },
          soft: {
            root: 'bg-elevated/50',
            description: 'text-toned'
          },
          subtle: {
            root: 'bg-elevated/50 ring ring-default',
            description: 'text-toned'
          },
          naked: {
            description: 'text-muted'
          }
        },
        loading: {
          true: {
            avatar: '[&>[data-slot=icon]]:animate-spin'
          }
        }
      },
      defaultVariants: {
        variant: 'outline',
        size: 'md'
      }
    }
  }
})

변경 이력 (Changelog)

컴포넌트와 테마의 커밋 기록을 확인하세요.

더 알아보기 (Learn more)