PromucFlow_constructor/app/client/src/components/designSystems/blueprint/CheckboxComponent.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

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