UNPKG

6.45 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
23
24var _IconButton = _interopRequireDefault(require("../IconButton"));
25
26var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
27
28var _AccordionContext = _interopRequireDefault(require("../Accordion/AccordionContext"));
29
30/* eslint-disable jsx-a11y/aria-role */
31var styles = function styles(theme) {
32 var transition = {
33 duration: theme.transitions.duration.shortest
34 };
35 return {
36 /* Styles applied to the root element. */
37 root: {
38 display: 'flex',
39 minHeight: 8 * 6,
40 transition: theme.transitions.create(['min-height', 'background-color'], transition),
41 padding: theme.spacing(0, 2),
42 '&:hover:not($disabled)': {
43 cursor: 'pointer'
44 },
45 '&$expanded': {
46 minHeight: 64
47 },
48 '&$focused': {
49 backgroundColor: theme.palette.action.focus
50 },
51 '&$disabled': {
52 opacity: theme.palette.action.disabledOpacity
53 }
54 },
55
56 /* Pseudo-class applied to the root element, children wrapper element and `IconButton` component if `expanded={true}`. */
57 expanded: {},
58
59 /* Pseudo-class applied to the root element if `focused={true}`. */
60 focused: {},
61
62 /* Pseudo-class applied to the root element if `disabled={true}`. */
63 disabled: {},
64
65 /* Styles applied to the children wrapper element. */
66 content: {
67 display: 'flex',
68 flexGrow: 1,
69 transition: theme.transitions.create(['margin'], transition),
70 margin: '12px 0',
71 '&$expanded': {
72 margin: '20px 0'
73 }
74 },
75
76 /* Styles applied to the `IconButton` component when `expandIcon` is supplied. */
77 expandIcon: {
78 transform: 'rotate(0deg)',
79 transition: theme.transitions.create('transform', transition),
80 '&:hover': {
81 // Disable the hover effect for the IconButton,
82 // because a hover effect should apply to the entire Expand button and
83 // not only to the IconButton.
84 backgroundColor: 'transparent'
85 },
86 '&$expanded': {
87 transform: 'rotate(180deg)'
88 }
89 }
90 };
91};
92
93exports.styles = styles;
94var AccordionSummary = /*#__PURE__*/React.forwardRef(function AccordionSummary(props, ref) {
95 var children = props.children,
96 classes = props.classes,
97 className = props.className,
98 expandIcon = props.expandIcon,
99 IconButtonProps = props.IconButtonProps,
100 onBlur = props.onBlur,
101 onClick = props.onClick,
102 onFocusVisible = props.onFocusVisible,
103 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "expandIcon", "IconButtonProps", "onBlur", "onClick", "onFocusVisible"]);
104
105 var _React$useState = React.useState(false),
106 focusedState = _React$useState[0],
107 setFocusedState = _React$useState[1];
108
109 var handleFocusVisible = function handleFocusVisible(event) {
110 setFocusedState(true);
111
112 if (onFocusVisible) {
113 onFocusVisible(event);
114 }
115 };
116
117 var handleBlur = function handleBlur(event) {
118 setFocusedState(false);
119
120 if (onBlur) {
121 onBlur(event);
122 }
123 };
124
125 var _React$useContext = React.useContext(_AccordionContext.default),
126 _React$useContext$dis = _React$useContext.disabled,
127 disabled = _React$useContext$dis === void 0 ? false : _React$useContext$dis,
128 expanded = _React$useContext.expanded,
129 toggle = _React$useContext.toggle;
130
131 var handleChange = function handleChange(event) {
132 if (toggle) {
133 toggle(event);
134 }
135
136 if (onClick) {
137 onClick(event);
138 }
139 };
140
141 return /*#__PURE__*/React.createElement(_ButtonBase.default, (0, _extends2.default)({
142 focusRipple: false,
143 disableRipple: true,
144 disabled: disabled,
145 component: "div",
146 "aria-expanded": expanded,
147 className: (0, _clsx.default)(classes.root, className, disabled && classes.disabled, expanded && classes.expanded, focusedState && classes.focused),
148 onFocusVisible: handleFocusVisible,
149 onBlur: handleBlur,
150 onClick: handleChange,
151 ref: ref
152 }, other), /*#__PURE__*/React.createElement("div", {
153 className: (0, _clsx.default)(classes.content, expanded && classes.expanded)
154 }, children), expandIcon && /*#__PURE__*/React.createElement(_IconButton.default, (0, _extends2.default)({
155 className: (0, _clsx.default)(classes.expandIcon, expanded && classes.expanded),
156 edge: "end",
157 component: "div",
158 tabIndex: null,
159 role: null,
160 "aria-hidden": true
161 }, IconButtonProps), expandIcon));
162});
163process.env.NODE_ENV !== "production" ? AccordionSummary.propTypes = {
164 // ----------------------------- Warning --------------------------------
165 // | These PropTypes are generated from the TypeScript type definitions |
166 // | To update them edit the d.ts file and run "yarn proptypes" |
167 // ----------------------------------------------------------------------
168
169 /**
170 * The content of the accordion summary.
171 */
172 children: _propTypes.default.node,
173
174 /**
175 * Override or extend the styles applied to the component.
176 * See [CSS API](#css) below for more details.
177 */
178 classes: _propTypes.default.object,
179
180 /**
181 * @ignore
182 */
183 className: _propTypes.default.string,
184
185 /**
186 * The icon to display as the expand indicator.
187 */
188 expandIcon: _propTypes.default.node,
189
190 /**
191 * Props applied to the `IconButton` element wrapping the expand icon.
192 */
193 IconButtonProps: _propTypes.default.object,
194
195 /**
196 * @ignore
197 */
198 onBlur: _propTypes.default.func,
199
200 /**
201 * @ignore
202 */
203 onClick: _propTypes.default.func,
204
205 /**
206 * @ignore
207 */
208 onFocusVisible: _propTypes.default.func
209} : void 0;
210
211var _default = (0, _withStyles.default)(styles, {
212 name: 'MuiAccordionSummary'
213})(AccordionSummary);
214
215exports.default = _default;
\No newline at end of file