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

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

96 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from "@wordpress/i18n";
2 import {
3 useBlockEditContext,
4 __experimentalBorderRadiusControl as RadiusControl,
5 } from "@wordpress/block-editor";
6 import { useColorPalettes } from "./useColorPalettes";
7 import {
8 __experimentalToolsPanelItem as ToolsPanelItem,
9 __experimentalBorderBoxControl as BorderBoxControl,
10 PanelBody,
11 } from "@wordpress/components";
12 import { Border } from "@wordpress/components/build-types/border-control/types";
13 import { Borders } from "@wordpress/components/build-types/border-box-control/types";
14 import { CSSProperties } from "react";
15
16 interface BorderWithRadiusControlPropTypes {
17 label: string;
18 value: Border | Borders;
19 onChange: (newBorder: Border | Borders | undefined) => any;
20 radiusValue: any;
21 onRadiusChange: (newRadius: any) => any;
22 resetAllFilter?: () => any;
23 onDeselect: () => any;
24 isShownByDefault?: boolean;
25 children?: any;
26 }
27
28 const objectifyRadius = (radius: CSSProperties["borderRadius"] | string) => {
29 if (typeof radius === "string") {
30 return {
31 topLeft: radius,
32 topRight: radius,
33 bottomRight: radius,
34 bottomLeft: radius,
35 };
36 }
37
38 return radius;
39 };
40
41 function BorderControl({
42 label,
43 isShownByDefault = true,
44 value,
45 onChange = () => {},
46 radiusValue = {},
47 onRadiusChange = () => {},
48 resetAllFilter,
49 onDeselect = () => {},
50 children,
51 }: BorderWithRadiusControlPropTypes) {
52 const { clientId } = useBlockEditContext();
53
54 // Theme, Default and Custom origins.
55 const colors = useColorPalettes();
56
57 if (!resetAllFilter) {
58 resetAllFilter = onDeselect;
59 }
60
61 return (
62 <ToolsPanelItem
63 panelId={clientId}
64 isShownByDefault={isShownByDefault}
65 resetAllFilter={resetAllFilter}
66 hasValue={() => true}
67 label={label}
68 onDeselect={onDeselect}
69 >
70 <PanelBody
71 title={label}
72 initialOpen={isShownByDefault}
73 className="tableberg-border-with-radius-control-handle"
74 >
75 {children}
76 <BorderBoxControl
77 enableAlpha
78 size={"__unstable-large"}
79 colors={colors}
80 label={label}
81 onChange={onChange}
82 value={value}
83 />
84 <RadiusControl
85 onChange={(val: any) =>
86 onRadiusChange(objectifyRadius(val))
87 }
88 values={radiusValue}
89 />
90 </PanelBody>
91 </ToolsPanelItem>
92 );
93 }
94
95 export default BorderControl;
96