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 #73 from eea/develop
Develop
- Loading branch information
Showing
6 changed files
with
226 additions
and
2 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,160 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import config from '@plone/volto/registry'; | ||
import DefaultImageSVG from '@plone/volto/components/manage/Blocks/Listing/default-image.svg'; | ||
import { Card, Message } from 'semantic-ui-react'; | ||
import { serializeNodes } from 'volto-slate/editor/render'; | ||
import { compose } from 'redux'; | ||
import { flattenToAppURL } from '@plone/volto/helpers'; | ||
import { withRouter } from 'react-router-dom'; | ||
import { injectIntl } from 'react-intl'; | ||
|
||
import './styles.less'; | ||
|
||
const alignmentTypes = { | ||
left: 'left', | ||
right: 'right', | ||
center: 'centered', | ||
full: 'left', | ||
}; | ||
|
||
export const getScaleUrl = (url, size) => | ||
(url || '').includes(config.settings.apiPath) | ||
? `${flattenToAppURL(url.replace('/api', ''))}/@@images/image/${size}` | ||
: `${url.replace('/api', '')}/@@images/image/${size}`; | ||
|
||
const Cards = (props) => { | ||
const { data, editable, history } = props; | ||
const { | ||
align, | ||
cards, | ||
image_scale, | ||
gridSize = 'one', | ||
theme = 'default', | ||
} = data; | ||
|
||
const makeImage = (item) => { | ||
const { attachedimage } = item; | ||
return ( | ||
<img | ||
className="cards-tile-image" | ||
src={ | ||
attachedimage | ||
? getScaleUrl( | ||
flattenToAppURL(attachedimage), | ||
image_scale || 'preview', | ||
) | ||
: DefaultImageSVG | ||
} | ||
alt={item.title} | ||
/> | ||
); | ||
}; | ||
|
||
const makeTextBody = (item) => ( | ||
<> | ||
<h3 className="tile-listing-title"> | ||
{item.title ? item.title : item.id} | ||
</h3> | ||
{item.text && ( | ||
<p className="tile-listing-description">{serializeNodes(item.text)}</p> | ||
)} | ||
</> | ||
); | ||
|
||
const handleNavigate = (link) => { | ||
history.push(flattenToAppURL(link)); | ||
}; | ||
|
||
return cards && cards.length > 0 ? ( | ||
<div className={cx('ui fluid cards', gridSize)}> | ||
{cards.map((item) => ( | ||
<Card | ||
onClick={() => handleNavigate(item.link)} | ||
key={item['@id']} | ||
className={cx( | ||
'navigation-card', | ||
alignmentTypes[align] || 'left', | ||
theme, | ||
)} | ||
> | ||
{makeImage(item)} | ||
{makeTextBody(item)} | ||
</Card> | ||
))} | ||
</div> | ||
) : ( | ||
<>{editable ? <Message>No image cards</Message> : ''}</> | ||
); | ||
}; | ||
|
||
Cards.schema = () => ({ | ||
title: 'Image Card', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['title', 'text', 'attachedimage', 'link'], | ||
}, | ||
], | ||
|
||
properties: { | ||
title: { | ||
type: 'string', | ||
title: 'Title', | ||
}, | ||
text: { | ||
widget: 'slate_richtext', | ||
title: 'Text', | ||
}, | ||
link: { | ||
widget: 'url', | ||
title: 'Link', | ||
}, | ||
attachedimage: { | ||
widget: 'attachedimage', | ||
title: 'Image', | ||
}, | ||
}, | ||
|
||
required: ['attachedimage'], | ||
}); | ||
|
||
Cards.schemaExtender = (schema) => { | ||
return { | ||
...schema, | ||
fieldsets: [ | ||
...schema.fieldsets, | ||
{ | ||
id: 'cards_grid', | ||
title: 'Cards grid', | ||
fields: ['gridSize', 'theme'], | ||
}, | ||
], | ||
properties: { | ||
...schema.properties, | ||
gridSize: { | ||
title: 'Grid Size', | ||
choices: [ | ||
['one', 'One'], | ||
['two', 'Two'], | ||
['three', 'Three'], | ||
['four', 'Four'], | ||
], | ||
factory: 'Choice', | ||
type: 'string', | ||
}, | ||
theme: { | ||
title: 'Theme', | ||
choices: [ | ||
['default', 'Default'], | ||
['primary', 'Primary'], | ||
['secondary', 'Secondary'], | ||
['tertiary', 'Tertiary'], | ||
], | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export default compose(withRouter, injectIntl)(Cards); |
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,19 @@ | ||
import Cards from './View'; | ||
|
||
export default (config) => { | ||
if ( | ||
config.blocks.blocksConfig.imagecards && | ||
config.blocks.blocksConfig.imagecards.blockRenderers | ||
) { | ||
config.blocks.blocksConfig.imagecards.blockRenderers = { | ||
...config.blocks.blocksConfig.imagecards.blockRenderers, | ||
fise_cards_grid: { | ||
title: 'FISE cards grid', | ||
view: Cards, | ||
schema: Cards.schema, | ||
schemaExtender: Cards.schemaExtender, | ||
}, | ||
}; | ||
} | ||
return config; | ||
}; |
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,31 @@ | ||
.cards-tile-image { | ||
height: 250px; | ||
object-fit: cover; | ||
} | ||
|
||
.navigation-card { | ||
border: none !important; | ||
box-shadow: none !important; | ||
} | ||
|
||
.tile-listing-title { | ||
margin: 10px 0 !important; | ||
font-weight: bold; | ||
|
||
p { | ||
margin: 0 !important; | ||
color: #564535; | ||
font-size: 20px; | ||
} | ||
} | ||
|
||
.tile-listing-title:hover { | ||
p { | ||
color: #cc4400; | ||
} | ||
} | ||
|
||
.tile-listing-description { | ||
color: #666; | ||
font-size: 14px; | ||
} |
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