Skip to content
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

Cover: Add Padding Styles #21492

Merged
merged 106 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
66ec200
Creating initial BoxControl component
Apr 2, 2020
dff4163
Add BoxControlIcon
Apr 3, 2020
7904c75
Add Flex component and integrate into BoxControl component
Apr 3, 2020
0f3c00d
Add labels for UnitControls
Apr 3, 2020
fb77888
Add react-use-gesture
Apr 3, 2020
69e4a1c
Add drag support to NumberControl
Apr 3, 2020
b0877d1
Improve layout for BoxControl
Apr 3, 2020
4f05a24
Update snapshot tests
Apr 3, 2020
65736fc
Add shiftStep in drag feature in NumberControl
Apr 3, 2020
779ae5b
Adjust Box control UI
Apr 7, 2020
d37a6f5
Initial integration with Cover
Apr 7, 2020
8ef3f80
Integrate PaddingControl with Cover using hooks
Apr 7, 2020
74e327c
Improve visualization of padding
Apr 7, 2020
aa790ea
Experiment with new Box Controls layout
Apr 8, 2020
aa5b18b
Improve NumberControl drag interaction
Apr 8, 2020
7687799
Create InputControl primitive. Add floating labels. Refactor BoxControl
Apr 8, 2020
21efbac
Adjust UI for BoxControl + InputControl labels
Apr 8, 2020
cd8c007
Fix tests
Apr 8, 2020
0acb9ee
Increase CSS scope. Minor label UI adjustments.
Apr 8, 2020
ebbf031
Refine UI for BoxControl
Apr 9, 2020
85979dd
Hook up inline style rendering with padding attribute values
Apr 14, 2020
2f14a64
Adjust tab order for BoxControl inputs to match visual order
Apr 14, 2020
1352863
Remove padding attribute declaration
Apr 14, 2020
9956662
Improve dragging experience
Apr 15, 2020
508124b
Add alt pair change support. Improve null value rendering.
Apr 15, 2020
6c8e05d
Remove unused BoxControl Icon
Apr 15, 2020
6dd9a2d
Improve RTL interactions
Apr 15, 2020
58a3968
Fix onChange type for NumberControl
Apr 17, 2020
33dadc6
Fix NumberControl onChange type
Apr 20, 2020
2780a8f
Add Prefix to InputControl
Apr 20, 2020
789cfd9
Refine labels for BoxControl inputs
Apr 21, 2020
23e252d
Adjust BoxControl Y indicator hieght
Apr 21, 2020
0a490f0
Refactor BoxControl inputs + update tests
Apr 21, 2020
3e48e86
Fix left tooltip label for BoxControl
Apr 21, 2020
b9ecc2b
Refactor number-control styles
Apr 21, 2020
bd522f6
Adding isPressToSubmit to unit-control
Apr 21, 2020
73f8215
Improve press enter to change mechanic for NumberControl.
Apr 22, 2020
3b2b4dc
Introduce unit parsing
Apr 22, 2020
51d42d9
Stabilized value/unit parsing
Apr 22, 2020
27fd539
Add unit support to Cover block padding.
Apr 22, 2020
31ef976
Hook up custom units via add_theme_support with Padding controls
Apr 22, 2020
b447ee6
Use floating labels for BoxControl inputs.
Apr 23, 2020
aba8973
Remove tooltip from InputControl. Refactor + update docs.
Apr 23, 2020
7cecdaf
Add InputControl docs to docs/manifest.json
Apr 23, 2020
8fb4dea
Fix tests for UnitControl. Adds tests for value/unit parsing.
Apr 23, 2020
8b282df
Update docs for InputControl and NumberControl
Apr 23, 2020
e6e4548
Update docs and code comments for Input, Number, and Unit control
Apr 23, 2020
2ebfcba
Fix BoxControl rendering
Apr 23, 2020
da3cb72
Fix block editor hook for padding styles
Apr 23, 2020
be8dedc
Cover: Fix BoxControl visualizer rendering
Apr 23, 2020
2a497b9
Fix classNames for Input, Number, and Unit controls. Improve value/un…
Apr 23, 2020
6713a08
Improve blur onChange when isPressEnterToChange is set
Apr 23, 2020
1856cc1
Refactor press enter to change interaction between InputControl and N…
Apr 23, 2020
5c4e7b2
Add Linked adjustment for BoxControl
Apr 23, 2020
16de5ae
Refactor and improve render performance of InputControl
Apr 24, 2020
23cbeaf
Remove defaultUnits static prop
Apr 24, 2020
03ea817
Improves performance and refactors BoxControlVisual styles
Apr 24, 2020
48b489d
Resets input value on blur
Apr 24, 2020
623de49
Fix coupled side update rendering when holding ALT key
Apr 24, 2020
853932f
Adds README for BoxControl and Flex
Apr 24, 2020
8686b4a
Update docs manifest
Apr 24, 2020
ed203c7
Update stories for NumberControl and UnitControl.
Apr 24, 2020
15307d5
Improve unit parsing to handle white space
Apr 24, 2020
db86e9c
Adjust all vs individual side controls layout
Apr 28, 2020
2556e4d
Improve value parsing + validation on submit
Apr 28, 2020
09ddc40
TEMPORARY: Testing inline layout for controls
Apr 29, 2020
58956c2
Implement stateReducer for InputControl, NumberControl, and UnitControl
Apr 29, 2020
73332d7
Fixes tests and wraps up stateReducer update
Apr 30, 2020
b5e923b
Persist events from Input Control reducer. Add comments.
Apr 30, 2020
728b5fd
Remove unused useControlledState hook
Apr 30, 2020
c5586e9
Add default values to InputField props
Apr 30, 2020
67d5690
Improve inline UI for unit controls within BoxControl
Apr 30, 2020
34e6cd4
Add opt-in flag for Spacing controls. Improves control integration wi…
Apr 30, 2020
a93def3
Rename stateReducer to unstable_stateReducer
Apr 30, 2020
2d3fe72
Remove unnecessary eslint-disable rule
Apr 30, 2020
3bc1dce
TEMP: Disable opt-in flag for spacing control for testing purposes.
May 1, 2020
0a972d6
Streamline combine stateReducer flow. Improve performance with memozi…
May 1, 2020
ce8de26
Improve dragEnd event triggering in InputControl
May 1, 2020
7342f4f
Fix memoization issue for state reducer updates
May 2, 2020
022bd12
Rename unstable_stateReducer to __unstableStateReducer
May 5, 2020
e646191
Replace Array.flat with lodash.flattenDeep for IE compatibility
May 5, 2020
78379ae
Fix reset value mechanic stability for BoxControl
May 5, 2020
96c5de8
Add value tests for InputControl
May 5, 2020
e966e62
TEMP: Disable guard for testing
May 5, 2020
c40b731
Remove fixed height for BoxControl
May 5, 2020
0831bf1
Make use of combineStateReducers more explicit for InputControl, Numb…
May 5, 2020
4c4a24b
Refactor useBoxControlState to simply useControlledState with defaults
May 5, 2020
02b51a5
Simplify side active matching for BoxControl/Icon
May 5, 2020
ae40997
Update packages/block-editor/src/components/spacing-panel-control/ind…
May 5, 2020
0716d21
Fix update value on blur
May 12, 2020
dab5b21
Fix tests for UnitControl
May 12, 2020
609b9c3
Memoize input state reducer to prevent unnecessary re-renders
May 12, 2020
2818628
Rename submit -> commit. Fix RTL (from rebase mixup).
May 13, 2020
6a376c0
Update InputControl, NumberControl, and UnitControl from master
May 21, 2020
2242ccd
Merge branch 'master' into try/cover-padding-control
May 21, 2020
c4ada30
Integrate lightBlockWrapper with new padding controls + visualizer
May 21, 2020
550b742
Move __experimentalPadding config to block.json
May 21, 2020
b87de71
Removing leftover comments
May 21, 2020
46f48ac
Adjust spacing for import comments
May 21, 2020
7ec2ea2
Merge branch 'master' into try/cover-padding-control
May 28, 2020
1cf533a
Fix padding theme setting check
Jun 1, 2020
0d5f647
Add sibling usage for BoxControl.Visualizer in README.md
Jun 1, 2020
e0ff560
Merge branch 'master' into try/cover-padding-control
Jun 2, 2020
f263906
Add more content + image examples to Flex README.md
Jun 2, 2020
f3d22fa
Remove experimental prefix for Flex
Jun 2, 2020
dbc99ce
Refactor Flex sub-components to be used/exported without static attac…
Jun 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@
"markdown_source": "../packages/components/src/base-control/README.md",
"parent": "components"
},
{
"title": "BoxControl",
"slug": "box-control",
"markdown_source": "../packages/components/src/box-control/README.md",
"parent": "components"
},
{
"title": "ButtonGroup",
"slug": "button-group",
Expand Down Expand Up @@ -773,6 +779,12 @@
"markdown_source": "../packages/components/src/external-link/README.md",
"parent": "components"
},
{
"title": "Flex",
"slug": "flex",
"markdown_source": "../packages/components/src/flex/README.md",
"parent": "components"
},
{
"title": "FocalPointPicker",
"slug": "focal-point-picker",
Expand Down
14 changes: 14 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,20 @@ function gutenberg_extend_settings_custom_units( $settings ) {
}
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_units' );

/**
* Extends block editor settings to determine whether to use custom spacing controls.
* Currently experimental.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_extend_settings_custom_spacing( $settings ) {
$settings['__experimentalEnableCustomSpacing'] = get_theme_support( 'experimental-custom-spacing' );
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_spacing' );

/*
* Register default patterns if not registered in Core already.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import InspectorControls from '../inspector-controls';

export default function SpacingPanelControl( { children, ...props } ) {
const isSpacingEnabled = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
return get( getSettings(), '__experimentalEnableCustomSpacing' );
ItsJonQ marked this conversation as resolved.
Show resolved Hide resolved
} );

if ( ! isSpacingEnabled ) return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rely on "useFeature"? cc @gziolo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can decide later, my take on it is what fits Global Styles, it should be considered editor features so site owners could decide what to allow for user with different roles.


return (
<InspectorControls { ...props }>
<PanelBody title={ __( 'Spacing' ) }>{ children }</PanelBody>
</InspectorControls>
);
}
48 changes: 28 additions & 20 deletions packages/block-editor/src/components/unit-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,34 @@ import { __experimentalUnitControl as BaseUnitControl } from '@wordpress/compone
*/
import useEditorFeature from '../use-editor-feature';

const { __defaultUnits } = BaseUnitControl;

export default function UnitControl( { units: unitsProp, ...props } ) {
const units = useCustomUnits( unitsProp );

return <BaseUnitControl units={ units } { ...props } />;
}

/**
* Filters available units based on values defined by settings.
*
* @param {Array} settings Collection of preferred units.
* @param {Array} units Collection of available units.
*
* @return {Array} Filtered units based on settings.
*/
function filterUnitsWithSettings( settings = [], units = [] ) {
return units.filter( ( unit ) => {
return settings.includes( unit.value );
} );
}

/**
* Custom hook to retrieve and consolidate units setting from add_theme_support().
*
* @param {Array} unitsProp Collection of available units.
*
* @return {Array} Filtered units based on settings.
*/
export function useCustomUnits( unitsProp ) {
const settings = useEditorFeature( '__experimentalDisableCustomUnits' );
const isDisabled = !! settings;

Expand All @@ -32,22 +57,5 @@ export default function UnitControl( { units: unitsProp, ...props } ) {
units = isDisabled ? false : unitsProp;
}

return <BaseUnitControl units={ units } { ...props } />;
}

// Hoisting statics from the BaseUnitControl
UnitControl.__defaultUnits = __defaultUnits;

/**
* Filters available units based on values defined by settings.
*
* @param {Array} settings Collection of preferred units.
* @param {Array} units Collection of available units.
*
* @return {Array} Filtered units based on settings.
*/
function filterUnitsWithSettings( settings = [], units = [] ) {
return units.filter( ( unit ) => {
return settings.includes( unit.value );
} );
return units;
}
68 changes: 68 additions & 0 deletions packages/block-editor/src/hooks/padding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Platform } from '@wordpress/element';
import { hasBlockSupport } from '@wordpress/blocks';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';

/**
* Internal dependencies
*/
import { cleanEmptyObject } from './utils';
import { useCustomUnits } from '../components/unit-control';

export const PADDING_SUPPORT_KEY = '__experimentalPadding';

/**
* Inspector control panel containing the line height related configuration
*
* @param {Object} props
*
* @return {WPElement} Line height edit element.
*/
export function PaddingEdit( props ) {
const {
name: blockName,
attributes: { style },
setAttributes,
} = props;

const units = useCustomUnits();

if ( ! hasBlockSupport( blockName, PADDING_SUPPORT_KEY ) ) {
return null;
}

const onChange = ( next ) => {
const newStyle = {
...style,
padding: next,
};

setAttributes( {
style: cleanEmptyObject( newStyle ),
} );
};

return Platform.select( {
web: (
<>
<BoxControl
values={ style?.padding }
onChange={ onChange }
label={ __( 'Padding' ) }
units={ units }
/>
</>
),
native: null,
} );
}

export const paddingStyleMappings = {
paddingTop: [ 'padding', 'top' ],
paddingRight: [ 'padding', 'right' ],
paddingBottom: [ 'padding', 'bottom' ],
paddingLeft: [ 'padding', 'left' ],
};
18 changes: 18 additions & 0 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ import { Platform } from '@wordpress/element';
* Internal dependencies
*/
import InspectorControls from '../components/inspector-controls';
import SpacingPanelControl from '../components/spacing-panel-control';
import { COLOR_SUPPORT_KEY, ColorEdit } from './color';
import { LINE_HEIGHT_SUPPORT_KEY, LineHeightEdit } from './line-height';
import { FONT_SIZE_SUPPORT_KEY, FontSizeEdit } from './font-size';
import {
PADDING_SUPPORT_KEY,
PaddingEdit,
paddingStyleMappings,
} from './padding';

const styleSupportKeys = [
COLOR_SUPPORT_KEY,
LINE_HEIGHT_SUPPORT_KEY,
FONT_SIZE_SUPPORT_KEY,
PADDING_SUPPORT_KEY,
];

const typographySupportKeys = [
Expand All @@ -43,6 +50,7 @@ const hasStyleSupport = ( blockType ) =>
*/
export function getInlineStyles( styles = {} ) {
const mappings = {
...paddingStyleMappings,
lineHeight: [ 'typography', 'lineHeight' ],
fontSize: [ 'typography', 'fontSize' ],
background: [ 'color', 'gradient' ],
Expand Down Expand Up @@ -144,6 +152,11 @@ export const withBlockControls = createHigherOrderComponent(
hasBlockSupport( blockName, key )
);

const hasPaddingSupport = hasBlockSupport(
blockName,
PADDING_SUPPORT_KEY
);

return [
Platform.OS === 'web' && hasTypographySupport && (
<InspectorControls key="typography">
Expand All @@ -155,6 +168,11 @@ export const withBlockControls = createHigherOrderComponent(
),
<ColorEdit key="colors" { ...props } />,
<BlockEdit key="edit" { ...props } />,
hasPaddingSupport && (
<SpacingPanelControl key="spacing">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this component to be used in the "style" hook instead of directly in "PaddingEdit"? Do we expect any other "spacing" hook to be added later?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential spacing related hook may be margin.

<PaddingEdit { ...props } />
</SpacingPanelControl>
),
];
},
'withToolbarControls'
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"supports": {
"align": true,
"html": false,
"lightBlockWrapper": true
"lightBlockWrapper": true,
"__experimentalPadding": true
}
}
5 changes: 5 additions & 0 deletions packages/block-library/src/cover/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ResizableBox,
ToggleControl,
withNotices,
__experimentalBoxControl as BoxControl,
} from '@wordpress/components';
import { compose, withInstanceId, useInstanceId } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -70,6 +71,8 @@ const INNER_BLOCKS_TEMPLATE = [
],
];

const { __Visualizer: BoxControlVisualizer } = BoxControl;

function retrieveFastAverageColor() {
if ( ! retrieveFastAverageColor.fastAverageColor ) {
retrieveFastAverageColor.fastAverageColor = new FastAverageColor();
Expand Down Expand Up @@ -244,6 +247,7 @@ function CoverEdit( {
hasParallax,
minHeight,
minHeightUnit,
style: styleAttribute,
url,
} = attributes;
const {
Expand Down Expand Up @@ -471,6 +475,7 @@ function CoverEdit( {
<>
{ controls }
<Block.div className={ classes } data-url={ url } style={ style }>
<BoxControlVisualizer values={ styleAttribute?.padding } />
ItsJonQ marked this conversation as resolved.
Show resolved Hide resolved
<ResizableCover
className="block-library-cover__resize-container"
onResizeStart={ () => {
Expand Down
Loading