summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/ui/tabs.tsx
blob: d82d3327ace1c71df0cb23c5e5e93945f424a649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Tabs as KobalteTabs } from "@kobalte/core/tabs"
import { splitProps } from "solid-js"
import type { ComponentProps, ParentProps } from "solid-js"

export interface TabsProps extends ComponentProps<typeof KobalteTabs> {}
export interface TabsListProps extends ComponentProps<typeof KobalteTabs.List> {}
export interface TabsTriggerProps extends ComponentProps<typeof KobalteTabs.Trigger> {}
export interface TabsContentProps extends ComponentProps<typeof KobalteTabs.Content> {}

function TabsRoot(props: TabsProps) {
  return <KobalteTabs {...props} />
}

function TabsList(props: TabsListProps) {
  const [local, others] = splitProps(props, ["class"])
  return (
    <KobalteTabs.List
      classList={{
        "relative flex items-center bg-background overflow-x-auto no-scrollbar": true,
        "divide-x divide-border-subtle/40": true,
        "after:content-[''] after:block after:grow after:h-8": true,
        "after:border-l empty:after:border-l-0! after:border-b after:border-border-subtle/40": true,
        [local.class ?? ""]: !!local.class,
      }}
      {...others}
    />
  )
}

function TabsTrigger(props: ParentProps<TabsTriggerProps>) {
  const [local, others] = splitProps(props, ["class", "children"])
  return (
    <KobalteTabs.Trigger
      classList={{
        "relative px-3 h-8 flex items-center": true,
        "text-sm font-medium text-text-muted/60 cursor-pointer": true,
        "whitespace-nowrap shrink-0 border-b border-border-subtle/40": true,
        "disabled:pointer-events-none disabled:opacity-50": true,
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring": true,
        "data-[selected]:text-text data-[selected]:bg-background-panel": true,
        "data-[selected]:!border-b-transparent": true,
        [local.class ?? ""]: !!local.class,
      }}
      {...others}
    >
      {local.children}
    </KobalteTabs.Trigger>
  )
}

function TabsContent(props: ParentProps<TabsContentProps>) {
  const [local, others] = splitProps(props, ["class", "children"])
  return (
    <KobalteTabs.Content
      classList={{
        "bg-background-panel overflow-y-auto h-full no-scrollbar": true,
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring": true,
        [local.class ?? ""]: !!local.class,
      }}
      {...others}
    >
      {local.children}
    </KobalteTabs.Content>
  )
}

export const Tabs = Object.assign(TabsRoot, {
  List: TabsList,
  Trigger: TabsTrigger,
  Content: TabsContent,
})