Skip to content

Commit

Permalink
Merge branch 'trunk' into update/date-time-picker-design
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks authored May 26, 2022
2 parents 35974c7 + 329fb9c commit c79f127
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
29 changes: 23 additions & 6 deletions docs/reference-guides/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ supports: {
- Subproperties:
- `margin`: type `boolean` or `array`, default value `false`
- `padding`: type `boolean` or `array`, default value `false`
- `blockGap`: type `boolean` or `array`, default value `false`

This value signals that a block supports some of the CSS style properties related to spacing. When it does, the block editor will show UI controls for the user to set their values, if [the theme declares support](/docs/how-to-guides/themes/theme-support.md#cover-block-padding).

Expand All @@ -548,25 +549,41 @@ supports: {
spacing: {
margin: true, // Enable margin UI control.
padding: true, // Enable padding UI control.
blockGap: true, // Enables block spacing UI control.
}
}
```

When the block declares support for a specific spacing property, the attributes definition is extended to include the `style` attribute.

- `style`: attribute of `object` type with no default assigned. This is added when `margin` or `padding` support is declared. It stores the custom values set by the user.
- `style`: attribute of `object` type with no default assigned. This is added when `margin` or `padding` support is declared. It stores the custom values set by the user, e.g.:

```js
supports: {
spacing: {
margin: [ 'top', 'bottom' ], // Enable margin for arbitrary sides.
padding: true, // Enable padding for all sides.
attributes: {
style: {
margin: 'value',
padding: {
top: 'value',
}
}
}
```

A spacing property may define an array of allowable sides that can be configured. When arbitrary sides are defined only UI controls for those sides are displayed. Axial sides are defined with the `vertical` and `horizontal` terms, and display a single UI control for each axial pair (for example, `vertical` controls both the top and bottom sides). A spacing property may support arbitrary individual sides **or** axial sides, but not a mix of both.
A spacing property may define an array of allowable sides – 'top', 'right', 'bottom', 'left' – that can be configured. When such arbitrary sides are defined, only UI controls for those sides are displayed.

Axial sides are defined with the `vertical` and `horizontal` terms, and display a single UI control for each axial pair (for example, `vertical` controls both the top and bottom sides). A spacing property may support arbitrary individual sides **or** axial sides, but not a mix of both.

Note: `blockGap` accepts `vertical` and `horizontal` axial sides, which adjust gap column and row values. `blockGap` doesn't support arbitrary sides.

```js
supports: {
spacing: {
margin: [ 'top', 'bottom' ], // Enable margin for arbitrary sides.
padding: true, // Enable padding for all sides.
blockGap: [ 'horizontal', 'vertical' ], // Enables axial (column/row) block spacing controls
}
}
```

## typography

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { switchToBlockType } from '@wordpress/blocks';
import { switchToBlockType, store as blocksStore } from '@wordpress/blocks';
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
import { group, row, stack } from '@wordpress/icons';
import { _x } from '@wordpress/i18n';
Expand All @@ -28,14 +28,20 @@ function BlockGroupToolbar() {
} = useConvertToGroupButtonProps();
const { replaceBlocks } = useDispatch( blockEditorStore );

const { canRemove } = useSelect(
const { canRemove, variations } = useSelect(
( select ) => {
const { canRemoveBlocks } = select( blockEditorStore );
const { getBlockVariations } = select( blocksStore );

return {
canRemove: canRemoveBlocks( clientIds ),
variations: getBlockVariations(
groupingBlockName,
'transform'
),
};
},
[ clientIds ]
[ clientIds, groupingBlockName ]
);

const onConvertToGroup = ( layout = 'group' ) => {
Expand Down Expand Up @@ -63,23 +69,34 @@ function BlockGroupToolbar() {
return null;
}

const canInsertRow = !! variations.find(
( { name } ) => name === 'group-row'
);
const canInsertStack = !! variations.find(
( { name } ) => name === 'group-stack'
);

return (
<ToolbarGroup>
<ToolbarButton
icon={ group }
label={ _x( 'Group', 'verb' ) }
onClick={ onConvertToGroup }
/>
<ToolbarButton
icon={ row }
label={ _x( 'Row', 'single horizontal line' ) }
onClick={ onConvertToRow }
/>
<ToolbarButton
icon={ stack }
label={ _x( 'Stack', 'verb' ) }
onClick={ onConvertToStack }
/>
{ canInsertRow && (
<ToolbarButton
icon={ row }
label={ _x( 'Row', 'single horizontal line' ) }
onClick={ onConvertToRow }
/>
) }
{ canInsertStack && (
<ToolbarButton
icon={ stack }
label={ _x( 'Stack', 'verb' ) }
onClick={ onConvertToStack }
/>
) }
</ToolbarGroup>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- `SelectControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#41269](https://github.com/WordPress/gutenberg/pull/41269)).
- `ColorPicker`: Strip leading hash character from hex values pasted into input. ([#41223](https://github.com/WordPress/gutenberg/pull/41223))
- Updated design for the `DateTimePicker`, `DatePicker` and `TimePicker` components ([#41097](https://github.com/WordPress/gutenberg/pull/41097)).
- `DateTimePicker`: Add `__nextRemoveHelpButton` and `__nextRemoveResetButton` for opting into new behaviour where there is no Help and Reset button ([#41097](https://github.com/WordPress/gutenberg/pull/41097)).

Expand Down
16 changes: 16 additions & 0 deletions packages/components/src/color-picker/hex-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Spacer } from '../spacer';
import { space } from '../ui/utils/space';
import { ColorHexInputControl } from './styles';
import { COLORS } from '../utils/colors-values';
import type { StateReducer } from '../input-control/reducer/state';

interface HexInputProps {
color: Colord;
Expand All @@ -33,6 +34,20 @@ export const HexInput = ( { color, onChange, enableAlpha }: HexInputProps ) => {
onChange( colord( hexValue ) );
};

const stateReducer: StateReducer = ( state, action ) => {
const nativeEvent = action.payload?.event?.nativeEvent as InputEvent;

if ( 'insertFromPaste' !== nativeEvent?.inputType ) {
return { ...state };
}

const value = state.value?.startsWith( '#' )
? state.value.slice( 1 ).toUpperCase()
: state.value?.toUpperCase();

return { ...state, value };
};

return (
<ColorHexInputControl
prefix={
Expand All @@ -50,6 +65,7 @@ export const HexInput = ( { color, onChange, enableAlpha }: HexInputProps ) => {
maxLength={ enableAlpha ? 9 : 7 }
label={ __( 'Hex color' ) }
hideLabelFromVision
__unstableStateReducer={ stateReducer }
/>
);
};

0 comments on commit c79f127

Please sign in to comment.