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.
Rounded Card variation - refs #148723
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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 CardTemplate = (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 card rounded big')}> | ||
{(href.hasPreviewImage || href.image_field || image) && ( | ||
<div className="image"> | ||
<img | ||
src={flattenToAppURL(getTeaserImageURL(href, image))} | ||
alt="a" | ||
/> | ||
</div> | ||
)} | ||
<div className="content"> | ||
<div className="header">{data?.title}</div> | ||
{!data.hide_description && ( | ||
<p className="description">{data?.description}</p> | ||
)} | ||
</div> | ||
</div> | ||
</MaybeWrap> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
CardTemplate.propTypes = { | ||
data: PropTypes.objectOf(PropTypes.any).isRequired, | ||
isEditMode: PropTypes.bool, | ||
}; | ||
|
||
export default CardTemplate; |
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