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

80 lines
2.0 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 11:34:11 +00:00
import { IconName, 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-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
}
`;
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 11:34:11 +00:00
icon?: IconName | MaybeElement;
showError?: boolean;
2019-11-14 09:01:23 +00:00
className?: string;
2019-10-21 15:12:45 +00:00
}
export const BaseTextInput = (props: TextInputProps) => {
2019-11-14 09:01:23 +00:00
const { placeholderMessage, input, meta, icon, showError, className } = props;
return (
2019-11-14 09:01:23 +00:00
<InputContainer className={className}>
2019-11-13 07:34:59 +00:00
<TextInput {...input} placeholder={placeholderMessage} leftIcon={icon} />
2019-11-13 11:34:11 +00:00
{showError && <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;