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