UNPKG

@massds/mayflower-react

Version:

React versions of Mayflower design system UI components

65 lines 2.91 kB
const _excluded = ["text", "hideText", "showText", "classes", "isOpen"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; } /** * ButtonAlert module. * @module @massds/mayflower-react/ButtonAlert * @requires module:@massds/mayflower-assets/scss/01-atoms/button-with-icon * @requires module:@massds/mayflower-assets/scss/01-atoms/button-search * @requires module:@massds/mayflower-assets/scss/01-atoms/input-typeahead * @requires module:@massds/mayflower-assets/scss/01-atoms/svg-icons * @requires module:@massds/mayflower-assets/scss/01-atoms/svg-loc-icons */ import React from "react"; import PropTypes from "prop-types"; import classNames from "classnames"; import ButtonWithIcon from "../ButtonWithIcon/index.mjs"; // eslint-disable-next-line import/no-unresolved import IconCaretDown from "../Icon/IconCaretDown.mjs"; const ButtonAlert = props => { var _classNames; const text = props.text, hideText = props.hideText, showText = props.showText, classes = props.classes, isOpen = props.isOpen, rest = _objectWithoutPropertiesLoose(props, _excluded); const buttonClasses = classNames((_classNames = { 'ma__button-alert': true }, _classNames["" + classes] = classes && classes.length > 0, _classNames['is-open'] = isOpen, _classNames)); const buttonProps = _extends({ classes: [buttonClasses], expanded: isOpen, text: isOpen ? hideText + " " + text : showText + " " + text, usage: 'alert', icon: /*#__PURE__*/React.createElement(IconCaretDown, { height: 10, width: 10 }) }, rest); return /*#__PURE__*/React.createElement(ButtonWithIcon, buttonProps); }; ButtonAlert.propTypes = process.env.NODE_ENV !== "production" ? { /** The text that will display on the button alert. */ text: PropTypes.string, /** Optional class(es) to pass to the button alert */ classes: PropTypes.string, /** An optional onClick function */ onClick: PropTypes.func, /** Text for showing alert */ showText: PropTypes.string.isRequired, /** Text for hiding alert */ hideText: PropTypes.string.isRequired, /** Adds is-open class to button if true. */ isOpen: PropTypes.bool, /** HTML `<button>` 'type' attribute */ type: PropTypes.oneOf(['submit', 'reset', 'button', '']), /** Theme of the button */ theme: PropTypes.oneOf(['', 'c-primary', 'c-highlight', 'c-gray-dark', 'c-black']) } : {}; ButtonAlert.defaultProps = { isOpen: false, type: 'button', theme: 'c-black' }; export default ButtonAlert;