add select

This commit is contained in:
Jesse Winton
2025-04-07 13:01:32 -04:00
parent e272fffcdf
commit cb09712daf
2 changed files with 52 additions and 15 deletions

View File

@@ -215,8 +215,43 @@
max-width: 75rem; max-width: 75rem;
} }
@layer components { @utility border-gradient {
.mask { --border-gradient-before: linear-gradient(
180deg,
rgba(255, 255, 255, 0.16) 0%,
rgba(255, 255, 255, 0) 100%
);
--border-gradient-after: linear-gradient(
180deg,
rgba(255, 255, 255, 0.12) 0%,
rgba(255, 255, 255, 0) 125.11%
);
--border-radius: 0.5rem;
&::before,
&::after {
content: '';
position: absolute;
inset: 0;
border-radius: var(--border-radius);
border: 1px solid transparent;
mask:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(#fff 0 0);
mask-composite: exclude;
pointer-events: none;
}
&::before {
background: var(--border-gradient-before) border-box;
}
&::after {
background: var(--border-gradient-after) border-box;
}
}
@utility mask {
mask-image: linear-gradient( mask-image: linear-gradient(
to var(--mask-direction, top), to var(--mask-direction, top),
transparent, transparent,
@@ -224,7 +259,6 @@
black calc(100% - var(--mask-height, 32px)), black calc(100% - var(--mask-height, 32px)),
black black
); );
}
} }
:root, :root,

View File

@@ -1,7 +1,5 @@
<script lang="ts"> <script lang="ts">
import { classNames } from '$lib/utils/classnames';
import { Select, type SelectProps } from 'melt/builders'; import { Select, type SelectProps } from 'melt/builders';
import type { HTMLButtonAttributes, SvelteHTMLElements } from 'svelte/elements';
type Props = { type Props = {
options: Array<{ options: Array<{
@@ -16,25 +14,30 @@
const { const {
options, options,
value = $bindable(), value = $bindable(),
onValueChange,
defaultValue = 'Select a value', defaultValue = 'Select a value',
...rest ...rest
}: Props = $props(); }: Props = $props();
type Option = (typeof options)[number];
const select = new Select<Option['value']>({ const select = new Select<Props['options'][number]['value']>({
value, value,
sameWidth: true,
forceVisible: false,
...rest ...rest
}); });
</script> </script>
<button <button
class="web-select is-colored text-primary relative flex h-8 min-w-[145px] cursor-pointer items-center text-sm leading-[1] select-none [all:unset]" class="border-gradient text-primary relative flex h-8 min-w-[145px] cursor-pointer items-center text-sm leading-[1] select-none"
{...select.trigger} {...select.trigger}
> >
{select.value ?? defaultValue} {select.value ?? defaultValue}
</button> </button>
<div {...select.content}> <div
class="text-primary relative box-border flex max-w-xs flex-col gap-2 overflow-y-auto rounded-xl p-1 text-sm leading-[1.2] select-none"
{...select.content}
>
{#each options as option} {#each options as option}
<div {...select.getOption(option.value)}> <div {...select.getOption(option.value)}>
{option.label} {option.label}