UNPKG

@krowdy-ui/core

Version:

React components that implement Google's Material Design.

209 lines (185 loc) 7.01 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.styles = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _clsx = _interopRequireDefault(require("clsx")); var _Button = _interopRequireDefault(require("@material-ui/core/Button")); var _capitalize = _interopRequireDefault(require("../utils/capitalize")); var _withStyles = _interopRequireDefault(require("../styles/withStyles")); var _colorManipulator = require("../styles/colorManipulator"); var _excluded = ["color", "variant"], _excluded2 = ["className", "classes", "fullWidth", "dashed"]; var styles = function styles(theme) { return { contained: { '&:hover': { boxShadow: 'none' }, boxShadow: 'none' }, containedError: { '&:hover': { '@media (hover: none)': { backgroundColor: theme.palette.error.main }, // Reset on touch devices, it doesn't add specificity backgroundColor: theme.palette.error.light }, backgroundColor: theme.palette.error.main, color: theme.palette.error.contrastText }, containedKrowdy: { '&:hover': { '@media (hover: none)': { backgroundColor: theme.palette.krowdy.main }, // Reset on touch devices, it doesn't add specificity backgroundColor: theme.palette.krowdy.light }, backgroundColor: theme.palette.krowdy.main, color: theme.palette.krowdy.contrastText }, containedPrimary: { '&:hover': { '@media (hover: none)': { backgroundColor: theme.palette.primary.main }, // Reset on touch devices, it doesn't add specificity backgroundColor: theme.palette.primary.light }, backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText }, containedSecondary: { '&:hover': { '@media (hover: none)': { backgroundColor: theme.palette.secondary.main }, // Reset on touch devices, it doesn't add specificity backgroundColor: theme.palette.secondary.light }, backgroundColor: theme.palette.secondary.main, color: theme.palette.secondary.contrastText }, dashed: { '&:hover': { border: '1px dashed' }, border: '1px dashed' }, disabled: {}, fullWidth: {}, outlinedError: { '&$disabled': { border: "1px solid ".concat(theme.palette.action.disabled) }, '&:hover': { '@media (hover: none)': { backgroundColor: 'transparent' }, backgroundColor: (0, _colorManipulator.fade)(theme.palette.error.main, theme.palette.action.hoverOpacity), // Reset on touch devices, it doesn't add specificity border: "1px solid ".concat(theme.palette.error.main) }, border: "1px solid ".concat((0, _colorManipulator.fade)(theme.palette.error.main, 0.5)), color: theme.palette.error.main }, outlinedKrowdy: { '&$disabled': { border: "1px solid ".concat(theme.palette.action.disabled) }, '&:hover': { '@media (hover: none)': { backgroundColor: 'transparent' }, backgroundColor: (0, _colorManipulator.fade)(theme.palette.krowdy.main, theme.palette.action.hoverOpacity), // Reset on touch devices, it doesn't add specificity border: "1px solid ".concat(theme.palette.krowdy.main) }, border: "1px solid ".concat((0, _colorManipulator.fade)(theme.palette.krowdy.main, 0.5)), color: theme.palette.krowdy.main }, /* Pseudo-class applied to the root element if `disabled={true}`. */ textError: { '&:hover': { '@media (hover: none)': { backgroundColor: 'transparent' }, backgroundColor: (0, _colorManipulator.fade)(theme.palette.error.main, theme.palette.action.hoverOpacity) }, color: theme.palette.error.main }, textKrowdy: { '&:hover': { '@media (hover: none)': { backgroundColor: 'transparent' }, backgroundColor: (0, _colorManipulator.fade)(theme.palette.krowdy.main, theme.palette.action.hoverOpacity) }, color: theme.palette.krowdy.main } }; }; exports.styles = styles; var Button = _react["default"].forwardRef(function Button(_ref, ref) { var _ref$color = _ref.color, color = _ref$color === void 0 ? 'default' : _ref$color, _ref$variant = _ref.variant, variant = _ref$variant === void 0 ? 'text' : _ref$variant, props = (0, _objectWithoutProperties2["default"])(_ref, _excluded); var classNameProps = props.className, classes = props.classes, _props$fullWidth = props.fullWidth, fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth, _props$dashed = props.dashed, dashed = _props$dashed === void 0 ? false : _props$dashed, otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded2); var className = (0, _clsx["default"])(classNameProps, classes[variant], color !== 'default' && color !== 'inherit' && classes["".concat(variant).concat((0, _capitalize["default"])(color))], fullWidth && classes.fullWidth, dashed && classes.dashed); if (color === 'krowdy' || color === 'error') color = 'default'; if (variant === 'krowdy') variant = 'text'; return /*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({ className: className, color: color, fullWidth: fullWidth, ref: ref, variant: variant }, otherProps)); }); process.env.NODE_ENV !== "production" ? Button.propTypes = { /** * The content of the button. */ children: _propTypes["default"].node.isRequired, /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ className: _propTypes["default"].string, /** * @ignore */ classes: _propTypes["default"].object.isRequired, /** * The color of the component. It supports those theme colors that make sense for this component. */ color: _propTypes["default"].oneOf(['default', 'inherit', 'primary', 'secondary', 'krowdy', 'error']), dashed: _propTypes["default"].bool, /** * If `true`, the button will take up the full width of its container. */ fullWidth: _propTypes["default"].bool, /** * The variant to use. */ variant: _propTypes["default"].oneOf(['text', 'outlined', 'contained']) } : void 0; var _default = (0, _withStyles["default"])(styles, { name: 'KrowdyButton' })(Button); exports["default"] = _default;