-
Notifications
You must be signed in to change notification settings - Fork 67
Feat: Icon Library #3317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat: Icon Library #3317
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0401825
add icon library in global settings
kaeizen 1097e04
change ProControl type
kaeizen 0dfe241
create reusable component
kaeizen 091f250
add icons to icon library
kaeizen 1fa30fd
Merge branch 'develop' into feat/icon-library
kaeizen 84331ed
improve code readability
bfintal 357db74
updated premium notice text
6e3a005
update popover
kaeizen e9275d6
Merge branch 'develop' into feat/icon-library
kaeizen b53b3ff
add debounce
kaeizen 1746e7d
fix remaining issues
kaeizen 2521917
Merge branch 'develop' into feat/icon-library
6bceaf8
if show premium notices are disabled, also hide this
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| /** | ||
| * 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 } from '@wordpress/element' | ||
| import { __ } from '@wordpress/i18n' | ||
|
|
||
| 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 ( | ||
| <BaseControl className={ classNames } label={ props.label }> | ||
| <Dropdown | ||
| renderToggle={ ( { onToggle, isOpen } ) => ( | ||
| <Button | ||
| className="ugb-global-settings-color-picker__add-button" | ||
| onClick={ dropdownOnAdd ? onToggle : handleAddItem } | ||
| icon="plus-alt2" | ||
| aria-expanded={ isOpen } | ||
| /> | ||
| ) } | ||
| renderContent={ ( { onClose } ) => ( | ||
| <AddItemPopover onClose={ onClose } onChange={ handleAddItem } /> | ||
| ) } | ||
| /> | ||
| <div | ||
| ref={ ref } | ||
| className={ classnames( | ||
| 'ugb-global-settings-color-picker__color-indicators', | ||
| { 'is-sorting': isSorting } | ||
| ) } | ||
| > | ||
| <SortableContainer | ||
| items={ items } | ||
| onSortStart={ () => setIsSorting( true ) } | ||
| onSortEnd={ ( { oldIndex, newIndex } ) => onSortEnd( { | ||
| oldIndex, newIndex, setIsSorting, | ||
| } ) } | ||
| axis="y" | ||
| useDragHandle | ||
| keyCodes={ DRAG_KEYCODES } | ||
| > | ||
| { items.map( ( item, i ) => ( | ||
| <SortableItem | ||
| key={ i } | ||
| index={ i } | ||
| item={ item } | ||
| onDelete={ () => onDeleteItem( item ) } | ||
| onChange={ item => onChangeItem( item ) } | ||
| ItemPreview={ props.ItemPreview } | ||
| ItemPicker={ props.ItemPicker } | ||
| /> ) ) } | ||
| </SortableContainer> | ||
| </div> | ||
| </BaseControl> | ||
| ) | ||
| } | ||
|
|
||
| SortablePicker.defaultProps = { | ||
| className: '', | ||
| label: '', | ||
| onReset: () => {}, | ||
| } | ||
|
|
||
| export default SortablePicker | ||
|
|
||
| const SortableItem = sortableElement( props => <LabeledItemIndicator { ...props } /> ) | ||
|
|
||
| const SortableContainer = sortableContainer( ( { children } ) => { | ||
| return <div>{ children }</div> | ||
| } ) | ||
|
|
||
| const DragHandle = sortableHandle( () => <Dashicon | ||
| icon="menu" | ||
| size="16" | ||
| tabIndex="0" | ||
| /> ) | ||
|
|
||
| const LabeledItemIndicator = props => { | ||
| const { | ||
| item, | ||
| onDelete, | ||
| onChange, | ||
| ItemPreview = null, | ||
| ItemPicker = null, | ||
|
|
||
| } = props | ||
|
|
||
| const [ isFocused, setIsFocused ] = useState( false ) | ||
|
|
||
| return ( | ||
| <HStack justify="space-between" className="stk-global-settings-color-picker__color-indicator-wrapper"> | ||
| <Dropdown | ||
| popoverProps={ popoverProps } | ||
| // This is so that when we click on the label to edit it, the input doesn't lose focus. | ||
| focusOnMount={ ! isFocused ? 'firstElement' : false } | ||
| renderToggle={ ( { onToggle, isOpen } ) => { | ||
| return ( | ||
| <Button | ||
| className="block-editor-panel-color-gradient-settings__dropdown" | ||
| onClick={ () => { | ||
| if ( ! isFocused ) { | ||
| onToggle() | ||
| } | ||
| } } | ||
| isPressed={ isOpen } | ||
| > | ||
| <HStack justify="flex-start"> | ||
| <ItemPreview item={ item } /> | ||
| <input | ||
| className="components-input-control__input" | ||
| value={ item.name } | ||
| onChange={ ev => { | ||
| onChange( { | ||
| ...item, | ||
| name: ev.target.value, | ||
| } ) | ||
| } } | ||
| onFocus={ () => setIsFocused( true ) } | ||
| onBlur={ ev => { | ||
| setIsFocused( false ) | ||
| if ( isOpen && ! ev.relatedTarget?.closest( '.components-popover' ) ) { | ||
| onToggle() | ||
| } | ||
| } } | ||
| onClick={ () => { | ||
| if ( ! isOpen ) { | ||
| onToggle() | ||
| } | ||
| } } | ||
| onKeyDown={ ev => { | ||
| // On enter, blur the input. | ||
| if ( ev.keyCode === 13 ) { | ||
| ev.target.blur() | ||
| } | ||
| } } | ||
| /> | ||
| <DragHandle /> | ||
| </HStack> | ||
| </Button> | ||
| ) | ||
| } } | ||
| renderContent={ () => ( | ||
| <div className="stk-color-palette-control__popover-content"> | ||
| <ItemPicker item={ item } onChange={ onChange } /> | ||
| </div> | ||
| ) } | ||
| /> | ||
| <Button | ||
| className="stk-global-settings-color-picker__delete-button" | ||
| icon="trash" | ||
| isSmall | ||
| isTertiary | ||
| onClick={ onDelete } | ||
| /> | ||
| </HStack> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.