UNPKG

@wordpress/components

Version:
56 lines (52 loc) 1.36 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { useMemo } from '@wordpress/element'; /** * Internal dependencies */ import { colorVariables, Wrapper } from './styles'; import { generateThemeVariables } from './color-algorithms'; import { useCx } from '../utils'; /** * `Theme` allows defining theme variables for components in the `@wordpress/components` package. * * Multiple `Theme` components can be nested in order to override specific theme variables. * * * @example * ```jsx * import { __experimentalTheme as Theme } from '@wordpress/components'; * * const Example = () => { * return ( * <Theme accent="red"> * <Button variant="primary">I'm red</Button> * <Theme accent="blue"> * <Button variant="primary">I'm blue</Button> * </Theme> * </Theme> * ); * }; * ``` */ function Theme(_ref) { let { accent, background, className, ...props } = _ref; const cx = useCx(); const classes = useMemo(() => cx(...colorVariables(generateThemeVariables({ accent, background })), className), [accent, background, className, cx]); return createElement(Wrapper, _extends({ className: classes }, props)); } export default Theme; //# sourceMappingURL=index.js.map