Skip to content

Commit

Permalink
add image prop to BasicBlock template (#104)
Browse files Browse the repository at this point in the history
* add image prop to BasicBlock template

* Avoid redundant links

* Update BasicBlock

* fix propTypes and defaultProps

* fix import
  • Loading branch information
janette authored Dec 18, 2020
1 parent 3c500eb commit 88e8bd0
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions src/templates/Blocks/BasicBlock.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from '@reach/router';
import Text from '../../components/Text';

class BasicBlock extends React.PureComponent {
render() {
const { content } = this.props;
const img = content.image ? <div><img alt="" src={content.image} /></div> : null;

let block = '';

if (content.ref) {
block = (
<div key={content.ref} className="basic-block">
<h2>
<Link to={content.ref}>
{img}
{content.title}
</Link>
</h2>
<Text value={content.teaser} />
</div>
);
} else {
block = (
<div key={content.title} className="basic-block">
<h2>
{img}
{content.title}
</h2>
<Text value={content.teaser} />
</div>
);
}

return (
<div key={content.ref} className="basic-block">
<h2>{content.title}</h2>
<Text value={content.content} />
</div>
<>
{block}
</>
);
}
}

BasicBlock.defaultProps = {
title: '',
content: '',
content: [
{
title: '',
content: '',
image: '',
teaser: '',
ref: '',
},
],
};

BasicBlock.propTypes = {
title: PropTypes.string,
content: PropTypes.string,
content: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string,
teaser: PropTypes.string,
image: PropTypes.string,
ref: PropTypes.string,
})),
};

export default BasicBlock;

0 comments on commit 88e8bd0

Please sign in to comment.