UNPKG

@massds/mayflower-react

Version:

React versions of Mayflower design system UI components

106 lines (83 loc) 5.32 kB
"use strict"; exports.__esModule = true; exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _classnames = _interopRequireDefault(require("classnames")); var _IconSearch = _interopRequireDefault(require("../Icon/IconSearch.js")); var _IconChevron = _interopRequireDefault(require("../Icon/IconChevron.js")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var ButtonWithIcon = function ButtonWithIcon(props) { var _classNames; var _props$classes = props.classes, classes = _props$classes === void 0 ? [] : _props$classes, iconSize = props.iconSize, icon = props.icon, expanded = props.expanded, capitalized = props.capitalized, usage = props.usage, theme = props.theme, setButtonRef = props.setButtonRef, text = props.text, size = props.size, rest = _objectWithoutPropertiesLoose(props, ["classes", "iconSize", "icon", "expanded", "capitalized", "usage", "theme", "setButtonRef", "text", "size"]); var buttonClasses = (0, _classnames["default"])((_classNames = { 'ma__button-icon': true }, _classNames["ma__button-icon--" + size] = size, _classNames['ma__button-icon--expanded'] = expanded, _classNames['ma__button-icon--capitalized'] = capitalized, _classNames['ma__icon-small'] = iconSize === 'small' || (icon === null || icon === void 0 ? void 0 : icon.type) === _IconChevron["default"], _classNames['ma__button-search'] = (icon === null || icon === void 0 ? void 0 : icon.type) === _IconSearch["default"], _classNames['ma__button-search--secondary'] = (icon === null || icon === void 0 ? void 0 : icon.type) === _IconSearch["default"] && usage === 'secondary', _classNames["ma__button-icon--" + theme] = theme, _classNames["ma__button-icon--" + usage] = usage, _classNames[classes.join(' ')] = classes, _classNames)); var buttonProps = _extends({}, rest, { className: buttonClasses, tabIndex: 0 }); var Element = rest.href ? 'a' : 'button'; return /*#__PURE__*/_react["default"].createElement(Element, _extends({}, buttonProps, { ref: setButtonRef, "aria-expanded": expanded }), /*#__PURE__*/_react["default"].createElement("span", null, rest.children ? rest.children : text), icon && icon); }; ButtonWithIcon.propTypes = process.env.NODE_ENV !== "production" ? { /** id for the button */ id: _propTypes["default"].string, /** button or link content rendered in a span */ children: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].node]), /** When populated with a url, this component renders a <a> vs a <button> */ href: _propTypes["default"].string, // Function to run on click of the button. onClick: _propTypes["default"].func, // Sets a reference to the button onto the passed node. setButtonRef: _propTypes["default"].oneOfType([// Either a function _propTypes["default"].func, // Or the instance of a DOM native element (see the note about SSR) _propTypes["default"].shape({ current: _propTypes["default"].object })]), // Button text. text: _propTypes["default"].string, /** HTML `<button>` 'type' attribute */ type: _propTypes["default"].oneOf(['submit', 'reset', 'button', '']), /** Create a smaller button */ size: _propTypes["default"].oneOf(['', 'small', 'large']), // Button classes. classes: _propTypes["default"].arrayOf(_propTypes["default"].string), // Icon to display within the button. icon: _propTypes["default"].element, // Adds expanded class to button if true. expanded: _propTypes["default"].bool, // Adds capitalized class to button if true. capitalized: _propTypes["default"].bool, // Defines the size, default size fits the most square icons and "small" setting is specific for the chevron icon. iconSize: _propTypes["default"].oneOf(['', 'small']), /** The aria-label property is used to provide the label to any assistive * technologies. This is useful if the text value is not descriptive of the * button's functionality. */ 'aria-label': _propTypes["default"].string, /** Themes correspond to site color scheme i.e. sass variables */ theme: _propTypes["default"].oneOf(['', 'c-primary', 'c-highlight', 'c-gray-dark', 'c-black', 'c-white']), /** Button usage */ usage: _propTypes["default"].oneOf(['', 'secondary', 'tertiary', 'quaternary', 'quaternary-simple', 'alert']), /** Whether the button has a popup or not */ 'aria-haspopup': _propTypes["default"].bool } : {}; var _default = ButtonWithIcon; exports["default"] = _default; module.exports = exports.default;