2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled, { css } from "styled-components";
|
|
|
|
|
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
|
|
|
|
import { ComponentProps } from "../../editorComponents/BaseComponent";
|
|
|
|
|
import { Container } from "../../editorComponents/ContainerComponent";
|
|
|
|
|
|
|
|
|
|
const InputStyles = css`
|
2019-10-29 12:02:58 +00:00
|
|
|
padding: ${props => `${props.theme.spaces[3]}px ${props.theme.spaces[1]}px`};
|
2019-10-21 15:12:45 +00:00
|
|
|
flex: 1;
|
|
|
|
|
border: 1px solid ${props => props.theme.colors.inputInactiveBorders};
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
height: 32px;
|
2019-10-25 05:35:20 +00:00
|
|
|
background-color: ${props => props.theme.colors.textOnDarkBG};
|
2019-10-21 15:12:45 +00:00
|
|
|
&:focus {
|
|
|
|
|
border-color: ${props => props.theme.colors.secondary};
|
|
|
|
|
background-color: ${props => props.theme.colors.textOnDarkBG};
|
|
|
|
|
outline: 0;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Input = styled.input`
|
|
|
|
|
${InputStyles}
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
const InputContainer = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Error = styled.span`
|
|
|
|
|
color: ${props => props.theme.colors.error};
|
|
|
|
|
fontsize: ${props => props.theme.fontSizes[1]};
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
const TextArea = styled.textarea`
|
|
|
|
|
${InputStyles}
|
|
|
|
|
height: 100px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export interface TextInputProps {
|
|
|
|
|
placeholderMessage?: string;
|
|
|
|
|
multiline?: boolean;
|
|
|
|
|
input?: WrappedFieldInputProps;
|
|
|
|
|
meta?: WrappedFieldMetaProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const BaseTextInput = (props: TextInputProps) => {
|
2019-10-29 12:02:58 +00:00
|
|
|
const { placeholderMessage, multiline, input, meta } = props;
|
2019-10-21 15:12:45 +00:00
|
|
|
if (multiline) {
|
|
|
|
|
return <TextArea placeholder={placeholderMessage} {...input} />;
|
|
|
|
|
}
|
2019-10-29 12:02:58 +00:00
|
|
|
return (
|
|
|
|
|
<InputContainer>
|
|
|
|
|
<Input placeholder={placeholderMessage} {...input} />
|
|
|
|
|
{meta && meta.touched && meta.error && <Error>{meta.error}</Error>}
|
|
|
|
|
</InputContainer>
|
|
|
|
|
);
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const TextInputComponent = (props: TextInputProps & ComponentProps) => {
|
|
|
|
|
return (
|
|
|
|
|
<Container {...props}>
|
|
|
|
|
<BaseTextInput {...props} />
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TextInputComponent;
|