用法
使用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属性设置初始值。
<template>
<UPinInput :default-value="['1', '2', '3']" />
</template>Type
使用type prop将输入类型. png更改为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属性设置占位符文本。
<template>
<UPinInput placeholder="○" />
</template>Length
使用length prop更改输入的数量。
<template>
<UPinInput :length="6" placeholder="○" />
</template>分隔符: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
使用color道具更改PinInput聚焦时的环颜色。
<template>
<UPinInput color="neutral" highlight placeholder="○" />
</template>highlight属性来显示焦点状态。当发生验证错误时,在内部使用它。Variant
使用variant prop更改PinInput的变体。
<template>
<UPinInput color="neutral" variant="subtle" placeholder="○" />
</template>Size
使用size属性更改PinInput的大小。
<template>
<UPinInput size="xl" placeholder="○" />
</template>禁用
使用disabled prop禁用PinInput。
<template>
<UPinInput disabled placeholder="○" />
</template>示例
带分隔槽: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
| 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; } |
Slots
| 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] |
曝光
通过模板引用访问组件时,可以使用以下命令:
| 名称 | 类型 |
|---|---|
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'
}
}
}
})
]
})