feat: 实现Tabs组件/样式
This commit is contained in:
23
src/lib/components/ui/tabs/Tabs.svelte
Normal file
23
src/lib/components/ui/tabs/Tabs.svelte
Normal file
@ -0,0 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { Tabs as BitsTabs } from 'bits-ui';
|
||||
import type { Snippet } from 'svelte';
|
||||
// import type { SvelteComponent } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
value?: string;
|
||||
onValueChange?: (value: string) => void;
|
||||
className?: string;
|
||||
children?: Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
value = $bindable(),
|
||||
onValueChange,
|
||||
className,
|
||||
children,
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<BitsTabs.Root bind:value {onValueChange} class={`w-full ${className}`}>
|
||||
{@render children?.()}
|
||||
</BitsTabs.Root>
|
||||
16
src/lib/components/ui/tabs/TabsContent.svelte
Normal file
16
src/lib/components/ui/tabs/TabsContent.svelte
Normal file
@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { Tabs as BitsTabs } from 'bits-ui';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
value: string;
|
||||
className?: string;
|
||||
children?: Snippet;
|
||||
}
|
||||
|
||||
let { value, className, children }: Props = $props();
|
||||
</script>
|
||||
|
||||
<BitsTabs.Content {value} class={`flex-1 outline-none ${className}`}>
|
||||
{@render children?.()}
|
||||
</BitsTabs.Content>
|
||||
17
src/lib/components/ui/tabs/TabsList.svelte
Normal file
17
src/lib/components/ui/tabs/TabsList.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { Tabs as BitsTabs } from 'bits-ui';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
children?: Snippet;
|
||||
}
|
||||
|
||||
let { className, children }: Props = $props();
|
||||
</script>
|
||||
|
||||
<BitsTabs.List
|
||||
class={`tabs-box tabs flex gap-2 border-b border-gray-200 dark:border-gray-700 ${className}`}
|
||||
>
|
||||
{@render children?.()}
|
||||
</BitsTabs.List>
|
||||
20
src/lib/components/ui/tabs/TabsTrigger.svelte
Normal file
20
src/lib/components/ui/tabs/TabsTrigger.svelte
Normal file
@ -0,0 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { Tabs as BitsTabs } from 'bits-ui';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
value: string;
|
||||
className?: string;
|
||||
children?: Snippet;
|
||||
}
|
||||
|
||||
let { value, className, children }: Props = $props();
|
||||
</script>
|
||||
|
||||
<BitsTabs.Trigger
|
||||
{value}
|
||||
class={`tab transition-colors data-[state='active']:bg-white data-[state='active']:shadow data-[state='inactive']:hover:bg-gray-200
|
||||
${className}`}
|
||||
>
|
||||
{@render children?.()}
|
||||
</BitsTabs.Trigger>
|
||||
4
src/lib/components/ui/tabs/index.ts
Normal file
4
src/lib/components/ui/tabs/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export { default as Tabs } from './Tabs.svelte';
|
||||
export { default as TabsList } from './TabsList.svelte';
|
||||
export { default as TabsTrigger } from './TabsTrigger.svelte';
|
||||
export { default as TabsContent } from './TabsContent.svelte';
|
||||
Reference in New Issue
Block a user