@mirrormedia/lilith-draft-renderer
Version:
## Introduction
66 lines (58 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BGImageBlock = BGImageBlock;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const BGImageRenderWrapper = _styledComponents.default.div`
padding: 30px;
position: relative;
width: 100%;
height: 100%;
background-image: url(${({
image
}) => image});
background-size: cover;
background-position: center center;
${({
textBlockAlign
}) => {
if (textBlockAlign === 'left') {
return `padding-right: 50%;`;
} else if (textBlockAlign === 'right') {
return `padding-left: 50%;`;
} else if (textBlockAlign === 'bottom') {
return `padding-top: 50%;`;
}
}}
`;
const BGImageRenderBody = _styledComponents.default.div`
background: rgba(0, 0, 0, 0.5);
padding: 4px 20px;
margin-bottom: 10px;
`;
function BGImageBlock(props, contentLayout) {
var _image$imageFile;
const {
block,
contentState
} = props;
const entityKey = block.getEntityAt(0);
const entity = contentState.getEntity(entityKey);
const {
textBlockAlign,
image,
body
} = entity.getData();
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGImageRenderWrapper, {
image: image === null || image === void 0 ? void 0 : (_image$imageFile = image.imageFile) === null || _image$imageFile === void 0 ? void 0 : _image$imageFile.url,
textBlockAlign: textBlockAlign
}, /*#__PURE__*/_react.default.createElement(BGImageRenderBody, {
dangerouslySetInnerHTML: {
__html: contentLayout === 'amp' ? (0, _utils.convertEmbeddedToAmp)(body) : body
}
})));
}