@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
33 lines (32 loc) • 1.38 kB
JavaScript
import { privateApis } from "@wordpress/block-editor";
import { useSetting, useStyle, useStyleWithResolvedBackground } from "./hooks.mjs";
import { unlock } from "./lock-unlock.mjs";
import { jsx } from "react/jsx-runtime";
// packages/global-styles-ui/src/background-panel.tsx
const BACKGROUND_DEFAULT_VALUES = { backgroundSize: "auto" };
const { BackgroundPanel: StylesBackgroundPanel } = unlock(privateApis);
/**
* Checks if there is a current value in the background image block support
* attributes.
*
* @param style Style attribute.
* @return Whether the block has a background image value set.
*/
function hasBackgroundImageValue(style) {
return !!style?.background?.backgroundImage?.id || !!style?.background?.backgroundImage?.url || typeof style?.background?.backgroundImage === "string";
}
function BackgroundPanel() {
const [style] = useStyle("", void 0, "user", false);
const [inheritedStyle, setStyle] = useStyle("", void 0, "merged", false);
const resolvedInheritedStyle = useStyleWithResolvedBackground(inheritedStyle);
const [settings] = useSetting("");
return /* @__PURE__ */ jsx(StylesBackgroundPanel, {
inheritedValue: resolvedInheritedStyle,
value: style,
onChange: setStyle,
settings,
defaultValues: BACKGROUND_DEFAULT_VALUES
});
}
export { BackgroundPanel as default, hasBackgroundImageValue };
//# sourceMappingURL=background-panel.mjs.map