-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add effects/box shadow tools to block inspector #57654
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
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f8d647d
wip
a03f038
wip
9b5917b
Add effects panel to block inspector
68438bd
add shadow classes for block settings in the editor
madhusudhand abd3452
add shadow attribute to template from the UI
madhusudhand bdeca70
fix typo
fc9f055
define support key in the supports hook
67367d6
remove internal dependencies block
9853838
remove effects panel from multi-selection inspector
6109148
read/write shadow from style attribute
6601478
make sure path and value computed correctly
07a120c
fix shadow being applied to block stead of inner element for button
madhusudhand f03ddda
revert generation of class names for shadows
madhusudhand f989659
revert support for shadow atribute.
madhusudhand 1694b85
don't use useMemo
1b77f1d
skip serialization for shadow when the support is enabled
madhusudhand 58a05ad
add entry to components changelog
8519221
Add shadow utils to native hooks file
mikachan 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
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,59 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { hasBlockSupport } from '@wordpress/blocks'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import StylesEffectsPanel, { | ||
| useHasEffectsPanel, | ||
| } from '../components/global-styles/effects-panel'; | ||
| import { InspectorControls } from '../components'; | ||
| import { store as blockEditorStore } from '../store'; | ||
|
|
||
| export const SHADOW_SUPPORT_KEY = 'shadow'; | ||
| export const EFFECTS_SUPPORT_KEYS = [ SHADOW_SUPPORT_KEY ]; | ||
|
|
||
| export function hasEffectsSupport( blockName ) { | ||
| return EFFECTS_SUPPORT_KEYS.some( ( key ) => | ||
| hasBlockSupport( blockName, key ) | ||
| ); | ||
| } | ||
|
|
||
| function EffectsInspectorControl( { children, resetAllFilter } ) { | ||
| return ( | ||
| <InspectorControls group="effects" resetAllFilter={ resetAllFilter }> | ||
| { children } | ||
| </InspectorControls> | ||
| ); | ||
| } | ||
| export function EffectsPanel( { clientId, setAttributes, settings } ) { | ||
| const isEnabled = useHasEffectsPanel( settings ); | ||
| const blockAttributes = useSelect( | ||
| ( select ) => select( blockEditorStore ).getBlockAttributes( clientId ), | ||
| [ clientId ] | ||
| ); | ||
| const shadow = blockAttributes?.style?.shadow; | ||
| const value = { shadow }; | ||
|
|
||
| const onChange = ( newValue ) => { | ||
| setAttributes( { | ||
| style: { ...blockAttributes.style, shadow: newValue.shadow }, | ||
| } ); | ||
| }; | ||
|
|
||
| if ( ! isEnabled ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <StylesEffectsPanel | ||
| as={ EffectsInspectorControl } | ||
| panelId={ clientId } | ||
| settings={ settings } | ||
| value={ value } | ||
| onChange={ onChange } | ||
| /> | ||
| ); | ||
| } |
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,39 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { hasEffectsSupport } from '../effects'; | ||
|
|
||
| describe( 'effects', () => { | ||
| describe( 'hasEffectsSupport', () => { | ||
| it( 'should return false if the block does not support effects', () => { | ||
| const settings = { | ||
| supports: { | ||
| shadow: false, | ||
| }, | ||
| }; | ||
|
|
||
| expect( hasEffectsSupport( settings ) ).toBe( false ); | ||
| } ); | ||
|
|
||
| it( 'should return true if the block supports effects', () => { | ||
| const settings = { | ||
| supports: { | ||
| shadow: true, | ||
| }, | ||
| }; | ||
|
|
||
| expect( hasEffectsSupport( settings ) ).toBe( true ); | ||
| } ); | ||
|
|
||
| it( 'should return true if the block supports effects and other features', () => { | ||
| const settings = { | ||
| supports: { | ||
| shadow: true, | ||
| align: true, | ||
| }, | ||
| }; | ||
|
|
||
| expect( hasEffectsSupport( settings ) ).toBe( true ); | ||
| } ); | ||
| } ); | ||
| } ); |
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,37 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getInlineStyles } from './style'; | ||
|
|
||
| // This utility is intended to assist where the serialization of the shadow | ||
| // block support is being skipped for a block but the shadow related CSS classes | ||
| // & styles still need to be generated so they can be applied to inner elements. | ||
|
|
||
| /** | ||
| * Provides the CSS class names and inline styles for a block's shadow support | ||
| * attributes. | ||
| * | ||
| * @param {Object} attributes Block attributes. | ||
| * @return {Object} Shadow block support derived CSS classes & styles. | ||
| */ | ||
| export function getShadowClassesAndStyles( attributes ) { | ||
| const shadow = attributes.style?.shadow || ''; | ||
|
|
||
| return { | ||
| className: undefined, | ||
| style: getInlineStyles( { shadow } ), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Derives the shadow related props for a block from its shadow block support | ||
| * attributes. | ||
| * | ||
| * @param {Object} attributes Block attributes. | ||
| * | ||
| * @return {Object} ClassName & style props from shadow block support. | ||
| */ | ||
| export function useShadowProps( attributes ) { | ||
| const shadowProps = getShadowClassesAndStyles( attributes ); | ||
| return shadowProps; | ||
| } | ||
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
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.