Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

FieldTab.tsx

82 lines2.4 KB

1import { Splitter } from '@ark-ui/solid'
2import { For, Show, createSignal } from 'solid-js'
3import { DevtoolsTab } from '../header/TabsNav'
4import { Separator } from '../ui/separator'
5import { ScrollArea } from '../ui/scroll-area'
6import { ResizableSidebar } from '../ui/resizable-sidebar'
7import { FieldDetailCard } from './fieldDetails/FieldDetailCard'
8import { FieldListSearch } from './leftPanel/listSearch/FieldListSearch'
9import { FieldList } from './leftPanel/FieldList'
10import type { SplitterPanelData } from '@ark-ui/solid'
11import { useFormDevtoolsStore } from '@/stores/formDevtoolsStore'
12​
13const sidebarId = 'fieldTabSidebar'
14const mainId = 'fieldTabMain'
15const panels: Array<SplitterPanelData> = [
16 {
17 id: sidebarId,
18 minSize: 10,
19 },
20 {
21 id: mainId,
22 minSize: 20,
23 },
25​
26function Sidebar() {
27 return (
28 <ResizableSidebar
29 sidebarPanelId={sidebarId}
30 mainPanelId={mainId}
31 class="grid gap-2 grid-rows-[auto_1fr]"
32 >
33 <div class="flex flex-col gap-2 px-2 pt-2">
34 <FieldListSearch />
35 <Separator />
36 </div>
37 <ScrollArea class="min-h-0 px-2">
38 <FieldList />
39 </ScrollArea>
40 </ResizableSidebar>
41 )
43​
44export function FieldTab() {
45 const { mainPanelFieldRows } = useFormDevtoolsStore().fieldList
46 const [size, setSize] = createSignal([0.25, 0.75])
47​
48 return (
49 <DevtoolsTab value="field" disableScroll>
50 <Splitter.Root
51 panels={panels}
52 size={size()}
53 onResize={(details) => setSize(details.size)}
54 >
55 <Sidebar />
56 <Splitter.Panel id={mainId} class="size-full min-w-0 relative">
57 <Show
58 when={mainPanelFieldRows().length > 0}
59 fallback={
60 <div class="flex size-full items-center justify-center text-sm text-muted-foreground">
61 No field selected
62 </div>
63 }
64 >
65 <ScrollArea class="size-full">
66 <div class="p-3 flex flex-wrap gap-y-4 gap-2 content-evenly">
67 <For each={mainPanelFieldRows()}>
68 {(field) => (
69 <FieldDetailCard
70 field={field}
71 class="flex-initial w-fit max-w-150 min-w-0"
72 />
73 )}
74 </For>
75 </div>
76 </ScrollArea>
77 </Show>
78 </Splitter.Panel>
79 </Splitter.Root>
80 </DevtoolsTab>
81 )