@krowdy-ui/core
Version:
React components that implement Google's Material Design.
125 lines (120 loc) • 4.42 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["color"],
_excluded2 = ["className", "variant", "classes", "tooltip", "square", "disabled"];
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { Tooltip } from '@material-ui/core';
import MuiIconButton from '@material-ui/core/IconButton';
import capitalize from '../utils/capitalize';
import withStyles from '../styles/withStyles';
import { fade, alpha } from '../styles/colorManipulator';
export var styles = function styles(theme) {
return {
disabled: {},
outlined: {
'&$disabled': {
border: "1px solid ".concat(theme.palette.action.disabledBackground)
},
border: "1px solid ".concat(theme.palette.mode === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)')
},
outlinedError: {
'&:hover': {
'@media (hover: none)': {
backgroundColor: 'transparent'
},
backgroundColor: fade(theme.palette.error.main, theme.palette.action.hoverOpacity),
color: theme.palette.error.light
},
border: "1px solid ".concat(alpha(theme.palette.error.main, 0.5)),
color: theme.palette.error.main
},
outlinedKrowdy: {
'&:hover': {
'@media (hover: none)': {
backgroundColor: 'transparent'
},
// Reset on touch devices, it doesn't add specificity
backgroundColor: fade(theme.palette.krowdy.main, theme.palette.action.hoverOpacity),
color: theme.palette.krowdy.light
},
border: "1px solid ".concat(alpha(theme.palette.krowdy.main, 0.5)),
color: theme.palette.krowdy.main
},
outlinedPrimary: {
'&:hover': {
color: theme.palette.primary.light
},
border: "1px solid ".concat(alpha(theme.palette.primary.main, 0.5))
},
outlinedSecondary: {
'&:hover': {
color: theme.palette.secondary.light
},
border: "1px solid ".concat(alpha(theme.palette.secondary.main, 0.5))
},
textError: {
color: theme.palette.error.main
},
textKrowdy: {
color: theme.palette.krowdy.main
},
typeSquare: {
borderRadius: 4
}
};
};
var IconButton = React.forwardRef(function IconButton(_ref, ref) {
var _ref$color = _ref.color,
color = _ref$color === void 0 ? 'default' : _ref$color,
props = _objectWithoutProperties(_ref, _excluded);
var classNameProps = props.className,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'text' : _props$variant,
classes = props.classes,
tooltip = props.tooltip,
square = props.square,
disabled = props.disabled,
otherProps = _objectWithoutProperties(props, _excluded2);
var className = clsx(classNameProps, classes[variant], classes["".concat(variant).concat(capitalize(color))] ? _defineProperty({}, classes["".concat(variant).concat(capitalize(color))], color !== 'default') : {}, square && classes.typeSquare, disabled && classes.disabled);
if (color === 'krowdy' || color === 'error') color = 'default';
return tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
title: tooltip
}, /*#__PURE__*/React.createElement(MuiIconButton, _extends({
className: className,
color: color,
disabled: disabled,
ref: ref
}, otherProps))) : /*#__PURE__*/React.createElement(MuiIconButton, _extends({
className: className,
color: color,
disabled: disabled,
ref: ref
}, otherProps));
});
process.env.NODE_ENV !== "production" ? IconButton.propTypes = {
/**
* 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']),
square: PropTypes.bool,
tooltip: PropTypes.string,
/**
* The variant to use.
*/
variant: PropTypes.oneOf(['text', 'outlined', 'contained'])
} : void 0;
export default withStyles(styles, {
name: 'KrowdyIconButton'
})(IconButton);