UNPKG

adwaita-web

Version:

A GTK inspired toolkit designed to build awesome web apps

60 lines (59 loc) 1.3 kB
import cx from "clsx"; import React from "react"; const noop = () => { }; let nextId = 1; class Radio extends React.Component { static defaultProps = { showLabel: true, size: "medium", onChange: noop }; id; constructor(props) { super(props); this.id = `radio_${nextId++}`; } onChange = (ev) => { if (this.props.onChange) this.props.onChange(ev.target.checked, ev); }; render() { const { id, name, label, showLabel, className, size, value, checked, defaultChecked, disabled, onChange, ...rest } = this.props; return /* @__PURE__ */ React.createElement("div", { className: cx("Radio", className, size, { disabled }) }, /* @__PURE__ */ React.createElement("input", { type: "radio", id: id || this.id, name, value, checked, defaultChecked, 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 { Radio };