UNPKG

@krowdy-ui/core

Version:

React components that implement Google's Material Design.

326 lines (272 loc) 12 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); 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 = _interopRequireWildcard(require("react")); var _reactIs = require("react-is"); var _propTypes = _interopRequireDefault(require("prop-types")); var _clsx = _interopRequireDefault(require("clsx")); var _capitalize = _interopRequireDefault(require("../utils/capitalize")); var _colorManipulator = require("../styles/colorManipulator"); var _withStyles = _interopRequireDefault(require("../styles/withStyles")); var _Button = _interopRequireDefault(require("../Button")); var _excluded = ["children", "classes", "className", "color", "component", "disabled", "disableFocusRipple", "disableRipple", "fullWidth", "orientation", "size", "variant"]; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } // Force a side effect so we don't have any override priority issue. // eslint-disable-next-line no-unused-expressions _Button["default"].styles; var styles = function styles(theme) { return { /* Styles applied to the root element. */ contained: { boxShadow: theme.shadows[2] }, /* Styles applied to the root element if `variant="contained"`. */ disabled: {}, /* Pseudo-class applied to child elements if `disabled={true}`. */ fullWidth: { width: '100%' }, /* Styles applied to the root element if `fullWidth={true}`. */ grouped: { minWidth: 40 }, /* Styles applied to the root element if `orientation="vertical"`. */ groupedContained: { boxShadow: 'none' }, /* Styles applied to the children. */ groupedContainedHorizontal: { '&:not(:last-child)': { '&$disabled': { borderRight: "1px solid ".concat(theme.palette.action.disabled) }, borderRight: "1px solid ".concat(theme.palette.grey[400]) } }, /* Styles applied to the children if `orientation="horizontal"`. */ groupedContainedPrimary: { '&:not(:last-child)': { borderColor: theme.palette.primary.dark } }, /* Styles applied to the children if `orientation="vertical"`. */ groupedContainedSecondary: { '&:not(:last-child)': { borderColor: theme.palette.secondary.dark } }, /* Styles applied to the children if `variant="text"`. */ groupedContainedVertical: { '&:not(:last-child)': { '&$disabled': { borderBottom: "1px solid ".concat(theme.palette.action.disabled) }, borderBottom: "1px solid ".concat(theme.palette.grey[400]) } }, /* Styles applied to the children if `variant="text"` and `orientation="horizontal"`. */ groupedHorizontal: { '&:not(:first-child)': { borderBottomLeftRadius: 0, borderTopLeftRadius: 0 }, '&:not(:last-child)': { borderBottomRightRadius: 0, borderTopRightRadius: 0 } }, /* Styles applied to the children if `variant="text"` and `orientation="vertical"`. */ groupedOutlined: {}, /* Styles applied to the children if `variant="text"` and `color="primary"`. */ groupedOutlinedHorizontal: { '&:not(:first-child)': { marginLeft: -1 }, '&:not(:last-child)': { borderRightColor: 'transparent' } }, /* Styles applied to the children if `variant="text"` and `color="secondary"`. */ groupedOutlinedPrimary: { '&:hover': { borderColor: theme.palette.primary.main } }, /* Styles applied to the children if `variant="outlined"`. */ groupedOutlinedSecondary: { '&:hover': { borderColor: theme.palette.secondary.main } }, /* Styles applied to the children if `variant="outlined"` and `orientation="horizontal"`. */ groupedOutlinedVertical: { '&:not(:first-child)': { marginTop: -1 }, '&:not(:last-child)': { borderBottomColor: 'transparent' } }, /* Styles applied to the children if `variant="outlined"` and `orientation="vertical"`. */ groupedText: {}, /* Styles applied to the children if `variant="outlined"` and `color="primary"`. */ groupedTextHorizontal: { '&:not(:last-child)': { borderRight: "1px solid ".concat(theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)') } }, /* Styles applied to the children if `variant="outlined"` and `color="secondary"`. */ groupedTextPrimary: { '&:not(:last-child)': { borderColor: (0, _colorManipulator.fade)(theme.palette.primary.main, 0.5) } }, /* Styles applied to the children if `variant="contained"`. */ groupedTextSecondary: { '&:not(:last-child)': { borderColor: (0, _colorManipulator.fade)(theme.palette.secondary.main, 0.5) } }, /* Styles applied to the children if `variant="contained"` and `orientation="horizontal"`. */ groupedTextVertical: { '&:not(:last-child)': { borderBottom: "1px solid ".concat(theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)') } }, /* Styles applied to the children if `variant="contained"` and `orientation="vertical"`. */ groupedVertical: { '&:not(:first-child)': { borderTopLeftRadius: 0, borderTopRightRadius: 0 }, '&:not(:last-child)': { borderBottomLeftRadius: 0, borderBottomRightRadius: 0 } }, /* Styles applied to the children if `variant="contained"` and `color="primary"`. */ root: { borderRadius: theme.shape.borderRadius, display: 'inline-flex' }, /* Styles applied to the children if `variant="contained"` and `color="secondary"`. */ vertical: { flexDirection: 'column' } }; }; exports.styles = styles; var ButtonGroup = React.forwardRef(function ButtonGroup(props, ref) { var children = props.children, classes = props.classes, className = props.className, _props$color = props.color, color = _props$color === void 0 ? 'default' : _props$color, _props$component = props.component, Component = _props$component === void 0 ? 'div' : _props$component, _props$disabled = props.disabled, disabled = _props$disabled === void 0 ? false : _props$disabled, _props$disableFocusRi = props.disableFocusRipple, disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi, _props$disableRipple = props.disableRipple, disableRipple = _props$disableRipple === void 0 ? false : _props$disableRipple, _props$fullWidth = props.fullWidth, fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth, _props$orientation = props.orientation, orientation = _props$orientation === void 0 ? 'horizontal' : _props$orientation, _props$size = props.size, size = _props$size === void 0 ? 'medium' : _props$size, _props$variant = props.variant, variant = _props$variant === void 0 ? 'outlined' : _props$variant, other = (0, _objectWithoutProperties2["default"])(props, _excluded); var buttonClassName = (0, _clsx["default"])(classes.grouped, classes["grouped".concat((0, _capitalize["default"])(orientation))], classes["grouped".concat((0, _capitalize["default"])(variant))], classes["grouped".concat((0, _capitalize["default"])(variant)).concat((0, _capitalize["default"])(orientation))], classes["grouped".concat((0, _capitalize["default"])(variant)).concat(color !== 'default' ? (0, _capitalize["default"])(color) : '')], disabled && classes.disabled); return /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({ className: (0, _clsx["default"])(classes.root, className, fullWidth && classes.fullWidth, { contained: classes.contained }[variant], { vertical: classes.vertical }[orientation]), ref: ref, role: "group" }, other), React.Children.map(children, function (child) { if (!React.isValidElement(child)) return null; if (process.env.NODE_ENV !== 'production') if ((0, _reactIs.isFragment)(child)) { console.error(["Material-UI: the ButtonGroup component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n')); } return React.cloneElement(child, { className: (0, _clsx["default"])(buttonClassName, child.props.className), color: child.props.color || color, disableFocusRipple: disableFocusRipple, disableRipple: disableRipple, disabled: child.props.disabled || disabled, fullWidth: fullWidth, size: child.props.size || size, variant: child.props.variant || variant }); })); }); process.env.NODE_ENV !== "production" ? ButtonGroup.propTypes = { /** * The content of the button group. */ 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']), /** * The component used for the root node. * Either a string to use a DOM element or a component. */ component: _propTypes["default"].elementType, /** * If `true`, the buttons will be disabled. */ disableFocusRipple: _propTypes["default"].bool, /** * If `true`, the button keyboard focus ripple will be disabled. * `disableRipple` must also be true. */ disableRipple: _propTypes["default"].bool, /** * If `true`, the button ripple effect will be disabled. */ disabled: _propTypes["default"].bool, /** * If `true`, the buttons will take up the full width of its container. */ fullWidth: _propTypes["default"].bool, /** * The group orientation. */ orientation: _propTypes["default"].oneOf(['vertical', 'horizontal']), /** * The size of the button. * `small` is equivalent to the dense button styling. */ size: _propTypes["default"].oneOf(['small', 'medium', 'large']), /** * The variant to use. */ variant: _propTypes["default"].oneOf(['text', 'outlined', 'contained']) } : void 0; var _default = (0, _withStyles["default"])(styles, { name: 'MuiButtonGroup' })(ButtonGroup); exports["default"] = _default;