InputDate 입력
Usage
v-model 지시어를 사용하여 선택한 날짜를 제어합니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const value = shallowRef(new CalendarDate(2022, 2, 3))
</script>
<template>
<UInputDate v-model="value" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const value = shallowRef(new CalendarDate(2022, 2, 3))
</script>
<template>
<UInputDate v-model="value" />
</template>상태를 제어할 필요가 없을 때 default-value Prop을 사용하여 초기 값을 설정합니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const defaultValue = shallowRef(new CalendarDate(2022, 2, 6))
</script>
<template>
<UInputDate :default-value="defaultValue" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const defaultValue = shallowRef(new CalendarDate(2022, 2, 6))
</script>
<template>
<UInputDate :default-value="defaultValue" />
</template>범위
range prop을 사용하여 날짜 범위를 선택합니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const value = shallowRef({
start: new CalendarDate(2022, 2, 3),
end: new CalendarDate(2022, 2, 20)
})
</script>
<template>
<UInputDate range v-model="value" />
</template><script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const value = shallowRef({
start: new CalendarDate(2022, 2, 3),
end: new CalendarDate(2022, 2, 20)
})
</script>
<template>
<UInputDate range v-model="value" />
</template>Color 색상
color prop 을 사용하여 InputDate 의 색상을 변경합니다.
<template>
<UInputDate color="neutral" highlight />
</template>Variant (### Variant)
variant prop 를 사용하여 InputDate 의 변형을 변경합니다.
<template>
<UInputDate variant="subtle" />
</template>Size
size prop 를 사용하여 InputDate 의 크기를 변경합니다.
<template>
<UInputDate size="xl" />
</template>Icon 이미지
icon prop을 사용하여 InputDate 내부에 Icon를 표시합니다.
<template>
<UInputDate icon="i-lucide-calendar" />
</template>leading 및 trailing props를 사용하여 아이콘 위치를 설정하거나 leading-icon 및 trailing-icon props를 사용하여 각 위치에 대해 다른 아이콘을 설정합니다.Separator 아이콘
separator-icon 소품을 사용하여 범위 구분 기호의 Icon를 변경합니다. 기본값은 i-lucide-minus입니다.
<template>
<UInputDate range separator-icon="i-lucide-arrow-right" />
</template>아바타
avatar prop을 사용하여 InputDate 내부에 Avatar를 표시합니다.
<template>
<UInputDate
:avatar="{
src: 'https://github.com/vuejs.png',
loading: 'lazy'
}"
size="md"
variant="outline"
/>
</template>비활성 화
disabled prop 를 사용하여 InputDate 를 비활성화합니다.
<template>
<UInputDate disabled />
</template>예제
Unavailable 날짜 포함
is-date-unavailable prop을 함수와 함께 사용하여 특정 날짜를 사용할 수 없음으로 표시합니다.
<script setup lang="ts">
import type { DateValue } from '@internationalized/date'
import { CalendarDate } from '@internationalized/date'
const modelValue = shallowRef({
start: new CalendarDate(2022, 1, 1),
end: new CalendarDate(2022, 1, 9)
})
const isDateUnavailable = (date: DateValue) => {
return date.day >= 10 && date.day <= 16
}
</script>
<template>
<UInputDate v-model="modelValue" :is-date-unavailable="isDateUnavailable" range />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import type { DateValue } from '@internationalized/date'
import { CalendarDate } from '@internationalized/date'
const modelValue = shallowRef({
start: new CalendarDate(2022, 1, 1),
end: new CalendarDate(2022, 1, 9)
})
const isDateUnavailable = (date: DateValue) => {
return date.day >= 10 && date.day <= 16
}
</script>
<template>
<UInputDate v-model="modelValue" :is-date-unavailable="isDateUnavailable" range />
</template>
최소/최대 날짜 포함
min-value 및 max-value 소품을 사용하여 날짜를 제한합니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const modelValue = shallowRef(new CalendarDate(2023, 9, 10))
const minDate = new CalendarDate(2023, 9, 1)
const maxDate = new CalendarDate(2023, 9, 30)
</script>
<template>
<UInputDate v-model="modelValue" :min-value="minDate" :max-value="maxDate" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const modelValue = shallowRef(new CalendarDate(2023, 9, 10))
const minDate = new CalendarDate(2023, 9, 1)
const maxDate = new CalendarDate(2023, 9, 30)
</script>
<template>
<UInputDate v-model="modelValue" :min-value="minDate" :max-value="maxDate" />
</template>
As 날짜 선택기
Calendar 및 Popover 구성 요소를 사용하여 날짜 선택기를 만듭니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const inputDate = useTemplateRef('inputDate')
const modelValue = shallowRef(new CalendarDate(2022, 1, 10))
</script>
<template>
<UInputDate ref="inputDate" v-model="modelValue">
<template #trailing>
<UPopover :reference="inputDate?.inputsRef[3]?.$el">
<UButton
color="neutral"
variant="link"
size="sm"
icon="i-lucide-calendar"
aria-label="Select a date"
class="px-0"
/>
<template #content>
<UCalendar v-model="modelValue" class="p-2" />
</template>
</UPopover>
</template>
</UInputDate>
</template>
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const inputDate = useTemplateRef('inputDate')
const modelValue = shallowRef(new CalendarDate(2022, 1, 10))
</script>
<template>
<UInputDate ref="inputDate" v-model="modelValue">
<template #trailing>
<UPopover :reference="inputDate?.inputsRef[3]?.$el">
<UButton
color="neutral"
variant="link"
size="sm"
icon="i-lucide-calendar"
aria-label="Select a date"
class="px-0"
/>
<template #content>
<UCalendar v-model="modelValue" class="p-2" />
</template>
</UPopover>
</template>
</UInputDate>
</template>
날짜 범위 선택기로
Calendar 및 Popover 구성 요소를 사용하여 날짜 범위 선택기를 만듭니다.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
const inputDate = useTemplateRef('inputDate')
const modelValue = shallowRef({
start: new CalendarDate(2022, 1, 10),
end: new CalendarDate(2022, 1, 20)
})
</script>
<template>
<UInputDate ref="inputDate" v-model="modelValue" range>
<template #trailing>
<UPopover :reference="inputDate?.inputsRef[0]?.$el">
<UButton
color="neutral"
variant="link"
size="sm"
icon="i-lucide-calendar"
aria-label="Select a date range"
class="px-0"
/>
<template #content>
<UCalendar v-model="modelValue" class="p-2" :number-of-months="2" range />
</template>
</UPopover>
</template>
</UInputDate>
</template>
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { CalendarDate } from '@internationalized/date'
const inputDate = useTemplateRef('inputDate')
const modelValue = shallowRef({
start: new CalendarDate(2022, 1, 10),
end: new CalendarDate(2022, 1, 20)
})
</script>
<template>
<UInputDate ref="inputDate" v-model="modelValue" range>
<template #trailing>
<UPopover :reference="inputDate?.inputsRef[0]?.$el">
<UButton
color="neutral"
variant="link"
size="sm"
icon="i-lucide-calendar"
aria-label="Select a date range"
class="px-0"
/>
<template #content>
<UCalendar v-model="modelValue" class="p-2" :number-of-months="2" range />
</template>
</UPopover>
</template>
</UInputDate>
</template>
API 파일
Props (### Props)
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
color | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'solid' | "outline" | "soft" | "subtle" | "ghost" | "none" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
highlight | boolean Highlight the ring color like a focus state. | |
fixed | boolean Keep the mobile text size on all breakpoints. | |
autofocus | boolean | |
autofocusDelay | 0 | number |
separatorIcon | appConfig.ui.icons.minus | anyThe icon to use as a range separator. |
range | RWhether or not a range of dates can be selected | |
defaultValue | CalendarDate | CalendarDateTime | ZonedDateTime | DateRange | |
modelValue | null | CalendarDate | CalendarDateTime | ZonedDateTime | DateRange | |
icon | anyDisplay an icon based on the | |
avatar | AvatarPropsDisplay an avatar on the left side. | |
leading | boolean When | |
leadingIcon | anyDisplay an icon on the left side. | |
trailing | boolean When | |
trailingIcon | anyDisplay an icon on the right side. | |
loading | boolean When | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
defaultPlaceholder | CalendarDate | CalendarDateTime | ZonedDateTime | |
placeholder | CalendarDate | CalendarDateTime | ZonedDateTime | |
hourCycle | 12 | 24The hour cycle used for formatting times. Defaults to the local preference | |
step | DateStepThe stepping interval for the time fields. Defaults to | |
stepSnapping | boolean Whether to enforce snapping the time value to the nearest step increment after input. Defaults to | |
granularity | "day" | "hour" | "minute" | "second"The granularity to use for formatting times. Defaults to day if a CalendarDate is provided, otherwise defaults to minute. The field will render segments for each part of the date up to and including the specified granularity | |
hideTimeZone | boolean Whether or not to hide the time zone segment of the field | |
maxValue | CalendarDate | CalendarDateTime | ZonedDateTime | |
minValue | CalendarDate | CalendarDateTime | ZonedDateTime | |
locale | stringThe locale to use for formatting dates | |
disabled | boolean Whether or not the date field is disabled | |
readonly | boolean Whether or not the date field is readonly | |
isDateUnavailable | (date: DateValue): booleanA function that returns whether or not a date is unavailable | |
id | stringId of the element | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | boolean When | |
ui | { base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; segment?: SlotClass; separatorIcon?: SlotClass; } |
Slots
| Slot | Type |
|---|---|
leading | { ui: object; } |
default | { ui: object; } |
trailing | { ui: object; } |
separator | { ui: object; } |
Emits 파일
| Event | Type |
|---|---|
update:modelValue | [value: InputDateModelValue<R>] |
update:placeholder | [date: DateValue] & [date: DateValue] |
change | [event: Event] |
blur | [event: FocusEvent] |
focus | [event: FocusEvent] |
Theme (## 테마)
export default defineAppConfig({
ui: {
inputDate: {
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: 'data-[segment=day]:w-8 data-[segment=month]:w-8 data-[segment=year]:w-10'
},
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: 'data-[segment=day]:w-8 data-[segment=month]:w-8 data-[segment=year]:w-10'
},
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: 'data-[segment=day]:w-9 data-[segment=month]:w-9 data-[segment=year]:w-11'
},
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: 'data-[segment=day]:w-9 data-[segment=month]:w-9 data-[segment=year]:w-11'
},
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: 'data-[segment=day]:w-10 data-[segment=month]:w-10 data-[segment=year]:w-12'
}
},
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: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
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'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
inputDate: {
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: 'data-[segment=day]:w-8 data-[segment=month]:w-8 data-[segment=year]:w-10'
},
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: 'data-[segment=day]:w-8 data-[segment=month]:w-8 data-[segment=year]:w-10'
},
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: 'data-[segment=day]:w-9 data-[segment=month]:w-9 data-[segment=year]:w-11'
},
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: 'data-[segment=day]:w-9 data-[segment=month]:w-9 data-[segment=year]:w-11'
},
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: 'data-[segment=day]:w-10 data-[segment=month]:w-10 data-[segment=year]:w-12'
}
},
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: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 has-focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
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'
}
}
}
})
]
})