-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPasswordInput.svelte
More file actions
31 lines (28 loc) · 1000 Bytes
/
PasswordInput.svelte
File metadata and controls
31 lines (28 loc) · 1000 Bytes
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
<script lang="ts">
import Eye from 'lucide-svelte/icons/eye';
import EyeOff from 'lucide-svelte/icons/eye-off';
import { Input } from '@/components/ui/input';
import { cn } from '@/lib/utils';
let { class: className = '', ...rest } = $props();
let showPassword = $state(false);
</script>
<div class="relative">
<Input
type={showPassword ? 'text' : 'password'}
class={cn('pr-10', className)}
{...rest}
/>
<button
type="button"
onclick={() => (showPassword = !showPassword)}
class="text-muted-foreground hover:text-foreground focus-visible:ring-ring absolute inset-y-0 right-0 flex items-center rounded-r-md px-3 focus-visible:outline-none focus-visible:ring-[3px]"
aria-label={showPassword ? 'Hide password' : 'Show password'}
tabindex={-1}
>
{#if showPassword}
<EyeOff class="size-4" />
{:else}
<Eye class="size-4" />
{/if}
</button>
</div>