270 lines
8.8 KiB
JavaScript
270 lines
8.8 KiB
JavaScript
|
|
"use strict";
|
|||
|
|
|
|||
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|||
|
|
|
|||
|
|
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 _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|||
|
|
|
|||
|
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|||
|
|
|
|||
|
|
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 _utils = require("@material-ui/utils");
|
|||
|
|
|
|||
|
|
var _Collapse = _interopRequireDefault(require("../Collapse"));
|
|||
|
|
|
|||
|
|
var _Paper = _interopRequireDefault(require("../Paper"));
|
|||
|
|
|
|||
|
|
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
|||
|
|
|
|||
|
|
var _ExpansionPanelContext = _interopRequireDefault(require("./ExpansionPanelContext"));
|
|||
|
|
|
|||
|
|
var _useControlled3 = _interopRequireDefault(require("../utils/useControlled"));
|
|||
|
|
|
|||
|
|
var styles = function styles(theme) {
|
|||
|
|
var transition = {
|
|||
|
|
duration: theme.transitions.duration.shortest
|
|||
|
|
};
|
|||
|
|
return {
|
|||
|
|
/* Styles applied to the root element. */
|
|||
|
|
root: {
|
|||
|
|
position: 'relative',
|
|||
|
|
transition: theme.transitions.create(['margin'], transition),
|
|||
|
|
'&:before': {
|
|||
|
|
position: 'absolute',
|
|||
|
|
left: 0,
|
|||
|
|
top: -1,
|
|||
|
|
right: 0,
|
|||
|
|
height: 1,
|
|||
|
|
content: '""',
|
|||
|
|
opacity: 1,
|
|||
|
|
backgroundColor: theme.palette.divider,
|
|||
|
|
transition: theme.transitions.create(['opacity', 'background-color'], transition)
|
|||
|
|
},
|
|||
|
|
'&:first-child': {
|
|||
|
|
'&:before': {
|
|||
|
|
display: 'none'
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'&$expanded': {
|
|||
|
|
margin: '16px 0',
|
|||
|
|
'&:first-child': {
|
|||
|
|
marginTop: 0
|
|||
|
|
},
|
|||
|
|
'&:last-child': {
|
|||
|
|
marginBottom: 0
|
|||
|
|
},
|
|||
|
|
'&:before': {
|
|||
|
|
opacity: 0
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'&$expanded + &': {
|
|||
|
|
'&:before': {
|
|||
|
|
display: 'none'
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
'&$disabled': {
|
|||
|
|
backgroundColor: theme.palette.action.disabledBackground
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/* Styles applied to the root element if `square={false}`. */
|
|||
|
|
rounded: {
|
|||
|
|
borderRadius: 0,
|
|||
|
|
'&:first-child': {
|
|||
|
|
borderTopLeftRadius: theme.shape.borderRadius,
|
|||
|
|
borderTopRightRadius: theme.shape.borderRadius
|
|||
|
|
},
|
|||
|
|
'&:last-child': {
|
|||
|
|
borderBottomLeftRadius: theme.shape.borderRadius,
|
|||
|
|
borderBottomRightRadius: theme.shape.borderRadius,
|
|||
|
|
// Fix a rendering issue on Edge
|
|||
|
|
'@supports (-ms-ime-align: auto)': {
|
|||
|
|
borderBottomLeftRadius: 0,
|
|||
|
|
borderBottomRightRadius: 0
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
/* Styles applied to the root element if `expanded={true}`. */
|
|||
|
|
expanded: {},
|
|||
|
|
|
|||
|
|
/* Styles applied to the root element if `disabled={true}`. */
|
|||
|
|
disabled: {}
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
exports.styles = styles;
|
|||
|
|
var warnedOnce = false;
|
|||
|
|
/**
|
|||
|
|
* ⚠️ The ExpansionPanel component was renamed to Accordion to use a more common naming convention.
|
|||
|
|
*
|
|||
|
|
* You should use `import { Accordion } from '@material-ui/core'`
|
|||
|
|
* or `import Accordion from '@material-ui/core/Accordion'`.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
var ExpansionPanel = /*#__PURE__*/React.forwardRef(function ExpansionPanel(props, ref) {
|
|||
|
|
if (process.env.NODE_ENV !== 'production') {
|
|||
|
|
if (!warnedOnce) {
|
|||
|
|
warnedOnce = true;
|
|||
|
|
console.error(['Material-UI: the ExpansionPanel component was renamed to Accordion to use a more common naming convention.', '', "You should use `import { Accordion } from '@material-ui/core'`", "or `import Accordion from '@material-ui/core/Accordion'`"].join('\n'));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var childrenProp = props.children,
|
|||
|
|
classes = props.classes,
|
|||
|
|
className = props.className,
|
|||
|
|
_props$defaultExpande = props.defaultExpanded,
|
|||
|
|
defaultExpanded = _props$defaultExpande === void 0 ? false : _props$defaultExpande,
|
|||
|
|
_props$disabled = props.disabled,
|
|||
|
|
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|||
|
|
expandedProp = props.expanded,
|
|||
|
|
onChange = props.onChange,
|
|||
|
|
_props$square = props.square,
|
|||
|
|
square = _props$square === void 0 ? false : _props$square,
|
|||
|
|
_props$TransitionComp = props.TransitionComponent,
|
|||
|
|
TransitionComponent = _props$TransitionComp === void 0 ? _Collapse.default : _props$TransitionComp,
|
|||
|
|
TransitionProps = props.TransitionProps,
|
|||
|
|
other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "defaultExpanded", "disabled", "expanded", "onChange", "square", "TransitionComponent", "TransitionProps"]);
|
|||
|
|
|
|||
|
|
var _useControlled = (0, _useControlled3.default)({
|
|||
|
|
controlled: expandedProp,
|
|||
|
|
default: defaultExpanded,
|
|||
|
|
name: 'ExpansionPanel',
|
|||
|
|
state: 'expanded'
|
|||
|
|
}),
|
|||
|
|
_useControlled2 = (0, _slicedToArray2.default)(_useControlled, 2),
|
|||
|
|
expanded = _useControlled2[0],
|
|||
|
|
setExpandedState = _useControlled2[1];
|
|||
|
|
|
|||
|
|
var handleChange = React.useCallback(function (event) {
|
|||
|
|
setExpandedState(!expanded);
|
|||
|
|
|
|||
|
|
if (onChange) {
|
|||
|
|
onChange(event, !expanded);
|
|||
|
|
}
|
|||
|
|
}, [expanded, onChange, setExpandedState]);
|
|||
|
|
|
|||
|
|
var _React$Children$toArr = React.Children.toArray(childrenProp),
|
|||
|
|
_React$Children$toArr2 = (0, _toArray2.default)(_React$Children$toArr),
|
|||
|
|
summary = _React$Children$toArr2[0],
|
|||
|
|
children = _React$Children$toArr2.slice(1);
|
|||
|
|
|
|||
|
|
var contextValue = React.useMemo(function () {
|
|||
|
|
return {
|
|||
|
|
expanded: expanded,
|
|||
|
|
disabled: disabled,
|
|||
|
|
toggle: handleChange
|
|||
|
|
};
|
|||
|
|
}, [expanded, disabled, handleChange]);
|
|||
|
|
return /*#__PURE__*/React.createElement(_Paper.default, (0, _extends2.default)({
|
|||
|
|
className: (0, _clsx.default)(classes.root, className, expanded && classes.expanded, disabled && classes.disabled, !square && classes.rounded),
|
|||
|
|
ref: ref,
|
|||
|
|
square: square
|
|||
|
|
}, other), /*#__PURE__*/React.createElement(_ExpansionPanelContext.default.Provider, {
|
|||
|
|
value: contextValue
|
|||
|
|
}, summary), /*#__PURE__*/React.createElement(TransitionComponent, (0, _extends2.default)({
|
|||
|
|
in: expanded,
|
|||
|
|
timeout: "auto"
|
|||
|
|
}, TransitionProps), /*#__PURE__*/React.createElement("div", {
|
|||
|
|
"aria-labelledby": summary.props.id,
|
|||
|
|
id: summary.props['aria-controls'],
|
|||
|
|
role: "region"
|
|||
|
|
}, children)));
|
|||
|
|
});
|
|||
|
|
process.env.NODE_ENV !== "production" ? ExpansionPanel.propTypes = {
|
|||
|
|
// ----------------------------- Warning --------------------------------
|
|||
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|||
|
|
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|||
|
|
// ----------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* The content of the expansion panel.
|
|||
|
|
*/
|
|||
|
|
children: (0, _utils.chainPropTypes)(_propTypes.default.node.isRequired, function (props) {
|
|||
|
|
var summary = React.Children.toArray(props.children)[0];
|
|||
|
|
|
|||
|
|
if ((0, _reactIs.isFragment)(summary)) {
|
|||
|
|
return new Error("Material-UI: The ExpansionPanel doesn't accept a Fragment as a child. " + 'Consider providing an array instead.');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (! /*#__PURE__*/React.isValidElement(summary)) {
|
|||
|
|
return new Error('Material-UI: Expected the first child of ExpansionPanel to be a valid element.');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return null;
|
|||
|
|
}),
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Override or extend the styles applied to the component.
|
|||
|
|
* See [CSS API](#css) below for more details.
|
|||
|
|
*/
|
|||
|
|
classes: _propTypes.default.object,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @ignore
|
|||
|
|
*/
|
|||
|
|
className: _propTypes.default.string,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* If `true`, expands the panel by default.
|
|||
|
|
*/
|
|||
|
|
defaultExpanded: _propTypes.default.bool,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* If `true`, the panel will be displayed in a disabled state.
|
|||
|
|
*/
|
|||
|
|
disabled: _propTypes.default.bool,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* If `true`, expands the panel, otherwise collapse it.
|
|||
|
|
* Setting this prop enables control over the panel.
|
|||
|
|
*/
|
|||
|
|
expanded: _propTypes.default.bool,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Callback fired when the expand/collapse state is changed.
|
|||
|
|
*
|
|||
|
|
* @param {object} event The event source of the callback.
|
|||
|
|
* @param {boolean} expanded The `expanded` state of the panel.
|
|||
|
|
*/
|
|||
|
|
onChange: _propTypes.default.func,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* If `true`, rounded corners are disabled.
|
|||
|
|
*/
|
|||
|
|
square: _propTypes.default.bool,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* The component used for the collapse effect.
|
|||
|
|
* [Follow this guide](/components/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
|
|||
|
|
*/
|
|||
|
|
TransitionComponent: _propTypes.default.elementType,
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Props applied to the [`Transition`](http://reactcommunity.org/react-transition-group/transition#Transition-props) element.
|
|||
|
|
*/
|
|||
|
|
TransitionProps: _propTypes.default.object
|
|||
|
|
} : void 0;
|
|||
|
|
|
|||
|
|
var _default = (0, _withStyles.default)(styles, {
|
|||
|
|
name: 'MuiExpansionPanel'
|
|||
|
|
})(ExpansionPanel);
|
|||
|
|
|
|||
|
|
exports.default = _default;
|