-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
password-field.svelte
51 lines (45 loc) · 1.28 KB
/
password-field.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script lang="ts">
import { mdiEyeOffOutline, mdiEyeOutline } from '@mdi/js';
import type { HTMLInputAttributes } from 'svelte/elements';
import Icon from '../elements/icon.svelte';
import { t } from 'svelte-i18n';
interface $$Props extends HTMLInputAttributes {
password: string;
autocomplete: string;
required?: boolean;
onInput?: (value: string) => void;
}
export let password: $$Props['password'];
export let required = true;
export let onInput: $$Props['onInput'] = undefined;
let showPassword = false;
</script>
<div class="relative w-full">
<input
{...$$restProps}
class="immich-form-input w-full !pr-12"
type={showPassword ? 'text' : 'password'}
{required}
value={password}
on:input={(e) => {
password = e.currentTarget.value;
onInput?.(password);
}}
/>
{#if password.length > 0}
<button
type="button"
tabindex="-1"
class="absolute inset-y-0 end-0 px-4 text-gray-700 dark:text-gray-200"
on:click={() => (showPassword = !showPassword)}
title={showPassword ? $t('hide_password') : $t('show_password')}
>
<Icon path={showPassword ? mdiEyeOffOutline : mdiEyeOutline} size="1.25em" />
</button>
{/if}
</div>
<style>
input::-ms-reveal {
display: none;
}
</style>