Skip to content

Commit

Permalink
Fix image block schema (#435)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Piercy <[email protected]>
Co-authored-by: David Glick <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 2eed4ee commit d4e7a71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/volto-light-theme/news/435.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't show image size and alignment settings for image block inside a grid. @danalvrz
40 changes: 24 additions & 16 deletions packages/volto-light-theme/src/components/Blocks/Image/schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineMessages } from 'react-intl';
import { insertInArray, reorderArray } from '@plone/volto/helpers/Utils/Utils';
import { insertInArray } from '@plone/volto/helpers/Utils/Utils';
import config from '@plone/volto/registry';

const messages = defineMessages({
Expand All @@ -19,7 +19,6 @@ const messages = defineMessages({

export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
if (formData.url) {
schema.fieldsets = reorderArray(schema.fieldsets, 2, 1);
schema.fieldsets[0].fields = insertInArray(
schema.fieldsets[0].fields,
'description',
Expand All @@ -31,6 +30,29 @@ export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
1,
);

schema.properties.description = {
title: intl.formatMessage(messages.Description),
widget: 'textarea',
};
schema.properties.title = {
title: intl.formatMessage(messages.Title),
};
}

return schema;
};

export const standAloneImageBlockSchemaEnhancer = ({
formData,
schema,
intl,
}) => {
if (formData.url) {
schema.properties.align.default = 'center';
schema.properties.align.actions = ['left', 'right', 'center'];

schema.properties.size.default = 'l';
schema.properties.size.disabled = formData.align === 'center';
schema.properties.styles.schema.fieldsets[0].fields = [
'blockWidth:noprefix',
'--image-aspect-ratio',
Expand All @@ -54,20 +76,6 @@ export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
],
};

schema.properties.description = {
title: intl.formatMessage(messages.Description),
widget: 'textarea',
};
schema.properties.title = {
title: intl.formatMessage(messages.Title),
};

schema.properties.align.default = 'center';
schema.properties.align.actions = ['left', 'right', 'center'];

schema.properties.size.default = 'l';
schema.properties.size.disabled = formData.align === 'center';

schema.properties.styles.schema.properties['blockWidth:noprefix'].disabled =
formData.align === 'left' || formData.align === 'right';
}
Expand Down
6 changes: 5 additions & 1 deletion packages/volto-light-theme/src/config/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import GridListingBlockTemplate from '../components/Blocks/Listing/GridTemplate'
import { ButtonStylingSchema } from '../components/Blocks/Button/schema';
import { SeparatorStylingSchema } from '../components/Blocks/Separator/schema';

import { imageBlockSchemaEnhancer } from '../components/Blocks/Image/schema';
import {
imageBlockSchemaEnhancer,
standAloneImageBlockSchemaEnhancer,
} from '../components/Blocks/Image/schema';
import { ImageBlockDataAdapter } from '../components/Blocks/Image/adapter';

import { AccordionSchemaEnhancer } from '../components/Blocks/Accordion/schema';
Expand Down Expand Up @@ -206,6 +209,7 @@ export default function install(config: ConfigType) {
schemaEnhancer: composeSchema(
defaultStylingSchema,
imageBlockSchemaEnhancer,
standAloneImageBlockSchemaEnhancer,
),
dataAdapter: ImageBlockDataAdapter,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-light-theme/src/theme/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ $secondary-grey: #ececec !default;
--link-foreground-color: var(--link-color);

// It is possible to set an aspect ratio for all images, using the folowing CSS custom property:
// --image-aspect-ratio: 16/9;
// --image-aspect-ratio: calc(16 / 9);
}

// Image Aspect Ratio
$aspect-ratio: 16/9 !default;
$aspect-ratio: calc(16 / 9) !default;

// Weights
$thin: 100 !default;
Expand Down

0 comments on commit d4e7a71

Please sign in to comment.