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

Allow defining custom Aspect Ratio options through theme.json #57707

Closed
fabiankaegy opened this issue Jan 10, 2024 · 3 comments
Closed

Allow defining custom Aspect Ratio options through theme.json #57707

fabiankaegy opened this issue Jan 10, 2024 · 3 comments
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle

Comments

@fabiankaegy
Copy link
Member

There are a few places now where we allow users to select an Aspect Ratio for their Image. The list of available Aspect Ratios is hard-coded however. (See:

options={ [
// These should use the same values as AspectRatioDropdown in @wordpress/block-editor
{
label: __( 'Original' ),
value: 'auto',
},
{
label: __( 'Square' ),
value: '1',
},
{
label: __( '16:9' ),
value: '16/9',
},
{
label: __( '4:3' ),
value: '4/3',
},
{
label: __( '3:2' ),
value: '3/2',
},
{
label: __( '9:16' ),
value: '9/16',
},
{
label: __( '3:4' ),
value: '3/4',
},
{
label: __( '2:3' ),
value: '2/3',
},
)

This means that there is currently no way to use any aspect ratios that are not a part of this predetermined list.

Especially in more custom designs we are working with style guides that go down to the aspect ratio level and not being able to filter / override the ratios that should be available is a real issue.

Ideally this could work similar to the spazingSizes preset in theme.json where a theme author and eventually maybe even the global styles interface would be able to define the available aspect ratios.

My proposed syntax would be:

{
    "version": 2,
    "settings": {
        "dimensions": {
            "aspectRatios": [ // allows you to define custom aspect ratios
                {
                    "slug": "5by4",
                    "label": "5:4",
                    "value": "5/4"
                }
            ],
            "defaultAspectRatios": false // disables the core provided ones
        }
    }
}
@fabiankaegy fabiankaegy added [Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Block] Post Featured Image Affects the Post Featured Image Block labels Jan 10, 2024
@fabiankaegy
Copy link
Member Author

Regarding the AspectGroups I think we should be able to programmatically determine whether something is Landscape or Horizontal:

<AspectGroup
isDisabled={ isInProgress }
onClick={ ( newAspect ) => {
setAspect( newAspect );
onClose();
} }
value={ aspect }
aspectRatios={ [
// All ratios should be mirrored in AspectRatioTool in @wordpress/block-editor.
{
title: __( 'Original' ),
aspect: defaultAspect,
},
{
title: __( 'Square' ),
aspect: 1,
},
] }
/>
<AspectGroup
label={ __( 'Landscape' ) }
isDisabled={ isInProgress }
onClick={ ( newAspect ) => {
setAspect( newAspect );
onClose();
} }
value={ aspect }
aspectRatios={ [
{
title: __( '16:9' ),
aspect: 16 / 9,
},
{
title: __( '4:3' ),
aspect: 4 / 3,
},
{
title: __( '3:2' ),
aspect: 3 / 2,
},
] }
/>
<AspectGroup
label={ __( 'Portrait' ) }
isDisabled={ isInProgress }
onClick={ ( newAspect ) => {
setAspect( newAspect );
onClose();
} }
value={ aspect }
aspectRatios={ [
{
title: __( '9:16' ),
aspect: 9 / 16,
},
{
title: __( '3:4' ),
aspect: 3 / 4,
},
{
title: __( '2:3' ),
aspect: 2 / 3,
},
] }
/>
</>

@justintadlock
Copy link
Contributor

There's a PR for theme-defined aspect ratios here: #47271

@annezazu
Copy link
Contributor

Looks like this can be closed out with #47271 merged. Closing but happy to reopen if I'm missing an aspect of this.

@fabiankaegy fabiankaegy added the Needs Dev Note Requires a developer note for a major WordPress release cycle label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle
Projects
Development

No branches or pull requests

3 participants