Skip to content
Snippets Groups Projects
Commit 80fe5092 authored by David Bühler's avatar David Bühler
Browse files

[ivette] Richtext: fixes Text component.

Do not modify the text argument in-place!
Uses array.map instead of React.Children.map.
parent f9981d4d
No related branches found
No related tags found
No related merge requests found
...@@ -98,26 +98,19 @@ function Marker(props: MarkerProps): JSX.Element { ...@@ -98,26 +98,19 @@ function Marker(props: MarkerProps): JSX.Element {
function makeContents(text: KernelData.text): React.ReactNode { function makeContents(text: KernelData.text): React.ReactNode {
if (Array.isArray(text)) { if (Array.isArray(text)) {
const tag = text.shift(); const tag = text[0];
let marker: string | undefined; const marker = tag && typeof (tag) === 'string';
if (tag) { const array = marker ? text.slice(1) : text;
if (Array.isArray(tag)) { const contents = React.Children.toArray(array.map(makeContents));
text.unshift(tag); if (marker) {
} else if (typeof tag === 'string') { return <Marker marker={tag}>{contents}</Marker>;
marker = tag;
}
// otherwize, ignore tag
} }
const contents = React.Children.map(text, makeContents);
if (marker)
return <Marker marker={marker}>{contents}</Marker>;
return <>{contents}</>; return <>{contents}</>;
} if (typeof text === 'string') { } if (typeof text === 'string') {
return text; return text;
} }
D.error('Unexpected text', text); D.error('Unexpected text', text);
return null; return null;
} }
export interface TextProps { export interface TextProps {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment