docusaurus/lib/core/GridBlock.js
Héctor Ramos 09354ab738 [BREAKING] Rename Marked to MarkdownBlock (#162)
* Switch to Remarkable

* Clean up references to custom code blocks

* Remove valdiateDOMNesting warning

* Add syntax highlighting

* Add Reason support

* Breaking change: prismColor to codeColor, remove CompLibrary.Prism, expose hljs

* Completely remove Prism and associated CSS rules

* Support loading plugins and scripts

* Remove CSS rules, allowing Highlight.js theme to be used entirely

* Remove unnecessary webplayer script

* Rename Marked to MarkdownBlock

* Rename Marked to MarkdownBlock

* Remove Marked.js
2017-10-30 15:47:13 -07:00

102 lines
2.5 KiB
JavaScript
Executable file

/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const React = require("react");
const classNames = require("classnames");
const MarkdownBlock = require("./MarkdownBlock.js");
class GridBlock extends React.Component {
renderBlock(block) {
const blockClasses = classNames("blockElement", this.props.className, {
alignCenter: this.props.align === "center",
alignRight: this.props.align === "right",
fourByGridBlock: this.props.layout === "fourColumn",
imageAlignBottom: block.image && block.imageAlign === "bottom",
imageAlignSide:
block.image &&
(block.imageAlign === "left" || block.imageAlign === "right"),
imageAlignTop: block.image && block.imageAlign === "top",
threeByGridBlock: this.props.layout === "threeColumn",
twoByGridBlock: this.props.layout === "twoColumn"
});
const topLeftImage =
(block.imageAlign === "top" || block.imageAlign === "left") &&
this.renderBlockImage(block.image, block.imageLink);
const bottomRightImage =
(block.imageAlign === "bottom" || block.imageAlign === "right") &&
this.renderBlockImage(block.image, block.imageLink);
return (
<div className={blockClasses} key={block.title}>
{topLeftImage}
<div className="blockContent">
{this.renderBlockTitle(block.title)}
<MarkdownBlock>
{block.content}
</MarkdownBlock>
</div>
{bottomRightImage}
</div>
);
}
renderBlockImage(image, imageLink) {
if (image) {
if (imageLink) {
return (
<div className="blockImage">
<a href={imageLink}>
<img src={image} />
</a>
</div>
);
} else {
return (
<div className="blockImage">
<img src={image} />
</div>
);
}
} else {
return null;
}
}
renderBlockTitle(title) {
if (title) {
return (
<h2>
<MarkdownBlock>
{title}
</MarkdownBlock>
</h2>
);
} else {
return null;
}
}
render() {
return (
<div className="gridBlock">
{this.props.contents.map(this.renderBlock, this)}
</div>
);
}
}
GridBlock.defaultProps = {
align: "left",
contents: [],
imagealign: "top",
layout: "twoColumn"
};
module.exports = GridBlock;