1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import { styled } from "../zero-styled/index.js";
|
8 | import memoTheme from "../utils/memoTheme.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import ButtonBase from "../ButtonBase/index.js";
|
11 | import AccordionContext from "../Accordion/AccordionContext.js";
|
12 | import accordionSummaryClasses, { getAccordionSummaryUtilityClass } from "./accordionSummaryClasses.js";
|
13 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
14 | const useUtilityClasses = ownerState => {
|
15 | const {
|
16 | classes,
|
17 | expanded,
|
18 | disabled,
|
19 | disableGutters
|
20 | } = ownerState;
|
21 | const slots = {
|
22 | root: ['root', expanded && 'expanded', disabled && 'disabled', !disableGutters && 'gutters'],
|
23 | focusVisible: ['focusVisible'],
|
24 | content: ['content', expanded && 'expanded', !disableGutters && 'contentGutters'],
|
25 | expandIconWrapper: ['expandIconWrapper', expanded && 'expanded']
|
26 | };
|
27 | return composeClasses(slots, getAccordionSummaryUtilityClass, classes);
|
28 | };
|
29 | const AccordionSummaryRoot = styled(ButtonBase, {
|
30 | name: 'MuiAccordionSummary',
|
31 | slot: 'Root',
|
32 | overridesResolver: (props, styles) => styles.root
|
33 | })(memoTheme(({
|
34 | theme
|
35 | }) => {
|
36 | const transition = {
|
37 | duration: theme.transitions.duration.shortest
|
38 | };
|
39 | return {
|
40 | display: 'flex',
|
41 | minHeight: 48,
|
42 | padding: theme.spacing(0, 2),
|
43 | transition: theme.transitions.create(['min-height', 'background-color'], transition),
|
44 | [`&.${accordionSummaryClasses.focusVisible}`]: {
|
45 | backgroundColor: (theme.vars || theme).palette.action.focus
|
46 | },
|
47 | [`&.${accordionSummaryClasses.disabled}`]: {
|
48 | opacity: (theme.vars || theme).palette.action.disabledOpacity
|
49 | },
|
50 | [`&:hover:not(.${accordionSummaryClasses.disabled})`]: {
|
51 | cursor: 'pointer'
|
52 | },
|
53 | variants: [{
|
54 | props: props => !props.disableGutters,
|
55 | style: {
|
56 | [`&.${accordionSummaryClasses.expanded}`]: {
|
57 | minHeight: 64
|
58 | }
|
59 | }
|
60 | }]
|
61 | };
|
62 | }));
|
63 | const AccordionSummaryContent = styled('div', {
|
64 | name: 'MuiAccordionSummary',
|
65 | slot: 'Content',
|
66 | overridesResolver: (props, styles) => styles.content
|
67 | })(memoTheme(({
|
68 | theme
|
69 | }) => ({
|
70 | display: 'flex',
|
71 | flexGrow: 1,
|
72 | margin: '12px 0',
|
73 | variants: [{
|
74 | props: props => !props.disableGutters,
|
75 | style: {
|
76 | transition: theme.transitions.create(['margin'], {
|
77 | duration: theme.transitions.duration.shortest
|
78 | }),
|
79 | [`&.${accordionSummaryClasses.expanded}`]: {
|
80 | margin: '20px 0'
|
81 | }
|
82 | }
|
83 | }]
|
84 | })));
|
85 | const AccordionSummaryExpandIconWrapper = styled('div', {
|
86 | name: 'MuiAccordionSummary',
|
87 | slot: 'ExpandIconWrapper',
|
88 | overridesResolver: (props, styles) => styles.expandIconWrapper
|
89 | })(memoTheme(({
|
90 | theme
|
91 | }) => ({
|
92 | display: 'flex',
|
93 | color: (theme.vars || theme).palette.action.active,
|
94 | transform: 'rotate(0deg)',
|
95 | transition: theme.transitions.create('transform', {
|
96 | duration: theme.transitions.duration.shortest
|
97 | }),
|
98 | [`&.${accordionSummaryClasses.expanded}`]: {
|
99 | transform: 'rotate(180deg)'
|
100 | }
|
101 | })));
|
102 | const AccordionSummary = React.forwardRef(function AccordionSummary(inProps, ref) {
|
103 | const props = useDefaultProps({
|
104 | props: inProps,
|
105 | name: 'MuiAccordionSummary'
|
106 | });
|
107 | const {
|
108 | children,
|
109 | className,
|
110 | expandIcon,
|
111 | focusVisibleClassName,
|
112 | onClick,
|
113 | ...other
|
114 | } = props;
|
115 | const {
|
116 | disabled = false,
|
117 | disableGutters,
|
118 | expanded,
|
119 | toggle
|
120 | } = React.useContext(AccordionContext);
|
121 | const handleChange = event => {
|
122 | if (toggle) {
|
123 | toggle(event);
|
124 | }
|
125 | if (onClick) {
|
126 | onClick(event);
|
127 | }
|
128 | };
|
129 | const ownerState = {
|
130 | ...props,
|
131 | expanded,
|
132 | disabled,
|
133 | disableGutters
|
134 | };
|
135 | const classes = useUtilityClasses(ownerState);
|
136 | return _jsxs(AccordionSummaryRoot, {
|
137 | focusRipple: false,
|
138 | disableRipple: true,
|
139 | disabled: disabled,
|
140 | component: "div",
|
141 | "aria-expanded": expanded,
|
142 | className: clsx(classes.root, className),
|
143 | focusVisibleClassName: clsx(classes.focusVisible, focusVisibleClassName),
|
144 | onClick: handleChange,
|
145 | ref: ref,
|
146 | ownerState: ownerState,
|
147 | ...other,
|
148 | children: [_jsx(AccordionSummaryContent, {
|
149 | className: classes.content,
|
150 | ownerState: ownerState,
|
151 | children: children
|
152 | }), expandIcon && _jsx(AccordionSummaryExpandIconWrapper, {
|
153 | className: classes.expandIconWrapper,
|
154 | ownerState: ownerState,
|
155 | children: expandIcon
|
156 | })]
|
157 | });
|
158 | });
|
159 | process.env.NODE_ENV !== "production" ? AccordionSummary.propTypes = {
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | |
165 |
|
166 |
|
167 | children: PropTypes.node,
|
168 | |
169 |
|
170 |
|
171 | classes: PropTypes.object,
|
172 | |
173 |
|
174 |
|
175 | className: PropTypes.string,
|
176 | |
177 |
|
178 |
|
179 | expandIcon: PropTypes.node,
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | focusVisibleClassName: PropTypes.string,
|
189 | |
190 |
|
191 |
|
192 | onClick: PropTypes.func,
|
193 | |
194 |
|
195 |
|
196 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
197 | } : void 0;
|
198 | export default AccordionSummary; |
\ | No newline at end of file |