forked from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.03 KB
/
index.js
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
/**
*
* T
*
*/
import React, { memo } from 'react';
import styled from '@emotion/styled';
import { Trans } from '@lingui/macro';
import { PropTypes } from 'prop-types';
import { If } from '@components/If';
import { fonts } from '@app/themes';
const StyledText = styled.p`
&& {
${(props) => props.marginBottom && `margin-bottom: ${props.marginBottom}px;`};
${(props) => props.font()};
}
`;
const getFontStyle = (type) => fonts.style[type] || (() => '');
const T = ({ type, text, id, marginBottom, values, ...otherProps }) => (
<StyledText data-testid="t" font={getFontStyle(type)} marginBottom={marginBottom} {...otherProps}>
<If condition={!!id} otherwise={text}>
<Trans id={id} values={values} />
</If>
</StyledText>
);
T.propTypes = {
id: PropTypes.string,
marginBottom: PropTypes.number,
values: PropTypes.object,
text: PropTypes.string,
type: PropTypes.oneOf(Object.keys(fonts.style))
};
T.defaultProps = {
values: {},
type: 'standard'
};
const TextComponent = memo(T);
export default TextComponent;