2020-01-21 12:48:42 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
2020-01-21 12:48:42 +00:00
|
|
|
import { Checkbox, Classes } from "@blueprintjs/core";
|
2020-02-06 07:01:25 +00:00
|
|
|
import { BlueprintControlTransform } from "constants/DefaultTheme";
|
2020-01-21 12:48:42 +00:00
|
|
|
|
2020-11-26 11:21:23 +00:00
|
|
|
const CheckboxContainer = styled.div<{ isValid: boolean }>`
|
2020-01-21 12:48:42 +00:00
|
|
|
&& {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
align-items: center;
|
2020-11-26 11:21:23 +00:00
|
|
|
|
|
|
|
|
.bp3-control-indicator {
|
2020-12-24 04:32:25 +00:00
|
|
|
border: ${(props) =>
|
2020-11-26 11:21:23 +00:00
|
|
|
!props.isValid
|
|
|
|
|
? `1px solid ${props.theme.colors.error} !important`
|
|
|
|
|
: `1px solid transparent`};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 12:48:42 +00:00
|
|
|
label {
|
|
|
|
|
margin: 0;
|
2020-12-24 04:32:25 +00:00
|
|
|
color: ${(props) =>
|
2020-11-26 11:21:23 +00:00
|
|
|
!props.isValid ? `${props.theme.colors.error}` : `inherit`};
|
2020-01-21 12:48:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
${BlueprintControlTransform}
|
2020-01-21 12:48:42 +00:00
|
|
|
`;
|
2019-09-09 09:08:54 +00:00
|
|
|
class CheckboxComponent extends React.Component<CheckboxComponentProps> {
|
2019-03-21 12:10:32 +00:00
|
|
|
render() {
|
|
|
|
|
return (
|
2020-11-26 11:21:23 +00:00
|
|
|
<CheckboxContainer
|
|
|
|
|
isValid={!(this.props.isRequired && !this.props.isChecked)}
|
|
|
|
|
>
|
2020-01-21 12:48:42 +00:00
|
|
|
<Checkbox
|
|
|
|
|
label={this.props.label}
|
|
|
|
|
className={
|
|
|
|
|
this.props.isLoading ? "bp3-skeleton" : Classes.RUNNING_TEXT
|
|
|
|
|
}
|
2021-02-08 07:30:01 +00:00
|
|
|
style={{ borderRadius: 0 }}
|
2020-01-21 12:48:42 +00:00
|
|
|
onChange={this.onCheckChange}
|
|
|
|
|
disabled={this.props.isDisabled}
|
2020-03-13 07:24:03 +00:00
|
|
|
checked={this.props.isChecked}
|
2020-01-21 12:48:42 +00:00
|
|
|
/>
|
|
|
|
|
</CheckboxContainer>
|
2019-09-05 17:47:50 +00:00
|
|
|
);
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
|
2020-03-13 07:24:03 +00:00
|
|
|
onCheckChange = () => {
|
|
|
|
|
this.props.onCheckChange(!this.props.isChecked);
|
2019-11-05 05:09:50 +00:00
|
|
|
};
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export interface CheckboxComponentProps extends ComponentProps {
|
2019-09-13 10:45:49 +00:00
|
|
|
label: string;
|
2020-03-13 07:24:03 +00:00
|
|
|
isChecked: boolean;
|
2019-11-05 05:09:50 +00:00
|
|
|
onCheckChange: (isChecked: boolean) => void;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-11-26 11:21:23 +00:00
|
|
|
isRequired?: boolean;
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-05 17:47:50 +00:00
|
|
|
export default CheckboxComponent;
|