components.wm.contexts.WindowContext.tsx Maven / Gradle / Ivy
import React, { createContext } from 'react';
import { SetState } from 'types/react';
import { useWindowContext } from '../hooks/useWindowContext';
import { PageConfig, PaneSplitType, WindowState } from '../types';
interface WindowContextProps extends WindowContextBaseProps {
setConfigs: SetState
configs: PageConfig[]
}
type WindowContextBaseProps = {
orientation: PaneSplitType
setOrientation: SetState
windowState: WindowState
setWindowState: SetState
width: string
setWidth: SetState
}
interface WindowProviderProps extends WindowContextBaseProps {
children: React.ReactNode;
}
export const WindowContext = createContext({} as WindowContextProps);
export const WindowProvider = ({ children, ...props }: WindowProviderProps): JSX.Element => {
const actions = useWindowContext();
const { windowState, setWindowState } = props
const setConfigs: SetState = (configs) => {
setWindowState(state => ({...state, configs: typeof configs == 'function' ? configs(state.configs) : configs }))
}
return (
{children}
);
};