Files
WRNexusJS/.publish/ui/components/PinInput.wrn
T
2026-08-01 01:09:58 +05:30

118 lines
4.5 KiB
Plaintext

component PinInput {
outputs {
input(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
change(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
complete(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
paste(payload: { sourceEvent?: Event; value: string | number | boolean | null | object; [key: string]: string | number | boolean | null | object } | string | number | boolean | null | object[])
clear(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
error(payload: { error: Error | string; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | Error | string)
}
props {
size: string = "default"
color: string = "primary"
label: string = "Verification code"
name: string = "pin"
value: string = ""
length: number = 4
pattern: string = "[0-9]"
type: string = "text"
inputMode: string = "numeric"
placeholder: string = "○"
autocomplete: string = "one-time-code"
masked: boolean = false
disabled: boolean = false
readonly: boolean = false
required: boolean = false
autoFocus: boolean = false
autoSubmit: boolean = false
allowPaste: boolean = true
clearable: boolean = true
clearLabel: string = "Clear code"
separator: string = ""
groupSize: number = 0
helpText: string = ""
invalid: boolean = false
validationMessage: string = ""
class: string = ""
}
functions {
shared function inputIndexes() {
return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].slice(
0,
Math.max(1, Math.min(12, Number(length)))
)
}
}
view {
<fieldset
{...attrs}
class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--pin-input {invalid ? 'wire-next--invalid' : ''} {disabled ? 'wire-next--disabled' : ''} {class}"
data-wrn-pin-input
data-length="{length}"
data-pattern="{pattern}"
data-allow-paste="{allowPaste ? 'true' : 'false'}"
data-auto-submit="{autoSubmit ? 'true' : 'false'}"
data-value="{value}"
disabled="{disabled}"
aria-describedby="{validationMessage ? `${name}-validation` : helpText ? `${name}-help` : ''}"
>
<div class="wire-next__pin-heading">
<legend>{label}</legend>
<button
type="button"
class="wire-next__pin-clear"
data-pin-clear
aria-label="{clearLabel}"
title="{clearLabel}"
style="{clearable && value ? '' : 'display: none'}"
>
<span class="icon-[lucide--rotate-ccw]" aria-hidden="true"></span>
<span>{clearLabel}</span>
</button>
</div>
<div class="wire-next__pin-cells" role="group" aria-label="{label}">
{#each inputIndexes() as index}
<input
data-pin-cell
data-pin-index="{index}"
id="{name}-{index}"
type="{masked ? 'password' : type}"
inputmode="{inputMode}"
maxlength="1"
value="{value[index] || ''}"
placeholder="{placeholder}"
autocomplete="{index === 0 ? autocomplete : 'off'}"
aria-label="{label} digit {index + 1} of {length}"
aria-required="{required ? 'true' : 'false'}"
readonly="{readonly}"
disabled="{disabled}"
autofocus="{autoFocus && index === 0}"
/>
{#if separator && groupSize !== 0 && (index + 1) % groupSize === 0 && index + 1 !== length}
<span class="wire-next__pin-separator" aria-hidden="true">{separator}</span>
{/if}
{/each}
</div>
<input
type="hidden"
name="{name}"
value="{value}"
required="{required}"
data-pin-value
/>
{#if helpText && !validationMessage}<small id="{name}-help">{helpText}</small>{/if}
<small
id="{name}-validation"
class="wire-next__validation"
data-error="{name}"
>{validationMessage}</small>
</fieldset>
}
}