Files
SCM-Manager/scm-ui/ui-components/src/forms/Checkbox.tsx

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import React, { ChangeEvent } from "react";
import { Help } from "../index";
type Props = {
label?: string;
name?: string;
checked: boolean;
onChange?: (value: boolean, name?: string) => void;
disabled?: boolean;
helpText?: string;
};
class Checkbox extends React.Component<Props> {
onCheckboxChange = (event: ChangeEvent<HTMLInputElement>) => {
if (this.props.onChange) {
this.props.onChange(event.target.checked, this.props.name);
}
};
2018-10-02 09:49:34 +02:00
renderHelp = () => {
const helpText = this.props.helpText;
2018-10-04 10:16:20 +02:00
if (helpText) {
return <Help message={helpText} />;
}
2018-10-02 09:49:34 +02:00
};
render() {
return (
2018-10-02 09:49:34 +02:00
<div className="field is-grouped">
2018-10-02 13:04:34 +02:00
<div className="control">
{/*
we have to ignore the next line,
because jsx label does not the custom disabled attribute
but bulma does.
// @ts-ignore */}
<label className="checkbox" disabled={this.props.disabled}>
<input
type="checkbox"
checked={this.props.checked}
onChange={this.onCheckboxChange}
disabled={this.props.disabled}
/>{" "}
{this.props.label}
{this.renderHelp()}
</label>
</div>
</div>
);
}
}
export default Checkbox;