2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import { Icons } from "../../icons";
|
|
|
|
import Text from "../../text";
|
2019-09-18 11:44:01 +00:00
|
|
|
|
|
|
|
const StyledComboButton = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-02-03 13:08:18 +00:00
|
|
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
height: ${(props) => (props.noBorder ? `18px` : `30px`)};
|
|
|
|
width: ${(props) =>
|
|
|
|
(props.scaled && "100%") ||
|
|
|
|
(props.size === "base" && "173px") ||
|
|
|
|
(props.size === "middle" && "300px") ||
|
|
|
|
(props.size === "big" && "350px") ||
|
|
|
|
(props.size === "huge" && "500px") ||
|
|
|
|
(props.size === "content" && "fit-content")};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
|
|
|
-webkit-touch-callout: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
|
2020-11-06 09:47:31 +00:00
|
|
|
padding-left: 8px;
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
background: ${(props) => (!props.noBorder ? "#FFFFFF" : "none")};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#333333")};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2019-12-05 11:15:03 +00:00
|
|
|
box-sizing: border-box;
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
${(props) =>
|
|
|
|
!props.noBorder &&
|
|
|
|
`
|
2019-09-18 11:44:01 +00:00
|
|
|
border: 1px solid #D0D5DA;
|
|
|
|
border-radius: 3px;
|
|
|
|
`}
|
2019-12-27 13:29:50 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
border-color: ${(props) => props.isOpen && "#2DA7DB"};
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.isDisabled &&
|
|
|
|
!props.noBorder &&
|
|
|
|
`
|
2019-09-18 11:44:01 +00:00
|
|
|
border-color: #ECEEF1;
|
|
|
|
background: #F8F9F9;
|
|
|
|
`}
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
${(props) =>
|
|
|
|
!props.noBorder &&
|
|
|
|
`
|
2019-09-18 11:44:01 +00:00
|
|
|
height: 32px;
|
|
|
|
`}
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
:hover {
|
|
|
|
border-color: ${(props) => (props.isOpen ? "#2DA7DB" : "#A3A9AE")};
|
|
|
|
cursor: ${(props) =>
|
|
|
|
props.isDisabled || (!props.containOptions && !props.withAdvancedOptions)
|
|
|
|
? "default"
|
|
|
|
: "pointer"};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
${(props) =>
|
|
|
|
props.isDisabled &&
|
|
|
|
`
|
2019-09-18 11:44:01 +00:00
|
|
|
border-color: #ECEEF1;
|
|
|
|
`}
|
|
|
|
}
|
2020-10-16 13:16:01 +00:00
|
|
|
.combo-button-label {
|
|
|
|
margin-right: ${(props) => (props.noBorder ? `4px` : `8px`)};
|
|
|
|
color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#333333")};
|
2019-09-30 11:52:23 +00:00
|
|
|
max-width: 175px;
|
2020-10-16 13:16:01 +00:00
|
|
|
${(props) =>
|
|
|
|
props.noBorder &&
|
|
|
|
`
|
2019-12-16 11:14:19 +00:00
|
|
|
line-height: 15px;
|
2020-01-10 15:27:22 +00:00
|
|
|
text-decoration: underline dashed transparent;
|
2019-09-30 11:52:23 +00:00
|
|
|
`}
|
2020-10-16 13:16:01 +00:00
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.isOpen &&
|
|
|
|
props.noBorder &&
|
|
|
|
`
|
2020-01-10 15:27:22 +00:00
|
|
|
text-decoration: underline dashed;
|
2019-12-27 13:51:13 +00:00
|
|
|
`};
|
2019-09-30 11:52:23 +00:00
|
|
|
}
|
2020-10-16 13:16:01 +00:00
|
|
|
.combo-button-label:hover {
|
|
|
|
${(props) =>
|
|
|
|
props.noBorder &&
|
|
|
|
!props.isDisabled &&
|
|
|
|
`
|
2020-01-10 15:27:22 +00:00
|
|
|
text-decoration: underline dashed;
|
2019-09-30 11:52:23 +00:00
|
|
|
`}
|
|
|
|
}
|
2019-09-18 11:44:01 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledOptionalItem = styled.div`
|
|
|
|
margin-right: 8px;
|
2019-12-27 11:41:01 +00:00
|
|
|
|
|
|
|
path {
|
2020-10-16 13:16:01 +00:00
|
|
|
fill: ${(props) => props.color && props.color};
|
2019-12-27 11:41:01 +00:00
|
|
|
}
|
2019-09-18 11:44:01 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledIcon = styled.div`
|
2020-11-28 10:21:02 +00:00
|
|
|
margin: -6px 8px 0px 0px;
|
2019-09-18 11:44:01 +00:00
|
|
|
width: 16px;
|
2020-11-28 10:21:02 +00:00
|
|
|
height: 16px;
|
2019-09-18 11:44:01 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledArrowIcon = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-self: start;
|
2020-10-16 13:16:01 +00:00
|
|
|
width: ${(props) => (props.needDisplay ? "8px" : "0px")};
|
|
|
|
flex: 0 0 ${(props) => (props.needDisplay ? "8px" : "0px")};
|
|
|
|
margin-top: ${(props) => (props.noBorder ? `5px` : `12px`)};
|
|
|
|
margin-right: ${(props) => (props.needDisplay ? "8px" : "0px")};
|
|
|
|
margin-left: ${(props) => (props.needDisplay ? "auto" : "0px")};
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.isOpen &&
|
|
|
|
`
|
2019-09-18 11:44:01 +00:00
|
|
|
transform: scale(1, -1);
|
|
|
|
`}
|
|
|
|
`;
|
|
|
|
|
|
|
|
class ComboButton extends React.Component {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
noBorder,
|
|
|
|
onClick,
|
|
|
|
isDisabled,
|
|
|
|
innerContainer,
|
|
|
|
innerContainerClassName,
|
|
|
|
selectedOption,
|
|
|
|
optionsLength,
|
|
|
|
withOptions,
|
|
|
|
withAdvancedOptions,
|
|
|
|
isOpen,
|
|
|
|
scaled,
|
2020-10-16 13:16:01 +00:00
|
|
|
size,
|
|
|
|
} = this.props;
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
const boxIconColor = isDisabled ? "#D0D5DA" : "#333333";
|
|
|
|
const arrowIconColor = isDisabled ? "#D0D5DA" : "#A3A9AE";
|
|
|
|
const defaultIconColor = selectedOption.default
|
|
|
|
? arrowIconColor
|
|
|
|
: boxIconColor;
|
2019-09-18 11:44:01 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledComboButton
|
|
|
|
isOpen={isOpen}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
noBorder={noBorder}
|
|
|
|
containOptions={optionsLength}
|
2019-09-19 10:44:53 +00:00
|
|
|
withAdvancedOptions={withAdvancedOptions}
|
2019-09-18 11:44:01 +00:00
|
|
|
onClick={onClick}
|
|
|
|
scaled={scaled}
|
|
|
|
size={size}
|
2020-03-28 10:04:12 +00:00
|
|
|
className="combo-button"
|
2019-09-18 11:44:01 +00:00
|
|
|
>
|
2020-10-16 13:16:01 +00:00
|
|
|
{innerContainer && (
|
|
|
|
<StyledOptionalItem
|
|
|
|
className={innerContainerClassName}
|
|
|
|
color={defaultIconColor}
|
|
|
|
>
|
2019-09-18 11:44:01 +00:00
|
|
|
{innerContainer}
|
|
|
|
</StyledOptionalItem>
|
2020-10-16 13:16:01 +00:00
|
|
|
)}
|
|
|
|
{selectedOption && selectedOption.icon && (
|
2019-12-27 11:41:01 +00:00
|
|
|
<StyledIcon className="forceColor">
|
2020-10-16 13:16:01 +00:00
|
|
|
{React.createElement(Icons[selectedOption.icon], {
|
|
|
|
size: "scale",
|
|
|
|
color: defaultIconColor,
|
|
|
|
isfill: true,
|
|
|
|
})}
|
2019-09-18 11:44:01 +00:00
|
|
|
</StyledIcon>
|
2020-10-16 13:16:01 +00:00
|
|
|
)}
|
2019-12-04 09:36:13 +00:00
|
|
|
<Text
|
2019-09-30 11:52:23 +00:00
|
|
|
noBorder={noBorder}
|
|
|
|
title={selectedOption.label}
|
|
|
|
as="div"
|
|
|
|
truncate={true}
|
|
|
|
fontWeight={600}
|
|
|
|
className="combo-button-label"
|
2020-02-12 10:07:39 +00:00
|
|
|
//color={selectedOption.default ? arrowIconColor +' !important' : boxIconColor}
|
2019-09-30 11:52:23 +00:00
|
|
|
>
|
2019-09-18 11:44:01 +00:00
|
|
|
{selectedOption.label}
|
2019-12-04 09:36:13 +00:00
|
|
|
</Text>
|
2019-09-18 11:44:01 +00:00
|
|
|
<StyledArrowIcon
|
|
|
|
needDisplay={withOptions || withAdvancedOptions}
|
|
|
|
noBorder={noBorder}
|
2020-10-16 13:16:01 +00:00
|
|
|
isOpen={isOpen}
|
2020-10-28 14:36:38 +00:00
|
|
|
className="combo-buttons_arrow-icon"
|
2020-10-16 13:16:01 +00:00
|
|
|
>
|
2019-09-18 11:44:01 +00:00
|
|
|
{(withOptions || withAdvancedOptions) &&
|
2020-10-16 13:16:01 +00:00
|
|
|
React.createElement(Icons["ExpanderDownIcon"], {
|
|
|
|
size: "scale",
|
2020-11-06 09:47:31 +00:00
|
|
|
color:
|
|
|
|
selectedOption.arrowIconColor && !isDisabled
|
|
|
|
? selectedOption.arrowIconColor
|
|
|
|
: arrowIconColor,
|
2020-10-16 13:16:01 +00:00
|
|
|
isfill: true,
|
|
|
|
})}
|
2019-09-18 11:44:01 +00:00
|
|
|
</StyledArrowIcon>
|
|
|
|
</StyledComboButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ComboButton.propTypes = {
|
|
|
|
noBorder: PropTypes.bool,
|
|
|
|
isDisabled: PropTypes.bool,
|
|
|
|
selectedOption: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.object),
|
2020-10-16 13:16:01 +00:00
|
|
|
PropTypes.object,
|
2019-09-18 11:44:01 +00:00
|
|
|
]),
|
|
|
|
withOptions: PropTypes.bool,
|
|
|
|
optionsLength: PropTypes.number,
|
|
|
|
withAdvancedOptions: PropTypes.bool,
|
|
|
|
innerContainer: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
2020-10-16 13:16:01 +00:00
|
|
|
PropTypes.node,
|
2019-09-18 11:44:01 +00:00
|
|
|
]),
|
|
|
|
innerContainerClassName: PropTypes.string,
|
|
|
|
isOpen: PropTypes.bool,
|
2020-10-16 13:16:01 +00:00
|
|
|
size: PropTypes.oneOf(["base", "middle", "big", "huge", "content"]),
|
2019-09-18 11:44:01 +00:00
|
|
|
scaled: PropTypes.bool,
|
2020-10-16 13:16:01 +00:00
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
|
|
|
ComboButton.defaultProps = {
|
|
|
|
noBorder: false,
|
|
|
|
isDisabled: false,
|
|
|
|
withOptions: true,
|
|
|
|
withAdvancedOptions: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
innerContainerClassName: "innerContainer",
|
2019-09-18 11:44:01 +00:00
|
|
|
isOpen: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
size: "content",
|
|
|
|
scaled: false,
|
|
|
|
};
|
2019-09-18 11:44:01 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
export default ComboButton;
|