import { __ } from "@wordpress/i18n"; import { useBlockEditContext, store as BlockEditorStore, __experimentalBorderRadiusControl as RadiusControl, } from "@wordpress/block-editor"; import { useSelect } from "@wordpress/data"; import { __experimentalToolsPanelItem as ToolsPanelItem, __experimentalBorderBoxControl as BorderBoxControl, PanelBody, } from "@wordpress/components"; import { Border } from "@wordpress/components/build-types/border-control/types"; import { Borders } from "@wordpress/components/build-types/border-box-control/types"; import { CSSProperties } from "react"; interface BorderWithRadiusControlPropTypes { label: string; value: Border | Borders; onChange: (newBorder: Border | Borders | undefined) => any; radiusValue: any; onRadiusChange: (newRadius: any) => any; resetAllFilter?: () => any; onDeselect: () => any; isShownByDefault?: boolean; children?: any; } const objectifyRadius = (radius: CSSProperties["borderRadius"] | string) => { if (typeof radius === "string") { return { topLeft: radius, topRight: radius, bottomRight: radius, bottomLeft: radius, }; } return radius; }; function BorderControl({ label, isShownByDefault = true, value, onChange = () => {}, radiusValue = {}, onRadiusChange = () => {}, resetAllFilter, onDeselect = () => {}, children, }: BorderWithRadiusControlPropTypes) { const { clientId } = useBlockEditContext(); const { defaultColors } = useSelect(select => { return { defaultColors: ( select(BlockEditorStore) as BlockEditorStoreSelectors ).getSettings()?.__experimentalFeatures?.color?.palette?.default, }; }, []); if (!resetAllFilter) { resetAllFilter = onDeselect; } return ( true} label={label} onDeselect={onDeselect} > {children} onRadiusChange(objectifyRadius(val)) } values={radiusValue} /> ); } export default BorderControl;