diff --git a/src/components/font-awesome-icon/index.js b/src/components/font-awesome-icon/index.js index cf454e270..499b4d3da 100644 --- a/src/components/font-awesome-icon/index.js +++ b/src/components/font-awesome-icon/index.js @@ -80,6 +80,10 @@ const addSVGAttributes = ( svgHTML, attributesToAdd = {}, attributesToRemove = [ } const FontAwesomeIcon = memo( props => { + const { + svgAttrsToAdd = { width: '32', height: '32' }, + svgAttrsToRemove = [ 'id', 'data-name' ], + } = props const [ forceUpdateCount, setForceUpdateCount ] = useState( 0 ) const forceUpdate = () => { setForceUpdateCount( forceUpdateCount + 1 ) @@ -91,7 +95,7 @@ const FontAwesomeIcon = memo( props => { if ( typeof props.value === 'string' && props.value.match( /^{ props.prependRenderString + svg } } @@ -109,7 +113,7 @@ const FontAwesomeIcon = memo( props => { let svg = addSVGAriaLabel( iconHTML, props.ariaLabel ) // Add fallback SVG width and height values. - svg = addSVGAttributes( svg, { width: '32', height: '32' } ) + svg = addSVGAttributes( svg, svgAttrsToAdd, svgAttrsToRemove ) return { props.prependRenderString + svg } } @@ -123,7 +127,7 @@ const FontAwesomeIcon = memo( props => { let svg = addSVGAriaLabel( iconHTML, props.ariaLabel ) // Add fallback SVG width and height values. - svg = addSVGAttributes( svg, { width: '32', height: '32' } ) + svg = addSVGAttributes( svg, svgAttrsToAdd, svgAttrsToRemove ) return { props.prependRenderString + svg } } ) diff --git a/src/components/icon-search-popover/index.js b/src/components/icon-search-popover/index.js index 272e81302..95163c872 100644 --- a/src/components/icon-search-popover/index.js +++ b/src/components/icon-search-popover/index.js @@ -11,7 +11,9 @@ import { PanelBody, TextControl, Spinner, } from '@wordpress/components' import { __ } from '@wordpress/i18n' -import { useState, useEffect } from '@wordpress/element' +import { + useState, useEffect, Fragment, +} from '@wordpress/element' /** * External dependencies @@ -25,6 +27,7 @@ import { import { faGetIcon, faFetchIcon } from '~stackable/util' import { FileDrop } from 'react-file-drop' import classnames from 'classnames' +import { applyFilters, doAction } from '@wordpress/hooks' let searchTimeout = null let tempMediaUpload = null @@ -83,7 +86,7 @@ export const cleanSvgString = svgString => { const IconSearchPopover = props => { const [ value, setValue ] = useState( '' ) - const [ results, setResults ] = useState( [] ) + const [ results, setResults ] = useState( { faIcons: [], iconLibrary: [] } ) const [ isBusy, setIsBusy ] = useState( false ) const [ isDropping, setIsDropping ] = useState( false ) @@ -151,6 +154,9 @@ const IconSearchPopover = props => { fr.onload = function( e ) { setIsDropping( false ) const svgString = cleanSvgString( addCustomIconClass( e.target.result ) ) + + doAction( 'stackable.icon-search-popover.svg-upload', svgString ) + props.onChange( svgString ) props.onClose() } @@ -168,6 +174,8 @@ const IconSearchPopover = props => { 'ugb-icon--has-reset': props.allowReset, } ) + const IconLibraryIcons = applyFilters( 'stackable.global-settings.inspector.icon-library.icons', Fragment ) + const content = (
{ fr.onload = function( e ) { setIsDropping( false ) const svgString = cleanSvgString( addCustomIconClass( e.target.result ) ) + + doAction( 'stackable.icon-search-popover.svg-upload', svgString ) props.onChange( svgString ) props.onClose() } @@ -244,13 +254,26 @@ const IconSearchPopover = props => {
{ isBusy && } - { ! isBusy && results.map( ( { prefix, iconName }, i ) => { + { ! isBusy && } + { ! isBusy && results.faIcons.map( ( { prefix, iconName }, i ) => { const iconValue = `${ prefix }-${ iconName }` return } ) } - { ! isBusy && ! results.length && + { ! isBusy && ! results.faIcons.length && ! results.iconLibrary.length &&

{ __( 'No matches found', i18n ) }

}
diff --git a/src/components/icon-search-popover/search.js b/src/components/icon-search-popover/search.js index 11aabc4d6..d3b7ea84d 100644 --- a/src/components/icon-search-popover/search.js +++ b/src/components/icon-search-popover/search.js @@ -1,3 +1,4 @@ +import { applyFilters } from '@wordpress/hooks' import { fontAwesomeSearchProIcons, iconsFaKit, iconsFaProKitVersion, iconsFaFreeKitVersion, } from 'stackable' @@ -23,13 +24,17 @@ export const searchFontAwesomeIconName = async ( name = 'icon', isPro = fontAwes } ) .then( r => r.json() ) - return data.data.search.reduce( ( iconResults, iconData ) => { + const faIcons = data.data.search.reduce( ( iconResults, iconData ) => { convertFontAwesomeToIcon( iconData, isPro ).forEach( icon => { iconResults.push( icon ) } ) return iconResults }, [] ) + + const iconLibrary = applyFilters( 'stackable.global-settings.inspector.icon-library.search-icons', null, name ) + + return { faIcons, iconLibrary } } /** diff --git a/src/components/index.js b/src/components/index.js index 08324109f..7881b4e39 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -115,3 +115,4 @@ export { default as ColumnsWidthMultiControl } from './columns-width-multi-contr export { default as Popover } from './popover' export { default as HelpTooltip } from './help-tooltip' export { default as RichText } from './rich-text' +export { default as SortablePicker } from './sortable-picker' diff --git a/src/components/pro-control/index.js b/src/components/pro-control/index.js index 79f29f52b..7f7512880 100644 --- a/src/components/pro-control/index.js +++ b/src/components/pro-control/index.js @@ -109,6 +109,14 @@ const LABELS = {
  • { __( 'Hide the current post - great for synced patterns', i18n ) }
  • , }, + 'icon-library': { + title: __( 'Unlock Your Icon Library', i18n ), + description: , + }, } const ProControl = props => { diff --git a/src/components/sortable-picker/index.js b/src/components/sortable-picker/index.js new file mode 100644 index 000000000..ce1406db5 --- /dev/null +++ b/src/components/sortable-picker/index.js @@ -0,0 +1,236 @@ +/** + * External dependencies + */ +import classnames from 'classnames' +import { Button } from '~stackable/components' +import { + sortableContainer, sortableElement, sortableHandle, +} from 'react-sortable-hoc' + +/** + * WordPress dependencies + */ +import { + BaseControl, + // eslint-disable-next-line @wordpress/no-unsafe-wp-apis + __experimentalHStack as HStack, + Dashicon, + Dropdown, +} from '@wordpress/components' +import { useState, useEffect } from '@wordpress/element' +import { __ } from '@wordpress/i18n' + +const addItemPopoverProps = { + placement: 'left-start', + offset: 236, + shift: true, +} + +const popoverProps = { + placement: 'left-start', + offset: 36, + shift: true, +} + +// We need to define these because 13 (return key) is not included in the +// default keyCodes to initiate a drag. +const DRAG_KEYCODES = { + lift: [ 32, 13 ], + drop: [ 32, 13 ], + cancel: [ 27 ], + up: [ 38, 37 ], + down: [ 40, 39 ], +} + +const SortablePicker = props => { + const { + items, + dropdownOnAdd = false, + onChangeItem, + onDeleteItem, + handleAddItem, + onSortEnd, + AddItemPopover = null, + ref, + } = props + const [ isSorting, setIsSorting ] = useState( false ) + + const classNames = classnames( + 'ugb-global-settings-color-picker', + 'components-circular-option-picker', + 'editor-color-palette-control__color-palette', + props.className + ) + + return ( + + ( + + ) + } } + renderContent={ () => ( + + ) } + /> + - ) - } } - renderContent={ () => ( -
    - onChange( { - ...color, - color: value, - } ) } - color={ color.color } - enableAlpha={ true } - /> -
    - ) } - /> -