PromucFlow_constructor/app/client/src/widgets/TextWidget/component/index.tsx

128 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-10-31 05:28:11 +00:00
import * as React from "react";
import { Text } from "@blueprintjs/core";
2019-10-31 05:28:11 +00:00
import styled from "styled-components";
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";
import {
FontStyleTypes,
TextSize,
TEXT_SIZES,
} from "constants/WidgetConstants";
2019-10-31 05:28:11 +00:00
export type TextAlign = "LEFT" | "CENTER" | "RIGHT" | "JUSTIFY";
2019-10-31 05:28:11 +00:00
export const TextContainer = styled.div`
& {
height: 100%;
width: 100%;
}
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-05-11 14:19:58 +00:00
export const StyledText = styled(Text)<{
scroll: boolean;
textAlign: string;
backgroundColor?: string;
textColor?: string;
fontStyle?: string;
fontSize?: TextSize;
2020-05-11 14:19:58 +00:00
}>`
height: 100%;
2020-12-24 04:32:25 +00:00
overflow-y: ${(props) => (props.scroll ? "auto" : "hidden")};
text-overflow: ellipsis;
2020-12-24 04:32:25 +00:00
text-align: ${(props) => props.textAlign.toLowerCase()};
display: flex;
width: 100%;
justify-content: flex-start;
2020-12-24 04:32:25 +00:00
align-items: ${(props) => (props.scroll ? "flex-start" : "center")};
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]};
word-break: break-word;
2020-05-11 14:19:58 +00:00
span {
width: 100%;
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;
fontSize?: TextSize;
2019-12-03 04:41:10 +00:00
isLoading: boolean;
2020-01-28 08:21:22 +00:00
shouldScroll?: boolean;
backgroundColor?: string;
textColor?: string;
fontStyle?: string;
disableLink: boolean;
2019-10-31 05:28:11 +00:00
}
class TextComponent extends React.Component<TextComponentProps> {
render() {
const {
backgroundColor,
disableLink,
ellipsize,
fontSize,
fontStyle,
text,
textAlign,
textColor,
} = this.props;
2020-01-08 12:30:16 +00:00
return (
<TextContainer>
<StyledText
backgroundColor={backgroundColor}
className={this.props.isLoading ? "bp3-skeleton" : "bp3-ui-text"}
ellipsize={ellipsize}
fontSize={fontSize}
fontStyle={fontStyle}
scroll={!!this.props.shouldScroll}
textAlign={textAlign}
textColor={textColor}
>
2021-05-26 03:17:46 +00:00
<Interweave
content={text}
matchers={
disableLink
? []
: [new EmailMatcher("email"), new UrlMatcher("url")]
}
newWindow
2021-05-26 03:17:46 +00:00
/>
</StyledText>
</TextContainer>
2020-01-08 12:30:16 +00:00
);
2019-10-31 05:28:11 +00:00
}
}
export default TextComponent;