UNPKG

@react-md/menu

Version:

Create menus that auto-position themselves within the viewport and adhere to the accessibility guidelines

67 lines 3.56 kB
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 React, { forwardRef } from "react"; import cn from "classnames"; import { useActionClassName, } from "@react-md/app-bar"; import { Button } from "@react-md/button"; import { useIcon } from "@react-md/icon"; import { bem } from "@react-md/utils"; import { ToggleChildren } from "./ToggleChildren"; var block = bem("rmd-menu-button"); /** * This component is an extension of the `Button` component that will: * - apply the required a11y prosp for a menu button * - dynamically add a dropdown icon after the button contents */ export var MenuButton = forwardRef(function MenuButton(_a, ref) { var _b; var _c = _a["aria-haspopup"], ariaHasPopup = _c === void 0 ? "menu" : _c, className = _a.className, visible = _a.visible, children = _a.children, propDropdownIcon = _a.dropdownIcon, _d = _a.disableDropdownIcon, disableDropdownIcon = _d === void 0 ? false : _d, _e = _a.first, first = _e === void 0 ? false : _e, _f = _a.last, last = _f === void 0 ? false : _f, inheritColor = _a.inheritColor, _g = _a.asAppBarAction, asAppBarAction = _g === void 0 ? false : _g, props = __rest(_a, ["aria-haspopup", "className", "visible", "children", "dropdownIcon", "disableDropdownIcon", "first", "last", "inheritColor", "asAppBarAction"]); var buttonType = props.buttonType; var dropdownIcon = useIcon("dropdown", propDropdownIcon); var actionClassName = useActionClassName({ first: first, last: last, inheritColor: inheritColor }); return (React.createElement(Button, __assign({}, props, { ref: ref, "aria-haspopup": ariaHasPopup, "aria-expanded": visible ? "true" : undefined, className: cn(block(), (_b = {}, _b[actionClassName] = first || last || inheritColor || asAppBarAction, _b), className) }), React.createElement(ToggleChildren, { visible: visible, dropdownIcon: dropdownIcon, disableDropdownIcon: disableDropdownIcon || buttonType === "icon" }, children))); }); if (process.env.NODE_ENV !== "production") { try { var PropTypes = require("prop-types"); MenuButton.propTypes = { "aria-haspopup": PropTypes.oneOf(["menu", "true", true]), id: PropTypes.string.isRequired, visible: PropTypes.bool.isRequired, dropdownIcon: PropTypes.node, disableDropdownIcon: PropTypes.bool, className: PropTypes.string, children: PropTypes.node, buttonType: PropTypes.oneOf(["text", "icon"]), first: PropTypes.bool, last: PropTypes.bool, inheritColor: PropTypes.bool, asAppBarAction: PropTypes.bool, }; } catch (e) { } } //# sourceMappingURL=MenuButton.js.map