UNPKG

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