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