({
children,
className,
vertical = false,
}: SplitViewProps)
| 88 | } |
| 89 | |
| 90 | export const SplitView = ({ |
| 91 | children, |
| 92 | className, |
| 93 | vertical = false, |
| 94 | }: SplitViewProps) => { |
| 95 | const [viewMap, setViewMap] = useState(new Map<string, ISplitViewItem>()) |
| 96 | const views = [...viewMap.values()] |
| 97 | |
| 98 | const registerView = useCallback((key: string, view: ISplitViewItem) => { |
| 99 | setViewMap((map) => { |
| 100 | map.set(key, view) |
| 101 | return new Map(map) |
| 102 | }) |
| 103 | }, []) |
| 104 | |
| 105 | const childList = Children.toArray(children) |
| 106 | if (!childList.length) return null |
| 107 | |
| 108 | return ( |
| 109 | <div className={clsx('SplitView relative h-full', className)}> |
| 110 | <SplitViewContext.Provider value={{ registerView }}> |
| 111 | <div |
| 112 | className={clsx( |
| 113 | 'SplitViewContainer flex h-full', |
| 114 | vertical && 'flex-col', |
| 115 | )} |
| 116 | > |
| 117 | {childList.reduce((a, c, i) => ( |
| 118 | <> |
| 119 | {a} |
| 120 | <Sash vertical={vertical} views={[views[i - 1], views[i]]} /> |
| 121 | {c} |
| 122 | </> |
| 123 | ))} |
| 124 | </div> |
| 125 | </SplitViewContext.Provider> |
| 126 | </div> |
| 127 | ) |
| 128 | } |
| 129 | |
| 130 | const SASH_SIZE = 4 |
| 131 | interface SashProps { |
nothing calls this directly
no outgoing calls
no test coverage detected