PromucFlow_constructor/app/client/src/components/designSystems/appsmith/TextInputComponent.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

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-11-13 07:34:59 +00:00
import { FormGroup, IconName, InputGroup, Intent } 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-13 07:34:59 +00:00
const TextInput = styled(InputGroup)`
2019-10-21 15:12:45 +00:00
flex: 1;
2019-11-13 07:34:59 +00:00
input {
border: 1px solid ${props => props.theme.colors.inputInactiveBorders};
border-radius: 4px;
box-shadow: none;
height: 38px;
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;
}
}
.bp3-icon {
border-radius: 4px 0 0 4px;
margin: 0;
height: 38px;
width: 30px;
background-color: ${props => props.theme.colors.menuButtonBGInactive};
display: flex;
align-items: center;
justify-content: center;
svg {
height: 20px;
width: 20px;
path {
fill: ${props => props.theme.colors.textDefault};
}
}
2019-10-21 15:12:45 +00:00
}
`;
const InputContainer = styled.div`
display: flex;
flex: 1;
flex-direction: column;
`;
2019-11-13 07:34:59 +00:00
const ErrorText = styled.span`
height: 10px;
padding: 3px;
font-size: 10px;
color: ${props => props.theme.colors.error};
2019-10-21 15:12:45 +00:00
`;
export interface TextInputProps {
placeholderMessage?: string;
2019-11-13 07:34:59 +00:00
input?: Partial<WrappedFieldInputProps>;
2019-10-21 15:12:45 +00:00
meta?: WrappedFieldMetaProps;
2019-11-13 07:34:59 +00:00
icon?: IconName;
2019-10-21 15:12:45 +00:00
}
export const BaseTextInput = (props: TextInputProps) => {
2019-11-13 07:34:59 +00:00
const { placeholderMessage, input, meta, icon } = props;
return (
<InputContainer>
2019-11-13 07:34:59 +00:00
<TextInput {...input} placeholder={placeholderMessage} leftIcon={icon} />
<ErrorText>{meta && meta.touched && meta.error}</ErrorText>
</InputContainer>
);
2019-10-21 15:12:45 +00:00
};
const TextInputComponent = (props: TextInputProps & ComponentProps) => {
return <BaseTextInput {...props} />;
2019-10-21 15:12:45 +00:00
};
export default TextInputComponent;