UNPKG

@wordpress/block-editor

Version:
52 lines (45 loc) 1.28 kB
import { createElement, Fragment } from "@wordpress/element"; /** * External dependencies */ import tinycolor from 'tinycolor2'; /** * WordPress dependencies */ import { useCallback } from '@wordpress/element'; /** * Internal dependencies */ import transformStyles from '../../utils/transform-styles'; const EDITOR_STYLES_SELECTOR = '.editor-styles-wrapper'; function useDarkThemeBodyClassName(styles) { return useCallback(node => { if (!node) { return; } const { ownerDocument } = node; const { defaultView, body } = ownerDocument; const canvas = ownerDocument.querySelector(EDITOR_STYLES_SELECTOR); const backgroundColor = defaultView.getComputedStyle(canvas, null).getPropertyValue('background-color'); if (tinycolor(backgroundColor).getLuminance() > 0.5) { body.classList.remove('is-dark-theme'); } else { body.classList.add('is-dark-theme'); } }, [styles]); } export default function EditorStyles({ styles }) { return createElement(Fragment, null, createElement("style", { ref: useDarkThemeBodyClassName(styles) }), transformStyles(styles, EDITOR_STYLES_SELECTOR).map((css, index) => createElement("style", { key: index }, css))); } //# sourceMappingURL=index.js.map