import clsx from 'clsx';
import {
getColorClassName,
InspectorControls,
useBlockProps,
__experimentalUseColorProps as useColorProps,
} from '@wordpress/block-editor';
import { HorizontalRule } from '@wordpress/components';
import { SelectControl } from '@wordpress/ui';
import { __ } from '@wordpress/i18n';
import type { BlockEditProps } from '@wordpress/blocks';
import useDeprecatedOpacity from './use-deprecated-opacity';
import type { HtmlElementControlProps, SeparatorAttributes } from './types';
const HTML_ELEMENT_ITEMS = [
{ label: __( 'Default (
', value: 'div' },
];
const HtmlElementControl = ( {
tagName = 'hr',
setAttributes,
}: HtmlElementControlProps ) => {
const selectedItem =
HTML_ELEMENT_ITEMS.find( ( item ) => item.value === tagName ) ??
HTML_ELEMENT_ITEMS[ 0 ];
return (
setAttributes( {
tagName: ( item?.value as 'hr' | 'div' ) ?? 'hr',
} )
}
items={ HTML_ELEMENT_ITEMS }
description={
tagName === 'hr'
? __(
'Only select
if the separator conveys important information and should be announced by screen readers.'
)
: __(
'The element should only be used if the block is a design element with no semantic meaning.'
)
}
/>
);
};
export default function SeparatorEdit( {
attributes,
setAttributes,
}: BlockEditProps< SeparatorAttributes > ) {
const { backgroundColor, opacity, style, tagName } = attributes;
const colorProps = useColorProps(
attributes as unknown as Parameters< typeof useColorProps >[ 0 ]
);
const currentColor = colorProps?.style?.backgroundColor as
string | undefined;
const hasCustomColor = !! (
style as { color?: { background?: string } } | undefined
)?.color?.background;
useDeprecatedOpacity( opacity, currentColor, setAttributes );
// The dots styles uses text for the dots, to change those dots color is
// using color, not backgroundColor.
const colorClass = getColorClassName(
'color',
backgroundColor as string | undefined
);
const className = clsx(
{
'has-text-color': backgroundColor || currentColor,
[ colorClass! ]: colorClass,
'has-css-opacity': opacity === 'css',
'has-alpha-channel-opacity': opacity === 'alpha-channel',
},
colorProps.className
);
const styles = {
color: currentColor,
backgroundColor: currentColor,
};
const Wrapper = ( tagName === 'hr' ? HorizontalRule : tagName ) as 'div';
return (
<>
>
);
}