PinInput (핀입력)
Usage
v-model 지시문을 사용하여 PinInput 값을 제어합니다.
<script setup lang="ts">
const value = ref([])
</script>
<template>
<UPinInput v-model="value" />
</template><script setup lang="ts">
import { ref } from 'vue'
const value = ref([])
</script>
<template>
<UPinInput v-model="value" />
</template>상태를 제어할 필요가 없을 때 default-value prop을 사용하여 초기 값을 설정합니다.
<template>
<UPinInput :default-value="['1', '2', '3']" />
</template>Type 형식
type prop을 사용하여 입력 유형을 변경합니다. 기본값은 text입니다.
<template>
<UPinInput type="number" />
</template>type가 number로 설정되면 숫자 문자만 허용됩니다.Mask
mask prop을 사용하여 입력을 암호로 처리합니다.
<template>
<UPinInput mask :default-value="['1', '2', '3', '4', '5']" />
</template>OTP 키
otp 소품을 사용하여 일회용 비밀번호 기능을 활성화합니다. 이 기능을 활성화하면 모바일 장치가 SMS 메시지 또는 클립보드 내용에서 OTP 코드를 자동으로 감지하고 자동 완성 기능을 지원합니다.
<template>
<UPinInput otp />
</template>자리표시자
placeholder Prop을 사용하여 자리 표시자 텍스트를 설정합니다.
<template>
<UPinInput placeholder="○" />
</template>길이
length prop을 사용하여 입력 양을 변경합니다.
<template>
<UPinInput :length="6" placeholder="○" />
</template>Separator: badge{label="4.9+" class="align-text-top"}
separator prop을 사용하여 입력 그룹 사이에 구분 기호를 삽입합니다. N번째 입력 후에 하나씩 삽입하려면 숫자를 전달합니다.
<template>
<UPinInput :length="6" :separator="3" placeholder="○" />
</template>또한 위치 배열을 전달하여 특정 입력 뒤에 구분 기호를 삽입할 수 있습니다.
<template>
<UPinInput :length="7" :separator="[3, 4]" placeholder="○" />
</template>Color 색상
PinInput에 초점을 맞출 때 color Prop을 사용하여 링 색상을 변경합니다.
<template>
<UPinInput color="neutral" highlight placeholder="○" />
</template>highlight prop은 초점 상태를 표시하기 위해 사용되며, 유효성 검사 오류가 발생할 때 내부적으로 사용됩니다.변형
variant prop을 사용하여 PinInput의 변형을 변경합니다.
<template>
<UPinInput color="neutral" variant="subtle" placeholder="○" />
</template>Size
size prop을 사용하여 PinInput의 크기를 변경합니다.
<template>
<UPinInput size="xl" placeholder="○" />
</template>비활성 화
disabled prop을 사용하여 PinInput을 비활성화합니다.
<template>
<UPinInput disabled placeholder="○" />
</template>examples 예제
Separator 슬롯 포함: badge{label="4.9+" class="align-text-top"}
separator 슬롯을 사용하여 구분 기호 모양을 사용자 정의합니다.
<template>
<UPinInput :length="6" :separator="3" placeholder="○">
<template #separator>
<UIcon name="i-lucide-minus" class="size-4" />
</template>
</UPinInput>
</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 | 'outline' | "outline" | "soft" | "subtle" | "ghost" | "none" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
length | 5 | string | numberThe number of input fields. |
autofocus | boolean | |
autofocusDelay | 0 | number |
highlight | boolean | |
fixed | boolean Keep the mobile text size on all breakpoints. | |
separator | number | number[]Group inputs by inserting a separator between them. Pass a number to insert one after every Nth input, or an array of positions to insert after specific inputs. | |
defaultValue | PinInputValue<T>The default value of the pin inputs when it is initially rendered. Use when you do not need to control its checked state. | |
disabled | boolean When | |
id | stringId of the element | |
mask | boolean When | |
modelValue | null | PinInputValue<T>The controlled checked state of the pin input. Can be binded as | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
otp | boolean When | |
placeholder | stringThe placeholder character to use for empty pin-inputs. | |
required | boolean When | |
type | 'text' | TInput type for the inputs. |
ui | { root?: SlotClass; base?: SlotClass; separator?: SlotClass; } |
슬롯
| Slot | Type |
|---|---|
separator | { index: number; } |
Emits
| Event | Type |
|---|---|
update:modelValue | [value: PinInputValue<T>] |
complete | [value: PinInputValue<T>] |
change | [event: Event] |
blur | [event: Event] |
focus | [event: Event] |
exose 소개
템플릿 참조를 통해 컴포넌트에 액세스하는 경우 다음을 사용할 수 있습니다.
| 이름 (Name) | 유형 (Type) |
|---|---|
inputsRef | Ref<ComponentPublicInstance[]> |
Theme 테마
export default defineAppConfig({
ui: {
pinInput: {
slots: {
root: 'relative inline-flex items-center gap-1.5',
base: [
'rounded-md border-0 placeholder:text-dimmed text-center disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
separator: 'text-dimmed flex items-center justify-center'
},
variants: {
size: {
xs: {
base: 'size-6 text-sm/4'
},
sm: {
base: 'size-7 text-sm/4'
},
md: {
base: 'size-8 text-base/5'
},
lg: {
base: 'size-9 text-base/5'
},
xl: {
base: 'size-10 text-base'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated 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 focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 focus-visible:outline-3 focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 focus-visible:outline-3 focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
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'
}
],
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: {
pinInput: {
slots: {
root: 'relative inline-flex items-center gap-1.5',
base: [
'rounded-md border-0 placeholder:text-dimmed text-center disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
separator: 'text-dimmed flex items-center justify-center'
},
variants: {
size: {
xs: {
base: 'size-6 text-sm/4'
},
sm: {
base: 'size-7 text-sm/4'
},
md: {
base: 'size-8 text-base/5'
},
lg: {
base: 'size-9 text-base/5'
},
xl: {
base: 'size-10 text-base'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated 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 focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 focus-visible:outline-3 focus-visible:ring-primary'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 focus-visible:outline-3 focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
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'
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
})
]
})