generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cards): add custom display for volto-block-image-cards
- Loading branch information
Showing
5 changed files
with
183 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import DefaultImageSVG from '@plone/volto/components/manage/Blocks/Listing/default-image.svg'; | ||
import React from 'react'; | ||
import { Card, Icon } from 'semantic-ui-react'; | ||
import { UniversalLink } from '@plone/volto/components'; | ||
import { serializeNodes } from 'volto-slate/editor/render'; | ||
|
||
import { getScaleUrl, getPath } from '@eeacms/volto-eea-design-system/utils'; | ||
|
||
const alignmentTypes = { | ||
left: 'left', | ||
right: 'right', | ||
center: 'centered', | ||
full: 'left', | ||
}; | ||
|
||
const Cards = ({ data }) => { | ||
const { align, cards, image_scale, gridSize = 'one' } = data; | ||
|
||
const makeImage = (item) => { | ||
const { attachedimage } = item; | ||
return ( | ||
<img | ||
src={ | ||
getScaleUrl(getPath(attachedimage), image_scale || 'preview') || | ||
DefaultImageSVG | ||
} | ||
alt={item.title} | ||
/> | ||
); | ||
}; | ||
|
||
const makeTextBody = (item) => ( | ||
<> | ||
<Card.Content> | ||
<Card.Header>{item.title ? item.title : item.id}</Card.Header> | ||
{item.meta && <Card.Meta>{serializeNodes(item.meta)}</Card.Meta>} | ||
{item.text && ( | ||
<Card.Description>{serializeNodes(item.text)}</Card.Description> | ||
)} | ||
</Card.Content> | ||
{item.link && ( | ||
<Card.Content extra> | ||
<UniversalLink href={item.link}> | ||
<Icon name="linkify" /> | ||
{item.linkTitle || item.link} | ||
</UniversalLink> | ||
</Card.Content> | ||
)} | ||
</> | ||
); | ||
|
||
return ( | ||
cards && | ||
cards.length > 0 && ( | ||
<div className={`ui fluid ${gridSize || ''} cards`}> | ||
{cards.map((item) => ( | ||
<Card key={item['@id']} className={alignmentTypes[align] || 'left'}> | ||
{makeImage(item)} | ||
{makeTextBody(item)} | ||
</Card> | ||
))} | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
export default 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,79 @@ | ||
export const getCardSchema = () => ({ | ||
title: 'Image Card', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: [ | ||
'title', | ||
'meta', | ||
'text', | ||
'attachedimage', | ||
'link', | ||
'linkTitle', | ||
'copyright', | ||
], | ||
}, | ||
], | ||
|
||
properties: { | ||
title: { | ||
type: 'string', | ||
title: 'Title', | ||
}, | ||
meta: { | ||
widget: 'slate_richtext', | ||
title: 'Meta data', | ||
}, | ||
text: { | ||
widget: 'slate_richtext', | ||
title: 'Text', | ||
}, | ||
link: { | ||
widget: 'url', | ||
title: 'Link', | ||
}, | ||
linkTitle: { | ||
type: 'string', | ||
title: 'Link title', | ||
}, | ||
attachedimage: { | ||
widget: 'attachedimage', | ||
title: 'Image', | ||
}, | ||
copyright: { | ||
widget: 'slate_richtext', | ||
title: 'Copyright', | ||
}, | ||
}, | ||
|
||
required: ['attachedimage'], | ||
}); | ||
|
||
export const getSchemaExtender = (schema, data, intl) => { | ||
return { | ||
...schema, | ||
fieldsets: [ | ||
...schema.fieldsets, | ||
{ | ||
id: 'cards_grid', | ||
title: 'Cards grid', | ||
fields: ['gridSize'], | ||
}, | ||
], | ||
properties: { | ||
...schema.properties, | ||
gridSize: { | ||
title: 'Grid Size', | ||
choices: [ | ||
['one', 'One'], | ||
['two', 'Two'], | ||
['three', 'Three'], | ||
['four', 'Four'], | ||
], | ||
factory: 'Choice', | ||
type: 'string', | ||
}, | ||
}, | ||
}; | ||
}; |
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,10 @@ | ||
import config from '@plone/volto/registry'; | ||
import { flattenToAppURL } from '@plone/volto/helpers'; | ||
|
||
export const getPath = (url = '') => | ||
(url || '').startsWith('http') ? new URL(url).pathname : url; | ||
|
||
export const getScaleUrl = (url, size) => | ||
(url || '').includes(config.settings.apiPath) | ||
? `${flattenToAppURL(url.replace('/api', ''))}/@@images/image/${size}` | ||
: `${url.replace('/api', '')}/@@images/image/${size}`; |
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,15 @@ | ||
/******************************* | ||
Theme Overrides | ||
*******************************/ | ||
|
||
.ui.cards > .card .meta, .ui.card .meta > .category { | ||
font-size: @metaFontSize; | ||
} | ||
|
||
.ui.left.card { | ||
margin-right: auto; | ||
} | ||
|
||
.ui.right.card { | ||
margin-left: auto; | ||
} |