📦 Add tabs UI component

This commit is contained in:
pheralb 2024-10-29 18:33:47 +00:00
parent 806452bffa
commit 759a57468f
4 changed files with 80 additions and 0 deletions

18
src/ui/tabs/index.ts Normal file
View File

@ -0,0 +1,18 @@
import { Tabs as TabsPrimitive } from 'bits-ui';
import Content from './tabs-content.svelte';
import List from './tabs-list.svelte';
import Trigger from './tabs-trigger.svelte';
const Root = TabsPrimitive.Root;
export {
Root,
Content,
List,
Trigger,
//
Root as Tabs,
Content as TabsContent,
List as TabsList,
Trigger as TabsTrigger
};

View File

@ -0,0 +1,21 @@
<script lang="ts">
import { Tabs as TabsPrimitive } from 'bits-ui';
import { cn } from '@/utils/cn';
type $$Props = TabsPrimitive.ContentProps;
let className: $$Props['class'] = undefined;
export let value: $$Props['value'];
export { className as class };
</script>
<TabsPrimitive.Content
class={cn(
'focus-visible:ring-ring mt-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
className
)}
{value}
{...$$restProps}
>
<slot />
</TabsPrimitive.Content>

View File

@ -0,0 +1,16 @@
<script lang="ts">
import { Tabs as TabsPrimitive } from 'bits-ui';
import { cn } from '@/utils/cn';
type $$Props = TabsPrimitive.ListProps;
let className: $$Props['class'] = undefined;
export { className as class };
</script>
<TabsPrimitive.List
class={cn('inline-flex h-9 items-center justify-center space-x-1 rounded-lg', className)}
{...$$restProps}
>
<slot />
</TabsPrimitive.List>

View File

@ -0,0 +1,25 @@
<script lang="ts">
import { Tabs as TabsPrimitive } from 'bits-ui';
import { cn } from '@/utils/cn';
type $$Props = TabsPrimitive.TriggerProps;
type $$Events = TabsPrimitive.TriggerEvents;
let className: $$Props['class'] = undefined;
export let value: $$Props['value'];
export { className as class };
</script>
<TabsPrimitive.Trigger
class={cn(
'inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium text-neutral-500 transition-all hover:bg-neutral-300/40 hover:text-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-200 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-neutral-300/40 data-[state=active]:text-black data-[state=active]:shadow dark:text-neutral-400 dark:hover:bg-neutral-800/40 dark:hover:text-white dark:focus-visible:ring-neutral-800 dark:data-[state=active]:bg-neutral-800/40 dark:data-[state=active]:text-white',
className
)}
{value}
{...$$restProps}
on:click
on:keydown
on:focus
>
<slot />
</TabsPrimitive.Trigger>