PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.7.1
GenerateBlocks v1.7.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 / gradient / index.js
generateblocks / src / components / gradient Last commit date
editor.scss 5 years ago index.js 3 years ago
index.js
237 lines
1 /**
2 * Internal dependencies
3 */
4 import './editor.scss';
5 import ColorPicker from '../color-picker';
6 import hasNumericValue from '../../utils/has-numeric-value';
7
8 /**
9 * WordPress dependencies
10 */
11 import {
12 __,
13 } from '@wordpress/i18n';
14
15 import {
16 Component,
17 Fragment,
18 } from '@wordpress/element';
19
20 import {
21 BaseControl,
22 ToggleControl,
23 TextControl,
24 RangeControl,
25 SelectControl,
26 } from '@wordpress/components';
27
28 /**
29 * Typography Component
30 */
31 class GradientControl extends Component {
32 render() {
33 const {
34 attributes,
35 setAttributes,
36 attrGradient,
37 attrGradientDirection,
38 attrGradientColorOne,
39 attrGradientColorOneOpacity,
40 attrGradientColorStopOne,
41 attrGradientColorTwo,
42 attrGradientColorTwoOpacity,
43 attrGradientColorStopTwo,
44 defaultColorOne,
45 defaultColorTwo,
46 } = this.props;
47
48 const {
49 gradientSelector,
50 innerZindex,
51 useInnerContainer,
52 position,
53 } = attributes;
54
55 const selectorHelp = 'element' === gradientSelector ? __( 'Displays behind the background image.', 'generateblocks' ) : __( 'Displays in front of the background image.', 'generateblocks' );
56
57 return (
58 <Fragment>
59 <ToggleControl
60 label={ __( 'Use Gradient', 'generateblocks' ) }
61 checked={ !! attributes[ attrGradient ] }
62 onChange={ ( value ) => {
63 const props = this.props;
64 let gradientDirection = attributes[ attrGradientDirection ],
65 gradientColorOne = attributes[ attrGradientColorOne ],
66 gradientColorTwo = attributes[ attrGradientColorTwo ];
67
68 if ( value ) {
69 gradientDirection = gradientDirection || 90;
70 gradientColorOne = gradientColorOne || 'rgba(255, 255, 255, 0.1)';
71 gradientColorTwo = gradientColorTwo || 'rgba(0, 0, 0, 0.30)';
72 }
73
74 setAttributes( {
75 [ props[ 'attrGradient' ] ]: value, // eslint-disable-line dot-notation
76 [ props[ 'attrGradientDirection' ] ]: gradientDirection, // eslint-disable-line dot-notation
77 [ props[ 'attrGradientColorOne' ] ]: gradientColorOne, // eslint-disable-line dot-notation
78 [ props[ 'attrGradientColorTwo' ] ]: gradientColorTwo, // eslint-disable-line dot-notation
79 } );
80 } }
81 />
82
83 { !! attributes[ attrGradient ] && (
84 <Fragment>
85 { 'undefined' !== typeof gradientSelector &&
86 <SelectControl
87 label={ __( 'Selector', 'generateblocks' ) }
88 help={ selectorHelp }
89 value={ gradientSelector }
90 options={ [
91 { label: __( 'Element', 'generateblocks' ), value: 'element' },
92 { label: __( 'Pseudo Element', 'generateblocks' ), value: 'pseudo-element' },
93 ] }
94 onChange={ ( value ) => {
95 setAttributes( {
96 gradientSelector: value,
97 } );
98
99 if ( useInnerContainer && ! hasNumericValue( innerZindex ) && 'pseudo-element' === value ) {
100 setAttributes( {
101 innerZindex: 1,
102 } );
103 }
104
105 if ( ! useInnerContainer && 'pseudo-element' === value && ! position ) {
106 setAttributes( { position: 'relative' } );
107 }
108 } }
109 />
110 }
111
112 <BaseControl>
113 <span className="components-base-control__label">{ __( 'Direction', 'generateblocks' ) }</span>
114
115 <RangeControl
116 value={ attributes[ attrGradientDirection ] ? attributes[ attrGradientDirection ] : 0 }
117 onChange={ ( value ) => {
118 setAttributes( {
119 [ attrGradientDirection ]: value,
120 } );
121 } }
122 min={ 0 }
123 max={ 360 }
124 step={ 1 }
125 initialPosition={ 90 }
126 />
127 </BaseControl>
128
129 <BaseControl>
130 <span className="components-base-control__label">{ __( 'Color One', 'generateblocks' ) }</span>
131
132 <div className="gblocks-component-gradient-control">
133 <ColorPicker
134 value={ attributes[ attrGradientColorOne ] }
135 alpha={ true }
136 valueOpacity={ attributes[ attrGradientColorOneOpacity ] || 0 === attributes[ attrGradientColorOneOpacity ] ? attributes[ attrGradientColorOneOpacity ] : 1 }
137 attrOpacity={ 'gradientColorOneOpacity' }
138 onChange={ ( value ) =>
139 setAttributes( {
140 [ attrGradientColorOne ]: value,
141 } )
142 }
143 onOpacityChange={ ( value ) =>
144 setAttributes( {
145 [ attrGradientColorOneOpacity ]: value,
146 } )
147 }
148 onClear={ () =>
149 setAttributes( {
150 [ attrGradientColorOne ]: defaultColorOne,
151 } )
152 }
153 />
154
155 <TextControl
156 className={ 'gblocks-component-gradient-stop-value' }
157 type={ 'text' }
158 value={ attributes[ attrGradientColorStopOne ] || 0 === attributes[ attrGradientColorStopOne ] ? attributes[ attrGradientColorStopOne ] : '' }
159 placeholder={ __( 'Stop position (%)', 'generateblocks' ) }
160 onChange={ ( value ) => {
161 setAttributes( {
162 [ attrGradientColorStopOne ]: value,
163 } );
164 } }
165 onBlur={ () => {
166 if ( attributes[ attrGradientColorStopOne ] || 0 === attributes[ attrGradientColorStopOne ] ) {
167 setAttributes( {
168 [ attrGradientColorStopOne ]: parseFloat( attributes[ attrGradientColorStopOne ] ),
169 } );
170 }
171 } }
172 onClick={ ( e ) => {
173 // Make sure onBlur fires in Firefox.
174 e.currentTarget.focus();
175 } }
176 />
177 </div>
178 </BaseControl>
179
180 <BaseControl>
181 <span className="components-base-control__label">{ __( 'Color Two', 'generateblocks' ) }</span>
182 <div className="gblocks-component-gradient-control">
183 <ColorPicker
184 value={ attributes[ attrGradientColorTwo ] }
185 alpha={ true }
186 valueOpacity={ attributes[ attrGradientColorTwoOpacity ] || 0 === attributes[ attrGradientColorTwoOpacity ] ? attributes[ attrGradientColorTwoOpacity ] : 1 }
187 attrOpacity={ 'gradientColorTwoOpacity' }
188 onChange={ ( value ) =>
189 setAttributes( {
190 [ attrGradientColorTwo ]: value,
191 } )
192 }
193 onOpacityChange={ ( value ) =>
194 setAttributes( {
195 [ attrGradientColorTwoOpacity ]: value,
196 } )
197 }
198 onClear={ () =>
199 setAttributes( {
200 [ attrGradientColorTwo ]: defaultColorTwo,
201 } )
202 }
203 />
204
205 <TextControl
206 className={ 'gblocks-component-gradient-stop-value' }
207 type={ 'text' }
208 value={ attributes[ attrGradientColorStopTwo ] || 0 === attributes[ attrGradientColorStopTwo ] ? attributes[ attrGradientColorStopTwo ] : '' }
209 placeholder={ __( 'Stop position (%)', 'generateblocks' ) }
210 onChange={ ( value ) => {
211 setAttributes( {
212 [ attrGradientColorStopTwo ]: value,
213 } );
214 } }
215 onBlur={ () => {
216 if ( attributes[ attrGradientColorStopTwo ] || 0 === attributes[ attrGradientColorStopTwo ] ) {
217 setAttributes( {
218 [ attrGradientColorStopTwo ]: parseFloat( attributes[ attrGradientColorStopTwo ] ),
219 } );
220 }
221 } }
222 onClick={ ( e ) => {
223 // Make sure onBlur fires in Firefox.
224 e.currentTarget.focus();
225 } }
226 />
227 </div>
228 </BaseControl>
229 </Fragment>
230 ) }
231 </Fragment>
232 );
233 }
234 }
235
236 export default GradientControl;
237