PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.4.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.4.1
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / button-single / save.js

save.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.4.1, at gutenberg/blocks/button-single/save.js

91 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import { RichText, useBlockProps } from '@wordpress/block-editor';
4 import { applyFilters } from '@wordpress/hooks';
5
6 import IconPicker from '../../components/icon-picker';
7 import metadata from './block.json';
8
9 const { name } = metadata;
10
11 /**
12 * Block Save Class.
13 *
14 * @param props
15 */
16 export default function BlockSave(props) {
17 const {
18 tagName,
19 text,
20 icon,
21 iconPosition,
22 hideText,
23 url,
24 ariaLabel,
25 target,
26 rel,
27 size,
28 focusOutlineWeight,
29 focusOutlineColor,
30 } = props.attributes;
31
32 let className = classnames(
33 'ghostkit-button',
34 size && `ghostkit-button-${size}`,
35 hideText && 'ghostkit-button-icon-only'
36 );
37
38 // focus outline
39 if (focusOutlineWeight && focusOutlineColor) {
40 className = classnames(className, 'ghostkit-button-with-outline');
41 }
42
43 className = applyFilters('ghostkit.blocks.className', className, {
44 name,
45 ...props,
46 });
47
48 const result = [];
49
50 if (!hideText) {
51 result.push(
52 <RichText.Content
53 tagName="span"
54 className="ghostkit-button-text"
55 value={text}
56 key="button-text"
57 />
58 );
59 }
60
61 // add icon.
62 if (icon) {
63 result.unshift(
64 <IconPicker.Render
65 name={icon}
66 tag="span"
67 className={`ghostkit-button-icon ghostkit-button-icon-${
68 iconPosition === 'right' ? 'right' : 'left'
69 }`}
70 key="button-icon"
71 />
72 );
73 }
74
75 const Tag = tagName || (url ? 'a' : 'span');
76
77 const blockProps = useBlockProps.save({
78 className,
79 ...(Tag === 'a'
80 ? {
81 href: url,
82 target: target || null,
83 rel: rel || null,
84 'aria-label': ariaLabel || null,
85 }
86 : {}),
87 });
88
89 return <Tag {...blockProps}>{result}</Tag>;
90 }
91