2019-11-13 07:00:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
2021-02-08 07:30:01 +00:00
|
|
|
import {
|
|
|
|
|
getBorderCSSShorthand,
|
|
|
|
|
IntentColors,
|
|
|
|
|
labelStyle,
|
|
|
|
|
} from "constants/DefaultTheme";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ComponentProps } from "widgets/BaseComponent";
|
2019-10-30 10:23:20 +00:00
|
|
|
import {
|
2021-08-17 11:08:04 +00:00
|
|
|
FontStyleTypes,
|
|
|
|
|
TextSize,
|
|
|
|
|
TEXT_SIZES,
|
|
|
|
|
} from "constants/WidgetConstants";
|
|
|
|
|
import {
|
|
|
|
|
Alignment,
|
2019-10-30 10:23:20 +00:00
|
|
|
Intent,
|
|
|
|
|
NumericInput,
|
|
|
|
|
IconName,
|
|
|
|
|
InputGroup,
|
|
|
|
|
Button,
|
2019-10-31 05:28:11 +00:00
|
|
|
Label,
|
2020-01-14 09:50:42 +00:00
|
|
|
Classes,
|
2020-01-21 12:48:42 +00:00
|
|
|
ControlGroup,
|
2020-02-06 07:01:25 +00:00
|
|
|
TextArea,
|
2021-08-17 11:08:04 +00:00
|
|
|
Tag,
|
|
|
|
|
Position,
|
2019-10-30 10:23:20 +00:00
|
|
|
} from "@blueprintjs/core";
|
2021-08-17 11:08:04 +00:00
|
|
|
import Tooltip from "components/ads/Tooltip";
|
|
|
|
|
import { ReactComponent as HelpIcon } from "assets/icons/control/help.svg";
|
|
|
|
|
import { IconWrapper } from "constants/IconConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2020-02-06 07:01:25 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2020-03-06 09:45:21 +00:00
|
|
|
import _ from "lodash";
|
2021-09-09 15:10:22 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
INPUT_WIDGET_DEFAULT_VALIDATION_ERROR,
|
|
|
|
|
} from "constants/messages";
|
|
|
|
|
import { InputType, InputTypes } from "../constants";
|
|
|
|
|
|
2021-08-26 10:52:45 +00:00
|
|
|
import CurrencyTypeDropdown, {
|
|
|
|
|
CurrencyDropdownOptions,
|
|
|
|
|
getSelectedCurrency,
|
2021-09-09 15:10:22 +00:00
|
|
|
} from "./CurrencyCodeDropdown";
|
2021-08-26 10:52:45 +00:00
|
|
|
import ISDCodeDropdown, {
|
|
|
|
|
ISDCodeDropdownOptions,
|
|
|
|
|
getSelectedISDCode,
|
2021-09-09 15:10:22 +00:00
|
|
|
} from "./ISDCodeDropdown";
|
|
|
|
|
|
|
|
|
|
// TODO(abhinav): All of the following imports should not be in widgets.
|
|
|
|
|
import ErrorTooltip from "components/editorComponents/ErrorTooltip";
|
|
|
|
|
|
2019-10-30 10:23:20 +00:00
|
|
|
/**
|
|
|
|
|
* All design system component specific logic goes here.
|
2020-03-06 09:45:21 +00:00
|
|
|
* Ex. Blueprint has a separate numeric input and text input so switching between them goes here
|
2019-10-30 10:23:20 +00:00
|
|
|
* Ex. To set the icon as currency, blue print takes in a set of defined types
|
|
|
|
|
* All generic logic like max characters for phone numbers should be 10, should go in the widget
|
|
|
|
|
*/
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
const InputComponentWrapper = styled((props) => (
|
2021-09-07 13:12:04 +00:00
|
|
|
<ControlGroup
|
|
|
|
|
{..._.omit(props, [
|
|
|
|
|
"hasError",
|
|
|
|
|
"numeric",
|
|
|
|
|
"labelTextColor",
|
|
|
|
|
"allowCurrencyChange",
|
|
|
|
|
"compactMode",
|
|
|
|
|
"labelStyle",
|
|
|
|
|
"labelTextSize",
|
|
|
|
|
"multiline",
|
|
|
|
|
"numeric",
|
|
|
|
|
"inputType",
|
|
|
|
|
])}
|
|
|
|
|
/>
|
2020-03-06 09:45:21 +00:00
|
|
|
))<{
|
2020-03-13 07:24:03 +00:00
|
|
|
numeric: boolean;
|
2020-03-06 09:45:21 +00:00
|
|
|
multiline: string;
|
|
|
|
|
hasError: boolean;
|
2021-07-15 12:50:01 +00:00
|
|
|
allowCurrencyChange?: boolean;
|
2021-08-26 10:52:45 +00:00
|
|
|
disabled?: boolean;
|
2021-07-15 12:50:01 +00:00
|
|
|
inputType: InputType;
|
2020-03-06 09:45:21 +00:00
|
|
|
}>`
|
2021-08-17 11:08:04 +00:00
|
|
|
flex-direction: ${(props) => (props.compactMode ? "row" : "column")};
|
2020-01-14 09:50:42 +00:00
|
|
|
&&&& {
|
2021-08-26 10:52:45 +00:00
|
|
|
.currency-type-filter,
|
|
|
|
|
.country-type-filter {
|
2021-09-20 14:20:46 +00:00
|
|
|
width: fit-content;
|
2021-07-15 12:50:01 +00:00
|
|
|
height: 32px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
left: 0;
|
|
|
|
|
z-index: 16;
|
|
|
|
|
svg {
|
|
|
|
|
path {
|
|
|
|
|
fill: ${(props) => props.theme.colors.icon?.hover};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
.${Classes.INPUT} {
|
2021-07-15 12:50:01 +00:00
|
|
|
${(props) =>
|
|
|
|
|
props.inputType === InputTypes.CURRENCY &&
|
|
|
|
|
props.allowCurrencyChange &&
|
|
|
|
|
`
|
|
|
|
|
padding-left: 45px;`};
|
|
|
|
|
${(props) =>
|
|
|
|
|
props.inputType === InputTypes.CURRENCY &&
|
|
|
|
|
!props.allowCurrencyChange &&
|
|
|
|
|
`
|
|
|
|
|
padding-left: 35px;`};
|
2021-08-26 10:52:45 +00:00
|
|
|
${(props) =>
|
|
|
|
|
props.inputType === InputTypes.PHONE_NUMBER && `padding-left: 85px;`};
|
2020-01-17 12:34:58 +00:00
|
|
|
box-shadow: none;
|
2020-03-06 09:45:21 +00:00
|
|
|
border: 1px solid;
|
|
|
|
|
border-color: ${({ hasError }) =>
|
|
|
|
|
hasError ? IntentColors.danger : Colors.GEYSER_LIGHT};
|
2021-02-08 07:30:01 +00:00
|
|
|
border-radius: 0;
|
2020-12-24 04:32:25 +00:00
|
|
|
height: ${(props) => (props.multiline === "true" ? "100%" : "inherit")};
|
2020-03-06 09:45:21 +00:00
|
|
|
width: 100%;
|
2020-12-24 04:32:25 +00:00
|
|
|
${(props) =>
|
2020-03-13 07:24:03 +00:00
|
|
|
props.numeric &&
|
|
|
|
|
`
|
|
|
|
|
border-top-right-radius: 0px;
|
|
|
|
|
border-bottom-right-radius: 0px;
|
|
|
|
|
border-right-width: 0px;
|
|
|
|
|
`}
|
2021-02-08 07:30:01 +00:00
|
|
|
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
2020-02-06 07:01:25 +00:00
|
|
|
&:active {
|
2020-03-06 09:45:21 +00:00
|
|
|
border-color: ${({ hasError }) =>
|
|
|
|
|
hasError ? IntentColors.danger : Colors.HIT_GRAY};
|
2020-02-06 07:01:25 +00:00
|
|
|
}
|
|
|
|
|
&:focus {
|
2020-03-06 09:45:21 +00:00
|
|
|
border-color: ${({ hasError }) =>
|
|
|
|
|
hasError ? IntentColors.danger : Colors.MYSTIC};
|
2021-02-08 07:30:01 +00:00
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
|
border: ${(props) => getBorderCSSShorthand(props.theme.borders[2])};
|
|
|
|
|
border-color: #80bdff;
|
|
|
|
|
outline: 0;
|
|
|
|
|
box-shadow: 0 0 0 0.1rem rgba(0, 123, 255, 0.25);
|
|
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
}
|
2020-01-17 12:34:58 +00:00
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
.${Classes.INPUT_GROUP} {
|
2020-01-14 09:50:42 +00:00
|
|
|
display: block;
|
|
|
|
|
margin: 0;
|
2021-08-17 11:08:04 +00:00
|
|
|
.bp3-tag {
|
|
|
|
|
background-color: transparent;
|
|
|
|
|
color: #5c7080;
|
|
|
|
|
}
|
2020-01-14 09:50:42 +00:00
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
.${Classes.CONTROL_GROUP} {
|
2020-01-14 09:50:42 +00:00
|
|
|
justify-content: flex-start;
|
|
|
|
|
}
|
2020-03-06 09:33:20 +00:00
|
|
|
height: 100%;
|
2020-01-21 12:48:42 +00:00
|
|
|
align-items: center;
|
|
|
|
|
label {
|
2020-01-28 08:21:22 +00:00
|
|
|
${labelStyle}
|
2021-08-17 11:08:04 +00:00
|
|
|
margin-right: 5px;
|
2020-01-21 12:48:42 +00:00
|
|
|
text-align: right;
|
2020-02-06 07:01:25 +00:00
|
|
|
align-self: flex-start;
|
2021-08-17 11:08:04 +00:00
|
|
|
color: ${(props) => props.labelTextColor || "inherit"};
|
|
|
|
|
font-size: ${(props) => props.labelTextSize};
|
|
|
|
|
font-weight: ${(props) =>
|
|
|
|
|
props?.labelStyle?.includes(FontStyleTypes.BOLD) ? "bold" : "normal"};
|
|
|
|
|
font-style: ${(props) =>
|
|
|
|
|
props?.labelStyle?.includes(FontStyleTypes.ITALIC) ? "italic" : ""};
|
|
|
|
|
text-decoration: ${(props) =>
|
|
|
|
|
props?.labelStyle?.includes(FontStyleTypes.UNDERLINE)
|
|
|
|
|
? "underline"
|
|
|
|
|
: ""};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-09-20 14:20:46 +00:00
|
|
|
const StyledNumericInput = styled(NumericInput)`
|
|
|
|
|
&&&& .bp3-input-group {
|
|
|
|
|
display: flex;
|
|
|
|
|
> {
|
|
|
|
|
&:first-child:not(input) {
|
|
|
|
|
position: static;
|
|
|
|
|
background: ${(props) =>
|
|
|
|
|
props.disabled ? Colors.INPUT_DISABLED : "#fff"};
|
|
|
|
|
color: ${(props) =>
|
|
|
|
|
props.disabled ? Colors.INPUT_TEXT_DISABLED : "#000"};
|
|
|
|
|
border: 1px solid #e7e7e7;
|
|
|
|
|
border-right: 0;
|
|
|
|
|
}
|
|
|
|
|
input:not(:first-child) {
|
|
|
|
|
padding-left: 5px;
|
|
|
|
|
border-left: 0;
|
|
|
|
|
z-index: 16;
|
|
|
|
|
line-height: 16px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-08-17 11:08:04 +00:00
|
|
|
const ToolTipIcon = styled(IconWrapper)`
|
|
|
|
|
cursor: help;
|
|
|
|
|
margin-top: 1.5px;
|
|
|
|
|
&&&:hover {
|
|
|
|
|
svg {
|
|
|
|
|
path {
|
|
|
|
|
fill: #716e6e;
|
|
|
|
|
}
|
2020-01-21 12:48:42 +00:00
|
|
|
}
|
2019-11-13 07:00:25 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-08-17 11:08:04 +00:00
|
|
|
const TextLableWrapper = styled.div<{
|
|
|
|
|
compactMode: boolean;
|
|
|
|
|
}>`
|
|
|
|
|
${(props) =>
|
|
|
|
|
props.compactMode ? "&&& {margin-right: 5px;}" : "width: 100%;"}
|
|
|
|
|
display: flex;
|
|
|
|
|
max-height: 20px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const TextInputWrapper = styled.div`
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-08-26 10:52:45 +00:00
|
|
|
export const isNumberInputType = (inputType: InputType) => {
|
2021-07-15 12:50:01 +00:00
|
|
|
return (
|
2021-08-26 10:52:45 +00:00
|
|
|
inputType === "INTEGER" ||
|
|
|
|
|
inputType === "NUMBER" ||
|
|
|
|
|
inputType === "CURRENCY" ||
|
|
|
|
|
inputType === "PHONE_NUMBER"
|
2021-07-15 12:50:01 +00:00
|
|
|
);
|
|
|
|
|
};
|
2019-10-30 10:23:20 +00:00
|
|
|
class InputComponent extends React.Component<
|
|
|
|
|
InputComponentProps,
|
|
|
|
|
InputComponentState
|
|
|
|
|
> {
|
|
|
|
|
constructor(props: InputComponentProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { showPassword: false };
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 09:45:21 +00:00
|
|
|
setFocusState = (isFocused: boolean) => {
|
|
|
|
|
this.props.onFocusChange(isFocused);
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-06 07:01:25 +00:00
|
|
|
onTextChange = (
|
|
|
|
|
event:
|
|
|
|
|
| React.ChangeEvent<HTMLInputElement>
|
|
|
|
|
| React.ChangeEvent<HTMLTextAreaElement>,
|
|
|
|
|
) => {
|
2019-10-31 05:28:11 +00:00
|
|
|
this.props.onValueChange(event.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onNumberChange = (valueAsNum: number, valueAsString: string) => {
|
2021-07-15 12:50:01 +00:00
|
|
|
if (this.props.inputType === InputTypes.CURRENCY) {
|
|
|
|
|
const fractionDigits = this.props.decimalsInCurrency || 0;
|
|
|
|
|
const currentIndexOfDecimal = valueAsString.indexOf(".");
|
|
|
|
|
const indexOfDecimal = valueAsString.length - fractionDigits - 1;
|
|
|
|
|
if (
|
|
|
|
|
valueAsString.includes(".") &&
|
|
|
|
|
currentIndexOfDecimal <= indexOfDecimal
|
|
|
|
|
) {
|
|
|
|
|
let value = valueAsString.split(",").join("");
|
|
|
|
|
if (value) {
|
|
|
|
|
const locale = navigator.languages?.[0] || "en-US";
|
|
|
|
|
const formatter = new Intl.NumberFormat(locale, {
|
|
|
|
|
style: "decimal",
|
|
|
|
|
minimumFractionDigits: fractionDigits,
|
|
|
|
|
});
|
2021-09-22 07:28:56 +00:00
|
|
|
const decimalValueArray = value.split(".");
|
|
|
|
|
//remove extra digits after decimal point
|
|
|
|
|
if (
|
|
|
|
|
this.props.decimalsInCurrency &&
|
|
|
|
|
decimalValueArray[1].length > this.props.decimalsInCurrency
|
|
|
|
|
) {
|
|
|
|
|
value =
|
|
|
|
|
decimalValueArray[0] +
|
|
|
|
|
"." +
|
|
|
|
|
decimalValueArray[1].substr(0, this.props.decimalsInCurrency);
|
|
|
|
|
}
|
2021-07-15 12:50:01 +00:00
|
|
|
const formattedValue = formatter.format(parseFloat(value));
|
|
|
|
|
this.props.onValueChange(formattedValue);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.onValueChange("");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.props.onValueChange(valueAsString);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.props.onValueChange(valueAsString);
|
|
|
|
|
}
|
2019-10-31 05:28:11 +00:00
|
|
|
};
|
|
|
|
|
|
2021-08-26 10:52:45 +00:00
|
|
|
getLeftIcon = (inputType: InputType, disabled: boolean) => {
|
|
|
|
|
if (inputType === InputTypes.PHONE_NUMBER) {
|
|
|
|
|
const selectedISDCode = getSelectedISDCode(
|
|
|
|
|
this.props.phoneNumberCountryCode,
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<ISDCodeDropdown
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onISDCodeChange={this.props.onISDCodeChange}
|
|
|
|
|
options={ISDCodeDropdownOptions}
|
|
|
|
|
selected={selectedISDCode}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else if (inputType === InputTypes.CURRENCY) {
|
|
|
|
|
const selectedCurrencyCountryCode = getSelectedCurrency(
|
|
|
|
|
this.props.currencyCountryCode,
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<CurrencyTypeDropdown
|
|
|
|
|
allowCurrencyChange={this.props.allowCurrencyChange && !disabled}
|
|
|
|
|
onCurrencyTypeChange={this.props.onCurrencyTypeChange}
|
|
|
|
|
options={CurrencyDropdownOptions}
|
|
|
|
|
selected={selectedCurrencyCountryCode}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else if (this.props.iconName && this.props.iconAlign === "left") {
|
|
|
|
|
return this.props.iconName;
|
|
|
|
|
}
|
|
|
|
|
return this.props.leftIcon;
|
|
|
|
|
};
|
2019-10-31 05:28:11 +00:00
|
|
|
|
|
|
|
|
getIcon(inputType: InputType) {
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case "SEARCH":
|
|
|
|
|
return "search";
|
|
|
|
|
case "EMAIL":
|
|
|
|
|
return "envelope";
|
|
|
|
|
default:
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getType(inputType: InputType) {
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case "PASSWORD":
|
2020-01-14 09:50:42 +00:00
|
|
|
return this.state.showPassword ? "text" : "password";
|
2019-10-31 05:28:11 +00:00
|
|
|
case "EMAIL":
|
|
|
|
|
return "email";
|
|
|
|
|
case "SEARCH":
|
|
|
|
|
return "search";
|
|
|
|
|
default:
|
|
|
|
|
return "text";
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-28 11:15:14 +00:00
|
|
|
onKeyDownTextArea = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
|
|
const isEnterKey = e.key === "Enter" || e.keyCode === 13;
|
|
|
|
|
const { disableNewLineOnPressEnterKey } = this.props;
|
|
|
|
|
if (isEnterKey && disableNewLineOnPressEnterKey && !e.shiftKey) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
if (typeof this.props.onKeyDown === "function") {
|
|
|
|
|
this.props.onKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
|
|
|
if (typeof this.props.onKeyDown === "function") {
|
|
|
|
|
this.props.onKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-15 12:50:01 +00:00
|
|
|
private numericInputComponent = () => {
|
2021-08-26 10:52:45 +00:00
|
|
|
const leftIcon = this.getLeftIcon(
|
|
|
|
|
this.props.inputType,
|
|
|
|
|
!!this.props.disabled,
|
|
|
|
|
);
|
2021-07-15 12:50:01 +00:00
|
|
|
const minorStepSize =
|
|
|
|
|
this.props.inputType === InputTypes.CURRENCY
|
|
|
|
|
? this.props.decimalsInCurrency || 0
|
|
|
|
|
: 0;
|
|
|
|
|
return (
|
2021-09-20 14:20:46 +00:00
|
|
|
<StyledNumericInput
|
2021-07-15 12:50:01 +00:00
|
|
|
allowNumericCharactersOnly
|
2021-10-01 15:09:59 +00:00
|
|
|
autoFocus={this.props.autoFocus}
|
2021-07-15 12:50:01 +00:00
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : Classes.FILL}
|
|
|
|
|
disabled={this.props.disabled}
|
|
|
|
|
intent={this.props.intent}
|
2021-08-26 10:52:45 +00:00
|
|
|
leftIcon={leftIcon}
|
2021-07-15 12:50:01 +00:00
|
|
|
max={this.props.maxNum}
|
|
|
|
|
maxLength={this.props.maxChars}
|
2021-08-26 10:52:45 +00:00
|
|
|
min={
|
|
|
|
|
this.props.inputType === InputTypes.PHONE_NUMBER
|
|
|
|
|
? 0
|
|
|
|
|
: this.props.minNum
|
|
|
|
|
}
|
2021-07-15 12:50:01 +00:00
|
|
|
minorStepSize={
|
|
|
|
|
minorStepSize === 0 ? undefined : Math.pow(10, -1 * minorStepSize)
|
|
|
|
|
}
|
|
|
|
|
onBlur={() => this.setFocusState(false)}
|
|
|
|
|
onFocus={() => this.setFocusState(true)}
|
|
|
|
|
onKeyDown={this.onKeyDown}
|
|
|
|
|
onValueChange={this.onNumberChange}
|
|
|
|
|
placeholder={this.props.placeholder}
|
|
|
|
|
stepSize={minorStepSize === 0 ? this.props.stepSize : undefined}
|
|
|
|
|
value={this.props.value}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
2020-03-13 07:24:03 +00:00
|
|
|
private textAreaInputComponent = () => (
|
2020-02-06 07:01:25 +00:00
|
|
|
<TextArea
|
2021-08-17 11:08:04 +00:00
|
|
|
autoFocus={this.props.autoFocus}
|
2021-04-28 10:28:39 +00:00
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : ""}
|
2020-02-06 07:01:25 +00:00
|
|
|
disabled={this.props.disabled}
|
2021-04-28 10:28:39 +00:00
|
|
|
growVertically={false}
|
2020-02-06 07:01:25 +00:00
|
|
|
intent={this.props.intent}
|
2021-04-28 10:28:39 +00:00
|
|
|
maxLength={this.props.maxChars}
|
|
|
|
|
onBlur={() => this.setFocusState(false)}
|
2020-02-06 07:01:25 +00:00
|
|
|
onChange={this.onTextChange}
|
2020-03-06 09:45:21 +00:00
|
|
|
onFocus={() => this.setFocusState(true)}
|
2021-01-28 11:15:14 +00:00
|
|
|
onKeyDown={this.onKeyDownTextArea}
|
2021-04-28 10:28:39 +00:00
|
|
|
placeholder={this.props.placeholder}
|
2021-07-02 11:23:38 +00:00
|
|
|
style={{ resize: "none" }}
|
2021-04-28 10:28:39 +00:00
|
|
|
value={this.props.value}
|
2020-02-06 07:01:25 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
private textInputComponent = (isTextArea: boolean) =>
|
|
|
|
|
isTextArea ? (
|
2020-03-13 07:24:03 +00:00
|
|
|
this.textAreaInputComponent()
|
2020-02-06 07:01:25 +00:00
|
|
|
) : (
|
|
|
|
|
<InputGroup
|
2021-08-17 11:08:04 +00:00
|
|
|
autoFocus={this.props.autoFocus}
|
2021-04-28 10:28:39 +00:00
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : ""}
|
2020-02-06 07:01:25 +00:00
|
|
|
disabled={this.props.disabled}
|
|
|
|
|
intent={this.props.intent}
|
2021-08-17 11:08:04 +00:00
|
|
|
leftIcon={
|
|
|
|
|
this.props.iconName && this.props.iconAlign === "left"
|
|
|
|
|
? this.props.iconName
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
maxLength={this.props.maxChars}
|
|
|
|
|
onBlur={() => this.setFocusState(false)}
|
2020-02-06 07:01:25 +00:00
|
|
|
onChange={this.onTextChange}
|
2021-04-28 10:28:39 +00:00
|
|
|
onFocus={() => this.setFocusState(true)}
|
|
|
|
|
onKeyDown={this.onKeyDown}
|
|
|
|
|
placeholder={this.props.placeholder}
|
2020-02-06 07:01:25 +00:00
|
|
|
rightElement={
|
|
|
|
|
this.props.inputType === "PASSWORD" ? (
|
|
|
|
|
<Button
|
|
|
|
|
icon={"lock"}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
this.setState({ showPassword: !this.state.showPassword });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2021-08-17 11:08:04 +00:00
|
|
|
) : this.props.iconName && this.props.iconAlign === "right" ? (
|
|
|
|
|
<Tag icon={this.props.iconName} />
|
2020-02-06 07:01:25 +00:00
|
|
|
) : (
|
|
|
|
|
undefined
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
type={this.getType(this.props.inputType)}
|
2021-04-28 10:28:39 +00:00
|
|
|
value={this.props.value}
|
2020-02-06 07:01:25 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
private renderInputComponent = (inputType: InputType, isTextArea: boolean) =>
|
2021-08-26 10:52:45 +00:00
|
|
|
isNumberInputType(inputType)
|
2020-02-06 07:01:25 +00:00
|
|
|
? this.numericInputComponent()
|
|
|
|
|
: this.textInputComponent(isTextArea);
|
2019-10-31 05:28:11 +00:00
|
|
|
|
2019-10-30 10:23:20 +00:00
|
|
|
render() {
|
2021-08-17 11:08:04 +00:00
|
|
|
const {
|
|
|
|
|
label,
|
|
|
|
|
labelStyle,
|
|
|
|
|
labelTextColor,
|
|
|
|
|
labelTextSize,
|
|
|
|
|
tooltip,
|
|
|
|
|
} = this.props;
|
|
|
|
|
const showLabelHeader = label || tooltip;
|
|
|
|
|
|
2019-10-30 10:23:20 +00:00
|
|
|
return (
|
2020-03-06 09:45:21 +00:00
|
|
|
<InputComponentWrapper
|
2021-07-15 12:50:01 +00:00
|
|
|
allowCurrencyChange={this.props.allowCurrencyChange}
|
2021-08-17 11:08:04 +00:00
|
|
|
compactMode={this.props.compactMode}
|
2021-08-26 10:52:45 +00:00
|
|
|
disabled={this.props.disabled}
|
2020-03-06 09:45:21 +00:00
|
|
|
fill
|
2021-04-28 10:28:39 +00:00
|
|
|
hasError={this.props.isInvalid}
|
2021-07-15 12:50:01 +00:00
|
|
|
inputType={this.props.inputType}
|
2021-08-17 11:08:04 +00:00
|
|
|
labelStyle={labelStyle}
|
|
|
|
|
labelTextColor={labelTextColor}
|
|
|
|
|
labelTextSize={labelTextSize ? TEXT_SIZES[labelTextSize] : "inherit"}
|
2020-03-06 09:45:21 +00:00
|
|
|
multiline={this.props.multiline.toString()}
|
2021-08-26 10:52:45 +00:00
|
|
|
numeric={isNumberInputType(this.props.inputType)}
|
2020-03-06 09:45:21 +00:00
|
|
|
>
|
2021-08-17 11:08:04 +00:00
|
|
|
{showLabelHeader && (
|
|
|
|
|
<TextLableWrapper
|
|
|
|
|
className="t--input-label-wrapper"
|
|
|
|
|
compactMode={this.props.compactMode}
|
2020-01-31 11:13:16 +00:00
|
|
|
>
|
2021-08-17 11:08:04 +00:00
|
|
|
{this.props.label && (
|
|
|
|
|
<Label
|
|
|
|
|
className={`
|
|
|
|
|
t--input-widget-label ${
|
|
|
|
|
this.props.isLoading
|
|
|
|
|
? Classes.SKELETON
|
|
|
|
|
: Classes.TEXT_OVERFLOW_ELLIPSIS
|
|
|
|
|
}
|
|
|
|
|
`}
|
|
|
|
|
>
|
|
|
|
|
{this.props.label}
|
|
|
|
|
</Label>
|
|
|
|
|
)}
|
|
|
|
|
{this.props.tooltip && (
|
|
|
|
|
<Tooltip
|
|
|
|
|
content={this.props.tooltip}
|
|
|
|
|
hoverOpenDelay={200}
|
|
|
|
|
position={Position.TOP}
|
|
|
|
|
>
|
|
|
|
|
<ToolTipIcon
|
|
|
|
|
color={Colors.SILVER_CHALICE}
|
|
|
|
|
height={14}
|
|
|
|
|
width={14}
|
|
|
|
|
>
|
|
|
|
|
<HelpIcon className="t--input-widget-tooltip" />
|
|
|
|
|
</ToolTipIcon>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</TextLableWrapper>
|
2020-01-28 11:46:04 +00:00
|
|
|
)}
|
2021-08-17 11:08:04 +00:00
|
|
|
<TextInputWrapper>
|
|
|
|
|
<ErrorTooltip
|
|
|
|
|
isOpen={this.props.isInvalid && this.props.showError}
|
|
|
|
|
message={
|
|
|
|
|
this.props.errorMessage ||
|
|
|
|
|
createMessage(INPUT_WIDGET_DEFAULT_VALIDATION_ERROR)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{this.renderInputComponent(
|
|
|
|
|
this.props.inputType,
|
|
|
|
|
this.props.multiline,
|
|
|
|
|
)}
|
|
|
|
|
</ErrorTooltip>
|
|
|
|
|
</TextInputWrapper>
|
2019-11-13 07:00:25 +00:00
|
|
|
</InputComponentWrapper>
|
2019-10-30 10:23:20 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputComponentState {
|
|
|
|
|
showPassword?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputComponentProps extends ComponentProps {
|
2020-03-06 09:45:21 +00:00
|
|
|
value: string;
|
2019-10-31 05:28:11 +00:00
|
|
|
inputType: InputType;
|
2019-10-30 10:23:20 +00:00
|
|
|
disabled?: boolean;
|
|
|
|
|
intent?: Intent;
|
2021-08-26 10:52:45 +00:00
|
|
|
defaultValue?: string | number;
|
2021-07-15 12:50:01 +00:00
|
|
|
currencyCountryCode?: string;
|
|
|
|
|
noOfDecimals?: number;
|
2021-08-26 10:52:45 +00:00
|
|
|
phoneNumberCountryCode?: string;
|
2021-07-15 12:50:01 +00:00
|
|
|
allowCurrencyChange?: boolean;
|
|
|
|
|
decimalsInCurrency?: number;
|
2019-10-31 05:28:11 +00:00
|
|
|
label: string;
|
2021-08-17 11:08:04 +00:00
|
|
|
labelTextColor?: string;
|
|
|
|
|
labelTextSize?: TextSize;
|
|
|
|
|
labelStyle?: string;
|
|
|
|
|
tooltip?: string;
|
2019-10-30 10:23:20 +00:00
|
|
|
leftIcon?: IconName;
|
|
|
|
|
allowNumericCharactersOnly?: boolean;
|
|
|
|
|
fill?: boolean;
|
2019-10-31 05:28:11 +00:00
|
|
|
errorMessage?: string;
|
|
|
|
|
maxChars?: number;
|
2019-10-30 10:23:20 +00:00
|
|
|
maxNum?: number;
|
|
|
|
|
minNum?: number;
|
2019-10-31 05:28:11 +00:00
|
|
|
onValueChange: (valueAsString: string) => void;
|
2021-07-15 12:50:01 +00:00
|
|
|
onCurrencyTypeChange: (code?: string) => void;
|
2021-08-26 10:52:45 +00:00
|
|
|
onISDCodeChange: (code?: string) => void;
|
2019-10-30 10:23:20 +00:00
|
|
|
stepSize?: number;
|
|
|
|
|
placeholder?: string;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-02-13 09:32:24 +00:00
|
|
|
multiline: boolean;
|
2021-08-17 11:08:04 +00:00
|
|
|
compactMode: boolean;
|
2020-03-06 09:45:21 +00:00
|
|
|
isInvalid: boolean;
|
2021-08-17 11:08:04 +00:00
|
|
|
autoFocus?: boolean;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Omit<Alignment, "center">;
|
2020-03-06 09:45:21 +00:00
|
|
|
showError: boolean;
|
|
|
|
|
onFocusChange: (state: boolean) => void;
|
2021-01-28 11:15:14 +00:00
|
|
|
disableNewLineOnPressEnterKey?: boolean;
|
|
|
|
|
onKeyDown?: (
|
|
|
|
|
e:
|
|
|
|
|
| React.KeyboardEvent<HTMLTextAreaElement>
|
|
|
|
|
| React.KeyboardEvent<HTMLInputElement>,
|
|
|
|
|
) => void;
|
2019-10-30 10:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputComponent;
|