PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.2.0
Tableberg – Simple Gutenberg Table Block v1.2.0
1.2.0 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 All 43 releases
tableberg / components / editor / ColorPickerDropdown.tsx

ColorPickerDropdown.tsx in Tableberg – Simple Gutenberg Table Block 1.2.0, at components/editor/ColorPickerDropdown.tsx

49 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Button, ColorIndicator, Dropdown } from "@wordpress/components";
2
3 import { ColorPalette } from "@wordpress/block-editor";
4 import { useColorPalettes } from "./useColorPalettes";
5 import { Color } from "@wordpress/components/build-types/palette-edit/types";
6
7 import "./color-picker-dropdown-style.scss";
8
9 export interface ColorPickerDropdownProps {
10 label: string;
11 value: string;
12 onChange: (value?: string) => void;
13 colors?: Color[];
14 }
15
16 const ColorPickerDropdown = (props: ColorPickerDropdownProps) => {
17 // Callers that pass no palette (e.g. the search highlight colour) used to
18 // get an empty swatch list. Fall back to the editor's own origins so the
19 // theme's Styles palette shows up here too.
20 const paletteColors = useColorPalettes();
21
22 return (
23 <Dropdown
24 className="tableberg-dropdown-color-picker"
25 contentClassName="tbdcp-picker"
26 popoverProps={{ placement: "bottom-start" }}
27 renderToggle={({ isOpen, onToggle }) => (
28 <Button
29 className="tbdcp-dropdown-handle"
30 onClick={onToggle}
31 aria-expanded={isOpen}
32 >
33 <ColorIndicator colorValue={props.value} />
34 <label className="tbdcp-label">{props.label}</label>
35 </Button>
36 )}
37 renderContent={() => (
38 <ColorPalette
39 value={props.value}
40 onChange={props.onChange}
41 colors={props.colors ?? paletteColors}
42 />
43 )}
44 />
45 );
46 };
47
48 export default ColorPickerDropdown;
49