@@ -25,6 +25,7 @@ import {
2525import { faGetIcon , faFetchIcon } from '~stackable/util'
2626import { FileDrop } from 'react-file-drop'
2727import classnames from 'classnames'
28+ import { applyFilters } from '@wordpress/hooks'
2829
2930let searchTimeout = null
3031let tempMediaUpload = null
@@ -82,7 +83,7 @@ export const cleanSvgString = svgString => {
8283
8384const IconSearchPopover = props => {
8485 const [ value , setValue ] = useState ( '' )
85- const [ results , setResults ] = useState ( [ ] )
86+ const [ results , setResults ] = useState ( { faIcons : [ ] , iconLibrary : [ ] } )
8687 const [ isBusy , setIsBusy ] = useState ( false )
8788 const [ isDropping , setIsDropping ] = useState ( false )
8889
@@ -150,6 +151,11 @@ const IconSearchPopover = props => {
150151 fr . onload = function ( e ) {
151152 setIsDropping ( false )
152153 const svgString = cleanSvgString ( addCustomIconClass ( e . target . result ) )
154+
155+ if ( isPro && props . showPrompt ) {
156+ applyFilters ( 'stackable.global-settings.inspector.icon-library.prompt' , null , svgString )
157+ }
158+
153159 props . onChange ( svgString )
154160 props . onClose ( )
155161 }
@@ -243,13 +249,24 @@ const IconSearchPopover = props => {
243249 </ div >
244250 < div className = "ugb-icon-popover__iconlist" >
245251 { isBusy && < Spinner /> }
246- { ! isBusy && results . map ( ( { prefix, iconName } , i ) => {
252+ { ! isBusy && applyFilters ( 'stackable.global-settings.inspector.icon-library.icons' , null , {
253+ icons : results . iconLibrary , onChange : props . onChange , onClose : props . onClose ,
254+ } ) }
255+ { ! isBusy && results . faIcons . map ( ( { prefix, iconName } , i ) => {
247256 const iconValue = `${ prefix } -${ iconName } `
248257 return < button
249258 key = { i }
250259 className = { `components-button ugb-prefix--${ prefix } ugb-icon--${ iconName } ` }
251260 onClick = { async ( ) => {
252- if ( props . returnSVGValue ) {
261+ if ( props . returnSVGValue && props . returnIconName ) {
262+ let svgIcon = faGetIcon ( prefix , iconName )
263+
264+ if ( ! svgIcon ) {
265+ await faFetchIcon ( prefix , iconName )
266+ svgIcon = faGetIcon ( prefix , iconName )
267+ }
268+ props . onChange ( cleanSvgString ( svgIcon ) , prefix , iconName )
269+ } else if ( props . returnSVGValue ) {
253270 let svgIcon = faGetIcon ( prefix , iconName )
254271
255272 if ( ! svgIcon ) {
@@ -266,7 +283,7 @@ const IconSearchPopover = props => {
266283 < FontAwesomeIcon prefix = { prefix } iconName = { iconName } />
267284 </ button >
268285 } ) }
269- { ! isBusy && ! results . length &&
286+ { ! isBusy && ! results . faIcons . length && ! results . iconLibrary . length &&
270287 < p className = "components-base-control__help" > { __ ( 'No matches found' , i18n ) } </ p >
271288 }
272289 </ div >
@@ -309,6 +326,7 @@ IconSearchPopover.defaultProps = {
309326 onClose : noop ,
310327 returnSVGValue : true , // If true, the value provided in onChange will be the SVG markup of the icon. If false, the value will be a prefix-iconName value.
311328 allowReset : true ,
329+ showPrompt : true ,
312330 __deprecatedAnchorRef : undefined ,
313331 __deprecatedPosition : 'center' ,
314332 __deprecatedOnClickOutside : noop ,
0 commit comments