1
0
resumarkdown/src/lib/components/nav-item.svelte

74 lines
1.4 KiB
Svelte
Raw Normal View History

2024-10-11 01:03:27 -05:00
<script lang="ts">
import { pane, type Pane } from '$lib/stores/nav';
export let destination: Pane;
let selected: boolean;
2024-10-11 01:45:12 -05:00
$: selected = destination === $pane;
2024-10-12 01:50:08 -05:00
// we need to hide the "preview" tab on desktop
let hiddenOnDesktop: boolean;
$: hiddenOnDesktop = destination === 'preview';
2024-10-11 01:03:27 -05:00
function handleKey({ key }: KeyboardEvent) {
if (key === ' ' || key === 'Enter' || key === 'Spacebar') {
navigate();
}
}
function navigate() {
pane.set(destination);
}
</script>
<li
2024-10-11 21:26:16 -05:00
aria-controls={`pane-${destination}`}
2024-10-11 01:45:12 -05:00
aria-selected={selected}
2024-10-11 01:03:27 -05:00
role="tab"
tabindex="0"
2024-10-12 01:50:08 -05:00
class:hiddenOnDesktop
2024-10-11 01:45:12 -05:00
class:selected
2024-10-11 01:03:27 -05:00
on:click={navigate}
on:keyup={handleKey}
>
<slot />
</li>
2024-10-11 00:23:32 -05:00
<style lang="less">
li {
2024-10-11 23:30:16 -05:00
font-weight: @weight-semibold;
2024-10-11 00:23:32 -05:00
margin: 0;
padding: @padding-md;
text-align: center;
2024-10-11 01:45:12 -05:00
transition: background-color 0.2s;
2024-10-11 23:10:25 -05:00
@media screen and (min-width: @sizes[lg]) {
flex-grow: 1;
2024-10-12 01:50:08 -05:00
&.hiddenOnDesktop {
display: none;
}
2024-10-11 23:10:25 -05:00
}
2024-10-11 22:59:30 -05:00
&.selected {
background-color: darken(@color-light, 20%);
}
2024-10-11 01:45:12 -05:00
2024-10-11 22:59:30 -05:00
&:focus,
&:hover {
background-color: darken(@color-light, 10%);
}
2024-10-11 00:23:32 -05:00
2024-10-11 22:59:30 -05:00
&:not(:last-of-type) {
2024-10-11 23:10:25 -05:00
@separator: 1px solid @color-dark;
border-bottom: @separator;
@media screen and (min-width: @sizes[lg]) {
border-bottom: unset;
border-right: @separator;
}
2024-10-11 22:59:30 -05:00
}
2024-10-11 00:23:32 -05:00
}
</style>