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

add ability to show drop cap setting in paragraph block by default #45994

Merged
Merged
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
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
Loading