UNPKG

@cainiaofe/cn-ui-m

Version:
25 lines (24 loc) 841 B
import { __assign, __rest } from "tslib"; import React, { useContext } from 'react'; import zhCN from "../../locales/zh-CN.json"; export var defaultConfigRef = { current: { locale: zhCN, }, }; export function setDefaultConfig(config) { defaultConfigRef.current = config; } export function getDefaultConfig() { return defaultConfigRef.current; } var ConfigContext = React.createContext(null); export var ConfigProvider = function (props) { var children = props.children, config = __rest(props, ["children"]); var parentConfig = useConfig(); return (React.createElement(ConfigContext.Provider, { value: __assign(__assign({}, parentConfig), config) }, children)); }; export function useConfig() { var _a; return (_a = useContext(ConfigContext)) !== null && _a !== void 0 ? _a : getDefaultConfig(); }