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.
feat(group): Variations support refs #157040 #26 from eea/variationsS…
…upport
- Loading branch information
Showing
6 changed files
with
168 additions
and
102 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as GroupBlockDefaultBody } from './manage/Blocks/Group/DefaultBody'; | ||
export { default as GroupBlockEdit } from './manage/Blocks/Group/Edit'; | ||
export { default as GroupBlockView } from './manage/Blocks/Group/View'; | ||
export { default as GroupBlockLayout } from './manage/Blocks/Group/LayoutSchema'; |
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,17 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { GroupBlockDefaultBody } from '@eeacms/volto-group-block/components'; | ||
|
||
const Body = (props) => { | ||
const { variation } = props; | ||
|
||
const BodyComponent = variation?.template || GroupBlockDefaultBody; | ||
|
||
return <BodyComponent {...props} />; | ||
}; | ||
|
||
Body.propTypes = { | ||
variation: PropTypes.objectOf(PropTypes.any).isRequired, | ||
}; | ||
|
||
export default Body; |
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,105 @@ | ||
import { Button } from 'semantic-ui-react'; | ||
import { BlocksForm, Icon, RenderBlocks } from '@plone/volto/components'; | ||
import EditBlockWrapper from './EditBlockWrapper'; | ||
|
||
import helpSVG from '@plone/volto/icons/help.svg'; | ||
|
||
const GroupBlockDefaultBody = (props) => { | ||
const { | ||
block, | ||
data, | ||
onChangeBlock, | ||
onChangeField, | ||
pathname, | ||
selected, | ||
selectedBlock, | ||
onSelectBlock, | ||
setSelectedBlock, | ||
manage, | ||
childBlocksForm, | ||
multiSelected, | ||
formDescription, | ||
isEditMode, | ||
} = props; | ||
const metadata = props.metadata || props.properties; | ||
const blockState = {}; | ||
|
||
// Get editing instructions from block settings or props | ||
let instructions = data?.instructions?.data || data?.instructions; | ||
if (!instructions || instructions === '<p><br/></p>') { | ||
instructions = formDescription; | ||
} | ||
return isEditMode ? ( | ||
<BlocksForm | ||
metadata={metadata} | ||
properties={childBlocksForm} | ||
manage={manage} | ||
selectedBlock={selected ? selectedBlock : null} | ||
allowedBlocks={data.allowedBlocks} | ||
title={data.placeholder} | ||
description={instructions} | ||
onSelectBlock={(id, l, e) => { | ||
const isMultipleSelection = e | ||
? e.shiftKey || e.ctrlKey || e.metaKey | ||
: false; | ||
onSelectBlock(id, isMultipleSelection, e, selectedBlock); | ||
}} | ||
onChangeFormData={(newFormData) => { | ||
onChangeBlock(block, { | ||
...data, | ||
data: newFormData, | ||
}); | ||
}} | ||
onChangeField={(id, value) => { | ||
if (['blocks', 'blocks_layout'].indexOf(id) > -1) { | ||
blockState[id] = value; | ||
onChangeBlock(block, { | ||
...data, | ||
data: { | ||
...data.data, | ||
...blockState, | ||
}, | ||
}); | ||
} else { | ||
onChangeField(id, value); | ||
} | ||
}} | ||
pathname={pathname} | ||
> | ||
{({ draginfo }, editBlock, blockProps) => ( | ||
<EditBlockWrapper | ||
draginfo={draginfo} | ||
blockProps={blockProps} | ||
disabled={data.disableInnerButtons} | ||
extraControls={ | ||
<> | ||
{instructions && ( | ||
<> | ||
<Button | ||
icon | ||
basic | ||
title="Section help" | ||
onClick={() => { | ||
setSelectedBlock(); | ||
const tab = manage ? 0 : 1; | ||
props.setSidebarTab(tab); | ||
}} | ||
> | ||
<Icon name={helpSVG} className="" size="19px" /> | ||
</Button> | ||
</> | ||
)} | ||
</> | ||
} | ||
multiSelected={multiSelected.includes(blockProps.block)} | ||
> | ||
{editBlock} | ||
</EditBlockWrapper> | ||
)} | ||
</BlocksForm> | ||
) : ( | ||
<RenderBlocks {...props} metadata={metadata} content={data?.data || {}} /> | ||
); | ||
}; | ||
|
||
export default GroupBlockDefaultBody; |
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