import classnames from 'classnames/dedupe';
import {
InspectorControls,
RichText,
useBlockProps,
} from '@wordpress/block-editor';
import {
PanelBody,
ResizableBox,
TabPanel,
TextControl,
ToggleControl,
} from '@wordpress/components';
import { applyFilters } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import ApplyFilters from '../../components/apply-filters';
import ColorIndicator from '../../components/color-indicator';
import ColorPicker from '../../components/color-picker';
import RangeControl from '../../components/range-control';
/**
* Block Edit Class.
*
* @param props
*/
export default function BlockEdit(props) {
const { attributes, setAttributes, isSelected, toggleSelection } = props;
let { className = '' } = props;
const {
caption,
height,
percent,
borderRadius,
striped,
animateInViewport,
showCount,
countPrefix,
countSuffix,
color,
backgroundColor,
hoverColor,
hoverBackgroundColor,
} = attributes;
className = classnames('ghostkit-progress', className);
className = applyFilters('ghostkit.editor.className', className, props);
const blockProps = useBlockProps({ className });
return (
<>
setAttributes({ height: value })}
min={1}
allowCustomMax
/>
setAttributes({ percent: value })}
min={0}
max={100}
/>
setAttributes({ borderRadius: value })
}
allowCustomMax
/>
setAttributes({ showCount: val })}
/>
{showCount ? (
<>
setAttributes({ countPrefix: value })
}
/>
setAttributes({ countSuffix: value })
}
/>
>
) : null}
setAttributes({ striped: val })}
/>
setAttributes({ animateInViewport: val })
}
/>
{__('Colors', 'ghostkit')}
>
}
initialOpen={false}
>
{(tabData) => {
const isHover = tabData.name === 'hover';
return (
<>
setAttributes(
isHover
? { hoverColor: val }
: { color: val }
)
}
alpha
gradient
/>
setAttributes(
isHover
? {
hoverBackgroundColor:
val,
}
: {
backgroundColor:
val,
}
)
}
alpha
gradient
/>
>
);
}}
{!RichText.isEmpty(caption) || isSelected ? (
setAttributes({ caption: newCaption })
}
/>
) : null}
{showCount ? (
{countPrefix}
{percent}
{countSuffix}
) : null}
{
toggleSelection(false);
}}
onResizeStop={(event, direction, elt, delta) => {
setAttributes({
height: parseInt(height + delta.height, 10),
});
toggleSelection(true);
}}
>
{
toggleSelection(false);
}}
onResizeStop={(event, direction, elt, delta) => {
setAttributes({
percent: Math.min(
100,
Math.max(
0,
percent +
parseInt(
(100 * delta.width) /
elt.parentNode.getBoundingClientRect()
.width,
10
)
)
),
});
toggleSelection(true);
}}
/>
>
);
}