Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | /* eslint-disable react/no-array-index-key */ import React from 'react'; import { css } from '@emotion/react'; import { TextBlock as TextBlockModel, TextBlockStyle } from '@uniquegood/realworld-web-interface/lib/models/game/Block/Text'; import { DeltaOperation } from 'quill'; import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html'; import { quillStyleCss } from '@uniquegood/realworld-web-interface/lib/styles/quill'; export default function TextBlock({ id, style, contents }: TextBlockModel) { const deltaOperation = typeof contents === 'string' ? [{ insert: contents }] : (contents as DeltaOperation[]); const config = {}; const converter = new QuillDeltaToHtmlConverter(deltaOperation, config); converter.renderCustomWith((op) => { if (op.insert.type === 'audio') { return `<audio controls src="${op.insert.value}" />`; } return ''; }); const containerStyle = React.useMemo(() => { const styleObj = TextBlockStyle.parse(style); return css` background-color: ${styleObj.backgroundColor}; `; }, [style]); const html = converter.convert(); return ( <div id={id} css={[containerStyle]}> <div css={[quillStyle, textStyle]}> <p dangerouslySetInnerHTML={{ __html: html }} /> </div> </div> ); } const quillStyle = css(quillStyleCss); const textStyle = css` font-size: 16px; line-height: 1.5; text-align: left; word-wrap: break-word; strong { font-weight: bold; } `; |