feat: implement collapsable first level tree

This commit is contained in:
Jean-Philippe Sirois
2019-07-30 06:45:19 -04:00
parent 96d9aec89a
commit 021a1d4aa2
4 changed files with 79 additions and 8 deletions
+35
View File
@@ -0,0 +1,35 @@
import React, { useState } from "react"
interface SidebarProviderProps {
children: React.ReactNode
}
export interface SidebarContextInterface {
current: number
setCurrent: (index: number) => void
}
export const SidebarContext = React.createContext<SidebarContextInterface | null>(
null
)
export function SidebarProvider({
children,
}: SidebarProviderProps): JSX.Element {
const [current, setCurrent] = useState(0)
function selectFirstLevel(index: number) {
setCurrent(index)
}
return (
<SidebarContext.Provider
value={{
current,
setCurrent: selectFirstLevel,
}}
>
{children}
</SidebarContext.Provider>
)
}