Skip to content

Commit

Permalink
Feature: add ability to show drop cap setting in paragraph block by d…
Browse files Browse the repository at this point in the history
…efault via defaultControls config (#45994)

Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>
  • Loading branch information
9 people authored Dec 9, 2024
1 parent ce01840 commit 0d757db
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useSettings,
useBlockEditingMode,
} from '@wordpress/block-editor';
import { getBlockSupport } from '@wordpress/blocks';
import { formatLtr } from '@wordpress/icons';

/**
Expand All @@ -47,7 +48,7 @@ function hasDropCapDisabled( align ) {
return align === ( isRTL() ? 'left' : 'right' ) || align === 'center';
}

function DropCapControl( { clientId, attributes, setAttributes } ) {
function DropCapControl( { clientId, attributes, setAttributes, name } ) {
// Please do not add a useSelect call to the paragraph block unconditionally.
// Every useSelect added to a (frequently used) block will degrade load
// and type performance. By moving it within InspectorControls, the subscription is
Expand All @@ -69,11 +70,18 @@ function DropCapControl( { clientId, attributes, setAttributes } ) {
helpText = __( 'Show a large initial letter.' );
}

const isDropCapControlEnabledByDefault = getBlockSupport(
name,
'typography.defaultControls.dropCap',
false
);

return (
<InspectorControls group="typography">
<ToolsPanelItem
hasValue={ () => !! dropCap }
label={ __( 'Drop cap' ) }
isShownByDefault={ isDropCapControlEnabledByDefault }
onDeselect={ () => setAttributes( { dropCap: undefined } ) }
resetAllFilter={ () => ( { dropCap: undefined } ) }
panelId={ clientId }
Expand All @@ -99,6 +107,7 @@ function ParagraphBlock( {
setAttributes,
clientId,
isSelected: isSingleSelected,
name,
} ) {
const { align, content, direction, dropCap, placeholder } = attributes;
const blockProps = useBlockProps( {
Expand Down Expand Up @@ -136,6 +145,7 @@ function ParagraphBlock( {
) }
{ isSingleSelected && (
<DropCapControl
name={ name }
clientId={ clientId }
attributes={ attributes }
setAttributes={ setAttributes }
Expand Down

0 comments on commit 0d757db

Please sign in to comment.