PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.1.1
GenerateBlocks v1.1.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 6 years ago index.js 6 years ago
index.js
172 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 } = wp.components;
19
20 /**
21 * Typography Component
22 */
23 class GradientControl extends Component {
24 render() {
25 const {
26 attributes,
27 setAttributes,
28 attrGradient,
29 attrGradientDirection,
30 attrGradientColorOne,
31 attrGradientColorOneOpacity,
32 attrGradientColorStopOne,
33 attrGradientColorTwo,
34 attrGradientColorTwoOpacity,
35 attrGradientColorStopTwo,
36 defaultColorOne,
37 defaultColorTwo,
38 } = this.props;
39
40 return (
41 <Fragment>
42 <ToggleControl
43 label={ __( 'Use Gradient', 'generateblocks' ) }
44 checked={ !! attributes[ attrGradient ] }
45 onChange={ ( value ) => {
46 setAttributes( {
47 [ this.props[ 'attrGradient' ] ]: value, // eslint-disable-line dot-notation
48 } );
49 } }
50 />
51
52 { !! attributes[ attrGradient ] && (
53 <Fragment>
54 <BaseControl
55 label={ __( 'Direction', 'generateblocks' ) }
56 >
57 <RangeControl
58 value={ attributes[ attrGradientDirection ] ? attributes[ attrGradientDirection ] : 1 }
59 onChange={ ( value ) => {
60 setAttributes( {
61 [ attrGradientDirection ]: value,
62 } );
63 } }
64 min={ 0 }
65 max={ 360 }
66 step={ 1 }
67 initialPosition={ 90 }
68 />
69 </BaseControl>
70
71 <BaseControl label={ __( 'Color One', 'generateblocks' ) }>
72 <div className="gblocks-component-gradient-control">
73 <ColorPicker
74 value={ attributes[ attrGradientColorOne ] }
75 alpha={ true }
76 valueOpacity={ attributes[ attrGradientColorOneOpacity ] }
77 attrOpacity={ 'gradientColorOneOpacity' }
78 onChange={ ( value ) =>
79 setAttributes( {
80 [ attrGradientColorOne ]: value,
81 } )
82 }
83 onOpacityChange={ ( value ) =>
84 setAttributes( {
85 [ attrGradientColorOneOpacity ]: value,
86 } )
87 }
88 onClear={ () =>
89 setAttributes( {
90 [ attrGradientColorOne ]: defaultColorOne,
91 } )
92 }
93 />
94
95 <TextControl
96 className={ 'gblocks-component-gradient-stop-value' }
97 type={ 'text' }
98 value={ attributes[ attrGradientColorStopOne ] || 0 === attributes[ attrGradientColorStopOne ] ? attributes[ attrGradientColorStopOne ] : '' }
99 placeholder={ __( 'Stop position (%)', 'generateblocks' ) }
100 onChange={ ( value ) => {
101 setAttributes( {
102 [ attrGradientColorStopOne ]: value,
103 } );
104 } }
105 onBlur={ () => {
106 setAttributes( {
107 [ attrGradientColorStopOne ]: parseFloat( attributes[ attrGradientColorStopOne ] ),
108 } );
109 } }
110 onClick={ ( e ) => {
111 // Make sure onBlur fires in Firefox.
112 e.currentTarget.focus();
113 } }
114 />
115 </div>
116 </BaseControl>
117
118 <BaseControl label={ __( 'Color Two', 'generateblocks' ) }>
119 <div className="gblocks-component-gradient-control">
120 <ColorPicker
121 value={ attributes[ attrGradientColorTwo ] }
122 alpha={ true }
123 valueOpacity={ attributes[ attrGradientColorTwoOpacity ] }
124 attrOpacity={ 'gradientColorTwoOpacity' }
125 onChange={ ( value ) =>
126 setAttributes( {
127 [ attrGradientColorTwo ]: value,
128 } )
129 }
130 onOpacityChange={ ( value ) =>
131 setAttributes( {
132 [ attrGradientColorTwoOpacity ]: value,
133 } )
134 }
135 onClear={ () =>
136 setAttributes( {
137 [ attrGradientColorTwo ]: defaultColorTwo,
138 } )
139 }
140 />
141
142 <TextControl
143 className={ 'gblocks-component-gradient-stop-value' }
144 type={ 'text' }
145 value={ attributes[ attrGradientColorStopTwo ] || 0 === attributes[ attrGradientColorStopTwo ] ? attributes[ attrGradientColorStopTwo ] : '' }
146 placeholder={ __( 'Stop position (%)', 'generateblocks' ) }
147 onChange={ ( value ) => {
148 setAttributes( {
149 [ attrGradientColorStopTwo ]: value,
150 } );
151 } }
152 onBlur={ () => {
153 setAttributes( {
154 [ attrGradientColorStopTwo ]: parseFloat( attributes[ attrGradientColorStopTwo ] ),
155 } );
156 } }
157 onClick={ ( e ) => {
158 // Make sure onBlur fires in Firefox.
159 e.currentTarget.focus();
160 } }
161 />
162 </div>
163 </BaseControl>
164 </Fragment>
165 ) }
166 </Fragment>
167 );
168 }
169 }
170
171 export default GradientControl;
172