forked from wednesday-solutions/next-bulletproof-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
46 lines (39 loc) · 1.19 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
*
* T
*
*/
import React, { CSSProperties, memo } from "react";
import styled, { FlattenSimpleInterpolation } from "styled-components";
import { FormattedMessage } from "react-intl";
import { If } from "@common";
import { fonts } from "@themes";
interface Props {
type: keyof typeof fonts["style"];
text?: string;
id?: string;
values?: any;
styles?: CSSProperties | FlattenSimpleInterpolation;
marginBottom?: CSSProperties["marginBottom"];
}
const StyledText = styled.p<Partial<Props> & { font: ReturnType<typeof getFontStyle> }>`
&& {
${props => props.marginBottom && `margin-bottom: ${props.marginBottom}px;`};
${props => props.font()};
}
`;
const getFontStyle = (type: keyof typeof fonts["style"]) =>
fonts.style[type] ? fonts.style[type] : () => null;
export const T = ({ type, text, id, marginBottom, values, ...otherProps }: Props) => (
<StyledText data-testid="t" font={getFontStyle(type)} marginBottom={marginBottom} {...otherProps}>
<If condition={id} otherwise={text}>
<FormattedMessage id={id} values={values} />
</If>
</StyledText>
);
T.defaultProps = {
values: {},
type: "standard",
};
const TextComponent = memo(T);
export default TextComponent;