Skip to content

Commit

Permalink
Trying to change the header labels for background
Browse files Browse the repository at this point in the history
- Background > Background image
- Using the title/url of the current image in the media uploader component
  • Loading branch information
ramonjd committed Apr 12, 2024
1 parent 73ee882 commit 7a56d04
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
<InspectorControls.Slot group="styles" />
<InspectorControls.Slot
group="background"
label={ __( 'Background' ) }
label={ __( 'Background image' ) }
/>
<PositionControls />
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ export const backgroundPositionToCoords = ( value ) => {
};

function InspectorImagePreview( { label, filename, url: imgUrl } ) {
const imgLabel = label || getFilename( imgUrl );
let imgLabel = label || getFilename( imgUrl );
// getFilename returns 'undefined' as a string.
imgLabel =
!! imgLabel && imgLabel !== 'undefined'
? imgLabel
: __( 'Select or upload image' );

return (
<ItemGroup as="span">
<HStack justify="flex-start" as="span">
Expand Down Expand Up @@ -295,7 +301,7 @@ function BackgroundImageToolsPanelItem( {
onSelect={ onSelectMedia }
name={
<InspectorImagePreview
label={ __( 'Background image' ) }
label={ title }
filename={ title || __( 'Untitled' ) }
url={ url }
/>
Expand Down Expand Up @@ -518,6 +524,7 @@ function BackgroundToolsPanel( {
value,
panelId,
children,
headerLabel,
} ) {
const resetAll = () => {
const updatedValue = resetAllFilter( value );
Expand All @@ -528,7 +535,7 @@ function BackgroundToolsPanel( {
<VStack
as={ ToolsPanel }
spacing={ 6 }
label={ __( 'Background' ) }
label={ headerLabel }
resetAll={ resetAll }
panelId={ panelId }
dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
Expand All @@ -552,6 +559,7 @@ export default function BackgroundPanel( {
panelId,
defaultControls = DEFAULT_CONTROLS,
defaultValues = {},
headerLabel = __( 'Background image' ),
} ) {
const resetAllFilter = useCallback( ( previousValue ) => {
return {
Expand All @@ -568,6 +576,7 @@ export default function BackgroundPanel( {
value={ value }
onChange={ onChange }
panelId={ panelId }
headerLabel={ headerLabel }
>
<BackgroundImageToolsPanelItem
onChange={ onChange }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const StylesTab = ( { blockName, clientId, hasBlockStyles } ) => {
/>
<InspectorControls.Slot
group="background"
label={ __( 'Background' ) }
label={ __( 'Background image' ) }
/>
<InspectorControls.Slot group="filter" />
<InspectorControls.Slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -34,6 +35,7 @@ export default function BackgroundPanel() {
value={ style }
onChange={ setStyle }
settings={ settings }
headerLabel={ __( 'Image' ) }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/global-styles/root-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ function RootMenu() {
<NavigationButtonAsItem
icon={ image }
path="/background"
aria-label={ __( 'Background styles' ) }
aria-label={ __( 'Background image styles' ) }
>
{ __( 'Background' ) }
{ __( 'Background image' ) }
</NavigationButtonAsItem>
) }
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ScreenBackground() {
const hasBackgroundPanel = useHasBackgroundPanel( settings );
return (
<>
<ScreenHeader title={ __( 'Background' ) } />
<ScreenHeader title={ __( 'Background image' ) } />
{ hasBackgroundPanel && <BackgroundPanel /> }
</>
);
Expand Down

0 comments on commit 7a56d04

Please sign in to comment.