import FieldStyles from "../styles/FieldStyles.wrn" import ComponentBaseStyles from "../styles/ComponentBaseStyles.wrn" component TogglePassword { outputs { input(payload: { name?: string; value: string | number | boolean | null | object; visible: boolean }) change(payload: { name?: string; value: string | number | boolean | null | object; visible: boolean }) toggle(payload: { visible: boolean }) } props { size: string = "default" color: string = "primary" label: string = "Password" name: string = "password" value: string = "" placeholder: string = "Enter your password" autocomplete: string = "current-password" minlength: string = "" maxlength: string = "" pattern: string = "(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9]).{8,}" fields: unknown[] = [] visible: boolean = false toggleable: boolean = true toggleMode: string = "button" checkboxLabel: string = "Show password" showLabel: string = "Show password" hideLabel: string = "Hide password" disabled: boolean = false readonly: boolean = false required: boolean = false invalid: boolean = false helpText: string = "" validationMessage: string = "" class: string = "" } state revealed = visible functions { shared function toggleVisibility() { if (disabled || readonly || !toggleable) { return } revealed = !revealed } shared function fieldId(field, index) { return field.id || field.name || name + "-" + index } shared function fieldName(field, index) { return field.name || name + "-" + index } } view {
{#if fields.length}
{#each fields as field, index}
{#if toggleable && toggleMode === "button"} {/if}
{/each}
{:else}
{#if toggleable && toggleMode === "button"} {/if}
{/if} {#if toggleable && toggleMode === "checkbox"} {/if} {#if helpText && !validationMessage}{helpText}{/if} {validationMessage}