1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
15 |
|
16 | var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
17 |
|
18 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
19 |
|
20 | var React = _interopRequireWildcard(require("react"));
|
21 |
|
22 | var _reactIs = require("react-is");
|
23 |
|
24 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
25 |
|
26 | var _clsx = _interopRequireDefault(require("clsx"));
|
27 |
|
28 | var _utils = require("@material-ui/utils");
|
29 |
|
30 | var _Collapse = _interopRequireDefault(require("../Collapse"));
|
31 |
|
32 | var _Paper = _interopRequireDefault(require("../Paper"));
|
33 |
|
34 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
35 |
|
36 | var _AccordionContext = _interopRequireDefault(require("./AccordionContext"));
|
37 |
|
38 | var _useControlled3 = _interopRequireDefault(require("../utils/useControlled"));
|
39 |
|
40 | var styles = function styles(theme) {
|
41 | var transition = {
|
42 | duration: theme.transitions.duration.shortest
|
43 | };
|
44 | return {
|
45 |
|
46 | root: {
|
47 | position: 'relative',
|
48 | transition: theme.transitions.create(['margin'], transition),
|
49 | '&:before': {
|
50 | position: 'absolute',
|
51 | left: 0,
|
52 | top: -1,
|
53 | right: 0,
|
54 | height: 1,
|
55 | content: '""',
|
56 | opacity: 1,
|
57 | backgroundColor: theme.palette.divider,
|
58 | transition: theme.transitions.create(['opacity', 'background-color'], transition)
|
59 | },
|
60 | '&:first-child': {
|
61 | '&:before': {
|
62 | display: 'none'
|
63 | }
|
64 | },
|
65 | '&$expanded': {
|
66 | margin: '16px 0',
|
67 | '&:first-child': {
|
68 | marginTop: 0
|
69 | },
|
70 | '&:last-child': {
|
71 | marginBottom: 0
|
72 | },
|
73 | '&:before': {
|
74 | opacity: 0
|
75 | }
|
76 | },
|
77 | '&$expanded + &': {
|
78 | '&:before': {
|
79 | display: 'none'
|
80 | }
|
81 | },
|
82 | '&$disabled': {
|
83 | backgroundColor: theme.palette.action.disabledBackground
|
84 | }
|
85 | },
|
86 |
|
87 |
|
88 | rounded: {
|
89 | borderRadius: 0,
|
90 | '&:first-child': {
|
91 | borderTopLeftRadius: theme.shape.borderRadius,
|
92 | borderTopRightRadius: theme.shape.borderRadius
|
93 | },
|
94 | '&:last-child': {
|
95 | borderBottomLeftRadius: theme.shape.borderRadius,
|
96 | borderBottomRightRadius: theme.shape.borderRadius,
|
97 |
|
98 | '@supports (-ms-ime-align: auto)': {
|
99 | borderBottomLeftRadius: 0,
|
100 | borderBottomRightRadius: 0
|
101 | }
|
102 | }
|
103 | },
|
104 |
|
105 |
|
106 | expanded: {},
|
107 |
|
108 |
|
109 | disabled: {}
|
110 | };
|
111 | };
|
112 |
|
113 | exports.styles = styles;
|
114 | var Accordion = React.forwardRef(function Accordion(props, ref) {
|
115 | var childrenProp = props.children,
|
116 | classes = props.classes,
|
117 | className = props.className,
|
118 | _props$defaultExpande = props.defaultExpanded,
|
119 | defaultExpanded = _props$defaultExpande === void 0 ? false : _props$defaultExpande,
|
120 | _props$disabled = props.disabled,
|
121 | disabled = _props$disabled === void 0 ? false : _props$disabled,
|
122 | expandedProp = props.expanded,
|
123 | onChange = props.onChange,
|
124 | _props$square = props.square,
|
125 | square = _props$square === void 0 ? false : _props$square,
|
126 | _props$TransitionComp = props.TransitionComponent,
|
127 | TransitionComponent = _props$TransitionComp === void 0 ? _Collapse.default : _props$TransitionComp,
|
128 | TransitionProps = props.TransitionProps,
|
129 | other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "defaultExpanded", "disabled", "expanded", "onChange", "square", "TransitionComponent", "TransitionProps"]);
|
130 |
|
131 | var _useControlled = (0, _useControlled3.default)({
|
132 | controlled: expandedProp,
|
133 | default: defaultExpanded,
|
134 | name: 'Accordion',
|
135 | state: 'expanded'
|
136 | }),
|
137 | _useControlled2 = (0, _slicedToArray2.default)(_useControlled, 2),
|
138 | expanded = _useControlled2[0],
|
139 | setExpandedState = _useControlled2[1];
|
140 |
|
141 | var handleChange = React.useCallback(function (event) {
|
142 | setExpandedState(!expanded);
|
143 |
|
144 | if (onChange) {
|
145 | onChange(event, !expanded);
|
146 | }
|
147 | }, [expanded, onChange, setExpandedState]);
|
148 |
|
149 | var _React$Children$toArr = React.Children.toArray(childrenProp),
|
150 | _React$Children$toArr2 = (0, _toArray2.default)(_React$Children$toArr),
|
151 | summary = _React$Children$toArr2[0],
|
152 | children = _React$Children$toArr2.slice(1);
|
153 |
|
154 | var contextValue = React.useMemo(function () {
|
155 | return {
|
156 | expanded: expanded,
|
157 | disabled: disabled,
|
158 | toggle: handleChange
|
159 | };
|
160 | }, [expanded, disabled, handleChange]);
|
161 | return React.createElement(_Paper.default, (0, _extends2.default)({
|
162 | className: (0, _clsx.default)(classes.root, className, expanded && classes.expanded, disabled && classes.disabled, !square && classes.rounded),
|
163 | ref: ref,
|
164 | square: square
|
165 | }, other), React.createElement(_AccordionContext.default.Provider, {
|
166 | value: contextValue
|
167 | }, summary), React.createElement(TransitionComponent, (0, _extends2.default)({
|
168 | in: expanded,
|
169 | timeout: "auto"
|
170 | }, TransitionProps), React.createElement("div", {
|
171 | "aria-labelledby": summary.props.id,
|
172 | id: summary.props['aria-controls'],
|
173 | role: "region"
|
174 | }, children)));
|
175 | });
|
176 | process.env.NODE_ENV !== "production" ? Accordion.propTypes = {
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | |
183 |
|
184 |
|
185 | children: (0, _utils.chainPropTypes)(_propTypes.default.node.isRequired, function (props) {
|
186 | var summary = React.Children.toArray(props.children)[0];
|
187 |
|
188 | if ((0, _reactIs.isFragment)(summary)) {
|
189 | return new Error("Material-UI: The Accordion doesn't accept a Fragment as a child. " + 'Consider providing an array instead.');
|
190 | }
|
191 |
|
192 | if (! React.isValidElement(summary)) {
|
193 | return new Error('Material-UI: Expected the first child of Accordion to be a valid element.');
|
194 | }
|
195 |
|
196 | return null;
|
197 | }),
|
198 |
|
199 | |
200 |
|
201 |
|
202 |
|
203 | classes: (0, _utils.chainPropTypes)(_propTypes.default.object, function (props) {
|
204 | if (props.classes && props.classes.focused) {
|
205 | throw new Error(['Material-UI: the classes.focused key is deprecated.', 'Use `classes.focusedVisible` instead', 'The name of the pseudo-class was changed for consistency.']).join('\n');
|
206 | }
|
207 |
|
208 | return null;
|
209 | }),
|
210 |
|
211 | |
212 |
|
213 |
|
214 | className: _propTypes.default.string,
|
215 |
|
216 | |
217 |
|
218 |
|
219 | defaultExpanded: _propTypes.default.bool,
|
220 |
|
221 | |
222 |
|
223 |
|
224 | disabled: _propTypes.default.bool,
|
225 |
|
226 | |
227 |
|
228 |
|
229 |
|
230 | expanded: _propTypes.default.bool,
|
231 |
|
232 | |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | onChange: _propTypes.default.func,
|
239 |
|
240 | |
241 |
|
242 |
|
243 | square: _propTypes.default.bool,
|
244 |
|
245 | |
246 |
|
247 |
|
248 |
|
249 | TransitionComponent: _propTypes.default.elementType,
|
250 |
|
251 | |
252 |
|
253 |
|
254 | TransitionProps: _propTypes.default.object
|
255 | } : void 0;
|
256 |
|
257 | var _default = (0, _withStyles.default)(styles, {
|
258 | name: 'MuiAccordion'
|
259 | })(Accordion);
|
260 |
|
261 | exports.default = _default; |
\ | No newline at end of file |