UNPKG

react-weekly-table

Version:

React weekly scheduler <br/> By default build time ranges for a week, supports up to 31 days <br/> Can work with different timezones, data always return to UTC+0

54 lines (53 loc) 3.31 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { createContext, useCallback, useContext, useEffect, useState, } from 'react'; import { schedulerColumns, schedulerRows, } from '../common'; import { Background, CustomTime, Popup, SchedulerLayout } from '../components'; import CanvasProvider from './CanvasProvider'; import CellsProvider from './CellsProvider'; import CustomTimeProvider from './CustomTimeProvider'; import PointerLockProvider from './PointerLockProvider'; import PopupProvider from './PopupProvider'; import TimeBlockProvider from './TimeBlockProvider'; const SchedulerContext = createContext({}); /** * Scheduler provider context hook * @returns [SchedulerProps]{@link SchedulerProps} */ export const useScheduler = () => useContext(SchedulerContext); /** * Root scheduler components * @param props{@link SchedulerInputProps} initial props */ const Scheduler = (props) => { const [update, setUpdate] = useState(0); const updater = useCallback(() => setUpdate((update) => update + 1), []); useEffect(() => { window.addEventListener('resize', updater); return () => { window.removeEventListener('resize', updater); }; }, []); return (_jsx(SchedulerContext.Provider, Object.assign({ value: { parentRef: props.parentRef, blockColors: (props === null || props === void 0 ? void 0 : props.blockColors) ? props.blockColors : { common: '#ff5722', temp: '#c6a700', draw: '#ff8a50', hover: '#ff3d00', }, headerHeightProp: (props === null || props === void 0 ? void 0 : props.headerHeightProp) ? props.headerHeightProp : 80, helperWidthProp: (props === null || props === void 0 ? void 0 : props.helperWidthProp) ? props.helperWidthProp : 80, bottomHeightProp: (props === null || props === void 0 ? void 0 : props.bottomHeightProp) ? props.bottomHeightProp : 20, baseZIndex: (props === null || props === void 0 ? void 0 : props.baseZIndex) ? props.baseZIndex : 0, timeframe: (props === null || props === void 0 ? void 0 : props.timeframe) ? props.timeframe : 60, columns: (props === null || props === void 0 ? void 0 : props.columns) ? props.columns : schedulerColumns, rows: (props === null || props === void 0 ? void 0 : props.rows) ? props.rows : schedulerRows, requiredTZOffset: props === null || props === void 0 ? void 0 : props.requiredTZOffset, mouseSpeed: (props === null || props === void 0 ? void 0 : props.mouseSpeed) ? props.mouseSpeed : 3, defaultValue: props === null || props === void 0 ? void 0 : props.defaultValue, onChange: props === null || props === void 0 ? void 0 : props.onChange, } }, { children: _jsx(CellsProvider, { children: _jsx(CanvasProvider, { children: _jsx(PointerLockProvider, { children: _jsx(TimeBlockProvider, { children: _jsx(PopupProvider, { children: _jsxs(CustomTimeProvider, { children: [_jsx(Background, {}), _jsx(SchedulerLayout, {}), _jsx(Popup, {}), _jsx(CustomTime, {})] }) }) }) }) }) }) }))); }; export default Scheduler;