-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathsave.js
41 lines (36 loc) · 1.22 KB
/
save.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import {
getColorClassName,
useBlockProps,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
} from '@wordpress/block-editor';
export default function separatorSave( { attributes } ) {
const { backgroundColor, style, opacity, tagName: Tag } = attributes;
const customColor = style?.color?.background;
const colorProps = getColorClassesAndStyles( attributes );
// The hr support changing color using border-color, since border-color
// is not yet supported in the color palette, we use background-color.
// The dots styles uses text for the dots, to change those dots color is
// using color, not backgroundColor.
const colorClass = getColorClassName( 'color', backgroundColor );
const className = clsx(
{
'has-text-color': backgroundColor || customColor,
[ colorClass ]: colorClass,
'has-css-opacity': opacity === 'css',
'has-alpha-channel-opacity': opacity === 'alpha-channel',
},
colorProps.className
);
const styles = {
backgroundColor: colorProps?.style?.backgroundColor,
color: colorClass ? undefined : customColor,
};
return <Tag { ...useBlockProps.save( { className, style: styles } ) } />;
}