Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions components/src/Switcher/Switcher.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
</DesignTokens>
</Story>

<Story name="Hidden Label" asChild>
<DesignTokens theme="light">
<Switcher
hideLabel
options={['Option A', 'Option B']}
value="Option A"
size="default"
label="Label"
/>
</DesignTokens>
</Story>

<Story
name="Four Options"
asChild
Expand Down
13 changes: 12 additions & 1 deletion components/src/Switcher/Switcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Display size
*/
size?: 'default' | 'small';
hideLabel?: boolean;
/**
* The currently-selected option (bindable)
*/
Expand All @@ -28,6 +29,7 @@
label,
options,
size = 'default',
hideLabel = false,
value = $bindable(null),
onchange
}: SwitcherProps = $props();
Expand All @@ -41,7 +43,9 @@
</script>

<fieldset class="container" class:small={size === 'small'}>
<FormLabel as="legend">{label}</FormLabel>
<div class="legend" class:hidden={hideLabel}>
<FormLabel as="legend">{label}</FormLabel>
</div>
<ul>
{#each options as o (o)}
<li class:is-selected={o === value}>
Expand Down Expand Up @@ -69,6 +73,13 @@
font-family: var(--swr-sans);
}

.legend {
&.hidden {
position: absolute;
left: -9999px;
}
}

ul {
width: 100%;
display: flex;
Expand Down