cloudaxe-opencode/packages/ui/src/components/tabs.tsx

119 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-10-14 17:06:13 +00:00
import { Tabs as Kobalte } from "@kobalte/core/tabs"
2025-11-13 20:47:25 +00:00
import { Show, splitProps, type JSX } from "solid-js"
2026-01-06 21:21:00 +00:00
import type { ComponentProps, ParentProps, Component } from "solid-js"
2025-10-14 17:06:13 +00:00
export interface TabsProps extends ComponentProps<typeof Kobalte> {
2026-01-06 21:21:00 +00:00
variant?: "normal" | "alt" | "settings"
2025-12-28 01:43:52 +00:00
orientation?: "horizontal" | "vertical"
}
2025-10-14 17:06:13 +00:00
export interface TabsListProps extends ComponentProps<typeof Kobalte.List> {}
2025-11-13 20:47:25 +00:00
export interface TabsTriggerProps extends ComponentProps<typeof Kobalte.Trigger> {
2025-11-24 20:52:32 +00:00
classes?: {
button?: string
}
2025-11-13 20:47:25 +00:00
hideCloseButton?: boolean
closeButton?: JSX.Element
onMiddleClick?: () => void
2025-11-13 20:47:25 +00:00
}
2025-10-14 17:06:13 +00:00
export interface TabsContentProps extends ComponentProps<typeof Kobalte.Content> {}
function TabsRoot(props: TabsProps) {
2025-12-28 01:43:52 +00:00
const [split, rest] = splitProps(props, ["class", "classList", "variant", "orientation"])
2025-10-14 17:06:13 +00:00
return (
<Kobalte
{...rest}
2025-12-28 01:43:52 +00:00
orientation={split.orientation}
2025-10-14 17:06:13 +00:00
data-component="tabs"
data-variant={split.variant || "normal"}
2025-12-28 01:43:52 +00:00
data-orientation={split.orientation || "horizontal"}
2025-10-14 17:06:13 +00:00
classList={{
...(split.classList ?? {}),
[split.class ?? ""]: !!split.class,
}}
/>
)
}
function TabsList(props: TabsListProps) {
const [split, rest] = splitProps(props, ["class", "classList"])
return (
<Kobalte.List
{...rest}
data-slot="tabs-list"
2025-10-14 17:06:13 +00:00
classList={{
...(split.classList ?? {}),
[split.class ?? ""]: !!split.class,
}}
/>
)
}
function TabsTrigger(props: ParentProps<TabsTriggerProps>) {
2025-11-24 20:52:32 +00:00
const [split, rest] = splitProps(props, [
"class",
"classList",
"classes",
"children",
"closeButton",
"hideCloseButton",
"onMiddleClick",
2025-11-24 20:52:32 +00:00
])
2025-10-14 17:06:13 +00:00
return (
2025-11-13 20:47:25 +00:00
<div
data-slot="tabs-trigger-wrapper"
2025-10-14 17:06:13 +00:00
classList={{
...(split.classList ?? {}),
[split.class ?? ""]: !!split.class,
}}
onAuxClick={(e) => {
if (e.button === 1 && split.onMiddleClick) {
e.preventDefault()
split.onMiddleClick()
}
}}
2025-10-14 17:06:13 +00:00
>
2025-11-24 20:52:32 +00:00
<Kobalte.Trigger
{...rest}
data-slot="tabs-trigger"
2025-11-24 20:52:32 +00:00
classList={{ "group/tab": true, [split.classes?.button ?? ""]: split.classes?.button }}
>
2025-11-13 20:47:25 +00:00
{split.children}
</Kobalte.Trigger>
<Show when={split.closeButton}>
{(closeButton) => (
<div data-slot="tabs-trigger-close-button" data-hidden={split.hideCloseButton}>
2025-11-13 20:47:25 +00:00
{closeButton()}
</div>
)}
</Show>
</div>
2025-10-14 17:06:13 +00:00
)
}
function TabsContent(props: ParentProps<TabsContentProps>) {
const [split, rest] = splitProps(props, ["class", "classList", "children"])
return (
<Kobalte.Content
{...rest}
data-slot="tabs-content"
2025-10-14 17:06:13 +00:00
classList={{
...(split.classList ?? {}),
[split.class ?? ""]: !!split.class,
}}
>
{split.children}
</Kobalte.Content>
)
}
2026-01-06 21:21:00 +00:00
const TabsSectionTitle: Component<ParentProps> = (props) => {
return <div data-slot="tabs-section-title">{props.children}</div>
}
2025-10-14 17:06:13 +00:00
export const Tabs = Object.assign(TabsRoot, {
List: TabsList,
Trigger: TabsTrigger,
Content: TabsContent,
2026-01-06 21:21:00 +00:00
SectionTitle: TabsSectionTitle,
2025-10-14 17:06:13 +00:00
})