PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.1
GenerateBlocks v1.4.1
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / url-input / index.js
generateblocks / src / components / url-input Last commit date
editor.scss 5 years ago index.js 5 years ago
index.js
137 lines
1 import classnames from 'classnames';
2 import getIcon from '../../utils/get-icon';
3
4 // Import CSS
5 import './editor.scss';
6
7 import {
8 __,
9 } from '@wordpress/i18n';
10
11 import {
12 Component,
13 } from '@wordpress/element';
14
15 import {
16 Button,
17 ToggleControl,
18 } from '@wordpress/components';
19
20 import {
21 URLInput,
22 } from '@wordpress/block-editor';
23
24 import {
25 applyFilters,
26 } from '@wordpress/hooks';
27
28 export default class ButtonURLInput extends Component {
29 constructor() {
30 super( ...arguments );
31
32 this.state = {
33 moreOptions: false,
34 };
35
36 this.onChange = this.onChange.bind( this );
37 }
38
39 onChange( data ) {
40 const {
41 url,
42 target,
43 relNoFollow,
44 relSponsored,
45 } = this.props;
46
47 this.props.onChange( {
48 ...{
49 url,
50 target,
51 relNoFollow,
52 relSponsored,
53 },
54 ...data,
55 } );
56 }
57
58 render() {
59 const {
60 url,
61 target,
62 relNoFollow,
63 relSponsored,
64 className,
65 autoFocus,
66 } = this.props;
67
68 const {
69 onChange,
70 } = this;
71
72 const {
73 moreOptions,
74 } = this.state;
75
76 return (
77 <div className={ classnames( 'gblocks-component-url-input', className ) }>
78 <div className="gblocks-component-url-input-flex">
79 <URLInput
80 value={ url }
81 onChange={ ( value ) => {
82 onChange( {
83 url: value,
84 } );
85 } }
86 autoFocus={ autoFocus } // eslint-disable-line jsx-a11y/no-autofocus
87 />
88 <Button
89 icon={ getIcon( 'ellipsis' ) }
90 label={ moreOptions ? __( 'Hide More Options', 'generateblocks' ) : __( 'Show More Options', 'generateblocks' ) }
91 onClick={ () => {
92 this.setState( {
93 moreOptions: ! moreOptions,
94 } );
95 } }
96 />
97 </div>
98 { moreOptions &&
99 <div className="gblocks-component-url-input-more-options">
100 { applyFilters( 'generateblocks.editor.urlInputMoreOptions', '', this.props, this.state ) }
101
102 <ToggleControl
103 label={ __( 'Open link in a new tab', 'generateblocks' ) }
104 checked={ target || '' }
105 onChange={ ( value ) => {
106 onChange( {
107 target: value,
108 } );
109 } }
110 />
111
112 <ToggleControl
113 label={ __( 'Add rel="nofollow"', 'generateblocks' ) }
114 checked={ relNoFollow || '' }
115 onChange={ ( value ) => {
116 onChange( {
117 relNoFollow: value,
118 } );
119 } }
120 />
121
122 <ToggleControl
123 label={ __( 'Add rel="sponsored"', 'generateblocks' ) }
124 checked={ relSponsored || '' }
125 onChange={ ( value ) => {
126 onChange( {
127 relSponsored: value,
128 } );
129 } }
130 />
131 </div>
132 }
133 </div>
134 );
135 }
136 }
137