impr: change Switch.svelte into radio based system

This commit is contained in:
Xylight committed 2025-09-24 16:51:25 -07:00
1 parent 6f2c7c8d2f
commit d85b889409
4 files changed
+44 -17

No files matched your search

+37 -12
View File
@@ -21,24 +21,49 @@
onselect,
}: Props = $props()
let selectedIndex = $state(0)
let id = $props.id()
/* you see id like this to be a super simple
*/
$effect(() => {
onselect?.(selected)
const newIndex = options.findIndex((i) => i === selected)
if (newIndex !== -1) {
selectedIndex = newIndex
}
})
$effect(() => {
const newSelected = options[selectedIndex]
if (newSelected !== undefined && newSelected !== selected) {
selected = newSelected
onselect?.(newSelected)
}
})
</script>
<div
<fieldset
class="flex items-center gap-1 w-max max-w-full z-0 relative overflow-auto"
>
{#each options as option, index}
{@const slctd = selected == option}
<TabButton
selected={slctd}
onselect={() => (selected = option)}
disabled={disabled[index]}
type="button"
>
{optionNames[index] || option}
</TabButton>
<label>
<input
type="radio"
bind:group={selectedIndex}
value={index}
name={id}
id="{id}-{option?.toString()}"
class="hidden"
/>
<TabButton
selected={selectedIndex == index}
disabled={disabled[index]}
element="div"
>
{optionNames[index] || option}
</TabButton>
</label>
{/each}
</div>
</fieldset>
{@render children?.({ selected })}
@@ -11,6 +11,7 @@
selected?: boolean
children: Snippet
size?: keyof typeof sizes
element?: 'div' | 'a' | 'button'
[key: string]: any
}
@@ -21,12 +22,13 @@
children,
href,
size = 'sm',
element = href ? 'a' : 'button',
...rest
}: Props = $props()
</script>
<svelte:element
this={href ? 'a' : 'button'}
this={element}
class={[
sizes[size],
'rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer border shadow-xs',
+2 -2
View File
@@ -88,7 +88,7 @@
<Label
text={label}
customText={customLabel}
class={['space-y-1 relative max-w-full w-max', baseClass]}
class={['space-y-1 relative max-w-full w-max min-w-0', baseClass]}
>
<div class="relative max-w-full" role="presentation">
<select
@@ -97,7 +97,7 @@
bind:this={element}
class={[
buttonSize[size],
'btn btn-secondary select rounded-xl appearance-none pr-6!',
'btn btn-secondary select rounded-xl appearance-none pr-6! w-full',
selectClass,
clazz,
]}
+2 -2
View File
@@ -41,8 +41,8 @@
<Header pageHeader>
{$t('routes.frontpage.title')}
{#snippet extended()}
<form class="" method="get" action={page.url.pathname}>
<div class="flex flex-row gap-2">
<form class="contents" method="get" action={page.url.pathname}>
<div class="flex flex-row gap-2 max-w-full">
<Location
name="type"
navigate