-
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.
Add effects/box shadow tools to block inspector (#57654)
* wip * wip * Add effects panel to block inspector @todo: for some reason, the Effects Panel is rendering, but the Shadow controls are not. * add shadow classes for block settings in the editor * add shadow attribute to template from the UI * fix typo * define support key in the supports hook * remove internal dependencies block * remove effects panel from multi-selection inspector * read/write shadow from style attribute * make sure path and value computed correctly * fix shadow being applied to block stead of inner element for button * revert generation of class names for shadows * revert support for shadow atribute. * don't use useMemo * skip serialization for shadow when the support is enabled * add entry to components changelog --------- Co-authored-by: madhusudhand <[email protected]>
- Loading branch information
1 parent
614e035
commit 43ac2af
Showing
20 changed files
with
194 additions
and
6 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
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
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 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
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 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 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.