2022-03-17 05:27:39 +00:00
|
|
|
import React, { memo } from "react";
|
2022-08-22 05:09:39 +00:00
|
|
|
import { Icon, IconSize } from "design-system";
|
2022-03-17 05:27:39 +00:00
|
|
|
import { Button } from "@blueprintjs/core";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
|
2022-03-21 07:57:25 +00:00
|
|
|
import { isEmptyOrNill } from "../../../utils/helpers";
|
2022-03-17 05:27:39 +00:00
|
|
|
import { StyledDiv } from "./index.styled";
|
|
|
|
|
|
2022-03-17 06:19:35 +00:00
|
|
|
export interface SelectButtonProps {
|
2022-03-17 05:27:39 +00:00
|
|
|
disabled?: boolean;
|
|
|
|
|
displayText?: string;
|
|
|
|
|
handleCancelClick?: (event: React.MouseEvent<Element, MouseEvent>) => void;
|
2022-03-17 06:26:44 +00:00
|
|
|
spanRef?: any;
|
2022-03-17 05:27:39 +00:00
|
|
|
togglePopoverVisibility: () => void;
|
2022-03-17 06:26:44 +00:00
|
|
|
tooltipText?: string;
|
2022-03-17 05:27:39 +00:00
|
|
|
value?: string;
|
2022-09-30 04:03:53 +00:00
|
|
|
hideCancelIcon?: boolean;
|
2022-03-17 05:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function SelectButton(props: SelectButtonProps) {
|
|
|
|
|
const {
|
|
|
|
|
disabled,
|
|
|
|
|
displayText,
|
|
|
|
|
handleCancelClick,
|
2022-09-30 04:03:53 +00:00
|
|
|
hideCancelIcon,
|
2022-03-17 06:26:44 +00:00
|
|
|
spanRef,
|
2022-03-17 05:27:39 +00:00
|
|
|
togglePopoverVisibility,
|
2022-03-17 06:26:44 +00:00
|
|
|
tooltipText,
|
2022-03-17 05:27:39 +00:00
|
|
|
value,
|
|
|
|
|
} = props;
|
2022-12-12 07:09:22 +00:00
|
|
|
|
2022-03-17 05:27:39 +00:00
|
|
|
return (
|
|
|
|
|
<Button
|
2022-03-21 14:45:17 +00:00
|
|
|
className="select-button"
|
2022-03-17 06:19:35 +00:00
|
|
|
data-testid="selectbutton.btn.main"
|
2022-03-17 05:27:39 +00:00
|
|
|
disabled={disabled}
|
|
|
|
|
onClick={togglePopoverVisibility}
|
|
|
|
|
rightIcon={
|
|
|
|
|
<StyledDiv>
|
2022-09-30 04:03:53 +00:00
|
|
|
{!isEmptyOrNill(value) && !hideCancelIcon ? (
|
2022-03-17 05:27:39 +00:00
|
|
|
<Icon
|
|
|
|
|
className="dropdown-icon cancel-icon"
|
2022-03-17 06:19:35 +00:00
|
|
|
data-testid="selectbutton.btn.cancel"
|
2022-04-25 12:36:36 +00:00
|
|
|
disabled={disabled}
|
2022-03-17 05:27:39 +00:00
|
|
|
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
|
|
|
|
|
name="cross"
|
2022-04-27 11:29:31 +00:00
|
|
|
onClick={handleCancelClick}
|
2022-03-17 05:27:39 +00:00
|
|
|
size={IconSize.XXS}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<Icon
|
|
|
|
|
className="dropdown-icon"
|
2022-04-25 12:36:36 +00:00
|
|
|
disabled={disabled}
|
2022-03-17 05:27:39 +00:00
|
|
|
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
|
|
|
|
|
name="dropdown"
|
|
|
|
|
/>
|
|
|
|
|
</StyledDiv>
|
|
|
|
|
}
|
2022-03-17 06:26:44 +00:00
|
|
|
>
|
|
|
|
|
<span ref={spanRef} title={tooltipText}>
|
|
|
|
|
{displayText}
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
2022-03-17 05:27:39 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(SelectButton);
|