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

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

85 lines 2.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 { useDispatch, useSelect } from "@wordpress/data";
6 import { __ } from "@wordpress/i18n";
7 import {
8 useBlockEditContext,
9 __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,
10 __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients,
11 } from "@wordpress/block-editor";
12
13 /**
14 * Internal dependencies
15 */
16 import { ColorSettingsWithToolsPanelProps } from "./types";
17
18 /**
19 * Color settings component with ToolsPanel integration
20 * Passes panelId to ColorGradientSettingsDropdown so it registers as a ToolsPanelItem
21 * automatically inside an InspectorControls group="color" slot
22 */
23 const ColorSettingsWithToolsPanel: React.FC<
24 ColorSettingsWithToolsPanelProps
25 > = ({ label, attrKey, onAttributesUpdate = () => null }) => {
26 const { clientId } = useBlockEditContext();
27 const { updateBlockAttributes } = useDispatch("core/block-editor") as any;
28
29 const attributes = useSelect((select) => {
30 return select("core/block-editor").getBlockAttributes(clientId);
31 }) as Record<string, any>;
32
33 const setAttributes = (newAttributes: Record<string, any>) => {
34 updateBlockAttributes(clientId, newAttributes);
35 onAttributesUpdate(newAttributes);
36 };
37
38 const colorGradientSettings = useMultipleOriginColorsAndGradients();
39
40 const { defaultColors } = useSelect((select) => {
41 return {
42 defaultColors:
43 select("core/block-editor")?.getSettings()?.__experimentalFeatures
44 ?.color?.palette?.default,
45 };
46 }) as { defaultColors: any };
47
48 const mergedColors = [
49 ...(colorGradientSettings.colors || []),
50 ...(defaultColors
51 ? [
52 {
53 name: "Default",
54 slug: "default",
55 colors: defaultColors,
56 },
57 ]
58 : []),
59 ];
60
61 return (
62 <ColorGradientSettingsDropdown
63 {...colorGradientSettings}
64 colors={mergedColors}
65 enableAlpha
66 title={__("Color Settings", "sliderberg")}
67 panelId={clientId}
68 popoverProps={{
69 placement: "left start",
70 }}
71 settings={[
72 {
73 clearable: true,
74 colorValue: attributes[attrKey],
75 label: label,
76 onColorChange: (newValue: any) =>
77 setAttributes({ [attrKey]: newValue }),
78 },
79 ]}
80 />
81 );
82 };
83
84 export default ColorSettingsWithToolsPanel;
85