generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ef6f14
commit ff1c052
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |