Skip to content

Commit

Permalink
change(column): wip adding styling schema as a block enhancer
Browse files Browse the repository at this point in the history
  • Loading branch information
ichim-david committed Nov 3, 2022
1 parent ce0a4a5 commit 85574a3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ColumnsBlock/icons/image-narrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions src/ColumnsBlock/schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { defineMessages } from 'react-intl';
import { cloneDeep } from 'lodash';

import config from '@plone/volto/registry';

import imageFitSVG from '@eeacms/volto-columns-block/ColumnsBlock/icons/image-narrow.svg';
import imageWideSVG from '@plone/volto/icons/image-wide.svg';
import imageFullSVG from '@plone/volto/icons/image-full.svg';
import { COLUMNSBLOCK } from '../constants';

const ALIGN_INFO_MAP = {
narrow_width: [imageFitSVG, 'Narrow width'],
container_width: [imageFitSVG, 'Container width'],
wide_width: [imageWideSVG, 'Wide width'],
full: [imageFullSVG, 'Full width'],
};

const messages = defineMessages({
labelColumn: {
Expand Down Expand Up @@ -80,3 +95,43 @@ export const ColumnsBlockSchema = (intl) => ({
},
required: [],
});

export const addStylingFieldsetSchemaEnhancer = ({ schema }) => {
const applied = schema.fieldsets[0].fields.includes('styling');
const enableStyling = config.blocks.blocksConfig[COLUMNSBLOCK].enableStyling;

if (!applied && enableStyling) {
const resSchema = cloneDeep(schema);

resSchema.fieldsets.push({
id: 'styling',
fields: ['styles'],
title: 'Styling',
});
resSchema.properties.styles = {
widget: 'object',
title: 'Styling',
schema: {
fieldsets: [
{
id: 'default',
title: 'Default',
fields: ['size'],
},
],
properties: {
size: {
widget: 'style_align',
title: 'Section size',
actions: Object.keys(ALIGN_INFO_MAP),
actionsInfoMap: ALIGN_INFO_MAP,
},
},
required: [],
},
};
return resSchema;
}

return schema;
};
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { COLUMNSBLOCK } from './constants';
import { cloneColumnsBlockData } from './utils';

import { getBlocks } from '@plone/volto/helpers';
import { addStylingFieldsetSchemaEnhancer } from './ColumnsBlock/schema';

const extendedSchema = (config) => {
const choices = Object.keys(config.blocks.blocksConfig)
Expand Down Expand Up @@ -58,6 +59,8 @@ export default function install(config) {
mostUsed: false,
blockHasOwnFocusManagement: true,
schema: extendedSchema(config),
enableStyling: true,
schemaEnhancer: addStylingFieldsetSchemaEnhancer,
sidebarTab: 1,
security: {
addPermission: [],
Expand Down

0 comments on commit 85574a3

Please sign in to comment.