@react-md/form
Version:
This package is for creating all the different form input types.
43 lines • 2.35 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import cn from "classnames";
import { CircularProgress, getProgressA11y } from "@react-md/progress";
import { Switch } from "./Switch";
// this is used while the loading state is enabled to "disable" the switch
// toggle. If we disable the entire switch, keyboard focus is lost which is not
// desired.
var noop = function () {
// do nothing
};
/**
* This component will create an async switch that will show a loading indicator
* and prevent the switch from being toggled while the loading state is true.
*/
export var AsyncSwitch = forwardRef(function AsyncSwitch(_a, ref) {
var id = _a.id, disabled = _a.disabled, className = _a.className, progressStyle = _a.progressStyle, progressClassName = _a.progressClassName, loading = _a.loading, onChange = _a.onChange, props = __rest(_a, ["id", "disabled", "className", "progressStyle", "progressClassName", "loading", "onChange"]);
var progressId = "".concat(id, "-loading");
return (_jsx(Switch, __assign({}, props, getProgressA11y(progressId, loading), { id: id, ref: ref, disabled: disabled, className: cn("rmd-switch--async", className), labelDisabled: disabled || false, onChange: loading ? noop : onChange }, { children: loading && (_jsx(CircularProgress, { id: progressId, style: progressStyle, className: cn("rmd-switch__progress", progressClassName), centered: false })) })));
});
//# sourceMappingURL=AsyncSwitch.js.map