Use a diretiva v-model para controlar o valor do PinInput.
<script setup lang="ts">
const value = ref([])
</script>
<template>
<NPinInput v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref([])
</script>
<template>
<NPinInput v-model="value" />
</template>
Use a prop default-value para definir o valor inicial quando você não precisa controlar o estado.
<template>
<NPinInput :default-value="['1', '2', '3']" />
</template>
Use a prop type para alterar o tipo do input. O padrão é text.
<template>
<NPinInput type="number" />
</template>
type é definido como number, ele só aceita caracteres numéricos.Use a prop mask para tratar o input como uma senha.
<template>
<NPinInput mask :default-value="['1', '2', '3', '4', '5']" />
</template>
Use a prop otp para habilitar a funcionalidade de senha de uso único (One-Time Password). Quando habilitada, os dispositivos móveis podem detectar e preencher automaticamente os códigos OTP de mensagens SMS ou do conteúdo da área de transferência, com suporte a autocomplete.
<template>
<NPinInput otp />
</template>
Use a prop placeholder para definir um texto de placeholder.
<template>
<NPinInput placeholder="○" />
</template>
Use a prop length para alterar a quantidade de inputs.
<template>
<NPinInput :length="6" placeholder="○" />
</template>
Use a prop separator para inserir um separador entre grupos de inputs. Passe um número para inserir um após cada N-ésimo input.
<template>
<NPinInput :length="6" :separator="3" placeholder="○" />
</template>
Você também pode passar um array de posições para inserir separadores após inputs específicos.
<template>
<NPinInput :length="7" :separator="[3, 4]" placeholder="○" />
</template>
Use a prop color para alterar a cor do ring quando o PinInput está em foco.
<template>
<NPinInput color="neutral" highlight placeholder="○" />
</template>
highlight é usada aqui para mostrar o estado de foco. Ela é usada internamente quando ocorre um erro de validação.Use a prop variant para alterar a variante do PinInput.
<template>
<NPinInput color="neutral" variant="subtle" placeholder="○" />
</template>
Use a prop size para alterar o tamanho do PinInput.
<template>
<NPinInput size="xl" placeholder="○" />
</template>
Use a prop disabled para desabilitar o PinInput.
<template>
<NPinInput disabled placeholder="○" />
</template>
Use o slot separator para personalizar a aparência do separador.
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
color | 'primary' | "primary" | "secondary" | "accent" | "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; } |
| Event | Type |
|---|---|
update:modelValue | [value: PinInputValue<T>] |
complete | [value: PinInputValue<T>] |
change | [event: Event] |
blur | [event: Event] |
Ao acessar o componente por meio de um template ref, você pode usar o seguinte:
| Name | Type |
|---|---|
inputsRef | Ref<ComponentPublicInstance[]> |
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 focus:outline-none disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
separator: 'text-dimmed flex items-center justify-center'
},
variants: {
size: {
xs: {
base: 'size-6 text-xs'
},
sm: {
base: 'size-7 text-xs'
},
md: {
base: 'size-8 text-sm'
},
lg: {
base: 'size-9 text-sm'
},
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'
},
color: {
primary: '',
secondary: '',
accent: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-inverted'
},
{
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 '@nitro/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 focus:outline-none disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
separator: 'text-dimmed flex items-center justify-center'
},
variants: {
size: {
xs: {
base: 'size-6 text-xs'
},
sm: {
base: 'size-7 text-xs'
},
md: {
base: 'size-8 text-sm'
},
lg: {
base: 'size-9 text-sm'
},
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'
},
color: {
primary: '',
secondary: '',
accent: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-inverted'
},
{
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'
}
}
}
})
]
})