2019-10-31 05:28:11 +00:00
|
|
|
import * as React from "react";
|
2021-04-01 08:30:33 +00:00
|
|
|
import { Text } from "@blueprintjs/core";
|
2019-10-31 05:28:11 +00:00
|
|
|
import styled from "styled-components";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ComponentProps } from "widgets/BaseComponent";
|
2021-05-26 11:27:01 +00:00
|
|
|
import Interweave from "interweave";
|
2021-05-26 03:17:46 +00:00
|
|
|
import { UrlMatcher, EmailMatcher } from "interweave-autolink";
|
2021-04-01 08:30:33 +00:00
|
|
|
import {
|
|
|
|
|
FontStyleTypes,
|
|
|
|
|
TextSize,
|
|
|
|
|
TEXT_SIZES,
|
|
|
|
|
} from "constants/WidgetConstants";
|
2019-10-31 05:28:11 +00:00
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
export type TextAlign = "LEFT" | "CENTER" | "RIGHT" | "JUSTIFY";
|
2019-10-31 05:28:11 +00:00
|
|
|
|
2020-01-21 12:48:42 +00:00
|
|
|
export const TextContainer = styled.div`
|
2021-12-07 10:29:04 +00:00
|
|
|
& {
|
2020-01-21 12:48:42 +00:00
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
2021-12-07 10:29:04 +00:00
|
|
|
|
|
|
|
|
ul {
|
|
|
|
|
list-style-type: disc;
|
|
|
|
|
list-style-position: inside;
|
|
|
|
|
}
|
|
|
|
|
ol {
|
|
|
|
|
list-style-type: decimal;
|
|
|
|
|
list-style-position: inside;
|
|
|
|
|
}
|
|
|
|
|
ul ul,
|
|
|
|
|
ol ul {
|
|
|
|
|
list-style-type: circle;
|
|
|
|
|
list-style-position: inside;
|
|
|
|
|
margin-left: 15px;
|
|
|
|
|
}
|
|
|
|
|
ol ol,
|
|
|
|
|
ul ol {
|
|
|
|
|
list-style-type: lower-latin;
|
|
|
|
|
list-style-position: inside;
|
|
|
|
|
margin-left: 15px;
|
|
|
|
|
}
|
2020-01-21 12:48:42 +00:00
|
|
|
`;
|
2021-07-02 09:55:50 +00:00
|
|
|
|
2020-05-11 14:19:58 +00:00
|
|
|
export const StyledText = styled(Text)<{
|
|
|
|
|
scroll: boolean;
|
|
|
|
|
textAlign: string;
|
2021-04-01 08:30:33 +00:00
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
|
|
|
|
fontSize?: TextSize;
|
2020-05-11 14:19:58 +00:00
|
|
|
}>`
|
2020-01-21 12:48:42 +00:00
|
|
|
height: 100%;
|
2020-12-24 04:32:25 +00:00
|
|
|
overflow-y: ${(props) => (props.scroll ? "auto" : "hidden")};
|
2020-01-21 12:48:42 +00:00
|
|
|
text-overflow: ellipsis;
|
2020-12-24 04:32:25 +00:00
|
|
|
text-align: ${(props) => props.textAlign.toLowerCase()};
|
2020-01-21 12:48:42 +00:00
|
|
|
display: flex;
|
|
|
|
|
width: 100%;
|
|
|
|
|
justify-content: flex-start;
|
2020-12-24 04:32:25 +00:00
|
|
|
align-items: ${(props) => (props.scroll ? "flex-start" : "center")};
|
2021-04-01 08:30:33 +00:00
|
|
|
background: ${(props) => props?.backgroundColor};
|
|
|
|
|
color: ${(props) => props?.textColor};
|
|
|
|
|
font-style: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.ITALIC) ? "italic" : ""};
|
|
|
|
|
text-decoration: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.UNDERLINE) ? "underline" : ""};
|
|
|
|
|
font-weight: ${(props) =>
|
|
|
|
|
props?.fontStyle?.includes(FontStyleTypes.BOLD) ? "bold" : "normal"};
|
|
|
|
|
font-size: ${(props) => props?.fontSize && TEXT_SIZES[props?.fontSize]};
|
2021-08-30 13:24:58 +00:00
|
|
|
word-break: break-word;
|
2020-05-11 14:19:58 +00:00
|
|
|
span {
|
|
|
|
|
width: 100%;
|
2021-04-28 05:43:03 +00:00
|
|
|
line-height: 1.2;
|
2020-05-11 14:19:58 +00:00
|
|
|
}
|
2020-01-14 09:48:01 +00:00
|
|
|
`;
|
|
|
|
|
|
2019-10-31 05:28:11 +00:00
|
|
|
export interface TextComponentProps extends ComponentProps {
|
|
|
|
|
text?: string;
|
2020-05-11 14:19:58 +00:00
|
|
|
textAlign: TextAlign;
|
2019-10-31 05:28:11 +00:00
|
|
|
ellipsize?: boolean;
|
2021-04-01 08:30:33 +00:00
|
|
|
fontSize?: TextSize;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-01-28 08:21:22 +00:00
|
|
|
shouldScroll?: boolean;
|
2021-04-01 08:30:33 +00:00
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
fontStyle?: string;
|
2021-09-27 06:00:40 +00:00
|
|
|
disableLink: boolean;
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TextComponent extends React.Component<TextComponentProps> {
|
|
|
|
|
render() {
|
2021-04-01 08:30:33 +00:00
|
|
|
const {
|
2021-05-13 08:35:39 +00:00
|
|
|
backgroundColor,
|
2021-09-27 06:00:40 +00:00
|
|
|
disableLink,
|
2021-04-01 08:30:33 +00:00
|
|
|
ellipsize,
|
|
|
|
|
fontSize,
|
2021-05-13 08:35:39 +00:00
|
|
|
fontStyle,
|
|
|
|
|
text,
|
|
|
|
|
textAlign,
|
2021-04-01 08:30:33 +00:00
|
|
|
textColor,
|
|
|
|
|
} = this.props;
|
2020-01-08 12:30:16 +00:00
|
|
|
return (
|
2020-01-21 12:48:42 +00:00
|
|
|
<TextContainer>
|
|
|
|
|
<StyledText
|
2021-04-28 10:28:39 +00:00
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : "bp3-ui-text"}
|
2020-01-21 12:48:42 +00:00
|
|
|
ellipsize={ellipsize}
|
2021-04-28 10:28:39 +00:00
|
|
|
fontSize={fontSize}
|
2021-04-01 08:30:33 +00:00
|
|
|
fontStyle={fontStyle}
|
2021-04-28 10:28:39 +00:00
|
|
|
scroll={!!this.props.shouldScroll}
|
|
|
|
|
textAlign={textAlign}
|
2021-04-01 08:30:33 +00:00
|
|
|
textColor={textColor}
|
2020-01-21 12:48:42 +00:00
|
|
|
>
|
2021-05-26 03:17:46 +00:00
|
|
|
<Interweave
|
|
|
|
|
content={text}
|
2021-09-27 06:00:40 +00:00
|
|
|
matchers={
|
|
|
|
|
disableLink
|
|
|
|
|
? []
|
|
|
|
|
: [new EmailMatcher("email"), new UrlMatcher("url")]
|
|
|
|
|
}
|
2021-08-04 13:34:44 +00:00
|
|
|
newWindow
|
2021-05-26 03:17:46 +00:00
|
|
|
/>
|
2020-01-21 12:48:42 +00:00
|
|
|
</StyledText>
|
|
|
|
|
</TextContainer>
|
2020-01-08 12:30:16 +00:00
|
|
|
);
|
2019-10-31 05:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TextComponent;
|