PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
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 0.5.7 All 42 releases
tableberg / components / editor / BorderWithRadiusControl.tsx

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

102 lines 2.9 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 store as BlockEditorStore,
5 __experimentalBorderRadiusControl as RadiusControl,
6 } from "@wordpress/block-editor";
7 import { useSelect } from "@wordpress/data";
8 import {
9 __experimentalToolsPanelItem as ToolsPanelItem,
10 __experimentalBorderBoxControl as BorderBoxControl,
11 PanelBody,
12 } from "@wordpress/components";
13 import { Border } from "@wordpress/components/build-types/border-control/types";
14 import { Borders } from "@wordpress/components/build-types/border-box-control/types";
15 import { CSSProperties } from "react";
16
17 interface BorderWithRadiusControlPropTypes {
18 label: string;
19 value: Border | Borders;
20 onChange: (newBorder: Border | Borders | undefined) => any;
21 radiusValue: any;
22 onRadiusChange: (newRadius: any) => any;
23 resetAllFilter?: () => any;
24 onDeselect: () => any;
25 isShownByDefault?: boolean;
26 children?: any;
27 }
28
29 const objectifyRadius = (radius: CSSProperties["borderRadius"] | string) => {
30 if (typeof radius === "string") {
31 return {
32 topLeft: radius,
33 topRight: radius,
34 bottomRight: radius,
35 bottomLeft: radius,
36 };
37 }
38
39 return radius;
40 };
41
42 function BorderControl({
43 label,
44 isShownByDefault = true,
45 value,
46 onChange = () => {},
47 radiusValue = {},
48 onRadiusChange = () => {},
49 resetAllFilter,
50 onDeselect = () => {},
51 children,
52 }: BorderWithRadiusControlPropTypes) {
53 const { clientId } = useBlockEditContext();
54
55 const { defaultColors } = useSelect(select => {
56 return {
57 defaultColors: (
58 select(BlockEditorStore) as BlockEditorStoreSelectors
59 ).getSettings()?.__experimentalFeatures?.color?.palette?.default,
60 };
61 }, []);
62
63 if (!resetAllFilter) {
64 resetAllFilter = onDeselect;
65 }
66
67 return (
68 <ToolsPanelItem
69 panelId={clientId}
70 isShownByDefault={isShownByDefault}
71 resetAllFilter={resetAllFilter}
72 hasValue={() => true}
73 label={label}
74 onDeselect={onDeselect}
75 >
76 <PanelBody
77 title={label}
78 initialOpen={isShownByDefault}
79 className="tableberg-border-with-radius-control-handle"
80 >
81 {children}
82 <BorderBoxControl
83 enableAlpha
84 size={"__unstable-large"}
85 colors={defaultColors}
86 label={label}
87 onChange={onChange}
88 value={value}
89 />
90 <RadiusControl
91 onChange={(val: any) =>
92 onRadiusChange(objectifyRadius(val))
93 }
94 values={radiusValue}
95 />
96 </PanelBody>
97 </ToolsPanelItem>
98 );
99 }
100
101 export default BorderControl;
102