|
| 1 | +<script lang="ts"> |
| 2 | +import { |
| 3 | + CheckmarkBadge02Icon, |
| 4 | + Upload03Icon, |
| 5 | + ViewIcon, |
| 6 | +} from "@hugeicons/core-free-icons"; |
| 7 | +import { HugeiconsIcon } from "@hugeicons/svelte"; |
| 8 | +import type { HTMLAttributes } from "svelte/elements"; |
| 9 | +
|
| 10 | +interface userData { |
| 11 | + [fieldName: string]: string; |
| 12 | +} |
| 13 | +interface IIdentityCard extends HTMLAttributes<HTMLElement> { |
| 14 | + variant?: "eName" | "ePassport" | "eVault"; |
| 15 | + userId?: string; |
| 16 | + viewBtn?: () => void; |
| 17 | + shareBtn?: () => void; |
| 18 | + userData?: userData; |
| 19 | + totalStorage?: number; |
| 20 | + usedStorage?: number; |
| 21 | +} |
| 22 | +
|
| 23 | +let { |
| 24 | + variant = "eName", |
| 25 | + userId, |
| 26 | + viewBtn, |
| 27 | + shareBtn, |
| 28 | + userData, |
| 29 | + totalStorage = 0, |
| 30 | + usedStorage = 0, |
| 31 | + ...restProps |
| 32 | +}: IIdentityCard = $props(); |
| 33 | +const state = $state({ |
| 34 | + progressWidth: "0%", |
| 35 | +}); |
| 36 | +
|
| 37 | +$effect(() => { |
| 38 | + state.progressWidth = |
| 39 | + usedStorage > 0 ? `${(usedStorage / totalStorage) * 100}%` : "0%"; |
| 40 | +}); |
| 41 | +</script> |
| 42 | + |
| 43 | +<div {...restProps} class="relative {variant === 'eName' ? "bg-black-900" : variant === 'ePassport' ? "bg-primary" : "bg-gray"} rounded-xl w-full min-h-[150px] text-white shadow-lg overflow-hidden"> |
| 44 | + <div class="w-full h-full pointer-events-none flex gap-13 justify-end absolute right-15 bottom-20"> |
| 45 | + <div class="w-10 {variant === 'eVault' ? "bg-white/40" : "bg-white/10"} h-[300%] rotate-40"></div> |
| 46 | + <div class="w-10 {variant === 'eVault' ? "bg-white/40" : "bg-white/10"} h-[300%] rotate-40"></div> |
| 47 | + </div> |
| 48 | + <div class="p-5 flex flex-col gap-2"> |
| 49 | + <div class="flex justify-between"> |
| 50 | + {#if variant === 'eName'} |
| 51 | + <HugeiconsIcon size={30} strokeWidth={2} color="var(--color-secondary)" icon={CheckmarkBadge02Icon} /> |
| 52 | + <div class="flex gap-3 items-center"> |
| 53 | + <button class="flex justify-start" onclick={shareBtn}> |
| 54 | + <HugeiconsIcon size={30} strokeWidth={2} color="white" icon={Upload03Icon} /> |
| 55 | + </button> |
| 56 | + <button class="flex justify-start" onclick={viewBtn}> |
| 57 | + <HugeiconsIcon size={30} strokeWidth={2} color="white" icon={ViewIcon} /> |
| 58 | + </button> |
| 59 | + </div> |
| 60 | + {:else if variant === 'ePassport'} |
| 61 | + <p class="bg-white text-black flex items-center rounded-4xl px-5 py-2 text-xs font-semibold">HIGH SECURITY</p> |
| 62 | + <button class="flex justify-start" onclick={viewBtn}> |
| 63 | + <HugeiconsIcon size={30} strokeWidth={2} color="white" icon={ViewIcon} /> |
| 64 | + </button> |
| 65 | + {:else if variant === 'eVault'} |
| 66 | + <div class="text-black-300 text-3xl mb-3">{state.progressWidth} Used</div> |
| 67 | + {/if} |
| 68 | + </div> |
| 69 | + <div> |
| 70 | + {#if variant === "eName"} |
| 71 | + <h2 class="text-md text-gray font-light">Your eName</h2> |
| 72 | + <div class="flex items-center justify-between w-full"> |
| 73 | + <p class="text-white w-[60%] font-medium">@{userId}</p> |
| 74 | + </div> |
| 75 | + {:else if variant === "ePassport"} |
| 76 | + <div class="flex gap-2 flex-col"> |
| 77 | + {#if userData} |
| 78 | + {#each Object.entries(userData) as [fieldName, value] } |
| 79 | + <div class="flex justify-between"> |
| 80 | + <div class="text-md font-normal text-gray">{fieldName}</div> |
| 81 | + <div class="text-md font-medium text-white">{value}</div> |
| 82 | + </div> |
| 83 | + {/each} |
| 84 | + {/if} |
| 85 | + </div> |
| 86 | + {:else if variant === "eVault"} |
| 87 | + <div> |
| 88 | + <div class="flex justify-between text-black mb-1"> |
| 89 | + <div>{usedStorage}GB Used</div> |
| 90 | + <div>{totalStorage}GB Used</div> |
| 91 | + </div> |
| 92 | + <div class="relative w-full h-3 rounded-full overflow-hidden bg-primary-400"> |
| 93 | + <div class="h-full bg-secondary rounded-full" style={`width: calc(${state.progressWidth})`}></div> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + {/if} |
| 97 | + </div> |
| 98 | + </div> |
| 99 | +</div> |
| 100 | + |
| 101 | + |
0 commit comments