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

93 lines
2.3 KiB
TypeScript
Raw Normal View History

import React from "react";
import styled from "styled-components";
import { Alignment, Checkbox, Classes } from "@blueprintjs/core";
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
import { AlignWidget } from "widgets/SwitchWidget";
type StyledCheckboxProps = {
rowSpace: number;
};
type StyledCheckboxContainerProps = {
isValid: boolean;
};
const CheckboxContainer = styled.div<StyledCheckboxContainerProps>`
&& {
align-items: center;
display: flex;
height: 100%;
justify-content: flex-start;
width: 100%;
&.${Alignment.RIGHT} {
justify-content: flex-end;
}
& .bp3-control-indicator {
2020-12-24 04:32:25 +00:00
border: ${(props) =>
!props.isValid && `1px solid ${props.theme.colors.error} !important`};
}
}
`;
export const StyledCheckbox = styled(Checkbox)<StyledCheckboxProps>`
height: ${({ rowSpace }) => rowSpace}px;
&.bp3-control input:checked ~ .bp3-control-indicator {
background-color: #03b365;
background-image: none;
box-shadow: none;
}
&.bp3-control input:disabled ~ .bp3-control-indicator {
opacity: 0.5;
}
&.bp3-control.bp3-checkbox .bp3-control-indicator {
border-radius: 0;
}
`;
2019-09-09 09:08:54 +00:00
class CheckboxComponent extends React.Component<CheckboxComponentProps> {
2019-03-21 12:10:32 +00:00
render() {
const checkboxAlignClass =
this.props.alignWidget === "RIGHT" ? Alignment.RIGHT : Alignment.LEFT;
2019-03-21 12:10:32 +00:00
return (
<CheckboxContainer
className={checkboxAlignClass}
isValid={!(this.props.isRequired && !this.props.isChecked)}
>
<StyledCheckbox
alignIndicator={checkboxAlignClass}
checked={this.props.isChecked}
className={
this.props.isLoading ? Classes.SKELETON : Classes.RUNNING_TEXT
}
disabled={this.props.isDisabled}
label={this.props.label}
onChange={this.onCheckChange}
rowSpace={this.props.rowSpace}
/>
</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 {
alignWidget?: AlignWidget;
2020-03-13 07:24:03 +00:00
isChecked: boolean;
2019-12-03 04:41:10 +00:00
isLoading: boolean;
isRequired?: boolean;
label: string;
onCheckChange: (isChecked: boolean) => void;
rowSpace: number;
2019-03-21 12:10:32 +00:00
}
2019-09-05 17:47:50 +00:00
export default CheckboxComponent;