mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add variant support for dropdown component styling
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
export let displayValue: (val: string | number) => string = (val) => {
|
export let displayValue: (val: string | number) => string = (val) => {
|
||||||
return options.find((o) => o.value === val)?.label ?? String(val);
|
return options.find((o) => o.value === val)?.label ?? String(val);
|
||||||
};
|
};
|
||||||
|
export let variant: string = '';
|
||||||
|
|
||||||
let isOpen = false;
|
let isOpen = false;
|
||||||
let searchQuery = '';
|
let searchQuery = '';
|
||||||
@@ -55,11 +56,12 @@
|
|||||||
|
|
||||||
<svelte:window on:click={handleClickOutside} />
|
<svelte:window on:click={handleClickOutside} />
|
||||||
|
|
||||||
<div bind:this={dropdownElement} class="relative w-full mb-2">
|
<div bind:this={dropdownElement} class="relative mb-2 w-full" class:dropdown-sm={variant === 'sm'}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
on:click={toggleDropdown}
|
on:click={toggleDropdown}
|
||||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-left transition-colors hover:bg-neutral-700"
|
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-left transition-colors hover:bg-neutral-700"
|
||||||
|
class:dropdown-sm-btn={variant === 'sm'}
|
||||||
>
|
>
|
||||||
{displayValue(value) || placeholder}
|
{displayValue(value) || placeholder}
|
||||||
</button>
|
</button>
|
||||||
@@ -67,12 +69,14 @@
|
|||||||
{#if isOpen}
|
{#if isOpen}
|
||||||
<div
|
<div
|
||||||
class="absolute top-full z-50 mt-1 w-full rounded border border-neutral-700 bg-neutral-800 shadow-lg"
|
class="absolute top-full z-50 mt-1 w-full rounded border border-neutral-700 bg-neutral-800 shadow-lg"
|
||||||
|
class:dropdown-sm-list={variant === 'sm'}
|
||||||
>
|
>
|
||||||
{#if searchable}
|
{#if searchable}
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
class="w-full border-b border-neutral-700 bg-neutral-800 p-2 outline-none"
|
class="w-full border-b border-neutral-700 bg-neutral-800 p-2 outline-none"
|
||||||
|
class:dropdown-sm-input={variant === 'sm'}
|
||||||
bind:value={searchQuery}
|
bind:value={searchQuery}
|
||||||
on:keydown={handleKeyDown}
|
on:keydown={handleKeyDown}
|
||||||
/>
|
/>
|
||||||
@@ -85,6 +89,7 @@
|
|||||||
on:click={() => handleSelect(option.value)}
|
on:click={() => handleSelect(option.value)}
|
||||||
class="w-full border-b border-neutral-700 px-3 py-2 text-left last:border-b-0 hover:bg-neutral-600"
|
class="w-full border-b border-neutral-700 px-3 py-2 text-left last:border-b-0 hover:bg-neutral-600"
|
||||||
class:bg-neutral-700={value === option.value}
|
class:bg-neutral-700={value === option.value}
|
||||||
|
class:dropdown-sm-option={variant === 'sm'}
|
||||||
>
|
>
|
||||||
{option.label}
|
{option.label}
|
||||||
</button>
|
</button>
|
||||||
@@ -93,3 +98,33 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.dropdown-sm {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.dropdown-sm-btn {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
.dropdown-sm-list {
|
||||||
|
min-width: 160px;
|
||||||
|
}
|
||||||
|
.dropdown-sm-input {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
.dropdown-sm-option {
|
||||||
|
padding-top: 0.15rem;
|
||||||
|
padding-bottom: 0.15rem;
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user