2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
2019-11-13 07:34:59 +00:00
|
|
|
import styled from "styled-components";
|
2019-10-21 15:12:45 +00:00
|
|
|
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
2019-12-06 13:16:08 +00:00
|
|
|
import {
|
|
|
|
|
IconName,
|
|
|
|
|
IInputGroupProps,
|
|
|
|
|
IIntentProps,
|
|
|
|
|
InputGroup,
|
|
|
|
|
MaybeElement,
|
|
|
|
|
} from "@blueprintjs/core";
|
2019-10-30 10:23:20 +00:00
|
|
|
import { ComponentProps } from "./BaseComponent";
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2019-11-14 09:01:23 +00:00
|
|
|
export const TextInput = styled(InputGroup)`
|
2019-10-21 15:12:45 +00:00
|
|
|
flex: 1;
|
2019-11-14 09:01:23 +00:00
|
|
|
& input {
|
2019-11-13 07:34:59 +00:00
|
|
|
border: 1px solid ${props => props.theme.colors.inputInactiveBorders};
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
box-shadow: none;
|
2019-11-13 11:34:11 +00:00
|
|
|
height: 32px;
|
2019-10-21 15:12:45 +00:00
|
|
|
background-color: ${props => props.theme.colors.textOnDarkBG};
|
2019-11-13 07:34:59 +00:00
|
|
|
&:focus {
|
|
|
|
|
border-color: ${props => props.theme.colors.secondary};
|
|
|
|
|
background-color: ${props => props.theme.colors.textOnDarkBG};
|
|
|
|
|
outline: 0;
|
2019-11-25 09:15:11 +00:00
|
|
|
box-shadow: none;
|
2019-11-13 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-14 09:01:23 +00:00
|
|
|
&.bp3-input-group .bp3-input:not(:first-child) {
|
2019-11-13 11:34:11 +00:00
|
|
|
padding-left: 35px;
|
|
|
|
|
}
|
2019-11-13 07:34:59 +00:00
|
|
|
.bp3-icon {
|
|
|
|
|
border-radius: 4px 0 0 4px;
|
|
|
|
|
margin: 0;
|
2019-11-13 11:34:11 +00:00
|
|
|
height: 32px;
|
2019-11-13 07:34:59 +00:00
|
|
|
width: 30px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
2019-11-13 11:34:11 +00:00
|
|
|
background-color: #eef2f5;
|
2019-11-13 07:34:59 +00:00
|
|
|
svg {
|
|
|
|
|
height: 20px;
|
|
|
|
|
width: 20px;
|
|
|
|
|
path {
|
2019-11-13 11:34:11 +00:00
|
|
|
fill: #979797;
|
2019-11-13 07:34:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
const InputContainer = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
flex-direction: column;
|
2019-12-06 13:16:08 +00:00
|
|
|
position: relative;
|
2019-10-29 12:02:58 +00:00
|
|
|
`;
|
|
|
|
|
|
2019-11-13 07:34:59 +00:00
|
|
|
const ErrorText = styled.span`
|
|
|
|
|
height: 10px;
|
|
|
|
|
padding: 3px;
|
|
|
|
|
font-size: 10px;
|
2019-10-29 12:02:58 +00:00
|
|
|
color: ${props => props.theme.colors.error};
|
2019-10-21 15:12:45 +00:00
|
|
|
`;
|
|
|
|
|
|
2019-12-06 13:16:08 +00:00
|
|
|
export interface TextInputProps extends IInputGroupProps {
|
2019-12-05 03:16:00 +00:00
|
|
|
/** TextInput Placeholder */
|
2019-11-25 09:15:11 +00:00
|
|
|
placeholder?: string;
|
2019-12-06 13:16:08 +00:00
|
|
|
intent?: IIntentProps["intent"];
|
2019-11-13 07:34:59 +00:00
|
|
|
input?: Partial<WrappedFieldInputProps>;
|
2019-12-05 03:16:00 +00:00
|
|
|
meta?: Partial<WrappedFieldMetaProps>;
|
2019-11-13 11:34:11 +00:00
|
|
|
icon?: IconName | MaybeElement;
|
2019-12-05 03:16:00 +00:00
|
|
|
/** Should show error when defined */
|
2019-11-13 11:34:11 +00:00
|
|
|
showError?: boolean;
|
2019-12-05 03:16:00 +00:00
|
|
|
/** Additional classname */
|
2019-11-14 09:01:23 +00:00
|
|
|
className?: string;
|
2019-12-06 13:16:08 +00:00
|
|
|
refHandler?: (ref: HTMLInputElement | null) => void;
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const BaseTextInput = (props: TextInputProps) => {
|
2019-12-06 13:16:08 +00:00
|
|
|
const { input, meta, showError, className, ...rest } = props;
|
2019-10-29 12:02:58 +00:00
|
|
|
return (
|
2019-11-14 09:01:23 +00:00
|
|
|
<InputContainer className={className}>
|
2019-11-25 09:15:11 +00:00
|
|
|
<TextInput
|
2019-12-06 13:16:08 +00:00
|
|
|
inputRef={props.refHandler}
|
2019-11-25 09:15:11 +00:00
|
|
|
{...input}
|
|
|
|
|
autoComplete={"off"}
|
2019-12-06 13:16:08 +00:00
|
|
|
{...rest}
|
2019-11-25 09:15:11 +00:00
|
|
|
/>
|
|
|
|
|
{showError && (
|
|
|
|
|
<ErrorText>
|
|
|
|
|
{meta && (meta.touched || meta.active) && meta.error}
|
|
|
|
|
</ErrorText>
|
|
|
|
|
)}
|
2019-10-29 12:02:58 +00:00
|
|
|
</InputContainer>
|
|
|
|
|
);
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
2019-12-05 03:16:00 +00:00
|
|
|
/**
|
|
|
|
|
* Text Input Component
|
|
|
|
|
* Has Icon, placholder, errors, etc.
|
|
|
|
|
*/
|
2019-10-21 15:12:45 +00:00
|
|
|
const TextInputComponent = (props: TextInputProps & ComponentProps) => {
|
2019-11-13 07:00:25 +00:00
|
|
|
return <BaseTextInput {...props} />;
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TextInputComponent;
|