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

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

72 lines 1.8 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 { useBlockEditContext } from "@wordpress/block-editor";
6 import { useSelect, useDispatch } from "@wordpress/data";
7 import {
8 RangeControl,
9 __experimentalToolsPanelItem as ToolsPanelItem,
10 } from "@wordpress/components";
11
12 /**
13 * Internal dependencies
14 */
15 import { RangeControlWithToolsPanelProps } from "./types";
16
17 /**
18 * Range control component with ToolsPanel integration
19 * Self-managed via useBlockEditContext, wrapped in ToolsPanelItem
20 */
21 const RangeControlWithToolsPanel: React.FC<RangeControlWithToolsPanelProps> = ({
22 label,
23 attrKey,
24 min,
25 max,
26 step,
27 defaultValue = 0,
28 required = false,
29 isShownByDefault = true,
30 }) => {
31 const { clientId } = useBlockEditContext();
32
33 const attributes = useSelect((select) =>
34 select("core/block-editor").getBlockAttributes(clientId),
35 ) as Record<string, any>;
36
37 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
38
39 const setAttributes = (newAttributes: Record<string, any>) => {
40 updateBlockAttributes(clientId, newAttributes);
41 };
42
43 const value = attributes[attrKey];
44
45 return (
46 <ToolsPanelItem
47 panelId={clientId}
48 isShownByDefault={isShownByDefault}
49 label={label}
50 hasValue={() => value !== defaultValue}
51 onDeselect={() => setAttributes({ [attrKey]: defaultValue })}
52 resetAllFilter={() => setAttributes({ [attrKey]: defaultValue })}
53 >
54 <RangeControl
55 label={label}
56 value={value}
57 onChange={(newValue: any) => {
58 setAttributes({ [attrKey]: newValue });
59 }}
60 min={min}
61 max={max}
62 step={step}
63 required={required}
64 __nextHasNoMarginBottom
65 __next40pxDefaultSize
66 />
67 </ToolsPanelItem>
68 );
69 };
70
71 export default RangeControlWithToolsPanel;
72