aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/@next/components/modals/input.tsx
blob: 61663d906af8700eb0dbf0027798d18783fe11dc (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
import * as React from 'react';
import styled from 'styled-components';

export enum InputWidth {
    Half,
    Full,
}

interface InputProps {
    name: string;
    width?: InputWidth;
    label: string;
    type?: string;
}

interface LabelProps {
    string: boolean;
}

export const Input = React.forwardRef((props: InputProps, ref?: React.Ref<HTMLInputElement>) => {
    const { name, label, type } = props;
    const id = `input-${name}`;
    const componentType = type === 'textarea' ? 'textarea' : 'input';

    return (
        <InputWrapper {...props}>
            <Label htmlFor={id}>{label}</Label>
            <StyledInput as={componentType} ref={ref} id={id} placeholder={label} {...props} />
        </InputWrapper>
    );
});

Input.defaultProps = {
    width: InputWidth.Full,
};

const StyledInput = styled.input`
    appearance: none;
    background-color: #fff;
    border: 1px solid #D5D5D5;
    color: #000;
    font-size: 1.294117647rem;
    padding: 16px 15px 14px;
    outline: none;
    width: 100%;
    min-height: ${props => props.type === 'textarea' && `120px`};

    &::placeholder {
        color: #C3C3C3;
    }
`;

const InputWrapper = styled.div<InputProps>`
    position: relative;
    flex-grow: ${props => props.width === InputWidth.Full && 1};
    width: ${props => props.width === InputWidth.Half && `calc(50% - 15px)`};

    @media (max-width: 768px) {
        width: 100%;
        margin-bottom: 30px;
    }
`;

const Label = styled.label`
    color: #000;
    font-size: 1.111111111rem;
    line-height: 1.4em;
    margin-bottom: 10px;
    display: inline-block;
`;