adwaita-web
Version:
A GTK inspired toolkit designed to build awesome web apps
58 lines (57 loc) • 1.3 kB
JavaScript
import cx from "clsx";
import React from "react";
const noop = () => {
};
let nextId = 1;
class Checkbox extends React.Component {
static defaultProps = {
showLabel: true,
size: "medium",
onChange: noop
};
id;
constructor(props) {
super(props);
this.id = `checkbox_${nextId++}`;
}
onChange = (ev) => {
if (this.props.onChange) {
this.props.onChange(ev.target.checked, ev);
}
};
render() {
const {
id,
label,
showLabel,
children,
className,
size,
value,
defaultValue,
disabled,
onChange,
...rest
} = this.props;
return /* @__PURE__ */ React.createElement("div", {
className: cx("Checkbox", className, size, { disabled })
}, /* @__PURE__ */ React.createElement("input", {
type: "checkbox",
id: id || this.id,
checked: value,
defaultChecked: defaultValue,
disabled,
onChange: this.onChange
}), /* @__PURE__ */ React.createElement("label", {
htmlFor: id || this.id,
...rest
}, /* @__PURE__ */ React.createElement("span", {
className: "element"
}), /* @__PURE__ */ React.createElement("span", {
className: cx("label__text", { "sr-only": !showLabel })
}, label)));
}
}
export {
Checkbox
};