cobalt/web/src/components/buttons/Switcher.svelte
wukko a478993599
web: improve screen reader usability
- switchers now have audible states
- toggles are now interpreted as toggles
- fixed weird spacing introduced in last commit
2024-07-03 14:09:09 +06:00

64 lines
1.6 KiB
Svelte

<script lang="ts">
export let big: boolean = false;
</script>
<div id="switcher-container" class="switcher" class:big={big} role="listbox">
<slot></slot>
</div>
<style>
.switcher {
display: flex;
width: auto;
flex-direction: row;
flex-wrap: nowrap;
scrollbar-width: none;
overflow-x: scroll;
border-radius: var(--border-radius);
}
.switcher :global(.button) {
white-space: nowrap;
}
.switcher:not(.big) :global(.button:first-child) {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.switcher:not(.big) :global(.button:last-child) {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.switcher.big {
background: var(--button);
box-shadow: var(--button-box-shadow);
padding: var(--switcher-padding);
}
.switcher.big :global(.button) {
width: 100%;
/* [base button height] - ([switcher padding] * [padding factor to accommodate for]) */
height: calc(40px - var(--switcher-padding) * 1.5);
border-radius: calc(var(--border-radius) - var(--switcher-padding));;
}
.switcher.big :global(.button:not(:focus-visible)) {
box-shadow: none;
}
.switcher.big :global(.button:not(.active, :hover, :active)) {
background-color: transparent;
}
.switcher:not(.big) :global(.button:not(:first-child, :last-child)) {
border-radius: 0;
}
/* hack to get rid of double border in a list of switches */
.switcher:not(.big) :global(:not(.button:first-child)) {
margin-left: -1.5px;
}
</style>