2020-07-21 12:02:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import TextInput from "../text-input";
|
|
|
|
import { Icons } from "../icons";
|
|
|
|
import IconButton from "../icon-button";
|
|
|
|
import commonInputStyle from "../text-input/common-input-styles";
|
2019-07-10 12:14:53 +00:00
|
|
|
|
|
|
|
const iconNames = Object.keys(Icons);
|
|
|
|
|
|
|
|
const StyledIconBlock = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2019-12-25 08:22:19 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
cursor: ${(props) =>
|
2019-12-13 09:25:21 +00:00
|
|
|
props.isDisabled || !props.isClickable ? "default" : "pointer"};
|
2019-07-10 12:14:53 +00:00
|
|
|
height: 100%;
|
2019-12-26 08:47:02 +00:00
|
|
|
padding-right: 8px;
|
|
|
|
padding-left: 1px;
|
2020-07-21 12:02:32 +00:00
|
|
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
2019-07-10 12:14:53 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledChildrenBlock = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2019-07-15 14:24:17 +00:00
|
|
|
padding: 2px 0px 2px 2px;
|
2019-07-10 12:14:53 +00:00
|
|
|
`;
|
|
|
|
|
2020-09-01 13:55:28 +00:00
|
|
|
/* eslint-disable react/prop-types, no-unused-vars */
|
2020-07-21 12:02:32 +00:00
|
|
|
const CustomInputGroup = ({
|
2020-10-16 13:16:01 +00:00
|
|
|
isIconFill,
|
2020-07-21 12:02:32 +00:00
|
|
|
hasError,
|
|
|
|
hasWarning,
|
|
|
|
isDisabled,
|
2020-10-16 13:16:01 +00:00
|
|
|
scale,
|
2020-07-21 12:02:32 +00:00
|
|
|
...props
|
|
|
|
}) => <div {...props}></div>;
|
2020-09-01 13:55:28 +00:00
|
|
|
/* eslint-enable react/prop-types, no-unused-vars */
|
2019-07-10 12:14:53 +00:00
|
|
|
const StyledInputGroup = styled(CustomInputGroup)`
|
2019-12-03 12:00:10 +00:00
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.prepend {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.append {
|
|
|
|
align-items: center;
|
|
|
|
margin: 0;
|
2019-07-10 12:14:53 +00:00
|
|
|
}
|
2019-12-03 12:00:10 +00:00
|
|
|
${commonInputStyle} :focus-within {
|
|
|
|
border-color: #2da7db;
|
2019-07-10 12:14:53 +00:00
|
|
|
}
|
|
|
|
`;
|
2019-09-12 11:10:15 +00:00
|
|
|
class InputBlock extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
2020-10-16 13:16:01 +00:00
|
|
|
onIconClick = (e) => {
|
2020-07-21 12:02:32 +00:00
|
|
|
if (typeof this.props.onIconClick === "function" && !this.props.isDisabled)
|
|
|
|
this.props.onIconClick(e);
|
|
|
|
};
|
2020-10-16 13:16:01 +00:00
|
|
|
onChange = (e) => {
|
2019-09-27 12:56:15 +00:00
|
|
|
if (typeof this.props.onChange === "function") this.props.onChange(e);
|
2020-07-21 12:02:32 +00:00
|
|
|
};
|
2019-07-11 09:39:36 +00:00
|
|
|
|
2019-09-12 11:10:15 +00:00
|
|
|
render() {
|
|
|
|
let iconButtonSize = 0;
|
2019-11-28 11:35:32 +00:00
|
|
|
const {
|
|
|
|
hasError,
|
|
|
|
hasWarning,
|
|
|
|
isDisabled,
|
|
|
|
scale,
|
|
|
|
size,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
children,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
value,
|
|
|
|
placeholder,
|
|
|
|
tabIndex,
|
|
|
|
maxLength,
|
|
|
|
onBlur,
|
|
|
|
onFocus,
|
|
|
|
isReadOnly,
|
|
|
|
isAutoFocussed,
|
|
|
|
autoComplete,
|
|
|
|
mask,
|
|
|
|
keepCharPositions,
|
|
|
|
iconName,
|
|
|
|
iconColor,
|
2019-12-26 08:47:02 +00:00
|
|
|
hoverColor,
|
2019-11-28 11:35:32 +00:00
|
|
|
isIconFill,
|
|
|
|
onIconClick,
|
2020-10-16 13:16:01 +00:00
|
|
|
iconSize,
|
2019-11-28 11:35:32 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (typeof iconSize == "number" && iconSize > 0) {
|
|
|
|
iconButtonSize = iconSize;
|
2019-09-12 11:10:15 +00:00
|
|
|
} else {
|
2019-11-28 11:35:32 +00:00
|
|
|
switch (size) {
|
2020-07-21 12:02:32 +00:00
|
|
|
case "base":
|
2020-11-28 10:09:56 +00:00
|
|
|
iconButtonSize = 16;
|
2019-09-12 11:10:15 +00:00
|
|
|
break;
|
2020-07-21 12:02:32 +00:00
|
|
|
case "middle":
|
2019-09-12 11:10:15 +00:00
|
|
|
iconButtonSize = 18;
|
|
|
|
break;
|
2020-07-21 12:02:32 +00:00
|
|
|
case "big":
|
2019-09-12 11:10:15 +00:00
|
|
|
iconButtonSize = 21;
|
|
|
|
break;
|
2020-07-21 12:02:32 +00:00
|
|
|
case "huge":
|
2019-09-12 11:10:15 +00:00
|
|
|
iconButtonSize = 24;
|
|
|
|
break;
|
2019-07-31 19:36:26 +00:00
|
|
|
}
|
2019-09-12 11:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-11-28 11:35:32 +00:00
|
|
|
<StyledInputGroup
|
|
|
|
hasError={hasError}
|
|
|
|
hasWarning={hasWarning}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
scale={scale}
|
|
|
|
size={size}
|
|
|
|
className={className}
|
|
|
|
style={style}
|
|
|
|
>
|
2019-12-03 12:00:10 +00:00
|
|
|
<div className="prepend">
|
2020-11-06 15:05:00 +00:00
|
|
|
<StyledChildrenBlock className="prepend-children">
|
|
|
|
{children}
|
|
|
|
</StyledChildrenBlock>
|
2019-12-03 12:00:10 +00:00
|
|
|
</div>
|
2019-09-12 11:10:15 +00:00
|
|
|
<TextInput
|
2019-11-28 11:35:32 +00:00
|
|
|
id={id}
|
|
|
|
name={name}
|
|
|
|
type={type}
|
|
|
|
value={value}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
hasError={hasError}
|
|
|
|
hasWarning={hasWarning}
|
|
|
|
placeholder={placeholder}
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
maxLength={maxLength}
|
|
|
|
onBlur={onBlur}
|
|
|
|
onFocus={onFocus}
|
|
|
|
isReadOnly={isReadOnly}
|
|
|
|
isAutoFocussed={isAutoFocussed}
|
|
|
|
autoComplete={autoComplete}
|
|
|
|
size={size}
|
|
|
|
scale={scale}
|
2019-09-12 11:10:15 +00:00
|
|
|
onChange={this.onChange}
|
|
|
|
withBorder={false}
|
2019-11-28 11:35:32 +00:00
|
|
|
mask={mask}
|
|
|
|
keepCharPositions={keepCharPositions}
|
2019-09-12 11:10:15 +00:00
|
|
|
/>
|
2020-07-21 12:02:32 +00:00
|
|
|
{iconNames.includes(iconName) && (
|
|
|
|
<div className="append">
|
|
|
|
<StyledIconBlock
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
onClick={this.onIconClick}
|
|
|
|
isClickable={typeof onIconClick === "function"}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
size={iconButtonSize}
|
|
|
|
color={iconColor}
|
|
|
|
hoverColor={hoverColor}
|
|
|
|
iconName={iconName}
|
|
|
|
isFill={isIconFill}
|
2019-12-13 09:25:21 +00:00
|
|
|
isDisabled={isDisabled}
|
2020-07-21 12:02:32 +00:00
|
|
|
isClickable={typeof onIconClick === "function"}
|
|
|
|
/>
|
|
|
|
</StyledIconBlock>
|
|
|
|
</div>
|
|
|
|
)}
|
2019-09-12 11:10:15 +00:00
|
|
|
</StyledInputGroup>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-10 12:14:53 +00:00
|
|
|
|
|
|
|
InputBlock.propTypes = {
|
|
|
|
id: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
2020-07-21 12:02:32 +00:00
|
|
|
type: PropTypes.oneOf(["text", "password"]),
|
2019-07-10 12:14:53 +00:00
|
|
|
maxLength: PropTypes.number,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
tabIndex: PropTypes.number,
|
2019-09-12 11:10:15 +00:00
|
|
|
mask: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
|
2019-09-06 08:54:19 +00:00
|
|
|
keepCharPositions: PropTypes.bool,
|
2019-07-10 12:14:53 +00:00
|
|
|
|
2020-07-21 12:02:32 +00:00
|
|
|
size: PropTypes.oneOf(["base", "middle", "big", "huge", "large"]),
|
2019-07-10 12:14:53 +00:00
|
|
|
scale: PropTypes.bool,
|
|
|
|
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
onBlur: PropTypes.func,
|
|
|
|
onFocus: PropTypes.func,
|
|
|
|
|
|
|
|
isAutoFocussed: PropTypes.bool,
|
|
|
|
isDisabled: PropTypes.bool,
|
|
|
|
isReadOnly: PropTypes.bool,
|
|
|
|
hasError: PropTypes.bool,
|
|
|
|
hasWarning: PropTypes.bool,
|
|
|
|
autoComplete: PropTypes.string,
|
2019-07-11 13:39:52 +00:00
|
|
|
value: PropTypes.string,
|
2019-07-10 12:14:53 +00:00
|
|
|
iconName: PropTypes.string,
|
|
|
|
iconColor: PropTypes.string,
|
2019-12-26 08:47:02 +00:00
|
|
|
hoverColor: PropTypes.string,
|
2019-07-17 13:50:29 +00:00
|
|
|
iconSize: PropTypes.number,
|
2019-07-10 12:14:53 +00:00
|
|
|
isIconFill: PropTypes.bool,
|
|
|
|
onIconClick: PropTypes.func,
|
|
|
|
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
2020-10-16 13:16:01 +00:00
|
|
|
PropTypes.node,
|
2019-11-28 11:35:32 +00:00
|
|
|
]),
|
|
|
|
|
|
|
|
className: PropTypes.string,
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2020-07-21 12:02:32 +00:00
|
|
|
};
|
2019-07-10 12:14:53 +00:00
|
|
|
|
|
|
|
InputBlock.defaultProps = {
|
2020-07-21 12:02:32 +00:00
|
|
|
type: "text",
|
2019-07-10 12:14:53 +00:00
|
|
|
maxLength: 255,
|
2020-07-21 12:02:32 +00:00
|
|
|
size: "base",
|
2019-07-10 12:14:53 +00:00
|
|
|
scale: false,
|
|
|
|
tabIndex: -1,
|
|
|
|
hasError: false,
|
|
|
|
hasWarning: false,
|
2020-07-21 12:02:32 +00:00
|
|
|
autoComplete: "off",
|
2019-07-10 12:14:53 +00:00
|
|
|
|
2020-07-21 12:02:32 +00:00
|
|
|
value: "",
|
2019-07-10 12:14:53 +00:00
|
|
|
iconName: "",
|
|
|
|
iconColor: "#ffffff",
|
2019-12-26 08:47:02 +00:00
|
|
|
hoverColor: "#ffffff",
|
2019-07-10 12:14:53 +00:00
|
|
|
isIconFill: false,
|
2019-09-06 08:54:19 +00:00
|
|
|
isDisabled: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
keepCharPositions: false,
|
2020-07-21 12:02:32 +00:00
|
|
|
};
|
2019-07-10 12:14:53 +00:00
|
|
|
|
2020-07-21 12:02:32 +00:00
|
|
|
export default InputBlock;
|