UNPKG

@wordpress/components

Version:
42 lines (39 loc) 1.44 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * External dependencies */ import { pick } from 'lodash'; /** * WordPress dependencies */ import { createContext, useContext } from '@wordpress/element'; /** * Internal dependencies */ import { BLOCK_STYLE_ATTRIBUTES, getBlockPaddings, getBlockColors } from './utils'; const GlobalStylesContext = createContext({ style: {} }); GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES = BLOCK_STYLE_ATTRIBUTES; export const getMergedGlobalStyles = (globalStyle, wrapperPropsStyle, blockAttributes, defaultColors) => { const blockStyleAttributes = pick(blockAttributes, BLOCK_STYLE_ATTRIBUTES); const mergedStyle = { ...globalStyle, ...wrapperPropsStyle }; const blockPaddings = getBlockPaddings(mergedStyle, wrapperPropsStyle, blockStyleAttributes); const blockColors = getBlockColors(blockStyleAttributes, defaultColors); return { ...mergedStyle, ...blockPaddings, ...blockColors }; }; export const useGlobalStyles = () => { const globalStyles = useContext(GlobalStylesContext); return globalStyles; }; export const withGlobalStyles = WrappedComponent => props => createElement(GlobalStylesContext.Consumer, null, globalStyles => createElement(WrappedComponent, _extends({}, props, { globalStyles: globalStyles }))); export default GlobalStylesContext; //# sourceMappingURL=index.native.js.map