mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-09-20 01:49:05 +02:00
39 lines
911 B
Svelte
39 lines
911 B
Svelte
<script lang="ts">
|
|
import { replaceState } from '$app/navigation';
|
|
import { page } from '$app/state';
|
|
import { cn } from '$lib/utils/style.js';
|
|
import { Tabs as TabsPrimitive } from 'bits-ui';
|
|
import { onMount } from 'svelte';
|
|
|
|
let {
|
|
ref = $bindable(null),
|
|
value = $bindable(''),
|
|
useHash = false,
|
|
class: className,
|
|
...restProps
|
|
}: TabsPrimitive.RootProps & {
|
|
useHash?: boolean;
|
|
} = $props();
|
|
|
|
onMount(() => {
|
|
if (useHash && page.url.hash) {
|
|
value = page.url.hash.substring(1);
|
|
}
|
|
});
|
|
|
|
function onTabChange(newValue: string) {
|
|
if (useHash && page.url.hash.substring(1) !== newValue) {
|
|
replaceState(location.pathname + location.search + `#${newValue}`, page.state);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<TabsPrimitive.Root
|
|
bind:ref
|
|
bind:value
|
|
onValueChange={onTabChange}
|
|
data-slot="tabs"
|
|
class={cn('gap-2 group/tabs flex data-[orientation=horizontal]:flex-col', className)}
|
|
{...restProps}
|
|
/>
|