tabs context created
This commit is contained in:
parent
3f8a920fc4
commit
bf678e5f86
2 changed files with 50 additions and 0 deletions
41
space_flow/src/contexts/tabsContext.tsx
Normal file
41
space_flow/src/contexts/tabsContext.tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { createContext, useState } from "react";
|
||||
|
||||
type flow={name:string,id:string,flow:any}
|
||||
|
||||
type TabsContextType={
|
||||
tabIndex:number;
|
||||
setTabIndex:(index:number)=>void;
|
||||
flows:Array<flow>
|
||||
removeFlow:(index:number)=>void;
|
||||
addFlow:(newFlow:flow)=>void;
|
||||
}
|
||||
|
||||
const TabsContextInitialValue = {
|
||||
tabIndex : 0,
|
||||
setTabIndex:(index:number)=>{},
|
||||
flows:[],
|
||||
removeFlow:(index:number)=>{},
|
||||
addFlow:(newFlow:flow)=>{}
|
||||
|
||||
}
|
||||
|
||||
export const TabsContext = createContext<TabsContextType>(TabsContextInitialValue)
|
||||
|
||||
export function TabsProvider({children}){
|
||||
const [tabIndex,setTabIndex] = useState(0)
|
||||
const [flows,setFlows] = useState<Array<flow>>([])
|
||||
function removeFlow(index:number){
|
||||
let newFlows = flows
|
||||
newFlows.splice(index)
|
||||
setFlows(newFlows)
|
||||
}
|
||||
function addFlow(newFlow:flow){
|
||||
setFlows([...flows,newFlow])
|
||||
}
|
||||
|
||||
return(
|
||||
<TabsContext.Provider value={{tabIndex,setTabIndex,flows,removeFlow,addFlow}}>
|
||||
{children}
|
||||
</TabsContext.Provider>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue