UNPKG

@krowdy-ui/core

Version:

React components that implement Google's Material Design.

185 lines (177 loc) 6.15 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["color", "variant"], _excluded2 = ["className", "classes", "fullWidth", "dashed"]; import React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import MuiButton from '@material-ui/core/Button'; import capitalize from '../utils/capitalize'; import withStyles from '../styles/withStyles'; import { fade } from '../styles/colorManipulator'; export 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: 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(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: 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(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: fade(theme.palette.error.main, theme.palette.action.hoverOpacity) }, color: theme.palette.error.main }, textKrowdy: { '&:hover': { '@media (hover: none)': { backgroundColor: 'transparent' }, backgroundColor: fade(theme.palette.krowdy.main, theme.palette.action.hoverOpacity) }, color: theme.palette.krowdy.main } }; }; var Button = React.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 = _objectWithoutProperties(_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 = _objectWithoutProperties(props, _excluded2); var className = clsx(classNameProps, classes[variant], color !== 'default' && color !== 'inherit' && classes["".concat(variant).concat(capitalize(color))], fullWidth && classes.fullWidth, dashed && classes.dashed); if (color === 'krowdy' || color === 'error') color = 'default'; if (variant === 'krowdy') variant = 'text'; return /*#__PURE__*/React.createElement(MuiButton, _extends({ 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.node.isRequired, /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ className: PropTypes.string, /** * @ignore */ classes: PropTypes.object.isRequired, /** * The color of the component. It supports those theme colors that make sense for this component. */ color: PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary', 'krowdy', 'error']), dashed: PropTypes.bool, /** * If `true`, the button will take up the full width of its container. */ fullWidth: PropTypes.bool, /** * The variant to use. */ variant: PropTypes.oneOf(['text', 'outlined', 'contained']) } : void 0; export default withStyles(styles, { name: 'KrowdyButton' })(Button);