PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
content-blocks-builder / src / features / custom-css / custom-css.js

custom-css.js in Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts trunk, at src/features/custom-css/custom-css.js

96 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External dependencies
3 */
4
5 /**
6 * WordPress dependencies
7 */
8 import { __ } from "@wordpress/i18n";
9 import { addFilter } from "@wordpress/hooks";
10 import { createHigherOrderComponent } from "@wordpress/compose";
11 import { InspectorControls } from "@wordpress/block-editor";
12 import { PanelBody } from "@wordpress/components";
13
14 /**
15 * Internal dependencies
16 */
17 import { getSettingFieldValue } from "sdk/utils";
18 import { CodeEditor } from "../../components/code-editor";
19 import { hasSupportCSS } from "./index";
20 import { labels, getProLabel } from "../../utils/labels";
21 import {
22 useStyleBlockControls,
23 userCanEditCSS,
24 useCustomCSSWarning,
25 } from "../../utils";
26
27 /**
28 * Define feature name
29 */
30 const featureName = "customCSS";
31
32 /**
33 * Override the default edit UI to include new inspector controls for custom settings.
34 *
35 * @param {Function} BlockEdit Block edit component.
36 * @return {Function} BlockEdit Modified block edit component.
37 */
38 const withInspectorControls = createHigherOrderComponent((BlockEdit) => {
39 return (props) => {
40 if (!hasSupportCSS(props.name)) {
41 return <BlockEdit {...props} />;
42 }
43
44 const displayBlockControls = useStyleBlockControls();
45
46 const { isSelected, attributes, clientId } = props;
47
48 const customCSS = getSettingFieldValue({
49 fieldName: "customCSS",
50 attributes,
51 defaultValue: {},
52 });
53
54 const { value = "" } = customCSS;
55
56 const canEditCSS = userCanEditCSS();
57
58 // Show the warning
59 useCustomCSSWarning({ canEditCSS, hasCustomCSS: !!value.trim() });
60
61 if (!canEditCSS) {
62 return <BlockEdit {...props} />;
63 }
64
65 return (
66 <>
67 <BlockEdit {...props} />
68 {isSelected && displayBlockControls && (
69 <InspectorControls group="styles">
70 <PanelBody
71 title={getProLabel(labels.customCSS)}
72 initialOpen={!!value}
73 className="cbb-settings"
74 >
75 {!!value ? (
76 <CodeEditor
77 id={`cbb-css-${clientId}`}
78 value={value}
79 help={labels.customCSSHelp}
80 />
81 ) : (
82 <p>{labels.customCSSHelp}</p>
83 )}
84 </PanelBody>
85 </InspectorControls>
86 )}
87 </>
88 );
89 };
90 }, "withInspectorControls");
91 addFilter(
92 "editor.BlockEdit",
93 `boldblocks/${featureName}/withInspectorControls`,
94 withInspectorControls,
95 );
96