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