UNPKG

@wordpress/compose

Version:
42 lines (40 loc) 1.43 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _usePreferredColorScheme = _interopRequireDefault(require("../use-preferred-color-scheme")); /** * Internal dependencies */ /** * Selects which of the passed style objects should be applied depending on the * user's preferred color scheme. * * The "light" color schemed is assumed to be the default, and its styles are * always applied. The "dark" styles will always extend those defined for the * light case. * * @example * const light = { padding: 10, backgroundColor: 'white' }; * const dark = { backgroundColor: 'black' }; * usePreferredColorSchemeStyle( light, dark); * // On light mode: * // => { padding: 10, backgroundColor: 'white' } * // On dark mode: * // => { padding: 10, backgroundColor: 'black' } * @param {Object} lightStyle * @param {Object} darkStyle * @return {Object} the combined styles depending on the current color scheme */ const usePreferredColorSchemeStyle = (lightStyle, darkStyle) => { const colorScheme = (0, _usePreferredColorScheme.default)(); const isDarkMode = colorScheme === 'dark'; return isDarkMode ? { ...lightStyle, ...darkStyle } : lightStyle; }; var _default = exports.default = usePreferredColorSchemeStyle; //# sourceMappingURL=index.native.js.map