사용자
사용자 (User)
사용자(User)는 이름·설명·아바타를 함께 표시해주는 컴포넌트예요. 프로필 정보를 한눈에 보여줄 때 유용하며, 링크 속성을 함께 전달하면 클릭 가능한 사용자 카드로도 만들 수 있어요.
출처: Nuxt UI
본문
이름, 설명, 아바타로 사용자 정보를 표시하는 컴포넌트예요.
사용법 (Usage)
Name (이름)
name prop으로 사용자의 이름을 표시할 수 있어요.
<template>
<UUser name="John Doe" />
</template>
Description (설명)
description prop으로 사용자에 대한 설명을 표시할 수 있어요.
<template>
<UUser name="John Doe" description="Software Engineer" />
</template>
Avatar (아바타)
avatar prop으로 Avatar 컴포넌트를 표시할 수 있어요.
<template>
<UUser name="John Doe" description="Software Engineer" :avatar="{
src: 'https://i.pravatar.cc/150?u=john-doe',
loading: 'lazy',
icon: 'i-lucide-image'
}" />
</template>
/**
* Props for the Avatar component
*/
interface AvatarProps {
/**
* The element or component this component should render as.
* @default 'span'
*/
as?: any;
src?: string | undefined;
alt?: string | undefined;
icon?: any;
text?: string | undefined;
/**
* @default 'md'
*/
size?: "md" | "xs" | "sm" | "lg" | "xl" | "3xs" | "2xs" | "2xl" | "3xl" | undefined;
/**
* @default 'neutral'
*/
color?: "error" | "primary" | "secondary" | "success" | "info" | "warning" | "neutral" | undefined;
chip?: boolean | ChipProps | undefined;
ui?: { root?: SlotClass; image?: SlotClass; fallback?: SlotClass; icon?: SlotClass; } | undefined;
loading?: "lazy" | "eager" | undefined;
referrerpolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | undefined;
decoding?: "async" | "auto" | "sync" | undefined;
height?: string | number | undefined;
sizes?: string | undefined;
srcset?: string | undefined;
usemap?: string | undefined;
width?: string | number | undefined;
crossorigin?: "anonymous" | "use-credentials" | undefined;
}
Chip (뱃지)
chip prop으로 Chip 컴포넌트를 표시할 수 있어요.
<template>
<UUser name="John Doe" description="Software Engineer" :avatar="{
src: 'https://i.pravatar.cc/150?u=john-doe'
}" :chip="{
color: 'primary',
position: 'top-right'
}" />
</template>
/**
* Props for the Chip component
*/
interface ChipProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
/**
* Display some text inside the chip.
*/
text?: string | number | undefined;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'md'
*/
size?: "xs" | "sm" | "md" | "lg" | "xl" | "3xs" | "2xs" | "2xl" | "3xl" | undefined;
/**
* The position of the chip.
* @default 'top-right'
*/
position?: "top-right" | "bottom-right" | "top-left" | "bottom-left" | undefined;
/**
* When `true`, keep the chip inside the component for rounded elements.
* @default false
*/
inset?: boolean | undefined;
/**
* When `true`, render the chip relatively to the parent.
* @default false
*/
standalone?: boolean | undefined;
ui?: { root?: SlotClass; base?: SlotClass; } | undefined;
/**
* @default true
*/
show?: boolean | undefined;
}
Size (크기)
size prop으로 사용자 아바타와 텍스트의 크기를 바꿀 수 있어요.
<template>
<UUser name="John Doe" description="Software Engineer" :avatar="{
src: 'https://i.pravatar.cc/150?u=john-doe'
}" chip size="xl" />
</template>
Orientation (배치 방향)
orientation prop으로 배치 방향을 바꿀 수 있어요. 기본값은 horizontal이에요.
<template>
<UUser orientation="vertical" name="John Doe" description="Software Engineer" :avatar="{
src: 'https://i.pravatar.cc/150?u=john-doe'
}" />
</template>
Link (링크)
<NuxtLink> 컴포넌트의 속성(to, target, rel 등)을 전달할 수 있어요.
<template>
<UUser to="https://github.com/benjamincanac" target="_blank" name="Benjamin Canac" description="Software Engineer" :avatar="{
src: 'https://github.com/benjamincanac.png'
}" />
</template>
[!NOTE]
NuxtLink컴포넌트는User컴포넌트에 전달한 다른 모든 속성을 그대로 이어받아요.
API
Props
/**
* Props for the User component
*/
interface UserProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
name?: string | undefined;
description?: string | undefined;
avatar?: Omit<AvatarProps, "size"> & { [key: string]: any; } | undefined;
chip?: boolean | Omit<ChipProps, "size" | "inset"> | undefined;
/**
* @default 'md'
*/
size?: "md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | undefined;
/**
* The orientation of the user.
* @default 'horizontal'
*/
orientation?: "horizontal" | "vertical" | undefined;
to?: string | it | et | undefined;
target?: null | "_blank" | "_parent" | "_self" | "_top" | string & {} | undefined;
onClick?: (event: MouseEvent): void | undefined;
ui?: { root?: SlotClass; wrapper?: SlotClass; name?: SlotClass; description?: SlotClass; avatar?: SlotClass; } | undefined;
}
Slots
/**
* Slots for the User component
*/
interface UserSlots {
avatar(): any;
name(): any;
description(): any;
default(): any;
}
테마 (Theme)
export default defineAppConfig({
ui: {
user: {
slots: {
root: 'relative group/user',
wrapper: '',
name: 'font-medium',
description: 'text-muted',
avatar: 'shrink-0'
},
variants: {
orientation: {
horizontal: {
root: 'flex items-center'
},
vertical: {
root: 'flex flex-col'
}
},
to: {
true: {
root: [
'rounded-md outline-primary/25 has-focus-visible:outline-3',
'transition'
],
name: [
'text-default peer-hover:text-highlighted peer-focus-visible:text-highlighted',
'transition-colors'
],
description: [
'peer-hover:text-toned peer-focus-visible:text-toned',
'transition-colors'
],
avatar: 'transform transition-transform ease-out motion-reduce:transition-none group-hover/user:scale-115 group-has-focus-visible/user:scale-115'
},
false: {
name: 'text-highlighted',
description: ''
}
},
size: {
'3xs': {
root: 'gap-1',
wrapper: 'flex items-center gap-1',
name: 'text-xs',
description: 'text-xs'
},
'2xs': {
root: 'gap-1.5',
wrapper: 'flex items-center gap-1.5',
name: 'text-xs',
description: 'text-xs'
},
xs: {
root: 'gap-1.5',
wrapper: 'flex items-center gap-1.5',
name: 'text-xs',
description: 'text-xs'
},
sm: {
root: 'gap-2',
name: 'text-xs',
description: 'text-xs'
},
md: {
root: 'gap-2',
name: 'text-sm',
description: 'text-xs'
},
lg: {
root: 'gap-2.5',
name: 'text-sm',
description: 'text-sm'
},
xl: {
root: 'gap-2.5',
name: 'text-base',
description: 'text-sm'
},
'2xl': {
root: 'gap-3',
name: 'text-base',
description: 'text-base'
},
'3xl': {
root: 'gap-3',
name: 'text-lg',
description: 'text-base'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})