-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Color Block Support: Switch to ToolsPanel for displaying UI (#34027)
- Loading branch information
1 parent
c3705b1
commit 8675f86
Showing
15 changed files
with
370 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
85 changes: 85 additions & 0 deletions
85
packages/block-editor/src/components/colors-gradients/tools-panel-color-dropdown.js
This file contains 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,85 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Button, | ||
ColorIndicator, | ||
Dropdown, | ||
FlexItem, | ||
__experimentalHStack as HStack, | ||
__experimentalToolsPanelItem as ToolsPanelItem, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ColorGradientControl from './control'; | ||
import useMultipleOriginColorsAndGradients from './use-multiple-origin-colors-and-gradients'; | ||
|
||
export default function ToolsPanelColorDropdown( { | ||
settings, | ||
enableAlpha, | ||
...otherProps | ||
} ) { | ||
const colorGradientSettings = useMultipleOriginColorsAndGradients(); | ||
const controlSettings = { | ||
...colorGradientSettings, | ||
clearable: false, | ||
enableAlpha, | ||
label: settings.label, | ||
onColorChange: settings.onColorChange, | ||
onGradientChange: settings.onGradientChange, | ||
colorValue: settings.colorValue, | ||
gradientValue: settings.gradientValue, | ||
}; | ||
const selectedColor = settings.gradientValue ?? settings.colorValue; | ||
|
||
return ( | ||
<ToolsPanelItem | ||
hasValue={ settings.hasValue } | ||
label={ settings.label } | ||
onDeselect={ settings.onDeselect } | ||
isShownByDefault={ settings.isShownByDefault } | ||
resetAllFilter={ settings.resetAllFilter } | ||
{ ...otherProps } | ||
className="block-editor-tools-panel-color-gradient-settings__item" | ||
> | ||
<Dropdown | ||
className="block-editor-tools-panel-color-dropdown" | ||
contentClassName="block-editor-panel-color-gradient-settings__dropdown-content" | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
onClick={ onToggle } | ||
aria-expanded={ isOpen } | ||
className={ classnames( | ||
'block-editor-panel-color-gradient-settings__dropdown', | ||
{ 'is-open': isOpen } | ||
) } | ||
> | ||
<HStack justify="flex-start"> | ||
<ColorIndicator | ||
className="block-editor-panel-color-gradient-settings__color-indicator" | ||
colorValue={ selectedColor } | ||
/> | ||
<FlexItem>{ settings.label }</FlexItem> | ||
</HStack> | ||
</Button> | ||
) } | ||
renderContent={ () => ( | ||
<ColorGradientControl | ||
showTitle={ false } | ||
__experimentalHasMultipleOrigins | ||
__experimentalIsRenderedInSidebar | ||
enableAlpha | ||
{ ...controlSettings } | ||
/> | ||
) } | ||
/> | ||
</ToolsPanelItem> | ||
); | ||
} |
This file contains 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 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 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 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 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.