UNPKG

@bianic-ui/system

Version:

Bianic UI system primitives

53 lines (50 loc) 1.58 kB
import { useColorMode } from "@bianic-ui/color-mode"; import { css } from "@bianic-ui/styled-system"; import { createContext, get, merge, runIfFn } from "@bianic-ui/utils"; import { Global, ThemeContext } from "@emotion/core"; import * as React from "react"; export var ThemeProvider = props => { var { children, theme } = props; var outerTheme = React.useContext(ThemeContext); var mergedTheme = merge({}, outerTheme, theme); return /*#__PURE__*/React.createElement(ThemeContext.Provider, { value: mergedTheme }, children); }; export function useTheme() { var theme = React.useContext(ThemeContext); if (!theme) { throw Error("useTheme: `theme` is undefined. Seems you forgot to wrap your app in `<BianicProvider />`"); } return theme; } var [StylesProvider, useStyles] = createContext({ name: "StylesContext", errorMessage: "useStyles: `styles` is undefined. Seems you forgot to wrap the components in `<StylesProvider />` " }); export { StylesProvider, useStyles }; /** * Applies styles defined in `theme.styles.global` globally * using emotion's `Global` component */ export var GlobalStyle = () => { var { colorMode } = useColorMode(); return /*#__PURE__*/React.createElement(Global, { styles: theme => { var styleObjectOrFn = get(theme, "styles.global"); var globalStyles = runIfFn(styleObjectOrFn, { theme, colorMode }); if (!globalStyles) return; var styles = css(globalStyles)(theme); return styles; } }); }; //# sourceMappingURL=providers.js.map