-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duotone: Add Global Styles controls for blocks that support duotone (#…
…48255) * create a panel for filters * created a duotone panel * add the duotone picker to the panel, changed filters icon * add the duotone picker to the panel, changed filters icon * fixed selectors for the block in the editor, save the value correctly for presets * move everything to a single panel * move preview panel to filters component * disable custom duotone for this PR * dont output unset * Simplify conditional nesting * Fix filter declarations not being unset * Rename DuotoneScreen to DuotonePanel * Use default header level for duotone panel * Rename filter-panel.js to filter-utils.js * Remove description from Filters screen header It seemed redundant with the duotone one on the same page now. --------- Co-authored-by: scruffian <ben@scruffian.com> Co-authored-by: Alex Lende <alex@lende.xyz>
- Loading branch information
1 parent
cddb8ea
commit fc4caf8
Showing
8 changed files
with
153 additions
and
4 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
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
82 changes: 82 additions & 0 deletions
82
packages/edit-site/src/components/global-styles/duotone-panel.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,82 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalToolsPanel as ToolsPanel, | ||
DuotonePicker, | ||
} from '@wordpress/components'; | ||
import { | ||
privateApis as blockEditorPrivateApis, | ||
useSetting, | ||
} from '@wordpress/block-editor'; | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../private-apis'; | ||
const { useGlobalStyle } = unlock( blockEditorPrivateApis ); | ||
|
||
const EMPTY_ARRAY = []; | ||
|
||
function useMultiOriginPresets( { presetSetting, defaultSetting } ) { | ||
const disableDefault = ! useSetting( defaultSetting ); | ||
const userPresets = | ||
useSetting( `${ presetSetting }.custom` ) || EMPTY_ARRAY; | ||
const themePresets = | ||
useSetting( `${ presetSetting }.theme` ) || EMPTY_ARRAY; | ||
const defaultPresets = | ||
useSetting( `${ presetSetting }.default` ) || EMPTY_ARRAY; | ||
return useMemo( | ||
() => [ | ||
...userPresets, | ||
...themePresets, | ||
...( disableDefault ? EMPTY_ARRAY : defaultPresets ), | ||
], | ||
[ disableDefault, userPresets, themePresets, defaultPresets ] | ||
); | ||
} | ||
|
||
function DuotonePanel( { name } ) { | ||
const [ themeDuotone, setThemeDuotone ] = useGlobalStyle( | ||
'filter.duotone', | ||
name | ||
); | ||
|
||
const duotonePalette = useMultiOriginPresets( { | ||
presetSetting: 'color.duotone', | ||
defaultSetting: 'color.defaultDuotone', | ||
} ); | ||
const colorPalette = useMultiOriginPresets( { | ||
presetSetting: 'color.palette', | ||
defaultSetting: 'color.defaultPalette', | ||
} ); | ||
|
||
if ( duotonePalette?.length === 0 ) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<ToolsPanel label={ __( 'Duotone' ) }> | ||
<span className="span-columns"> | ||
{ __( | ||
'Create a two-tone color effect without losing your original image.' | ||
) } | ||
</span> | ||
<div className="span-columns"> | ||
<DuotonePicker | ||
colorPalette={ colorPalette } | ||
duotonePalette={ duotonePalette } | ||
disableCustomColors={ true } | ||
disableCustomDuotone={ true } | ||
value={ themeDuotone } | ||
onChange={ setThemeDuotone } | ||
/> | ||
</div> | ||
</ToolsPanel> | ||
</> | ||
); | ||
} | ||
|
||
export default DuotonePanel; |
9 changes: 9 additions & 0 deletions
9
packages/edit-site/src/components/global-styles/filter-utils.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,9 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useSupportedStyles } from './hooks'; | ||
|
||
export function useHasFilterPanel( name ) { | ||
const supports = useSupportedStyles( name ); | ||
return supports.includes( 'filter' ); | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/edit-site/src/components/global-styles/screen-filters.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,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DuotonePanel from './duotone-panel'; | ||
import BlockPreviewPanel from './block-preview-panel'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ScreenHeader from './header'; | ||
|
||
function ScreenFilters( { name } ) { | ||
return ( | ||
<> | ||
<ScreenHeader title={ __( 'Filters' ) } /> | ||
<BlockPreviewPanel name={ name } /> | ||
<DuotonePanel name={ name } /> | ||
</> | ||
); | ||
} | ||
|
||
export default ScreenFilters; |
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
fc4caf8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in fc4caf8.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4260581258
📝 Reported issues:
specs/editor/various/block-editor-keyboard-shortcuts.test.js