PluginProbe
Slider Block by Sliderberg – WordPress Slider & Carousel Plugin for Gutenberg / 1.2.3
Slider Block by Sliderberg – WordPress Slider & Carousel Plugin for Gutenberg v1.2.3
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 / SpacingControlWithToolsPanel.tsx

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

52 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 { SpacingControlWithToolsPanelProps } from "./types";
15
16 /**
17 * Spacing control with ToolsPanel component
18 * Provides spacing control wrapped in ToolsPanel for reset functionality
19 */
20 const SpacingControlWithToolsPanel: React.FC<
21 SpacingControlWithToolsPanelProps
22 > = ({ label, attrKey, minimumCustomValue = 0 }) => {
23 const { clientId } = useBlockEditContext();
24
25 const attributes = useSelect((select) =>
26 select("core/block-editor").getBlockAttributes(clientId),
27 ) as Record<string, any>;
28
29 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
30
31 const setAttributes = (newAttributes: Record<string, any>) => {
32 updateBlockAttributes(clientId, newAttributes);
33 };
34
35 return (
36 <SpacingSizesControl
37 minimumCustomValue={minimumCustomValue}
38 allowReset={true}
39 label={label}
40 values={attributes[attrKey]}
41 sides={["top", "right", "bottom", "left"]}
42 onChange={(newValue: any) => {
43 setAttributes({
44 [attrKey]: newValue,
45 });
46 }}
47 />
48 );
49 };
50
51 export default SpacingControlWithToolsPanel;
52