import * as React from "react"; export interface NoticeTextSelectionProps { icon?: string; text: string; idSuffix: string; onClick?: (event: React.MouseEvent) => unknown; children?: React.ReactNode; } export interface NoticeTextSelectionState { } class NoticeTextSelectionComponent extends React.Component { constructor(props: NoticeTextSelectionProps) { super(props); } render(): React.ReactElement { const style: React.CSSProperties = {}; if (this.props.onClick) { style.cursor = "pointer"; style.textDecoration = "underline" } return ( {this.props.icon ? : null} {this.getTextElements(this.props.text)} ); } private getTextElements(text: string): Array { const elements: Array = []; const textParts = text.split(/(?=\s+)/); for (const textPart of textParts) { if (textPart.match(/^\s*http/)) { elements.push( {textPart} ); } else { elements.push(textPart); } } return elements; } } export default NoticeTextSelectionComponent;