Skip to content

Commit

Permalink
change(policy): added styling schema as a block enhancer useful for s…
Browse files Browse the repository at this point in the history
…everal packages
  • Loading branch information
ichim-david committed Nov 3, 2022
1 parent 6670763 commit 1cc294f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/Blocks/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.
50 changes: 50 additions & 0 deletions src/components/Blocks/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { cloneDeep } from 'lodash';
import imageFitSVG from '@eeacms/volto-eea-website-policy/components/Blocks/icons/image-narrow.svg';
import imageWideSVG from '@plone/volto/icons/image-wide.svg';
import imageFullSVG from '@plone/volto/icons/image-full.svg';

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

export const addStylingFieldsetSchemaEnhancer = ({ schema }) => {
const applied = schema?.properties?.styles;

if (!applied) {
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;
};
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runtimeConfig } from '@plone/volto/runtime_config';
import installCallout from '@plone/volto-slate/editor/plugins/Callout';
import installContextNavigationBlock from '@eeacms/volto-eea-website-policy/components/Blocks/ContextNavigation';
import { addStylingFieldsetSchemaEnhancer } from '@eeacms/volto-eea-website-policy/components/Blocks/schema';

const applyConfig = (config) => {
// if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -90,6 +91,7 @@ const applyConfig = (config) => {
// Columns
if (config.blocks.blocksConfig.columnsBlock) {
config.blocks.blocksConfig.columnsBlock.mostUsed = true;
config.blocks.blocksConfig.columnsBlock.schemaEnhancer = addStylingFieldsetSchemaEnhancer;
}

// Accordion
Expand Down

0 comments on commit 1cc294f

Please sign in to comment.