This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from eea/develop
Develop
- Loading branch information
Showing
7 changed files
with
102 additions
and
6 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
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
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,3 @@ | ||
describe('Blocks Tests', () => { | ||
it('Add Blocks: Empty', () => {}); | ||
}); |
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
22 changes: 22 additions & 0 deletions
22
src/customizations/volto/components/manage/Blocks/Block/StyleWrapper.jsx
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,22 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { buildStyleClassNamesFromData } from '@plone/volto/helpers'; | ||
|
||
const StyleWrapper = (props) => { | ||
const { children, data = {} } = props; | ||
const styles = buildStyleClassNamesFromData(data.styles); | ||
const rewrittenChildren = React.Children.map(children, (child) => { | ||
if (React.isValidElement(child)) { | ||
const childProps = { | ||
...props, | ||
className: cx([child.props.className, ...styles]), | ||
}; | ||
return React.cloneElement(child, childProps); | ||
} | ||
return child; | ||
}); | ||
|
||
return rewrittenChildren; | ||
}; | ||
|
||
export default StyleWrapper; |
65 changes: 65 additions & 0 deletions
65
src/customizations/volto/components/theme/View/RenderBlocks.jsx
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,65 @@ | ||
import React from 'react'; | ||
import { getBaseUrl, applyBlockDefaults } from '@plone/volto/helpers'; | ||
import { defineMessages, injectIntl } from 'react-intl'; | ||
import { map } from 'lodash'; | ||
import { | ||
getBlocksFieldname, | ||
getBlocksLayoutFieldname, | ||
hasBlocksData, | ||
} from '@plone/volto/helpers'; | ||
import config from '@plone/volto/registry'; | ||
import StyleWrapper from '../../manage/Blocks/Block/StyleWrapper'; | ||
|
||
const messages = defineMessages({ | ||
unknownBlock: { | ||
id: 'Unknown Block', | ||
defaultMessage: 'Unknown Block {block}', | ||
}, | ||
}); | ||
|
||
const RenderBlocks = (props) => { | ||
const { content, intl, location, metadata } = props; | ||
const blocksFieldname = getBlocksFieldname(content); | ||
const blocksLayoutFieldname = getBlocksLayoutFieldname(content); | ||
const blocksConfig = props.blocksConfig || config.blocks.blocksConfig; | ||
const CustomTag = props.as || React.Fragment; | ||
|
||
return hasBlocksData(content) ? ( | ||
<CustomTag> | ||
{map(content[blocksLayoutFieldname].items, (block) => { | ||
const Block = | ||
blocksConfig[content[blocksFieldname]?.[block]?.['@type']]?.view; | ||
|
||
const blockData = applyBlockDefaults({ | ||
data: content[blocksFieldname][block], | ||
intl, | ||
metadata, | ||
properties: content, | ||
}); | ||
|
||
return Block ? ( | ||
<StyleWrapper key={block} {...props} id={block} data={blockData}> | ||
<Block | ||
id={block} | ||
metadata={metadata} | ||
properties={content} | ||
data={blockData} | ||
path={getBaseUrl(location?.pathname || '')} | ||
blocksConfig={blocksConfig} | ||
/> | ||
</StyleWrapper> | ||
) : ( | ||
<div key={block}> | ||
{intl.formatMessage(messages.unknownBlock, { | ||
block: content[blocksFieldname]?.[block]?.['@type'], | ||
})} | ||
</div> | ||
); | ||
})} | ||
</CustomTag> | ||
) : ( | ||
'' | ||
); | ||
}; | ||
|
||
export default injectIntl(RenderBlocks); |
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