@react-md/form
Version:
This package is for creating all the different form input types.
75 lines • 4.2 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 { useIcon } from "@react-md/icon";
import { ListItem } from "@react-md/list";
import { bem, useKeyboardFocusableElement } from "@react-md/utils";
import { InputToggleIcon } from "../toggle/InputToggleIcon";
import { SwitchTrack } from "../toggle/SwitchTrack";
var styles = bem("rmd-input-toggle-menu-item");
/**
* This is a low-level component that should probably not be used externally and
* instead the `MenuItemCheckbox`, `MenuItemRadio`, or `MenuItemSwitch` should
* be used instead.
*
* @see {@link MenuItemCheckbox} for checkbox examples
* @see {@link MenuItemRadio} for radio examples
* @see {@link MenuItemSwitch} for switch examples
* @remarks \@since 2.8.0
*/
export var MenuItemInputToggle = forwardRef(function MenuItemInputToggle(_a, nodeRef) {
var children = _a.children, _b = _a.tabIndex, tabIndex = _b === void 0 ? -1 : _b, checked = _a.checked, type = _a.type, propIcon = _a.icon, _c = _a.iconAfter, iconAfter = _c === void 0 ? false : _c, addon = _a.addon, addonType = _a.addonType, addonPosition = _a.addonPosition, onClick = _a.onClick, onCheckedChange = _a.onCheckedChange, _d = _a.disabled, disabled = _d === void 0 ? false : _d, className = _a.className, _e = _a.indeterminate, indeterminate = _e === void 0 ? false : _e, props = __rest(_a, ["children", "tabIndex", "checked", "type", "icon", "iconAfter", "addon", "addonType", "addonPosition", "onClick", "onCheckedChange", "disabled", "className", "indeterminate"]);
var ref = useKeyboardFocusableElement(nodeRef);
var icon = useIcon(type === "radio" ? "radio" : "checkbox", propIcon);
if (type === "switch" && typeof propIcon === "undefined") {
icon = _jsx(SwitchTrack, { checked: checked });
}
else if (icon && type !== "switch") {
icon = (_jsx("span", __assign({ className: cn("rmd-toggle", styles("toggle")) }, { children: _jsx(InputToggleIcon, __assign({ circle: type === "radio", disabled: disabled, overlay: true, checked: checked, indeterminate: indeterminate }, { children: icon })) })));
}
var leftAddon;
var leftAddonType;
var leftAddonPosition;
var rightAddon;
var rightAddonType;
var rightAddonPosition;
if (iconAfter) {
leftAddon = addon;
leftAddonType = addonType;
leftAddonPosition = addonPosition;
rightAddon = icon;
}
else {
leftAddon = icon;
rightAddon = addon;
rightAddonType = addonType;
rightAddonPosition = addonPosition;
}
return (_jsx(ListItem, __assign({}, props, { disableRipple: true, "aria-disabled": disabled || undefined, "aria-checked": checked, role: type === "radio" ? "menuitemradio" : "menuitemcheckbox", onClick: function (event) {
onClick === null || onClick === void 0 ? void 0 : onClick(event);
onCheckedChange(!checked, event);
}, ref: ref, className: cn(styles({ switch: type === "switch" }), className), tabIndex: tabIndex, leftAddon: leftAddon, leftAddonType: leftAddonType, leftAddonPosition: leftAddonPosition, rightAddon: rightAddon, rightAddonType: rightAddonType, rightAddonPosition: rightAddonPosition }, { children: children })));
});
//# sourceMappingURL=MenuItemInputToggle.js.map