PluginProbe
Slider Block by Sliderberg – WordPress Slider & Carousel Plugin for Gutenberg / trunk
Slider Block by Sliderberg – WordPress Slider & Carousel Plugin for Gutenberg vtrunk
1.2.3 1.2.2 1.2.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.7 1.0.8 1.0.9
sliderberg / shared / src / components / BorderControlWithToolsPanel.tsx

BorderControlWithToolsPanel.tsx in Slider Block by Sliderberg – WordPress Slider & Carousel Plugin for Gutenberg trunk, at shared/src/components/BorderControlWithToolsPanel.tsx

116 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import React from "react";
5 import {
6 useBlockEditContext,
7 __experimentalBorderRadiusControl as BorderRadiusControl,
8 } from "@wordpress/block-editor";
9 import { useSelect, useDispatch } from "@wordpress/data";
10 import {
11 BaseControl,
12 __experimentalBorderBoxControl as BorderBoxControl,
13 __experimentalToolsPanelItem as ToolsPanelItem,
14 } from "@wordpress/components";
15
16 /**
17 * Internal dependencies
18 */
19 import { BorderControlWithToolsPanelProps } from "./types";
20 import { splitBorderRadius } from "./utils/styling-helpers";
21
22 /**
23 * Border control component with ToolsPanel integration
24 * Each sub-control (border + border radius) is wrapped in its own ToolsPanelItem
25 */
26 const BorderControlWithToolsPanel: React.FC<
27 BorderControlWithToolsPanelProps
28 > = ({
29 borderLabel,
30 attrBorderKey,
31 borderRadiusLabel,
32 attrBorderRadiusKey,
33 isShowBorder = true,
34 isShowBorderRadius = true,
35 showDefaultBorder = false,
36 showDefaultBorderRadius = false,
37 }) => {
38 const { clientId } = useBlockEditContext();
39
40 const attributes = useSelect((select) =>
41 select("core/block-editor").getBlockAttributes(clientId),
42 ) as Record<string, any>;
43
44 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
45
46 const setAttributes = (newAttributes: Record<string, any>) => {
47 updateBlockAttributes(clientId, newAttributes);
48 };
49
50 const { defaultColors } = useSelect((select) => {
51 return {
52 defaultColors:
53 select("core/block-editor")?.getSettings()?.__experimentalFeatures
54 ?.color?.palette?.default,
55 };
56 }) as { defaultColors: any };
57
58 return (
59 <>
60 {isShowBorder && (
61 <ToolsPanelItem
62 panelId={clientId}
63 isShownByDefault={showDefaultBorder}
64 label={borderLabel}
65 hasValue={() =>
66 attributes[attrBorderKey] != null &&
67 Object.keys(attributes[attrBorderKey] || {}).length > 0
68 }
69 onDeselect={() => setAttributes({ [attrBorderKey]: {} })}
70 resetAllFilter={() => setAttributes({ [attrBorderKey]: {} })}
71 >
72 <BorderBoxControl
73 enableAlpha
74 size={"__unstable-large"}
75 colors={defaultColors}
76 label={borderLabel}
77 onChange={(newBorder: any) => {
78 setAttributes({ [attrBorderKey]: newBorder });
79 }}
80 value={attributes[attrBorderKey]}
81 />
82 </ToolsPanelItem>
83 )}
84
85 {isShowBorderRadius && (
86 <ToolsPanelItem
87 panelId={clientId}
88 isShownByDefault={showDefaultBorderRadius}
89 label={borderRadiusLabel}
90 hasValue={() =>
91 attributes[attrBorderRadiusKey] != null &&
92 Object.keys(attributes[attrBorderRadiusKey] || {}).length > 0
93 }
94 onDeselect={() => setAttributes({ [attrBorderRadiusKey]: {} })}
95 resetAllFilter={() => setAttributes({ [attrBorderRadiusKey]: {} })}
96 >
97 <BaseControl.VisualLabel as="legend">
98 {borderRadiusLabel}
99 </BaseControl.VisualLabel>
100 <div className="sliderberg-border-radius-control">
101 <BorderRadiusControl
102 values={attributes[attrBorderRadiusKey]}
103 onChange={(newBorderRadius: any) => {
104 const splitted = splitBorderRadius(newBorderRadius);
105 setAttributes({ [attrBorderRadiusKey]: splitted });
106 }}
107 />
108 </div>
109 </ToolsPanelItem>
110 )}
111 </>
112 );
113 };
114
115 export default BorderControlWithToolsPanel;
116