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

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

57 lines 1.3 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 __experimentalSpacingSizesControl as SpacingSizesControl,
8 } from "@wordpress/block-editor";
9 import { useSelect, useDispatch } from "@wordpress/data";
10
11 /**
12 * Internal dependencies
13 */
14 import { SpacingControlProps } from "./types";
15
16 /**
17 * Spacing control component
18 * Provides control for padding/margin spacing
19 */
20 const SpacingControl: React.FC<SpacingControlProps> = ({
21 label,
22 attrKey,
23 minimumCustomValue = 0,
24 sides = ["top", "right", "bottom", "left"],
25 }) => {
26 const { clientId } = useBlockEditContext();
27
28 const attributes = useSelect(
29 (select) => select("core/block-editor").getSelectedBlock()?.attributes
30 ) as Record<string, any>;
31
32 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
33
34 const setAttributes = (newAttributes: Record<string, any>) => {
35 updateBlockAttributes(clientId, newAttributes);
36 };
37
38 return (
39 <>
40 <SpacingSizesControl
41 minimumCustomValue={minimumCustomValue}
42 allowReset={true}
43 label={label}
44 values={attributes[attrKey]}
45 sides={sides}
46 onChange={(newValue: any) => {
47 setAttributes({
48 [attrKey]: newValue,
49 });
50 }}
51 />
52 </>
53 );
54 };
55
56 export default SpacingControl;
57