PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
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.7.2, at gutenberg/blocks/button-single/save.js

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