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 #10 from eea/develop
Release
- Loading branch information
Showing
12 changed files
with
195 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,73 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Message } from 'semantic-ui-react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import imageBlockSVG from '@plone/volto/components/manage/Blocks/Image/block-image.svg'; | ||
import { flattenToAppURL } from '@plone/volto/helpers'; | ||
import { getTeaserImageURL } from './utils'; | ||
import { MaybeWrap } from '@plone/volto/components'; | ||
import { UniversalLink } from '@plone/volto/components'; | ||
import cx from 'classnames'; | ||
|
||
const messages = defineMessages({ | ||
PleaseChooseContent: { | ||
id: 'Please choose an existing content as source for this element', | ||
defaultMessage: | ||
'Please choose an existing content as source for this element', | ||
}, | ||
}); | ||
|
||
const TeaserCardTemplate = (props) => { | ||
const { data, isEditMode } = props; | ||
const intl = useIntl(); | ||
const href = data.href?.[0]; | ||
const image = data.preview_image?.[0]; | ||
|
||
return ( | ||
<> | ||
{!href && isEditMode && ( | ||
<Message> | ||
<div className="grid-teaser-item placeholder"> | ||
<img src={imageBlockSVG} alt="" /> | ||
<p>{intl.formatMessage(messages.PleaseChooseContent)}</p> | ||
</div> | ||
</Message> | ||
)} | ||
{href && ( | ||
<MaybeWrap | ||
condition={!isEditMode} | ||
as={UniversalLink} | ||
href={href['@id']} | ||
target={data.openLinkInNewTab ? '_blank' : null} | ||
> | ||
<div className={cx('ui fluid card', data?.styles?.theme)}> | ||
{(href.hasPreviewImage || href.image_field || image) && ( | ||
<div className="image"> | ||
<img | ||
src={flattenToAppURL(getTeaserImageURL(href, image))} | ||
alt="a" | ||
/> | ||
</div> | ||
)} | ||
<div className="content"> | ||
{data?.head_title && ( | ||
<div className="meta">{data?.head_title}</div> | ||
)} | ||
<div className="header">{data?.title}</div> | ||
{!data.hide_description && ( | ||
<p className="description">{data?.description}</p> | ||
)} | ||
</div> | ||
</div> | ||
</MaybeWrap> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
TeaserCardTemplate.propTypes = { | ||
data: PropTypes.objectOf(PropTypes.any).isRequired, | ||
isEditMode: PropTypes.bool, | ||
}; | ||
|
||
export default TeaserCardTemplate; |
Empty file.
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,57 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
const messages = defineMessages({ | ||
Type: { | ||
id: 'Teaser', | ||
defaultMessage: 'Teaser', | ||
}, | ||
Theme: { | ||
id: 'Theme', | ||
defaultMessage: 'Theme', | ||
}, | ||
ThemeHelp: { | ||
id: 'Theme', | ||
defaultMessage: 'Theme', | ||
}, | ||
ThemeDefault: { | ||
id: 'Default', | ||
defaultMessage: 'Default', | ||
}, | ||
ThemePrimary: { | ||
id: 'Primary', | ||
defaultMessage: 'Primary', | ||
}, | ||
ThemeSecondary: { | ||
id: 'Secondary', | ||
defaultMessage: 'Secondary', | ||
}, | ||
ThemeTertiary: { | ||
id: 'Tertiary', | ||
defaultMessage: 'Tertiary', | ||
}, | ||
}); | ||
|
||
export const StylingSchema = ({ intl }) => ({ | ||
title: intl.formatMessage(messages.Type), | ||
block: 'teaserGrid', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['theme'], | ||
}, | ||
], | ||
properties: { | ||
theme: { | ||
title: intl.formatMessage(messages.Theme), | ||
description: intl.formatMessage(messages.ThemeHelp), | ||
choices: [ | ||
['', intl.formatMessage(messages.ThemeDefault)], | ||
['primary', intl.formatMessage(messages.ThemePrimary)], | ||
['secondary', intl.formatMessage(messages.ThemeSecondary)], | ||
['tertiary', intl.formatMessage(messages.ThemeTertiary)], | ||
], | ||
}, | ||
}, | ||
required: [], | ||
}); |
Empty file.
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,26 @@ | ||
import TeaserCardTemplate from './Card'; | ||
import { StylingSchema } from './Schema'; | ||
|
||
export default (config) => { | ||
// Teaser | ||
if (config.blocks.blocksConfig.teaser) { | ||
config.blocks.blocksConfig.teaser.variations = [ | ||
...(config.blocks.blocksConfig.teaser.variations || []), | ||
{ | ||
id: 'card', | ||
isDefault: true, | ||
title: 'Card (top image)', | ||
template: TeaserCardTemplate, | ||
}, | ||
]; | ||
config.blocks.blocksConfig.teaser.enableStyling = true; | ||
config.blocks.blocksConfig.teaser.stylesSchema = StylingSchema; | ||
} | ||
|
||
// Teaser Grid | ||
if (config.blocks.blocksConfig.teaserGrid) { | ||
config.blocks.blocksConfig.teaserGrid.title = 'Teaser (Cards)'; | ||
} | ||
|
||
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,18 @@ | ||
import { isInternalURL } from '@plone/volto/helpers'; | ||
import config from '@plone/volto/registry'; | ||
|
||
export function getTeaserImageURL(href, image) { | ||
const imageScale = | ||
config.blocks.blocksConfig['teaser'].imageScale || 'preview'; | ||
if (image) { | ||
if (isInternalURL(image['@id'])) { | ||
return `${image['@id']}/@@images/image/${imageScale}`; | ||
} else { | ||
return image['@id']; | ||
} | ||
} else { | ||
return `${href['@id']}/@@images/${ | ||
href.image_field || 'preview_image' | ||
}/${imageScale}`; | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
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