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 / BorderControl.tsx

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

92 lines 2.4 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 } from "@wordpress/components";
14
15 /**
16 * Internal dependencies
17 */
18 import { BorderControlProps } from "./types";
19 import { splitBorderRadius } from "./utils/styling-helpers";
20
21 /**
22 * Border control component
23 * Provides dual control for border and border radius with ToolsPanel integration
24 */
25 const BorderControl: React.FC<BorderControlProps> = ({
26 borderLabel,
27 attrBorderKey,
28 borderRadiusLabel,
29 attrBorderRadiusKey,
30 isShowBorder = true,
31 isShowBorderRadius = true,
32 }) => {
33 const { clientId } = useBlockEditContext();
34
35 const attributes = useSelect((select) =>
36 select("core/block-editor").getBlockAttributes(clientId),
37 ) as Record<string, any>;
38
39 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
40
41 const setAttributes = (newAttributes: Record<string, any>) => {
42 updateBlockAttributes(clientId, newAttributes);
43 };
44
45 const { defaultColors } = useSelect((select) => {
46 return {
47 defaultColors:
48 select("core/block-editor")?.getSettings()?.__experimentalFeatures
49 ?.color?.palette?.default,
50 };
51 }) as { defaultColors: any };
52
53 return (
54 <>
55 {isShowBorder && (
56 <BorderBoxControl
57 enableAlpha
58 size={"__unstable-large"}
59 colors={defaultColors}
60 label={borderLabel}
61 onChange={(newBorder: any) => {
62 setAttributes({ [attrBorderKey]: newBorder });
63 }}
64 value={attributes[attrBorderKey]}
65 />
66 )}
67
68 {isShowBorderRadius && (
69 <div>
70 <BaseControl.VisualLabel as="legend">
71 {borderRadiusLabel}
72 </BaseControl.VisualLabel>
73 <div className="sliderberg-border-radius-control">
74 <BorderRadiusControl
75 values={attributes[attrBorderRadiusKey]}
76 onChange={(newBorderRadius: any) => {
77 const splitted = splitBorderRadius(newBorderRadius);
78
79 setAttributes({
80 [attrBorderRadiusKey]: splitted,
81 });
82 }}
83 />
84 </div>
85 </div>
86 )}
87 </>
88 );
89 };
90
91 export default BorderControl;
92