|
1 | 1 | <script lang="ts"> |
2 | | - let countries = [ |
3 | | - { code: '+41', flag: '🇬🇧', name: 'United Kingdom' }, |
4 | | - { code: '+49', flag: '🇩🇪', name: 'Germany' }, |
5 | | - { code: '+33', flag: '🇫🇷', name: 'France' } |
6 | | - // Add more as needed |
7 | | - ]; |
| 2 | + import { cn } from '$lib/utils'; |
| 3 | + import type { HTMLAttributes } from 'svelte/elements'; |
8 | 4 |
|
9 | | - let selectedCode = countries[0].code; |
| 5 | + interface ISelectProps extends HTMLAttributes<HTMLElement> { |
| 6 | + options: Array<{ |
| 7 | + code: string; |
| 8 | + flag: string; |
| 9 | + name: string; |
| 10 | + }>; |
| 11 | + } |
| 12 | +
|
| 13 | + let { |
| 14 | + options = [ |
| 15 | + { code: '+41', flag: '🇬🇧', name: 'United Kingdom' }, |
| 16 | + { code: '+49', flag: '🇩🇪', name: 'Germany' }, |
| 17 | + { code: '+33', flag: '🇫🇷', name: 'France' } |
| 18 | + ], |
| 19 | + ...restProps |
| 20 | + }: ISelectProps = $props(); |
| 21 | +
|
| 22 | + let selectedCode = $state(options[0].code); |
| 23 | +
|
| 24 | + const cBase = 'bg-grey flex w-[max-content] items-center space-x-2 rounded-full p-1.5'; |
10 | 25 | </script> |
11 | 26 |
|
12 | | -<div class="bg-grey flex w-[max-content] items-center space-x-2 rounded-full p-1.5"> |
13 | | - <div class="rounded-full text-xl">{countries.find((c) => c.code === selectedCode)?.flag}</div> |
| 27 | +<div {...restProps} class={cn([cBase, restProps.class].join(' '))}> |
| 28 | + <div class="rounded-full text-xl">{options.find((c) => c.code === selectedCode)?.flag}</div> |
14 | 29 | <select |
15 | 30 | bind:value={selectedCode} |
16 | 31 | class="text-md focus:ring-2 focus:ring-transparent focus:outline-none" |
17 | 32 | > |
18 | | - {#each countries as country} |
| 33 | + {#each options as country} |
19 | 34 | <option value={country.code} class="text-md text-black-600"> |
20 | 35 | {country.code} |
21 | 36 | </option> |
|
0 commit comments