generated from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
43 lines (38 loc) · 1.07 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
/**
*
* T
*
*/
import React, { memo } from 'react';
import styled from 'styled-components';
import { FormattedMessage } from 'react-intl';
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] ? fonts.style[type] : () => {});
export const T = ({ type, text, id, marginBottom, values, ...otherProps }) => (
<StyledText data-testid="t" font={getFontStyle(type)} marginBottom={marginBottom} {...otherProps}>
<If condition={id} otherwise={text}>
<FormattedMessage id={id} values={values} />
</If>
</StyledText>
);
T.propTypes = {
id: PropTypes.string,
marginBottom: PropTypes.number,
values: PropTypes.object,
text: PropTypes.string,
type: PropTypes.oneOfType(Object.keys(fonts.style))
};
T.defaultProps = {
values: {},
type: 'standard'
};
const TextComponent = memo(T);
export default TextComponent;