-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathAccordionSummary.js
206 lines (192 loc) · 6.48 KB
/
AccordionSummary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { styled } from '../zero-styled';
import memoTheme from '../utils/memoTheme';
import { useDefaultProps } from '../DefaultPropsProvider';
import ButtonBase from '../ButtonBase';
import AccordionContext from '../Accordion/AccordionContext';
import accordionSummaryClasses, {
getAccordionSummaryUtilityClass,
} from './accordionSummaryClasses';
const useUtilityClasses = (ownerState) => {
const { classes, expanded, disabled, disableGutters } = ownerState;
const slots = {
root: ['root', expanded && 'expanded', disabled && 'disabled', !disableGutters && 'gutters'],
focusVisible: ['focusVisible'],
content: ['content', expanded && 'expanded', !disableGutters && 'contentGutters'],
expandIconWrapper: ['expandIconWrapper', expanded && 'expanded'],
};
return composeClasses(slots, getAccordionSummaryUtilityClass, classes);
};
const AccordionSummaryRoot = styled(ButtonBase, {
name: 'MuiAccordionSummary',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})(
memoTheme(({ theme }) => {
const transition = {
duration: theme.transitions.duration.shortest,
};
return {
display: 'flex',
width: '100%',
minHeight: 48,
padding: theme.spacing(0, 2),
transition: theme.transitions.create(['min-height', 'background-color'], transition),
[`&.${accordionSummaryClasses.focusVisible}`]: {
backgroundColor: (theme.vars || theme).palette.action.focus,
},
[`&.${accordionSummaryClasses.disabled}`]: {
opacity: (theme.vars || theme).palette.action.disabledOpacity,
},
[`&:hover:not(.${accordionSummaryClasses.disabled})`]: {
cursor: 'pointer',
},
variants: [
{
props: (props) => !props.disableGutters,
style: {
[`&.${accordionSummaryClasses.expanded}`]: {
minHeight: 64,
},
},
},
],
};
}),
);
const AccordionSummaryContent = styled('span', {
name: 'MuiAccordionSummary',
slot: 'Content',
overridesResolver: (props, styles) => styles.content,
})(
memoTheme(({ theme }) => ({
display: 'flex',
textAlign: 'start',
flexGrow: 1,
margin: '12px 0',
variants: [
{
props: (props) => !props.disableGutters,
style: {
transition: theme.transitions.create(['margin'], {
duration: theme.transitions.duration.shortest,
}),
[`&.${accordionSummaryClasses.expanded}`]: {
margin: '20px 0',
},
},
},
],
})),
);
const AccordionSummaryExpandIconWrapper = styled('span', {
name: 'MuiAccordionSummary',
slot: 'ExpandIconWrapper',
overridesResolver: (props, styles) => styles.expandIconWrapper,
})(
memoTheme(({ theme }) => ({
display: 'flex',
color: (theme.vars || theme).palette.action.active,
transform: 'rotate(0deg)',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
}),
[`&.${accordionSummaryClasses.expanded}`]: {
transform: 'rotate(180deg)',
},
})),
);
const AccordionSummary = React.forwardRef(function AccordionSummary(inProps, ref) {
const props = useDefaultProps({ props: inProps, name: 'MuiAccordionSummary' });
const { children, className, expandIcon, focusVisibleClassName, onClick, ...other } = props;
const { disabled = false, disableGutters, expanded, toggle } = React.useContext(AccordionContext);
const handleChange = (event) => {
if (toggle) {
toggle(event);
}
if (onClick) {
onClick(event);
}
};
const ownerState = {
...props,
expanded,
disabled,
disableGutters,
};
const classes = useUtilityClasses(ownerState);
return (
<AccordionSummaryRoot
focusRipple={false}
disableRipple
disabled={disabled}
aria-expanded={expanded}
className={clsx(classes.root, className)}
focusVisibleClassName={clsx(classes.focusVisible, focusVisibleClassName)}
onClick={handleChange}
ref={ref}
ownerState={ownerState}
{...other}
>
<AccordionSummaryContent className={classes.content} ownerState={ownerState}>
{children}
</AccordionSummaryContent>
{expandIcon && (
<AccordionSummaryExpandIconWrapper
className={classes.expandIconWrapper}
ownerState={ownerState}
>
{expandIcon}
</AccordionSummaryExpandIconWrapper>
)}
</AccordionSummaryRoot>
);
});
AccordionSummary.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The icon to display as the expand indicator.
*/
expandIcon: PropTypes.node,
/**
* This prop can help identify which element has keyboard focus.
* The class name will be applied when the element gains the focus through keyboard interaction.
* It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo).
* The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/HEAD/explainer.md).
* A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components
* if needed.
*/
focusVisibleClassName: PropTypes.string,
/**
* @ignore
*/
onClick: PropTypes.func,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
};
export default AccordionSummary;