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

Button: Add lint rule for 40px size prop usage #64835

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ module.exports = {
'FormFileUpload should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
},
// Temporary rules until all existing components have the `__next40pxDefaultSize` prop.
...[ 'SelectControl', 'UnitControl' ].map(
...[ 'Button', 'SelectControl', 'UnitControl' ].map(
( componentName ) => ( {
// Not strict. Allows pre-existing __next40pxDefaultSize={ false } usage until they are all manually updated.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"])):not(:has(JSXAttribute[name.name="size"]))`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ function DownloadableBlockListItem( { composite, item, onClick } ) {
<CompositeItem
render={
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
accessibleWhenDisabled
type="button"
role="option"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ const ModifiedWarning = ( { originalBlock, ...props } ) => {
originalBlock.title || originalName
);
actions.push(
<Button key="convert" onClick={ convertToHTML } variant="tertiary">
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key="convert"
onClick={ convertToHTML }
variant="tertiary"
>
{ __( 'Keep as HTML' ) }
</Button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default function InstallButton( { attributes, block, clientId } ) {

return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
onClick={ () =>
installBlockType( block ).then( ( success ) => {
if ( success ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function BlockBreadcrumb( { rootLabelText } ) {
>
{ hasSelection && (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className="block-editor-block-breadcrumb__button"
variant="tertiary"
onClick={ () => {
Expand Down Expand Up @@ -94,6 +96,8 @@ function BlockBreadcrumb( { rootLabelText } ) {
{ parents.map( ( parentClientId ) => (
<li key={ parentClientId }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className="block-editor-block-breadcrumb__button"
variant="tertiary"
onClick={ () => selectBlock( parentClientId ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export default function BlockView( {
</div>

<div className="block-editor-block-compare__action">
<Button variant="secondary" tabIndex="0" onClick={ action }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="secondary"
tabIndex="0"
onClick={ action }
>
{ actionText }
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export function MultipleUsageWarning( {
<Warning
actions={ [
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key="find-original"
variant="secondary"
onClick={ () => selectBlock( originalBlockClientId ) }
>
{ __( 'Find original' ) }
</Button>,
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key="remove"
variant="secondary"
onClick={ () => onReplace( [] ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export default function BlockInvalidWarning( { clientId } ) {
<Warning
actions={ [
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key="recover"
onClick={ convert.toRecoveredBlock }
variant="primary"
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-mover/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const BlockMoverButton = forwardRef(
return (
<>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
ref={ ref }
className={ clsx(
'block-editor-block-mover-button',
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function BlockMover( {
<BlockDraggable clientIds={ clientIds } fadeWhenDisabled>
{ ( draggableProps ) => (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ dragHandle }
className="block-editor-block-mover__drag-handle"
label={ __( 'Drag' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function BlockNavigationDropdownToggle( {
} ) {
return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...props }
ref={ innerRef }
icon={ listView }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { VIEWMODES } from './constants';

const Actions = ( { onBlockPatternSelect } ) => (
<div className="block-editor-block-pattern-setup__actions">
<Button variant="primary" onClick={ onBlockPatternSelect }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="primary"
onClick={ onBlockPatternSelect }
>
{ __( 'Choose' ) }
</Button>
</div>
Expand All @@ -31,13 +36,17 @@ const CarouselNavigation = ( {
} ) => (
<div className="block-editor-block-pattern-setup__navigation">
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ chevronLeft }
label={ __( 'Previous pattern' ) }
onClick={ handlePrevious }
disabled={ activeSlide === 0 }
accessibleWhenDisabled
/>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ chevronRight }
label={ __( 'Next pattern' ) }
onClick={ handleNext }
Expand All @@ -60,12 +69,16 @@ const SetupToolbar = ( {
const displayControls = (
<div className="block-editor-block-pattern-setup__display-controls">
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ stretchFullWidth }
label={ __( 'Carousel view' ) }
onClick={ () => setViewMode( VIEWMODES.carousel ) }
isPressed={ isCarouselView }
/>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ grid }
label={ __( 'Grid view' ) }
onClick={ () => setViewMode( VIEWMODES.grid ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default function Pagination( {
className="block-editor-patterns__grid-pagination-previous"
>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="tertiary"
onClick={ () => changePage( 1 ) }
disabled={ currentPage === 1 }
Expand All @@ -47,6 +49,8 @@ export default function Pagination( {
<span>«</span>
</Button>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="tertiary"
onClick={ () => changePage( currentPage - 1 ) }
disabled={ currentPage === 1 }
Expand All @@ -70,6 +74,8 @@ export default function Pagination( {
className="block-editor-patterns__grid-pagination-next"
>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="tertiary"
onClick={ () => changePage( currentPage + 1 ) }
disabled={ currentPage === numPages }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function BlockQuickNavigationItem( { clientId, onSelect } ) {

return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
isPressed={ isSelected }
onClick={ async () => {
await selectBlock( clientId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
<BlockDraggable clientIds={ [ clientId ] }>
{ ( draggableProps ) => (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
icon={ dragHandle }
className="block-selection-button_drag-handle"
label={ dragHandleLabel }
Expand All @@ -272,6 +274,8 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
{ editorMode === 'navigation' && (
<FlexItem>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
ref={ ref }
onClick={
editorMode === 'navigation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function BlockVariationPicker( {
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
{ allowSkip && (
<div className="block-editor-block-variation-picker__skip">
<Button variant="link" onClick={ () => onSelect() }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="link"
onClick={ () => onSelect() }
>
{ __( 'Skip' ) }
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function VariationsButtons( {
</VisuallyHidden>
{ variations.map( ( variation ) => (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key={ variation.name }
icon={ <BlockIcon icon={ variation.icon } showColors /> }
isPressed={ selectedValue === variation.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function ButtonBlockAppender(

let inserterButton = (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
ref={ ref }
onFocus={ onFocus }
tabIndex={ tabIndex }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ const renderToggle =
};

return (
<Button { ...toggleProps }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...toggleProps }
>
<LabeledColorIndicator
colorValue={ colorValue }
label={ label }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ function ColorPanelDropdown( {
};

return (
<Button { ...toggleProps }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...toggleProps }
>
<LabeledColorIndicators
indicators={ indicators }
label={ label }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export default function FiltersPanel( {

return (
<ItemGroup isBordered isSeparated>
<Button { ...toggleProps }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...toggleProps }
>
<LabeledColorIndicator
indicator={ duotone }
label={ __( 'Duotone' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export function ShadowPopoverContainer( { shadow, onShadowChange, settings } ) {
/>
<div className="block-editor-global-styles__clear-shadow">
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="tertiary"
onClick={ () => onShadowChange( undefined ) }
>
Expand Down Expand Up @@ -99,6 +101,8 @@ export function ShadowIndicator( { type, label, isActive, onSelect, shadow } ) {
} ) }
render={
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className={ clsx(
'block-editor-global-styles__shadow-indicator',
{
Expand Down Expand Up @@ -151,7 +155,11 @@ function renderShadowToggle() {
};

return (
<Button { ...toggleProps }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...toggleProps }
>
<HStack justify="flex-start">
<Icon
className="block-editor-global-styles__toggle-icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ function InserterListboxItem(
if ( typeof children === 'function' ) {
return children( propsWithTabIndex );
}
return <Button { ...propsWithTabIndex }>{ children }</Button>;
return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
{ ...propsWithTabIndex }
>
{ children }
</Button>
);
} }
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function PatternCategoriesList( {
{ patternCategories.map( ( { name, label } ) => {
return (
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
key={ name }
label={ label }
className={ `${ baseClassName }__categories-list__item` }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function BlockPatternsTab( {
{ children }
</CategoryTabs>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className="block-editor-inserter__patterns-explore-button"
onClick={ () => setShowPatternsExplorer( true ) }
variant="secondary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ function InsertExternalImageModal( { onClose, onSubmit } ) {
expanded={ false }
>
<FlexItem>
<Button variant="tertiary" onClick={ onClose }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="tertiary"
onClick={ onClose }
>
{ __( 'Cancel' ) }
</Button>
</FlexItem>
<FlexItem>
<Button variant="primary" onClick={ onSubmit }>
<Button
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
variant="primary"
onClick={ onSubmit }
>
{ __( 'Insert' ) }
</Button>
</FlexItem>
Expand Down
Loading
Loading