PromucFlow_constructor/app/client/src/components/designSystems/blueprint/TextComponent.tsx

55 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-10-31 05:28:11 +00:00
import * as React from "react";
import { Text, Classes } from "@blueprintjs/core";
import styled from "styled-components";
2019-11-25 05:07:27 +00:00
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
import { TextStyle } from "widgets/TextWidget";
2020-01-08 12:30:16 +00:00
import Interweave from "interweave";
import { UrlMatcher, EmailMatcher } from "interweave-autolink";
2019-10-31 05:28:11 +00:00
type TextStyleProps = {
2019-11-28 07:08:39 +00:00
accent: "primary" | "secondary" | "error";
2019-10-31 05:28:11 +00:00
};
export const BaseText = styled(Text)<TextStyleProps>``;
export interface TextComponentProps extends ComponentProps {
text?: string;
ellipsize?: boolean;
textStyle?: TextStyle;
2019-12-03 04:41:10 +00:00
isLoading: boolean;
2019-10-31 05:28:11 +00:00
}
class TextComponent extends React.Component<TextComponentProps> {
getTextClass(textStyle?: TextStyle) {
2019-12-03 04:41:10 +00:00
let className = this.props.isLoading ? "bp3-skeleton " : "";
2019-10-31 05:28:11 +00:00
switch (textStyle) {
case "HEADING":
2019-12-03 04:41:10 +00:00
className += Classes.TEXT_LARGE;
break;
2019-10-31 05:28:11 +00:00
case "BODY":
2019-12-03 04:41:10 +00:00
className += Classes.TEXT_SMALL;
break;
case "LABEL":
break;
2019-10-31 05:28:11 +00:00
default:
2019-12-03 04:41:10 +00:00
break;
2019-10-31 05:28:11 +00:00
}
2019-12-03 04:41:10 +00:00
return className;
2019-10-31 05:28:11 +00:00
}
render() {
2020-01-08 12:30:16 +00:00
const { textStyle, text, ellipsize } = this.props;
return (
<Text className={this.getTextClass(textStyle)} ellipsize={ellipsize}>
<Interweave
content={text}
matchers={[new UrlMatcher("url"), new EmailMatcher("email")]}
/>
2020-01-08 12:30:16 +00:00
</Text>
);
2019-10-31 05:28:11 +00:00
}
}
export default TextComponent;