From 20ca80f48c1b022305164cdbb16baf1329d785f4 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Wed, 11 Sep 2024 10:24:18 +0200 Subject: [PATCH 01/17] DatePicker: better hover/focus styles (#65117) * DatePicker: better hover/focus styles * CHANGELOG * Use after pseudo-element to avoid conflict with calendar event dot * Make event dots compatible with high contrast mode * Apply box sizing utility * Use themed colors * Use translate to prevent event dot from jumping --- Co-authored-by: ciampo Co-authored-by: tyxla Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: t-hamano --- packages/components/CHANGELOG.md | 4 ++ .../components/src/date-time/date/styles.ts | 42 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 8c656f4adb48bb..8a9151e3fdc05e 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -14,6 +14,10 @@ - `Modal`: Decrease close button size and remove horizontal offset ([#65131](https://github.com/WordPress/gutenberg/pull/65131)). +### Bug Fixes + +- `DatePicker`: better hover/focus styles ([#65117](https://github.com/WordPress/gutenberg/pull/65117)). + ### Internal - `Composite`: Remove from private APIs ([#63569](https://github.com/WordPress/gutenberg/pull/63569)). diff --git a/packages/components/src/date-time/date/styles.ts b/packages/components/src/date-time/date/styles.ts index bffc8ae35d2a64..84405854827ec9 100644 --- a/packages/components/src/date-time/date/styles.ts +++ b/packages/components/src/date-time/date/styles.ts @@ -7,13 +7,13 @@ import styled from '@emotion/styled'; * Internal dependencies */ import Button from '../../button'; -import { COLORS, CONFIG } from '../../utils'; +import { boxSizingReset, COLORS, CONFIG } from '../../utils'; import { HStack } from '../../h-stack'; import { Heading } from '../../heading'; import { space } from '../../utils/space'; export const Wrapper = styled.div` - box-sizing: border-box; + ${ boxSizingReset } `; export const Navigator = styled( HStack )` @@ -38,7 +38,7 @@ export const Calendar = styled.div` `; export const DayOfWeek = styled.div` - color: ${ COLORS.gray[ 700 ] }; + color: ${ COLORS.theme.gray[ 700 ] }; font-size: ${ CONFIG.fontSize }; line-height: ${ CONFIG.fontLineHeightBase }; @@ -90,15 +90,34 @@ export const DayButton = styled( Button, { ${ ( props ) => props.isSelected && ` - background: ${ COLORS.theme.accent }; - color: ${ COLORS.white }; + background: ${ COLORS.theme.accent }; + + &, + &:hover:not(:disabled, [aria-disabled=true]) { + color: ${ COLORS.theme.accentInverted }; + } + + &:focus:not(:disabled), + &:focus:not(:disabled) { + border: ${ CONFIG.borderWidthFocus } solid currentColor; + } + + /* Highlight the selected day for high-contrast mode */ + &::after { + content: ''; + position: absolute; + pointer-events: none; + inset: 0; + border-radius: inherit; + border: 1px solid transparent; + } ` } ${ ( props ) => ! props.isSelected && props.isToday && ` - background: ${ COLORS.gray[ 200 ] }; + background: ${ COLORS.theme.gray[ 200 ] }; ` } } @@ -106,15 +125,16 @@ export const DayButton = styled( Button, { props.hasEvents && ` ::before { - background: ${ props.isSelected ? COLORS.white : COLORS.theme.accent }; + border: 2px solid ${ + props.isSelected + ? COLORS.theme.accentInverted + : COLORS.theme.accent + }; border-radius: ${ CONFIG.radiusRound }; - bottom: 2px; content: " "; - height: 4px; left: 50%; - margin-left: -2px; position: absolute; - width: 4px; + transform: translate(-50%, 9px); } ` } `; From 5daa582f7fa20f28daabf546e1686c016432b04f Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Wed, 11 Sep 2024 11:05:07 +0200 Subject: [PATCH 02/17] Navigator Screen: warn if path doesn't follow a URL-like scheme (#65231) * Navigator Screen: warn if path doesn't follow the expected scheme * Add test * CHANGELOG --- Co-authored-by: ciampo Co-authored-by: Mamaduka Co-authored-by: ramonjd --- packages/components/CHANGELOG.md | 1 + .../src/navigator/navigator-screen/component.tsx | 7 +++++++ packages/components/src/navigator/test/index.tsx | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 8a9151e3fdc05e..55c85565f522aa 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -12,6 +12,7 @@ ### Enhancements +- `Navigator`: warn if a screen's `path` doesn't follow a URL-like scheme ([#65231](https://github.com/WordPress/gutenberg/pull/65231)). - `Modal`: Decrease close button size and remove horizontal offset ([#65131](https://github.com/WordPress/gutenberg/pull/65131)). ### Bug Fixes diff --git a/packages/components/src/navigator/navigator-screen/component.tsx b/packages/components/src/navigator/navigator-screen/component.tsx index be5c4bfaf41ec4..5882f271d4518f 100644 --- a/packages/components/src/navigator/navigator-screen/component.tsx +++ b/packages/components/src/navigator/navigator-screen/component.tsx @@ -17,6 +17,7 @@ import { import { useMergeRefs } from '@wordpress/compose'; import { isRTL as isRTLFn } from '@wordpress/i18n'; import { escapeAttribute } from '@wordpress/escape-html'; +import warning from '@wordpress/warning'; /** * Internal dependencies @@ -33,6 +34,12 @@ function UnconnectedNavigatorScreen( props: WordPressComponentProps< NavigatorScreenProps, 'div', false >, forwardedRef: ForwardedRef< any > ) { + if ( ! /^\//.test( props.path ) ) { + warning( + 'wp.components.NavigatorScreen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.' + ); + } + const screenId = useId(); const { children, className, path, ...otherProps } = useContextSystem( props, diff --git a/packages/components/src/navigator/test/index.tsx b/packages/components/src/navigator/test/index.tsx index 9b9b257ea09681..820942a22644ba 100644 --- a/packages/components/src/navigator/test/index.tsx +++ b/packages/components/src/navigator/test/index.tsx @@ -642,6 +642,14 @@ describe( 'Navigator', () => { ).toHaveAttribute( 'id', INVALID_HTML_ATTRIBUTE.escaped ); } ); + it( 'should warn if the `path` prop does not follow the required format', () => { + render( Test ); + + expect( console ).toHaveWarnedWith( + 'wp.components.NavigatorScreen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.' + ); + } ); + it( 'should match correctly paths with named arguments', async () => { const user = userEvent.setup(); From 3d5dacd3ed50fb2cba64cf62781a8859716e3738 Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:45:50 +0200 Subject: [PATCH 03/17] Populate block context with inherited post type from template slug (#65062) * Inherit post type from template slug * Move map outside of `useSelect` Co-authored-by: SantosGuillamot Co-authored-by: Mamaduka Co-authored-by: artemiomorales Co-authored-by: cbravobernal --- .../editor/src/components/provider/index.js | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index aaf25621d3324b..11b1478d58434a 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -4,7 +4,11 @@ import { useEffect, useLayoutEffect, useMemo } from '@wordpress/element'; import { useDispatch, useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; -import { EntityProvider, useEntityBlockEditor } from '@wordpress/core-data'; +import { + EntityProvider, + useEntityBlockEditor, + store as coreStore, +} from '@wordpress/core-data'; import { BlockEditorProvider, BlockContextProvider, @@ -48,7 +52,6 @@ const noop = () => {}; */ const NON_CONTEXTUAL_POST_TYPES = [ 'wp_block', - 'wp_template', 'wp_navigation', 'wp_template_part', ]; @@ -161,31 +164,59 @@ export const ExperimentalEditorProvider = withRegistryProvider( BlockEditorProviderComponent = ExperimentalBlockEditorProvider, __unstableTemplate: template, } ) => { - const { editorSettings, selection, isReady, mode } = useSelect( - ( select ) => { + const { editorSettings, selection, isReady, mode, postTypes } = + useSelect( ( select ) => { const { getEditorSettings, getEditorSelection, getRenderingMode, __unstableIsEditorReady, } = select( editorStore ); + const { getPostTypes } = select( coreStore ); + return { editorSettings: getEditorSettings(), isReady: __unstableIsEditorReady(), mode: getRenderingMode(), selection: getEditorSelection(), + postTypes: getPostTypes( { per_page: -1 } ), }; - }, - [] - ); + }, [] ); const shouldRenderTemplate = !! template && mode !== 'post-only'; const rootLevelPost = shouldRenderTemplate ? template : post; const defaultBlockContext = useMemo( () => { - const postContext = + const postContext = {}; + // If it is a template, try to inherit the post type from the slug. + if ( post.type === 'wp_template' ) { + if ( ! post.is_custom ) { + const [ kind ] = post.slug.split( '-' ); + switch ( kind ) { + case 'page': + postContext.postType = 'page'; + break; + case 'single': + // Infer the post type from the slug. + const postTypesSlugs = + postTypes?.map( ( entity ) => entity.slug ) || + []; + const match = post.slug.match( + `^single-(${ postTypesSlugs.join( + '|' + ) })(?:-.+)?$` + ); + if ( match ) { + postContext.postType = match[ 1 ]; + } + break; + } + } + } else if ( ! NON_CONTEXTUAL_POST_TYPES.includes( rootLevelPost.type ) || shouldRenderTemplate - ? { postId: post.id, postType: post.type } - : {}; + ) { + postContext.postId = post.id; + postContext.postType = post.type; + } return { ...postContext, @@ -200,6 +231,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( post.type, rootLevelPost.type, rootLevelPost.slug, + postTypes, ] ); const { id, type } = rootLevelPost; const blockEditorSettings = useBlockEditorSettings( From b2766478255b83b9a44be72bceaa843734778be2 Mon Sep 17 00:00:00 2001 From: Akshat Kakkad <87222220+AKSHAT2802@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:48:58 +0530 Subject: [PATCH 04/17] Remove Warning and add notice for Navigation (#63921) Co-authored-by: AKSHAT2802 Co-authored-by: Mamaduka Co-authored-by: afercia --- .../edit/deleted-navigation-warning.js | 42 ++++++++++--------- .../edit/menu-inspector-controls.js | 4 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/block-library/src/navigation/edit/deleted-navigation-warning.js b/packages/block-library/src/navigation/edit/deleted-navigation-warning.js index b0521f16cfb5d5..22d1e339c5c004 100644 --- a/packages/block-library/src/navigation/edit/deleted-navigation-warning.js +++ b/packages/block-library/src/navigation/edit/deleted-navigation-warning.js @@ -2,28 +2,32 @@ * WordPress dependencies */ import { Warning } from '@wordpress/block-editor'; -import { Button } from '@wordpress/components'; +import { Button, Notice } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { createInterpolateElement } from '@wordpress/element'; -function DeletedNavigationWarning( { onCreateNew } ) { - return ( - - { createInterpolateElement( - __( - 'Navigation Menu has been deleted or is unavailable. ' - ), - { - button: ( - ' + ), + { + button: ( +