-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
save.js
66 lines (58 loc) · 1.38 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import getColorAndStyleProps from './color-props';
export default function save( { attributes, className } ) {
const {
borderRadius,
linkTarget,
rel,
text,
title,
url,
width,
} = attributes;
if ( ! text ) {
return null;
}
const colorProps = getColorAndStyleProps( attributes );
const buttonClasses = classnames(
'wp-block-button__link',
colorProps.className,
{
'no-border-radius': borderRadius === 0,
}
);
const buttonStyle = {
borderRadius: borderRadius ? borderRadius + 'px' : undefined,
...colorProps.style,
};
// The use of a `title` attribute here is soft-deprecated, but still applied
// if it had already been assigned, for the sake of backward-compatibility.
// A title will no longer be assigned for new or updated button block links.
const wrapperClasses = classnames( className, {
[ `has-custom-width wp-block-button__width-${ width }` ]: width,
} );
return (
<div { ...useBlockProps.save( { className: wrapperClasses } ) }>
<RichText.Content
tagName="a"
className={ buttonClasses }
href={ url }
title={ title }
style={ buttonStyle }
value={ text }
target={ linkTarget }
rel={ rel }
/>
</div>
);
}