시간 입력
시간 입력 (InputTime)
시간을 선택하기 위한 입력 컴포넌트예요. v-model로 선택된 시간을 제어할 수 있고, 시간 범위 선택, 시간 주기(12/24시간) 설정 등을 지원합니다.
출처: Nuxt UI
본문
v-model 디렉티브를 사용해 선택된 시간을 제어해요.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const value = shallowRef(new Time(12, 30, 0))
</script>
<template>
<UInputTime v-model="value" />
</template>
상태를 제어할 필요가 없을 때는 default-value prop으로 초기 값을 설정해 주세요.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(9, 45, 0))
</script>
<template>
<UInputTime :default-value="defaultValue" />
</template>
Nuxt:
[!NOTE] See: /docs/getting-started/integrations/i18n/nuxt#locale
이 컴포넌트는 로케일 인식 포매팅을 위해
@internationalized/date패키지를 사용해요. 시간 형식은 App 컴포넌트의localeprop에 의해 결정됩니다.
Vue:
[!NOTE] See: /docs/getting-started/integrations/i18n/vue#locale
이 컴포넌트는 로케일 인식 포매팅을 위해
@internationalized/date패키지를 사용해요. 시간 형식은 App 컴포넌트의localeprop에 의해 결정됩니다.
범위 (Range)
range prop을 사용하면 시작과 종료 시간으로 시간 범위 선택을 활성화할 수 있어요.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const value = shallowRef({ start: new Time(9, 0, 0), end: new Time(17, 30, 0) })
</script>
<template>
<UInputTime range v-model="value" />
</template>
시간 주기 (Hour Cycle)
hour-cycle prop을 사용해 InputTime의 시간 주기를 바꿔요. 기본값은 12입니다.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const defaultValue = shallowRef(new Time(16, 30, 0))
</script>
<template>
<UInputTime :hour-cycle="24" :default-value="defaultValue" />
</template>
색상 (Color)
color prop을 사용해 InputTime의 색상을 바꿔요.
<template>
<UInputTime color="neutral" highlight />
</template>
[!NOTE]
여기서
highlightprop은 포커스 상태를 보여주기 위해 사용됐어요. 유효성 검사 오류가 발생했을 때 내부적으로 사용됩니다.
변형 (Variant)
variant prop을 사용해 InputTime의 변형을 바꿔요.
<template>
<UInputTime variant="subtle" />
</template>
크기 (Size)
size prop을 사용해 InputTime의 크기를 바꿔요.
<template>
<UInputTime size="xl" />
</template>
아이콘 (Icon)
icon prop을 사용해 InputTime 안에 Icon을 표시할 수 있어요.
<template>
<UInputTime icon="i-lucide-clock" />
</template>
[!NOTE]
leading과trailingprop으로 아이콘 위치를 정하거나,leading-icon과trailing-iconprop으로 각 위치에 다른 아이콘을 지정할 수 있어요.
구분 아이콘 (Separator Icon)
separator-icon prop으로 범위 구분선의 Icon을 바꿔요. 기본값은 i-lucide-minus입니다.
<template>
<UInputTime range separator-icon="i-lucide-arrow-right" />
</template>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
이 아이콘은
app.config.ts의ui.icons.minus키 아래에서 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
이 아이콘은
vite.config.ts의ui.icons.minus키 아래에서 전역으로 커스터마이즈할 수 있어요.
아바타 (Avatar)
avatar prop을 사용해 InputTime 안에 Avatar를 표시할 수 있어요.
<template>
<UInputTime :avatar="{
src: 'https://github.com/vuejs.png',
loading: 'lazy'
}" size="md" variant="outline" />
</template>
비활성화 (Disabled)
disabled prop을 사용해 InputTime을 비활성화해요.
<template>
<UInputTime disabled />
</template>
예시 (Examples)
FormField 안에서 사용 (Within a FormField)
InputTime을 FormField 컴포넌트 안에서 사용해 라벨, 도움말 텍스트, 필수 표시 등을 보여줄 수 있어요.
<script setup lang="ts">
import { Time } from '@internationalized/date'
const time = shallowRef(new Time(12, 30, 0))
</script>
<template>
<UFormField label="Time" help="Specify the time" required>
<UInputTime v-model="time" />
</UFormField>
</template>
API
Props
/**
* Props for the InputTime component
*/
interface InputTimeProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'outline'
*/
variant?: "outline" | "soft" | "subtle" | "ghost" | "none" | undefined;
/**
* @default 'md'
*/
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
/**
* Highlight the ring color like a focus state.
*/
highlight?: boolean | undefined;
/**
* Keep the mobile text size on all breakpoints.
*/
fixed?: boolean | undefined;
autofocus?: boolean | undefined;
/**
* @default 0
*/
autofocusDelay?: number | undefined;
/**
* The icon to use as a range separator.
* @default appConfig.ui.icons.minus
*/
separatorIcon?: any;
/**
* Enable time range selection.
* @default false
*/
range?: R | undefined;
defaultValue?: Time | CalendarDateTime | ZonedDateTime;
modelValue?: null | Time | CalendarDateTime | ZonedDateTime;
ui?: { base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; segment?: SlotClass; separatorIcon?: SlotClass; } | undefined;
/**
* Display an icon based on the `leading` and `trailing` props.
*/
icon?: any;
/**
* Display an avatar on the left side.
*/
avatar?: AvatarProps | undefined;
/**
* When `true`, the icon will be displayed on the left side.
*/
leading?: boolean | undefined;
/**
* Display an icon on the left side.
*/
leadingIcon?: any;
/**
* When `true`, the icon will be displayed on the right side.
*/
trailing?: boolean | undefined;
/**
* Display an icon on the right side.
*/
trailingIcon?: any;
/**
* 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;
defaultPlaceholder?: Time | CalendarDateTime | ZonedDateTime;
placeholder?: Time | CalendarDateTime | ZonedDateTime;
/**
* The hour cycle used for formatting times. Defaults to the local preference
*/
hourCycle?: 12 | 24 | undefined;
/**
* The stepping interval for the time fields. Defaults to `1`.
*/
step?: DateStep | undefined;
/**
* Whether to enforce snapping the value to the nearest step increment after input. Defaults to `false`.
*/
stepSnapping?: boolean | undefined;
/**
* The granularity to use for formatting times. Defaults to minute if a Time is provided, otherwise defaults to minute. The field will render segments for each part of the date up to and including the specified granularity
*/
granularity?: "hour" | "minute" | "second" | undefined;
/**
* Whether or not to hide the time zone segment of the field
*/
hideTimeZone?: boolean | undefined;
maxValue?: Time | CalendarDateTime | ZonedDateTime;
minValue?: Time | CalendarDateTime | ZonedDateTime;
/**
* The locale to use for formatting dates
*/
locale?: string | undefined;
/**
* Whether or not the time field is disabled
*/
disabled?: boolean | undefined;
/**
* Whether or not the time field is readonly
*/
readonly?: boolean | undefined;
/**
* Id of the element
*/
id?: string | undefined;
/**
* The name of the field. Submitted with its owning form as part of a name/value pair.
*/
name?: string | undefined;
/**
* When `true`, indicates that the user must set the value before the owning form can be submitted.
*/
required?: boolean | undefined;
/**
* A function that returns whether or not a time is unavailable
*/
isTimeUnavailable?: (date: DateValue): boolean | undefined;
}
Slots
/**
* Slots for the InputTime component
*/
interface InputTimeSlots {
leading(): any;
default(): any;
trailing(): any;
separator(): any;
}
Emits
/**
* Emitted events for the InputTime component
*/
interface InputTimeEmits {
update:modelValue: (payload: [value: InputTimeModelValue<R>]) => void;
update:placeholder: (payload: [date: TimeValue] & [date: TimeValue]) => void;
change: (payload: [event: Event]) => void;
blur: (payload: [event: FocusEvent]) => void;
focus: (payload: [event: FocusEvent]) => void;
}
테마 (Theme)
export default defineAppConfig({
ui: {
inputTime: {
slots: {
base: [
'group relative inline-flex items-center rounded-md select-none',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 text-dimmed',
segment: [
'rounded-sm text-center outline-hidden data-placeholder:text-dimmed data-[segment=literal]:text-muted data-invalid:text-error data-disabled:cursor-not-allowed data-disabled:opacity-75',
'transition-colors'
],
separatorIcon: 'shrink-0 size-4 text-muted'
},
variants: {
fieldGroup: {
horizontal: 'not-only:first:rounded-e-none not-only:last:rounded-s-none not-last:not-first:rounded-none focus-visible:z-[1]',
vertical: 'not-only:first:rounded-b-none not-only:last:rounded-t-none not-last:not-first:rounded-none focus-visible:z-[1]'
},
size: {
xs: {
base: [
'px-2 py-1 text-sm/4 gap-1',
'gap-0.25'
],
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
sm: {
base: [
'px-2.5 py-1.5 text-sm/4 gap-1.5',
'gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
segment: 'not-data-[segment=literal]:w-8'
},
md: {
base: [
'px-2.5 py-1.5 text-base/5 gap-1.5',
'gap-0.5'
],
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
lg: {
base: [
'px-3 py-2 text-base/5 gap-2',
'gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
segment: 'not-data-[segment=literal]:w-9'
},
xl: {
base: [
'px-3 py-2 text-base gap-2',
'gap-0.75'
],
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
segment: 'not-data-[segment=literal]:w-10'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated has-focus:bg-elevated disabled:bg-elevated/50',
subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented',
ghost: 'text-highlighted bg-transparent hover:bg-elevated has-focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent has-focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none'
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 has-focus-visible:outline-3 has-focus-visible:ring-primary'
},
{
color: 'secondary',
variant: [
'outline',
'subtle'
],
class: 'outline-secondary/25 has-focus-visible:outline-3 has-focus-visible:ring-secondary'
},
{
color: 'success',
variant: [
'outline',
'subtle'
],
class: 'outline-success/25 has-focus-visible:outline-3 has-focus-visible:ring-success'
},
{
color: 'info',
variant: [
'outline',
'subtle'
],
class: 'outline-info/25 has-focus-visible:outline-3 has-focus-visible:ring-info'
},
{
color: 'warning',
variant: [
'outline',
'subtle'
],
class: 'outline-warning/25 has-focus-visible:outline-3 has-focus-visible:ring-warning'
},
{
color: 'error',
variant: [
'outline',
'subtle'
],
class: 'outline-error/25 has-focus-visible:outline-3 has-focus-visible:ring-error'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'secondary',
variant: [
'soft',
'ghost'
],
class: 'outline-secondary/25 has-focus-visible:outline-3'
},
{
color: 'success',
variant: [
'soft',
'ghost'
],
class: 'outline-success/25 has-focus-visible:outline-3'
},
{
color: 'info',
variant: [
'soft',
'ghost'
],
class: 'outline-info/25 has-focus-visible:outline-3'
},
{
color: 'warning',
variant: [
'soft',
'ghost'
],
class: 'outline-warning/25 has-focus-visible:outline-3'
},
{
color: 'error',
variant: [
'soft',
'ghost'
],
class: 'outline-error/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'secondary',
highlight: true,
class: 'ring ring-inset ring-secondary'
},
{
color: 'success',
highlight: true,
class: 'ring ring-inset ring-success'
},
{
color: 'info',
highlight: true,
class: 'ring ring-inset ring-info'
},
{
color: 'warning',
highlight: true,
class: 'ring ring-inset ring-warning'
},
{
color: 'error',
highlight: true,
class: 'ring ring-inset ring-error'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 has-focus-visible:outline-3 has-focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 has-focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
},
{
variant: 'outline',
class: {
segment: 'focus:bg-elevated'
}
},
{
variant: 'soft',
class: {
segment: 'focus:bg-accented/50 group-hover:focus:bg-accented'
}
},
{
variant: 'subtle',
class: {
segment: 'focus:bg-accented'
}
},
{
variant: 'ghost',
class: {
segment: 'focus:bg-elevated group-hover:focus:bg-accented'
}
},
{
variant: 'none',
class: {
segment: 'focus:bg-elevated'
}
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
})