PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.1.0
GenerateBlocks v1.1.0
2.4.1 2.4.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 / icon-picker / index.js
generateblocks / src / components / icon-picker Last commit date
editor.scss 6 years ago index.js 6 years ago svgs-general.js 6 years ago svgs-social.js 6 years ago
index.js
251 lines
1 /**
2 * Internal dependencies
3 */
4 import './editor.scss';
5 import socialSvgs from './svgs-social';
6 import generalSvgs from './svgs-general';
7 import sanitizeSVG from '../../utils/sanitize-svg';
8
9 /**
10 * WordPress dependencies
11 */
12 const {
13 __,
14 } = wp.i18n;
15
16 const {
17 Component,
18 Fragment,
19 renderToString,
20 } = wp.element;
21
22 const {
23 BaseControl,
24 SelectControl,
25 ToggleControl,
26 TextControl,
27 Tooltip,
28 Button,
29 PanelBody,
30 PanelRow,
31 } = wp.components;
32
33 /**
34 * Typography Component
35 */
36 class IconPicker extends Component {
37 constructor() {
38 super( ...arguments );
39
40 this.state = {
41 showIcons: false,
42 showGeneralIcons: false,
43 showSocialIcons: false,
44 };
45 }
46
47 render() {
48 const {
49 attributes,
50 setAttributes,
51 attrIcon,
52 attrIconLocation,
53 locationOptions,
54 attrRemoveText,
55 } = this.props;
56
57 return (
58 <Fragment>
59 <BaseControl className="gb-svg-html">
60 <TextControl
61 label={ __( 'Icon SVG HTML', 'generateblocks' ) }
62 value={ attributes[ attrIcon ] }
63 onChange={ ( value ) => {
64 setAttributes( {
65 [ this.props[ 'attrIcon' ] ]: sanitizeSVG( value ), // eslint-disable-line dot-notation
66 } );
67
68 if ( '' !== value ) {
69 setAttributes( {
70 'hasIcon': true, // eslint-disable-line quote-props
71 } );
72 } else {
73 setAttributes( {
74 'hasIcon': false, // eslint-disable-line quote-props
75 } );
76 }
77 } }
78 />
79
80 <div className="gb-icon-preview">
81 <span dangerouslySetInnerHTML={ { __html: sanitizeSVG( attributes[ attrIcon ] ) } } />
82
83 <Button
84 isSmall
85 className="reset-icon is-secondary"
86 onClick={ () => {
87 setAttributes( {
88 [ this.props[ 'attrIcon' ] ]: '', // eslint-disable-line dot-notation
89 'hasIcon': false, // eslint-disable-line quote-props
90 } );
91 } }
92 >
93 <span className="editor-block-types-list__item-icon">
94 { __( 'Clear', 'generateblocks' ) }
95 </span>
96 </Button>
97 </div>
98 </BaseControl>
99
100 <BaseControl className="gb-icon-chooser">
101 <PanelBody title={ __( 'General Icons', 'generateblocks' ) } initialOpen={ false }>
102 <PanelRow>
103 <BaseControl>
104 <ul className="gblocks-icon-chooser">
105 {
106 Object.keys( generalSvgs ).map( ( svg, i ) => {
107 return (
108 <li key={ `editor-pblock-types-list-item-${ i }` }>
109 <Tooltip text={ ( generalSvgs[ svg ].label ) }>
110 <Button
111 isLarge
112 className="editor-block-list-item-button"
113 onClick={ () => {
114 setAttributes( {
115 [ this.props[ 'attrIcon' ] ]: renderToString( generalSvgs[ svg ][ 'icon' ] ), // eslint-disable-line dot-notation
116 'hasIcon': true, // eslint-disable-line quote-props
117 } );
118 } }
119 >
120 <span className="editor-block-types-list__item-icon">
121 { generalSvgs[ svg ].icon }
122 </span>
123 </Button>
124 </Tooltip>
125 </li>
126 );
127 } )
128 }
129 </ul>
130 </BaseControl>
131 </PanelRow>
132 </PanelBody>
133
134 <PanelBody title={ __( 'Social Icons', 'generateblocks' ) } initialOpen={ false }>
135 <PanelRow>
136 <BaseControl>
137 <ul className="gblocks-icon-chooser">
138 {
139 Object.keys( socialSvgs ).map( ( svg, i ) => {
140 return (
141 <li key={ `editor-pblock-types-list-item-${ i }` }>
142 <Tooltip text={ ( socialSvgs[ svg ].label ) }>
143 <Button
144 isLarge
145 className="editor-block-list-item-button"
146 onClick={ () => {
147 setAttributes( {
148 [ this.props[ 'attrIcon' ] ]: renderToString( socialSvgs[ svg ][ 'icon' ] ), // eslint-disable-line dot-notation
149 'hasIcon': true, // eslint-disable-line quote-props
150 } );
151 } }
152 >
153 <span className="editor-block-types-list__item-icon">
154 { socialSvgs[ svg ].icon }
155 </span>
156 </Button>
157 </Tooltip>
158 </li>
159 );
160 } )
161 }
162 </ul>
163 </BaseControl>
164 </PanelRow>
165 </PanelBody>
166 </BaseControl>
167
168 { ( typeof attributes[ attrIconLocation ] !== 'undefined' && ! attributes[ attrRemoveText ] && !! attributes[ attrIcon ] ) &&
169 <SelectControl
170 label={ __( 'Icon Location', 'generateblocks' ) }
171 value={ attributes[ attrIconLocation ] }
172 options={ locationOptions }
173 onChange={ ( value ) => {
174 const leftPadding = attributes.iconPaddingLeft,
175 rightPadding = attributes.iconPaddingRight,
176 rightPaddingTablet = attributes.iconPaddingRightTablet,
177 leftPaddingTablet = attributes.iconPaddingLeftTablet,
178 rightPaddingMobile = attributes.iconPaddingRightMobile,
179 leftPaddingMobile = attributes.iconPaddingLeftMobile;
180
181 if ( 'right' === value ) {
182 if ( ! leftPadding && rightPadding ) {
183 setAttributes( {
184 iconPaddingLeft: rightPadding,
185 iconPaddingRight: '',
186 } );
187 }
188
189 if ( ! leftPaddingTablet && rightPaddingTablet ) {
190 setAttributes( {
191 iconPaddingLeftTablet: rightPaddingTablet,
192 iconPaddingRightTablet: '',
193 } );
194 }
195
196 if ( ! leftPaddingMobile && rightPaddingMobile ) {
197 setAttributes( {
198 iconPaddingLeftMobile: rightPaddingMobile,
199 iconPaddingRightMobile: '',
200 } );
201 }
202 }
203
204 if ( 'left' === value ) {
205 if ( ! rightPadding && leftPadding ) {
206 setAttributes( {
207 iconPaddingRight: leftPadding,
208 iconPaddingLeft: '',
209 } );
210 }
211
212 if ( ! rightPaddingTablet && leftPaddingTablet ) {
213 setAttributes( {
214 iconPaddingRightTablet: leftPaddingTablet,
215 iconPaddingLeftTablet: '',
216 } );
217 }
218
219 if ( ! rightPaddingMobile && leftPaddingMobile ) {
220 setAttributes( {
221 iconPaddingRightMobile: leftPaddingMobile,
222 iconPaddingLeftMobile: '',
223 } );
224 }
225 }
226
227 setAttributes( {
228 [ this.props[ 'attrIconLocation' ] ]: value, // eslint-disable-line dot-notation
229 } );
230 } }
231 />
232 }
233
234 { ( typeof attributes[ attrRemoveText ] !== 'undefined' && !! attributes[ attrIcon ] ) &&
235 <ToggleControl
236 label={ __( 'Remove Text', 'generateblocks' ) }
237 checked={ !! attributes[ attrRemoveText ] }
238 onChange={ ( value ) => {
239 setAttributes( {
240 [ this.props[ 'attrRemoveText' ] ]: value, // eslint-disable-line dot-notation
241 } );
242 } }
243 />
244 }
245 </Fragment>
246 );
247 }
248 }
249
250 export default IconPicker;
251