From 4263e8549989b374bbf8f47c61e1e08a3fe3b041 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 12 Dec 2024 17:42:58 +0100 Subject: [PATCH 01/13] BoxControl: Add support for presets (#67688) Co-authored-by: youknowriad Co-authored-by: ntsekouras Co-authored-by: ramonjd Co-authored-by: jorgefilipecosta Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: jameskoster --- packages/components/CHANGELOG.md | 6 +- packages/components/src/box-control/README.md | 16 ++ packages/components/src/box-control/index.tsx | 4 + .../src/box-control/input-control.tsx | 182 ++++++++++++++---- .../src/box-control/stories/index.story.tsx | 12 ++ packages/components/src/box-control/types.ts | 18 ++ packages/components/src/box-control/utils.ts | 60 ++++++ 7 files changed, 256 insertions(+), 42 deletions(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index e8ae2bc7ba6092..49cc196b1f7e69 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancements + +- `BoxControl`: Add presets support ([#67688](https://github.com/WordPress/gutenberg/pull/67688)). + ### Deprecations - `SelectControl`: Deprecate 36px default size ([#66898](https://github.com/WordPress/gutenberg/pull/66898)). @@ -24,7 +28,7 @@ - `Menu`: Replace hardcoded white color with theme-ready variable ([#67649](https://github.com/WordPress/gutenberg/pull/67649)). - `Navigation` (deprecated): Replace hardcoded white color with theme-ready variable ([#67649](https://github.com/WordPress/gutenberg/pull/67649)). - `ToggleGroupControl`: Replace hardcoded white color with theme-ready variable ([#67649](https://github.com/WordPress/gutenberg/pull/67649)). -- `RangeControl`: Update the design of the range control marks ([#67611](https://github.com/WordPress/gutenberg/pull/67611)) +- `RangeControl`: Update the design of the range control marks ([#67611](https://github.com/WordPress/gutenberg/pull/67611)). - `BorderBoxControl`: Reduce gap value when unlinked ([#67049](https://github.com/WordPress/gutenberg/pull/67049)). - `DropdownMenu`: Increase option height to 40px ([#67435](https://github.com/WordPress/gutenberg/pull/67435)). - `MenuItem`: Increase height to 40px ([#67435](https://github.com/WordPress/gutenberg/pull/67435)). diff --git a/packages/components/src/box-control/README.md b/packages/components/src/box-control/README.md index 8bcb5a5dad8fc2..da08cafceee42f 100644 --- a/packages/components/src/box-control/README.md +++ b/packages/components/src/box-control/README.md @@ -79,6 +79,22 @@ A callback function when an input value changes. - Required: No - Default: `() => {}` +### `presets` + +Available presets to pick from. + + - Type: `Preset[]` + - Required: No + +### `presetKey` + +The key of the preset to apply. +If you provide a list of presets, you must provide a preset key to use. +The format of preset selected values is going to be `var:preset|${ presetKey }|${ presetSlug }` + + - Type: `string` + - Required: No + ### `resetValues` The `top`, `right`, `bottom`, and `left` box dimension values to use when the control is reset. diff --git a/packages/components/src/box-control/index.tsx b/packages/components/src/box-control/index.tsx index 279dfa55eafe38..d4d4b03f893036 100644 --- a/packages/components/src/box-control/index.tsx +++ b/packages/components/src/box-control/index.tsx @@ -83,6 +83,8 @@ function BoxControl( { splitOnAxis = false, allowReset = true, resetValues = DEFAULT_VALUES, + presets, + presetKey, onMouseOver, onMouseOut, }: BoxControlProps ) { @@ -153,6 +155,8 @@ function BoxControl( { sides, values: inputValues, __next40pxDefaultSize, + presets, + presetKey, }; maybeWarnDeprecated36pxSize( { diff --git a/packages/components/src/box-control/input-control.tsx b/packages/components/src/box-control/input-control.tsx index 2e1765f518a57d..81fbcad42c1d08 100644 --- a/packages/components/src/box-control/input-control.tsx +++ b/packages/components/src/box-control/input-control.tsx @@ -3,6 +3,8 @@ */ import { useInstanceId } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; +import { useState } from '@wordpress/element'; +import { settings } from '@wordpress/icons'; /** * Internal dependencies @@ -11,10 +13,13 @@ import Tooltip from '../tooltip'; import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils'; import { CUSTOM_VALUE_SETTINGS, - getAllowedSides, getMergedValue, - isValueMixed, + getAllowedSides, + getPresetIndexFromValue, + getPresetValueFromIndex, + isValuePreset, isValuesDefined, + isValueMixed, LABELS, } from './utils'; import { @@ -24,6 +29,7 @@ import { StyledUnitControl, } from './styles/box-control-styles'; import type { BoxControlInputControlProps, BoxControlValue } from './types'; +import Button from '../button'; const noop = () => {}; @@ -79,6 +85,8 @@ export default function BoxInputControl( { sides, side, min = 0, + presets, + presetKey, ...props }: BoxControlInputControlProps ) { const defaultValuesToModify = getSidesToModify( side, sides ); @@ -91,6 +99,15 @@ export default function BoxInputControl( { onChange( nextValues ); }; + const handleRawOnValueChange = ( next?: string ) => { + const nextValues = { ...values }; + defaultValuesToModify.forEach( ( modifiedSide ) => { + nextValues[ modifiedSide ] = next; + } ); + + handleOnChange( nextValues ); + }; + const handleOnValueChange = ( next?: string, extra?: { event: React.SyntheticEvent< Element, Event > } @@ -148,52 +165,135 @@ export default function BoxInputControl( { const usedValue = mergedValue === undefined && computedUnit ? computedUnit : mergedValue; const mixedPlaceholder = isMixed || isMixedUnit ? __( 'Mixed' ) : undefined; + const hasPresets = presets && presets.length > 0 && presetKey; + const hasPresetValue = + hasPresets && + mergedValue !== undefined && + ! isMixed && + isValuePreset( mergedValue, presetKey ); + const [ showCustomValueControl, setShowCustomValueControl ] = useState( + ! hasPresets || + ( ! hasPresetValue && ! isMixed && mergedValue !== undefined ) + ); + const presetIndex = hasPresetValue + ? getPresetIndexFromValue( mergedValue, presetKey, presets ) + : undefined; + const marks = hasPresets + ? [ { value: 0, label: '', tooltip: __( 'None' ) } ].concat( + presets.map( ( preset, index ) => ( { + value: index + 1, + label: '', + tooltip: preset.name ?? preset.slug, + } ) ) + ) + : []; return ( - - + + + + + { + handleOnValueChange( + newValue !== undefined + ? [ newValue, computedUnit ].join( '' ) + : undefined + ); + } } + min={ isFinite( min ) ? min : 0 } + max={ + CUSTOM_VALUE_SETTINGS[ computedUnit ?? 'px' ] + ?.max ?? 10 + } + step={ + CUSTOM_VALUE_SETTINGS[ computedUnit ?? 'px' ] + ?.step ?? 0.1 + } + value={ parsedQuantity ?? 0 } + withInputField={ false } + /> + + ) } + + { hasPresets && ! showCustomValueControl && ( + { + const newValue = + newIndex === 0 || newIndex === undefined + ? undefined + : getPresetValueFromIndex( + newIndex - 1, + presetKey, + presets + ); + handleRawOnValueChange( newValue ); + } } + withInputField={ false } + aria-valuenow={ + presetIndex !== undefined ? presetIndex + 1 : 0 + } + aria-valuetext={ + marks[ presetIndex !== undefined ? presetIndex + 1 : 0 ] + .label + } + renderTooltipContent={ ( index ) => + marks[ ! index ? 0 : index ].tooltip + } + min={ 0 } + max={ marks.length - 1 } + marks={ marks } label={ LABELS[ side ] } - placeholder={ mixedPlaceholder } hideLabelFromVision + __nextHasNoMarginBottom + /> + ) } + + { hasPresets && ( + - ); - } ) } - - + { + handleChange( undefined ); + } } + > + !! selectedWidth } + onDeselect={ () => handleChange( undefined ) } + > + + { [ 25, 50, 75, 100 ].map( ( widthValue ) => { + return ( + + ); + } ) } + + + ); } From 63b0e7f1ce6a8626fecf6714d6288b534220f46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20K=C3=A4gy?= Date: Thu, 12 Dec 2024 20:27:21 +0100 Subject: [PATCH 09/13] Adding @fabiankaegy as a code owner of the block library package (#67891) Co-authored-by: fabiankaegy Co-authored-by: youknowriad --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2ec03cba722c6b..3e02267da7c512 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -13,7 +13,7 @@ /packages/data-controls @nerrad # Blocks -/packages/block-library @ajitbohra +/packages/block-library @ajitbohra @fabiankaegy /packages/block-library/src/gallery @geriux /packages/block-library/src/comment-template @michalczaplinski /packages/block-library/src/comments @michalczaplinski From cff73d475e9323e63657c0c246cb613ca3388c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 12 Dec 2024 21:19:27 +0100 Subject: [PATCH 10/13] Pages: update layout-specific config when the view is updated (#67881) Co-authored-by: oandregal Co-authored-by: youknowriad --- packages/edit-site/src/components/post-list/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/post-list/index.js b/packages/edit-site/src/components/post-list/index.js index a67a505795b3c8..bbf5d654ddb57a 100644 --- a/packages/edit-site/src/components/post-list/index.js +++ b/packages/edit-site/src/components/post-list/index.js @@ -109,6 +109,7 @@ function useView( postType ) { return { ...initialView, type, + ...defaultLayouts[ type ], }; } ); @@ -140,13 +141,15 @@ function useView( postType ) { // without affecting any other config. const onUrlLayoutChange = useEvent( () => { setView( ( prevView ) => { - const layoutToApply = layout ?? LAYOUT_LIST; - if ( layoutToApply === prevView.type ) { + const newType = layout ?? LAYOUT_LIST; + if ( newType === prevView.type ) { return prevView; } + return { ...prevView, - type: layout ?? LAYOUT_LIST, + type: newType, + ...defaultLayouts[ newType ], }; } ); } ); @@ -168,6 +171,7 @@ function useView( postType ) { setView( { ...newView, type, + ...defaultLayouts[ type ], } ); } } ); From 8d6b8c5c05a2427af04e8639341ddcfac299751e Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 13 Dec 2024 04:09:55 +0530 Subject: [PATCH 11/13] Refactor "Settings" panel of Table block to use ToolsPanel instead of PanelBody (#67896) Co-authored-by: Sukhendu2002 Co-authored-by: fabiankaegy --- packages/block-library/src/table/edit.js | 74 +++++++++++++++++------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/packages/block-library/src/table/edit.js b/packages/block-library/src/table/edit.js index f1cb3fa5d8b8ae..1d61bab0787e44 100644 --- a/packages/block-library/src/table/edit.js +++ b/packages/block-library/src/table/edit.js @@ -20,12 +20,13 @@ import { import { __ } from '@wordpress/i18n'; import { Button, - PanelBody, Placeholder, TextControl, ToggleControl, ToolbarDropdownMenu, __experimentalHasSplitBorders as hasSplitBorders, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { alignLeft, @@ -473,33 +474,66 @@ function TableEdit( { ) } - { + setAttributes( { + hasFixedLayout: true, + head: [], + foot: [], + } ); + } } > - hasFixedLayout !== true } label={ __( 'Fixed width table cells' ) } - checked={ !! hasFixedLayout } - onChange={ onChangeFixedLayout } - /> + onDeselect={ () => + setAttributes( { hasFixedLayout: true } ) + } + isShownByDefault + > + + { ! isEmpty && ( <> - head && head.length } label={ __( 'Header section' ) } - checked={ !! ( head && head.length ) } - onChange={ onToggleHeaderSection } - /> - + setAttributes( { head: [] } ) + } + isShownByDefault + > + + + foot && foot.length } label={ __( 'Footer section' ) } - checked={ !! ( foot && foot.length ) } - onChange={ onToggleFooterSection } - /> + onDeselect={ () => + setAttributes( { foot: [] } ) + } + isShownByDefault + > + + ) } - + { ! isEmpty && ( Date: Fri, 13 Dec 2024 09:02:59 +0200 Subject: [PATCH 12/13] Storybook: Fix warnings in Layout document (#67865) Co-authored-by: tyxla Co-authored-by: jameskoster Co-authored-by: mirka <0mirka00@git.wordpress.org> --- storybook/stories/foundations/layout.mdx | 60 ++++++++++++------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/storybook/stories/foundations/layout.mdx b/storybook/stories/foundations/layout.mdx index abc0c7c4f6947f..578f4e8b66e428 100644 --- a/storybook/stories/foundations/layout.mdx +++ b/storybook/stories/foundations/layout.mdx @@ -1,4 +1,4 @@ -import { Meta } from '@storybook/addon-docs/blocks'; +import { Meta } from '@storybook/blocks'; import areas from './static/areas.svg'; import pageLayoutExample1 from './static/page-layout-example-1.svg'; import pageLayoutExample2 from './static/page-layout-example-2.svg'; @@ -27,32 +27,34 @@ At the highest level admin pages are comprised of _areas_, that can be arranged Areas can be combined in different ways depending on the use case. Here are some examples.
- - - - - - - - + + + + + + + + + +
- #### Sidebar, Content Frame and Preview Frame - Diagram illustrating an example of the 'Sidebar, Content Frame and Preview Frame' arrangement - - A demonstration of this arrangement can be found in the Styles section of the Site Editor, and in the Pages and Templates sections when List layout is selected. - - #### Sidebar and Preview Frame - Diagram illustrating an example of the 'Sidebar and Preview Frame' arrangement - - A demonstration of this arrangement can be found in the Design section. -
- #### Sidebar and Content Frame - Diagram illustrating an example of the 'Sidebar and Content Frame' arrangement - - A demonstration of this arrangement can be found in the Patterns and Templates sections of the Site Editor, or in the Pages section when Table or Grid layout are selected. - - #### Sidebar and multiple Content Frames - Diagram illustrating an example of the 'Sidebar and multiple Content Frames' arrangement - - Multiple content frames can be utilised as required. -
+ #### Sidebar, Content Frame and Preview Frame + Diagram illustrating an example of the 'Sidebar, Content Frame and Preview Frame' arrangement + + A demonstration of this arrangement can be found in the Styles section of the Site Editor, and in the Pages and Templates sections when List layout is selected. + + #### Sidebar and Preview Frame + Diagram illustrating an example of the 'Sidebar and Preview Frame' arrangement + + A demonstration of this arrangement can be found in the Design section. +
+ #### Sidebar and Content Frame + Diagram illustrating an example of the 'Sidebar and Content Frame' arrangement + + A demonstration of this arrangement can be found in the Patterns and Templates sections of the Site Editor, or in the Pages section when Table or Grid layout are selected. + + #### Sidebar and multiple Content Frames + Diagram illustrating an example of the 'Sidebar and multiple Content Frames' arrangement + + Multiple content frames can be utilised as required. +
From cbe7ef4d597cc28f3ab0fc9c7593b9af8085aa36 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Fri, 13 Dec 2024 13:49:27 +0530 Subject: [PATCH 13/13] Refactor "Settings" panel of Date block to use ToolsPanel instead of PanelBody (#67906) Co-authored-by: Sukhendu2002 Co-authored-by: fabiankaegy --- packages/block-library/src/post-date/edit.js | 97 +++++++++++++++----- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js index 5057466c6af453..6ac39c0f14798d 100644 --- a/packages/block-library/src/post-date/edit.js +++ b/packages/block-library/src/post-date/edit.js @@ -26,7 +26,8 @@ import { ToolbarGroup, ToolbarButton, ToggleControl, - PanelBody, + __experimentalToolsPanel as ToolsPanel, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; import { edit } from '@wordpress/icons'; @@ -160,16 +161,36 @@ export default function PostDateEdit( { - - - setAttributes( { format: nextFormat } ) + { + setAttributes( { + format: undefined, + isLink: false, + displayType: 'date', + } ); + } } + > + + format !== undefined && format !== siteFormat + } + label={ __( 'Date Format' ) } + onDeselect={ () => + setAttributes( { format: undefined } ) } - /> - + + setAttributes( { format: nextFormat } ) + } + /> + + isLink !== false } label={ postType?.labels.singular_name ? sprintf( @@ -179,23 +200,49 @@ export default function PostDateEdit( { ) : __( 'Link to post' ) } - onChange={ () => setAttributes( { isLink: ! isLink } ) } - checked={ isLink } - /> - setAttributes( { isLink: false } ) } + isShownByDefault + > + + setAttributes( { isLink: ! isLink } ) + } + checked={ isLink } + /> + + displayType !== 'date' } label={ __( 'Display last modified date' ) } - onChange={ ( value ) => - setAttributes( { - displayType: value ? 'modified' : 'date', - } ) + onDeselect={ () => + setAttributes( { displayType: 'date' } ) } - checked={ displayType === 'modified' } - help={ __( - 'Only shows if the post has been modified' - ) } - /> - + isShownByDefault + > + + setAttributes( { + displayType: value ? 'modified' : 'date', + } ) + } + checked={ displayType === 'modified' } + help={ __( + 'Only shows if the post has been modified' + ) } + /> + +
{ postDate }