@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
49 lines (47 loc) • 1.86 kB
JavaScript
import defaultTheme from "../../theme/defaultTheme.js";
import { VuiContextProvider } from "./context.js";
import globalStyle_default from "./globalStyle.js";
import resetCSS_default from "./resetCSS.js";
import { Portal } from "../../portal/portal.js";
import Toaster_default from "../../toast/Toaster.js";
import notifyOffline_default from "./notifyOffline.js";
import { genericReducer, toastsReducer } from "./reducers.js";
import { useReducer } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
import { ThemeProvider } from "styled-components";
//#region src/core/vuiProvider/vuiProvider.tsx
/** Provides theme to all wrapped components and by default includes CSS reset and global styles. */
const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = defaultTheme, notifyOffline = false }) => {
const [toasts, toastsDispatch] = useReducer(toastsReducer, { list: [] });
const [portalSlot, setPortalSlot] = useReducer(genericReducer, null);
const addToast = (toast) => toastsDispatch({
type: "add",
toast
});
const removeToast = (id) => toastsDispatch({
type: "remove",
toast: { id }
});
return /* @__PURE__ */ jsx(VuiContextProvider, {
value: {
toasts,
addToast,
removeToast,
setPortalSlot
},
children: /* @__PURE__ */ jsx(ThemeProvider, {
theme,
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [
resetCSS && /* @__PURE__ */ jsx(resetCSS_default, {}),
/* @__PURE__ */ jsx(globalStyle_default, { globalStyle }),
children,
notifyOffline && /* @__PURE__ */ jsx(notifyOffline_default, {}),
/* @__PURE__ */ jsxs(Portal, { children: [portalSlot, /* @__PURE__ */ jsx(Toaster_default, {})] })
] })
})
});
};
//#endregion
export { VuiProvider as default };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=vuiProvider.js.map