mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-04-20 21:46:17 +00:00
Refactore MultilineText component from class-based to functional
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import {injectIntl, WrappedComponentProps} from 'react-intl';
|
|
||||||
import Linkify from 'react-linkify';
|
import Linkify from 'react-linkify';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
lines: (JSX.Element | string)[];
|
lines: (JSX.Element | string)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinLines(lines: (JSX.Element | string)[]) {
|
export function MultilineText(props: Props) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{lines.map((line, index) => (
|
{props.lines.map((line, index) => (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
<Linkify properties={{target: '_blank'}}>{line}</Linkify>
|
<Linkify properties={{target: '_blank'}}>{line}</Linkify>
|
||||||
<br />
|
<br />
|
||||||
@@ -18,14 +16,3 @@ function joinLines(lines: (JSX.Element | string)[]) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultilineTextComponent extends React.Component<
|
|
||||||
Props & WrappedComponentProps,
|
|
||||||
{}
|
|
||||||
> {
|
|
||||||
render() {
|
|
||||||
return joinLines(this.props.lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MultilineText = injectIntl(MultilineTextComponent);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user