PromucFlow_constructor/app/client/src/widgets/SelectWidget/component/SelectButton.tsx

62 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-03-17 05:27:39 +00:00
import React, { memo } from "react";
import Icon, { IconSize } from "components/ads/Icon";
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;
spanRef?: any;
2022-03-17 05:27:39 +00:00
togglePopoverVisibility: () => void;
tooltipText?: string;
2022-03-17 05:27:39 +00:00
value?: string;
}
function SelectButton(props: SelectButtonProps) {
const {
disabled,
displayText,
handleCancelClick,
spanRef,
2022-03-17 05:27:39 +00:00
togglePopoverVisibility,
tooltipText,
2022-03-17 05:27:39 +00:00
value,
} = props;
return (
<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>
{!isEmptyOrNill(value) ? (
<Icon
className="dropdown-icon cancel-icon"
2022-03-17 06:19:35 +00:00
data-testid="selectbutton.btn.cancel"
2022-03-17 05:27:39 +00:00
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
name="cross"
onClick={handleCancelClick}
size={IconSize.XXS}
/>
) : null}
<Icon
className="dropdown-icon"
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
name="dropdown"
/>
</StyledDiv>
}
>
<span ref={spanRef} title={tooltipText}>
{displayText}
</span>
</Button>
2022-03-17 05:27:39 +00:00
);
}
export default memo(SelectButton);