aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-tools-pages/ts/components/ui/text.tsx
blob: 8e314beaef95f4cf19834093e541f5d7890b1e4e (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { colors } from '@0xproject/react-shared';
import { darken } from 'polished';
import * as React from 'react';
import styled from 'styled-components';

export type TextTag = 'p' | 'div' | 'span' | 'label' | 'h1' | 'h2' | 'h3' | 'h4' | 'i';

export interface TextProps {
    className?: string;
    Tag?: TextTag;
    fontSize?: string;
    fontFamily?: string;
    fontStyle?: string;
    fontColor?: string;
    lineHeight?: string;
    minHeight?: string;
    center?: boolean;
    fontWeight?: number | string;
    textDecorationLine?: string;
    onClick?: (event: React.MouseEvent<HTMLElement>) => void;
    hoverColor?: string;
    noWrap?: boolean;
    display?: string;
}

const PlainText: React.StatelessComponent<TextProps> = ({ children, className, onClick, Tag }) => (
    <Tag className={className} onClick={onClick}>
        {children}
    </Tag>
);

export const Text = styled(PlainText)`
    font-family: ${props => props.fontFamily};
    font-style: ${props => props.fontStyle};
    font-weight: ${props => props.fontWeight};
    font-size: ${props => props.fontSize};
    text-decoration-line: ${props => props.textDecorationLine};
    ${props => (props.lineHeight ? `line-height: ${props.lineHeight}` : '')};
    ${props => (props.center ? 'text-align: center' : '')};
    color: ${props => props.fontColor};
    ${props => (props.minHeight ? `min-height: ${props.minHeight}` : '')};
    ${props => (props.onClick ? 'cursor: pointer' : '')};
    transition: color 0.5s ease;
    ${props => (props.noWrap ? 'white-space: nowrap' : '')};
    ${props => (props.display ? `display: ${props.display}` : '')};
    &:hover {
        ${props => (props.onClick ? `color: ${props.hoverColor || darken(0.3, props.fontColor || 'black')}` : '')};
    }
`;

Text.defaultProps = {
    fontFamily: 'Roboto',
    fontStyle: 'normal',
    fontWeight: 400,
    fontColor: colors.black,
    fontSize: '15px',
    lineHeight: '1.5em',
    textDecorationLine: 'none',
    Tag: 'div',
    noWrap: false,
};

Text.displayName = 'Text';

export const Title: React.StatelessComponent<TextProps> = props => <Text {...props} />;

Title.defaultProps = {
    Tag: 'h2',
    fontSize: '20px',
    fontWeight: 600,
    fontColor: colors.black,
};

Title.displayName = 'Title';