Skip to content

Commit

Permalink
added missing schema-utils.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
ichim-david committed May 10, 2023
1 parent 4ef6f14 commit ff1c052
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/helpers/schema-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { cloneDeep } from 'lodash';
import imageNarrowSVG from '@eeacms/volto-eea-website-theme/icons/image-narrow.svg';
import imageFitSVG from '@plone/volto/icons/image-fit.svg';
import imageWideSVG from '@plone/volto/icons/image-wide.svg';
import imageFullSVG from '@plone/volto/icons/image-full.svg';

export const ALIGN_INFO_MAP = {
narrow_width: [imageNarrowSVG, '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;
};
export const getVoltoStyles = (props) => {
// return an object with same key and value for cx class setting
const styles = props ? props : {};
const output = {};
for (const [key, value] of Object.entries(styles)) {
if (key === '@type') {
continue;
}
if (styles[key] === true) {
output[key] = key;
} else {
output[value] = value;
}
}
return output;
};

0 comments on commit ff1c052

Please sign in to comment.