|
| 1 | +<script lang="ts"> |
| 2 | + import { cn } from "$lib/utils/styles.js"; |
| 3 | + import { Accordion, useId, Button } from "bits-ui"; |
| 4 | + import CaretDown from "phosphor-svelte/lib/CaretDown"; |
| 5 | + import { SvelteSet } from "svelte/reactivity"; |
| 6 | +
|
| 7 | + let activeStep = $state(""); |
| 8 | + let completedSteps = new SvelteSet<string>(); |
| 9 | +</script> |
| 10 | + |
| 11 | +{#snippet MyAccordionHeader({ value, title }: { value: string; title: string })} |
| 12 | + {@const isCompleted = completedSteps.has(value)} |
| 13 | + <Accordion.Header> |
| 14 | + <Accordion.Trigger |
| 15 | + class="flex w-full flex-1 select-none items-center justify-between gap-3 py-5 text-[15px] font-medium transition-all [&[data-state=open]>span>svg]:rotate-180" |
| 16 | + > |
| 17 | + <div |
| 18 | + class={cn( |
| 19 | + "border-foreground/30 flex size-6 shrink-0 items-center justify-center rounded-full border text-xs font-medium", |
| 20 | + isCompleted ? "text-foreground" : "text-muted-foreground" |
| 21 | + )} |
| 22 | + > |
| 23 | + {isCompleted ? "✓" : value} |
| 24 | + </div> |
| 25 | + <span class="w-full text-left"> |
| 26 | + {title} |
| 27 | + </span> |
| 28 | + <span |
| 29 | + class="hover:bg-dark-10 inline-flex size-8 items-center justify-center rounded-[7px] bg-transparent" |
| 30 | + > |
| 31 | + <CaretDown class="size-[18px] transition-transform duration-200" /> |
| 32 | + </span> |
| 33 | + </Accordion.Trigger> |
| 34 | + </Accordion.Header> |
| 35 | +{/snippet} |
| 36 | + |
| 37 | +{#snippet InputField({ |
| 38 | + label, |
| 39 | + placeholder, |
| 40 | + type = "text", |
| 41 | +}: { |
| 42 | + label: string; |
| 43 | + placeholder: string; |
| 44 | + type?: string; |
| 45 | +})} |
| 46 | + {@const id = useId()} |
| 47 | + <div class="flex flex-col gap-1"> |
| 48 | + <label class="select-none text-sm font-medium" for={id}>{label}</label> |
| 49 | + <input |
| 50 | + {type} |
| 51 | + {id} |
| 52 | + name={label} |
| 53 | + {placeholder} |
| 54 | + class="rounded-card-sm border-border-input bg-background placeholder:text-foreground-alt/50 hover:border-dark-40 focus-override inline-flex h-10 w-full items-center border px-4 text-base sm:text-sm" |
| 55 | + /> |
| 56 | + </div> |
| 57 | +{/snippet} |
| 58 | + |
| 59 | +<Accordion.Root bind:value={activeStep} class="w-full sm:max-w-[70%]" type="single"> |
| 60 | + <Accordion.Item value="1" class="border-dark-10 group border-b px-1.5"> |
| 61 | + {@render MyAccordionHeader({ title: "Shipping Information", value: "1" })} |
| 62 | + <Accordion.Content |
| 63 | + class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm tracking-[-0.01em]" |
| 64 | + > |
| 65 | + <div class="flex flex-col gap-4 pb-6 pt-2"> |
| 66 | + <div class="grid grid-cols-2 gap-4"> |
| 67 | + {@render InputField({ label: "First Name", placeholder: "John" })} |
| 68 | + {@render InputField({ label: "Last Name", placeholder: "Doe" })} |
| 69 | + <div class="col-span-2"> |
| 70 | + {@render InputField({ |
| 71 | + label: "Address", |
| 72 | + placeholder: "1234 Elm Street", |
| 73 | + })} |
| 74 | + </div> |
| 75 | + {@render InputField({ label: "City", placeholder: "Tampa" })} |
| 76 | + {@render InputField({ label: "ZIP", placeholder: "123456" })} |
| 77 | + </div> |
| 78 | + <div class="pt-2"> |
| 79 | + <Button.Root |
| 80 | + class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]" |
| 81 | + onclick={() => { |
| 82 | + completedSteps.add("1"); |
| 83 | + activeStep = "2"; |
| 84 | + }} |
| 85 | + > |
| 86 | + Continue to Payment |
| 87 | + </Button.Root> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </Accordion.Content> |
| 91 | + </Accordion.Item> |
| 92 | + <Accordion.Item value="2" class="border-dark-10 group border-b px-1.5"> |
| 93 | + {@render MyAccordionHeader({ title: "Payment Method", value: "2" })} |
| 94 | + <Accordion.Content |
| 95 | + class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm tracking-[-0.01em]" |
| 96 | + > |
| 97 | + <div class="flex flex-col gap-4 pb-6 pt-2"> |
| 98 | + <div class="grid grid-cols-3 gap-4"> |
| 99 | + <div class="col-span-3"> |
| 100 | + {@render InputField({ |
| 101 | + label: "Card Number", |
| 102 | + placeholder: "4242 4242 4242 4242", |
| 103 | + })} |
| 104 | + </div> |
| 105 | + {@render InputField({ label: "Exp. Month", placeholder: "MM" })} |
| 106 | + {@render InputField({ label: "Exp. Year", placeholder: "YY" })} |
| 107 | + {@render InputField({ label: "CVC", placeholder: "123" })} |
| 108 | + </div> |
| 109 | + <div class="pt-2"> |
| 110 | + <Button.Root |
| 111 | + class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]" |
| 112 | + onclick={() => { |
| 113 | + completedSteps.add("2"); |
| 114 | + activeStep = "3"; |
| 115 | + }} |
| 116 | + > |
| 117 | + Continue to Review |
| 118 | + </Button.Root> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + </Accordion.Content> |
| 122 | + </Accordion.Item> |
| 123 | + <Accordion.Item value="3" class="border-dark-10 group border-b px-1.5"> |
| 124 | + {@render MyAccordionHeader({ title: "Payment Method", value: "3" })} |
| 125 | + <Accordion.Content |
| 126 | + class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden pb-6 text-sm tracking-[-0.01em]" |
| 127 | + > |
| 128 | + <div class="flex flex-col gap-4 pt-2"> |
| 129 | + <div class="rounded-lg border p-4"> |
| 130 | + <h4 class="mb-2 font-medium">Order Summary</h4> |
| 131 | + <div class="flex flex-col gap-2"> |
| 132 | + <div class="flex justify-between text-sm"> |
| 133 | + <span class="text-muted-foreground">Product 1</span> |
| 134 | + <span>$29.99</span> |
| 135 | + </div> |
| 136 | + <div class="flex justify-between text-sm"> |
| 137 | + <span class="text-muted-foreground">Product 2</span> |
| 138 | + <span>$49.99</span> |
| 139 | + </div> |
| 140 | + <div class="flex justify-between text-sm"> |
| 141 | + <span class="text-muted-foreground">Shipping</span> |
| 142 | + <span>$4.99</span> |
| 143 | + </div> |
| 144 | + <div class="mt-2 flex justify-between border-t pt-2 font-medium"> |
| 145 | + <span>Total</span> |
| 146 | + <span>$84.97</span> |
| 147 | + </div> |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + <div class="pt-2"> |
| 151 | + <Button.Root |
| 152 | + class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]" |
| 153 | + onclick={() => { |
| 154 | + completedSteps.add("3"); |
| 155 | + activeStep = ""; |
| 156 | + }} |
| 157 | + > |
| 158 | + Place Order |
| 159 | + </Button.Root> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + </Accordion.Content> |
| 163 | + </Accordion.Item> |
| 164 | +</Accordion.Root> |
0 commit comments