@trellixio/roaster-coffee
Version:
Beans' product component library
56 lines (50 loc) • 1.64 kB
JavaScript
;
var React = require('react');
var index$1 = require('../../utils/classNames/index.js');
var index = require('../../utils/useUid/index.js');
require('@floating-ui/react');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const Switch = React__namespace.forwardRef((props, ref) => {
const {
id,
label,
name,
disabled,
defaultChecked = false,
helpText,
labelClassName,
inputClassName,
onChange
} = props;
const [checked, setChecked] = React__namespace.useState(defaultChecked);
const uid = index.useUid(id);
const handleChange = (event) => {
setChecked(event.currentTarget.checked);
onChange?.(event.currentTarget.checked);
};
return /* @__PURE__ */ React__namespace.createElement("label", { htmlFor: uid }, label && /* @__PURE__ */ React__namespace.createElement("p", { className: labelClassName }, label), /* @__PURE__ */ React__namespace.createElement("span", { className: index$1.classNames("switch", inputClassName) }, /* @__PURE__ */ React__namespace.createElement(
"input",
{
ref,
type: "checkbox",
name,
id: uid,
checked,
disabled,
onChange: handleChange
}
), /* @__PURE__ */ React__namespace.createElement("figure", null)), helpText && /* @__PURE__ */ React__namespace.createElement("small", null, helpText));
});
Switch.displayName = "Switch";
exports.Switch = Switch;
//# sourceMappingURL=Switch.js.map