Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
- Convert `SpacingSizesControl`, `FitTextSizeWarning`, the line height hook and the spacing visualizer to TypeScript ([#84907](https://github.com/WordPress/gutenberg/pull/84907)).
- Convert the block color contrast warning hook, the block bindings panel, the block style variation hook and the position hook to TypeScript ([#84908](https://github.com/WordPress/gutenberg/pull/84908)).
- Convert `AlignmentControl`, `BlockAlignmentMatrixControl`, `HeadingLevelDropdown`, `HTMLElementControl`, `BlockFullHeightAlignmentControl`, `BlockEditVisuallyButton`, `ToolSelector`, `PreviewOptions`, `useBlockOverlayActive`, `UnitControl`, `ResizableBoxPopover` and `HeightControl` to TypeScript ([#84912](https://github.com/WordPress/gutenberg/pull/84912)).
- Convert `InserterListbox`, `BlockPatternsPaging`, `__unstableInserterMenuExtension`, `BlockCard`, `BlockVariationTransforms`, `BlockVariationPicker`, `InspectorPopoverHeader`, `MultiSelectionInspector`, `BlockQuickNavigation` and `TabbedSidebar` to TypeScript ([#84913](https://github.com/WordPress/gutenberg/pull/84913)).

## 18.1.0 (2026-10-07)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import { getBlockType } from '@wordpress/blocks';
import { unlock } from '../../lock-unlock';
import { store as blockEditorStore } from '../../store';
import BlockIcon from '../block-icon';
import type { BlockCardProps, OptionalParentSelectButtonProps } from './types';

function OptionalParentSelectButton( { children, onClick } ) {
function OptionalParentSelectButton( {
children,
onClick,
}: OptionalParentSelectButtonProps ) {
if ( ! onClick ) {
return children;
}
Expand Down Expand Up @@ -51,20 +55,20 @@ function OptionalParentSelectButton( { children, onClick } ) {
* }
* ```
*
* @param {Object} props Component props.
* @param {string} props.title The title of the block.
* @param {string|Object} props.icon The icon of the block. This can be any of [WordPress' Dashicons](https://developer.wordpress.org/resource/dashicons/), or a custom `svg` element.
* @param {string} props.description The description of the block.
* @param {Object} [props.blockType] Deprecated: Object containing block type data.
* @param {string} [props.className] Additional classes to apply to the card.
* @param {string} [props.name] Custom block name to display before the title.
* @param {string} [props.allowParentNavigation] Show a back arrow to the parent block in some situations.
* @param {string} [props.parentClientId] The parent clientId, if this card is for a parent block.
* @param {string} [props.isChild] Whether the block card is for a child block, in which case, indent the block using an arrow.
* @param {string} [props.clientId] Whether the block card is for a child block, in which case, indent the block using an arrow.
* @param {Element} [props.controls] Controls rendered beside the block title.
* @param {Element} [props.children] Children.
* @return {Element} Block card component.
* @param props Component props.
* @param props.title The title of the block.
* @param props.icon The icon of the block. This can be any of [WordPress' Dashicons](https://developer.wordpress.org/resource/dashicons/), or a custom `svg` element.
* @param props.description The description of the block.
* @param props.blockType Deprecated: Object containing block type data.
* @param props.className Additional classes to apply to the card.
* @param props.name Custom block name to display before the title.
* @param props.allowParentNavigation Show a back arrow to the parent block in some situations.
* @param props.parentClientId The parent clientId, if this card is for a parent block.
* @param props.isChild Whether the block card is for a child block, in which case, indent the block using an arrow.
* @param props.clientId Whether the block card is for a child block, in which case, indent the block using an arrow.
* @param props.controls Controls rendered beside the block title.
* @param props.children Children.
* @return Block card component.
*/
function BlockCard( {
title,
Expand All @@ -79,7 +83,7 @@ function BlockCard( {
children,
clientId,
controls,
} ) {
}: BlockCardProps ) {
if ( blockType ) {
deprecated( '`blockType` property in `BlockCard component`', {
since: '5.7',
Expand All @@ -97,8 +101,9 @@ function BlockCard( {
unlock( select( blockEditorStore ) );

// Find the top-most parent block that participates in List View.
const parents = getBlockParents( clientId, false );
const foundParentId = parents.find( ( parentId ) =>
// Parent navigation is only allowed for a block's card.
const parents = getBlockParents( clientId!, false );
const foundParentId = parents.find( ( parentId: string ) =>
shouldRenderBlockListView( parentId )
);

Expand Down Expand Up @@ -140,8 +145,9 @@ function BlockCard( {
? sprintf(
/* translators: %s: The name of the parent block. */
__( 'Go to "%s" block' ),
// A selected parent block is registered.
getBlockType( parentBlockName )
?.title
?.title as string
)
: __( 'Go to parent block' )
}
Expand Down Expand Up @@ -179,7 +185,8 @@ function BlockCard( {
{ ! parentClientId &&
! isChild &&
!! name?.length && (
<Badge>{ title }</Badge>
// A named card has a title.
<Badge>{ title as string }</Badge>
) }
</TitleElement>
{ children }
Expand Down
66 changes: 66 additions & 0 deletions packages/block-editor/src/components/block-card/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { ReactNode } from 'react';
import type { BlockIconProps } from '../block-icon/types';

/**
* Props of the button selecting the parent block, rendered only with a click
* handler.
*/
export interface OptionalParentSelectButtonProps {
children?: ReactNode;
onClick?: () => void;
}

/**
* Props of `BlockCard`.
*/
export interface BlockCardProps {
/**
* The title of the block.
*/
title?: string;
/**
* The icon of the block.
*/
icon?: BlockIconProps[ 'icon' ];
/**
* The description of the block.
*/
description?: string;
/**
* Deprecated: Object containing block type data.
*/
blockType?: {
title?: string;
icon?: BlockIconProps[ 'icon' ];
description?: string;
};
/**
* Additional classes to apply to the card.
*/
className?: string;
/**
* Custom block name to display before the title.
*/
name?: string;
/**
* Show a back arrow to the parent block in some situations.
*/
allowParentNavigation?: boolean;
/**
* The parent clientId, if this card is for a parent block.
*/
parentClientId?: string;
/**
* Whether the block card is for a child block.
*/
isChild?: boolean;
/**
* The client ID of the block.
*/
clientId?: string;
/**
* Controls rendered beside the block title.
*/
controls?: ReactNode;
children?: ReactNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import {
Button,
} from '@wordpress/components';
import { __, _x, _n, sprintf } from '@wordpress/i18n';
import type { PaginationProps } from './types';

export default function Pagination( {
currentPage,
numPages,
changePage,
totalItems,
} ) {
}: PaginationProps ) {
return (
<VStack className="block-editor-patterns__grid-pagination-wrapper">
<WCText variant="muted">
{ sprintf(
// translators: %s: Total number of patterns.
_n( '%s item', '%s items', totalItems ),
totalItems
// `sprintf` formats numbers with `%s`.
totalItems as unknown as string
) }
</WCText>
{ numPages > 1 && (
Expand Down Expand Up @@ -60,8 +62,9 @@ export default function Pagination( {
{ sprintf(
// translators: 1: Current page number. 2: Total number of pages.
_x( '%1$s of %2$s', 'paging' ),
currentPage,
numPages
// `sprintf` formats numbers with `%s`.
currentPage as unknown as string,
numPages as unknown as string
) }
</WCText>
<HStack
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Props of the patterns pagination.
*/
export interface PaginationProps {
currentPage: number;
numPages: number;
changePage: ( page: number ) => void;
totalItems: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ import BlockIcon from '../block-icon';
import useBlockDisplayInformation from '../use-block-display-information';
import useBlockDisplayTitle from '../block-title/use-block-display-title';
import { unlock } from '../../lock-unlock';
import type {
BlockQuickNavigationItemProps,
BlockQuickNavigationProps,
} from './types';

export default function BlockQuickNavigation( {
clientIds,
onSelect,
onSwitchToListView,
hasListViewTab,
} ) {
}: BlockQuickNavigationProps ) {
if ( ! clientIds.length ) {
return null;
}
Expand All @@ -46,7 +50,7 @@ function BlockQuickNavigationItem( {
onSelect,
onSwitchToListView,
hasListViewTab,
} ) {
}: BlockQuickNavigationItemProps ) {
const blockInformation = useBlockDisplayInformation( clientId );
const { isSelected, childBlocks, shouldRenderListView, blockName } =
useSelect(
Expand Down Expand Up @@ -102,7 +106,8 @@ function BlockQuickNavigationItem( {
toggleBlockHighlight( clientId, false )
);
useEffect(
() => () => clearBlockHighlightOnUnmount(),
// React ignores the value the cleanup returns.
() => ( () => clearBlockHighlightOnUnmount() ) as () => void,
[ clearBlockHighlightOnUnmount ]
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Props of `BlockQuickNavigation`.
*/
export interface BlockQuickNavigationProps {
clientIds: string[];
onSelect?: ( clientId: string ) => void;
onSwitchToListView?: ( clientId: string ) => void;
hasListViewTab?: boolean;
}

/**
* Props of one block in the quick navigation.
*/
export interface BlockQuickNavigationItemProps extends Omit<
BlockQuickNavigationProps,
'clientIds'
> {
clientId: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import clsx from 'clsx';
import { __ } from '@wordpress/i18n';
import { Button, Placeholder } from '@wordpress/components';
import { layout } from '@wordpress/icons';
import type { ComponentProps } from 'react';
import type { BlockTypeIconDescriptor } from '@wordpress/blocks';
import type { BlockVariationPickerProps } from './types';

function BlockVariationPicker( {
icon = layout,
Expand All @@ -10,7 +13,7 @@ function BlockVariationPicker( {
variations,
onSelect,
allowSkip,
} ) {
}: BlockVariationPickerProps ) {
const classes = clsx( 'block-editor-block-variation-picker', {
'has-many-variations': variations.length > 4,
} );
Expand All @@ -37,10 +40,17 @@ function BlockVariationPicker( {
<Button
__next40pxDefaultSize
variant="tertiary"
// A variation icon is a descriptor or the icon itself.
icon={
variation.icon && variation.icon.src
? variation.icon.src
: variation.icon
( variation.icon &&
( variation.icon as BlockTypeIconDescriptor )
.src
? (
variation.icon as BlockTypeIconDescriptor
).src
: variation.icon ) as ComponentProps<
typeof Button
>[ 'icon' ]
}
iconSize={ 48 }
onClick={ () => onSelect( variation ) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { BlockTypeIcon, BlockVariation } from '@wordpress/blocks';
import type { ComponentProps } from 'react';
import type { Placeholder } from '@wordpress/components';

/**
* A variation offered by `BlockVariationPicker`.
*/
export type PickableBlockVariation = Omit< BlockVariation, 'icon' > & {
icon?: BlockTypeIcon;
};

/**
* Props of `BlockVariationPicker`.
*/
export interface BlockVariationPickerProps {
icon?: ComponentProps< typeof Placeholder >[ 'icon' ];
label?: string;
instructions?: string;
variations: PickableBlockVariation[];
onSelect: ( variation?: PickableBlockVariation ) => void;
allowSkip?: boolean;
}
Loading
Loading