@@ -11,7 +11,9 @@ import {
1111 PanelBody , TextControl , Spinner ,
1212} from '@wordpress/components'
1313import { __ } from '@wordpress/i18n'
14- import { useState , useEffect } from '@wordpress/element'
14+ import {
15+ useState , useEffect , Fragment ,
16+ } from '@wordpress/element'
1517
1618/**
1719 * External dependencies
@@ -25,6 +27,7 @@ import {
2527import { faGetIcon , faFetchIcon } from '~stackable/util'
2628import { FileDrop } from 'react-file-drop'
2729import classnames from 'classnames'
30+ import { applyFilters , doAction } from '@wordpress/hooks'
2831
2932let searchTimeout = null
3033let tempMediaUpload = null
@@ -83,7 +86,7 @@ export const cleanSvgString = svgString => {
8386
8487const IconSearchPopover = props => {
8588 const [ value , setValue ] = useState ( '' )
86- const [ results , setResults ] = useState ( [ ] )
89+ const [ results , setResults ] = useState ( { faIcons : [ ] , iconLibrary : [ ] } )
8790 const [ isBusy , setIsBusy ] = useState ( false )
8891 const [ isDropping , setIsDropping ] = useState ( false )
8992
@@ -151,6 +154,9 @@ const IconSearchPopover = props => {
151154 fr . onload = function ( e ) {
152155 setIsDropping ( false )
153156 const svgString = cleanSvgString ( addCustomIconClass ( e . target . result ) )
157+
158+ doAction ( 'stackable.icon-search-popover.svg-upload' , svgString )
159+
154160 props . onChange ( svgString )
155161 props . onClose ( )
156162 }
@@ -168,6 +174,8 @@ const IconSearchPopover = props => {
168174 'ugb-icon--has-reset' : props . allowReset ,
169175 } )
170176
177+ const IconLibraryIcons = applyFilters ( 'stackable.global-settings.inspector.icon-library.icons' , Fragment )
178+
171179 const content = (
172180 < div className = "stk-icon-search-popover-container" >
173181 < FileDrop
@@ -191,6 +199,8 @@ const IconSearchPopover = props => {
191199 fr . onload = function ( e ) {
192200 setIsDropping ( false )
193201 const svgString = cleanSvgString ( addCustomIconClass ( e . target . result ) )
202+
203+ doAction ( 'stackable.icon-search-popover.svg-upload' , svgString )
194204 props . onChange ( svgString )
195205 props . onClose ( )
196206 }
@@ -244,13 +254,26 @@ const IconSearchPopover = props => {
244254 </ div >
245255 < div className = "ugb-icon-popover__iconlist" >
246256 { isBusy && < Spinner /> }
247- { ! isBusy && results . map ( ( { prefix, iconName } , i ) => {
257+ { ! isBusy && < IconLibraryIcons
258+ icons = { results . iconLibrary }
259+ onChange = { props . onChange }
260+ onClose = { props . onClose }
261+ /> }
262+ { ! isBusy && results . faIcons . map ( ( { prefix, iconName } , i ) => {
248263 const iconValue = `${ prefix } -${ iconName } `
249264 return < button
250265 key = { i }
251266 className = { `components-button ugb-prefix--${ prefix } ugb-icon--${ iconName } ` }
252267 onClick = { async ( ) => {
253- if ( props . returnSVGValue ) {
268+ if ( props . returnSVGValue && props . returnIconName ) {
269+ let svgIcon = faGetIcon ( prefix , iconName )
270+
271+ if ( ! svgIcon ) {
272+ await faFetchIcon ( prefix , iconName )
273+ svgIcon = faGetIcon ( prefix , iconName )
274+ }
275+ props . onChange ( cleanSvgString ( svgIcon ) , prefix , iconName )
276+ } else if ( props . returnSVGValue ) {
254277 let svgIcon = faGetIcon ( prefix , iconName )
255278
256279 if ( ! svgIcon ) {
@@ -267,7 +290,7 @@ const IconSearchPopover = props => {
267290 < FontAwesomeIcon prefix = { prefix } iconName = { iconName } />
268291 </ button >
269292 } ) }
270- { ! isBusy && ! results . length &&
293+ { ! isBusy && ! results . faIcons . length && ! results . iconLibrary . length &&
271294 < p className = "components-base-control__help" > { __ ( 'No matches found' , i18n ) } </ p >
272295 }
273296 </ div >
0 commit comments