UNPKG

6.54 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import memoTheme from "../utils/memoTheme.js";
9import { useDefaultProps } from "../DefaultPropsProvider/index.js";
10import ButtonBase from "../ButtonBase/index.js";
11import AccordionContext from "../Accordion/AccordionContext.js";
12import accordionSummaryClasses, { getAccordionSummaryUtilityClass } from "./accordionSummaryClasses.js";
13import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14const 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};
29const 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}));
63const 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})));
85const 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})));
102const AccordionSummary = /*#__PURE__*/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 /*#__PURE__*/_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: [/*#__PURE__*/_jsx(AccordionSummaryContent, {
149 className: classes.content,
150 ownerState: ownerState,
151 children: children
152 }), expandIcon && /*#__PURE__*/_jsx(AccordionSummaryExpandIconWrapper, {
153 className: classes.expandIconWrapper,
154 ownerState: ownerState,
155 children: expandIcon
156 })]
157 });
158});
159process.env.NODE_ENV !== "production" ? AccordionSummary.propTypes /* remove-proptypes */ = {
160 // ┌────────────────────────────── Warning ──────────────────────────────┐
161 // │ These PropTypes are generated from the TypeScript type definitions. │
162 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
163 // └─────────────────────────────────────────────────────────────────────┘
164 /**
165 * The content of the component.
166 */
167 children: PropTypes.node,
168 /**
169 * Override or extend the styles applied to the component.
170 */
171 classes: PropTypes.object,
172 /**
173 * @ignore
174 */
175 className: PropTypes.string,
176 /**
177 * The icon to display as the expand indicator.
178 */
179 expandIcon: PropTypes.node,
180 /**
181 * This prop can help identify which element has keyboard focus.
182 * The class name will be applied when the element gains the focus through keyboard interaction.
183 * It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo).
184 * The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/HEAD/explainer.md).
185 * A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components
186 * if needed.
187 */
188 focusVisibleClassName: PropTypes.string,
189 /**
190 * @ignore
191 */
192 onClick: PropTypes.func,
193 /**
194 * The system prop that allows defining system overrides as well as additional CSS styles.
195 */
196 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
197} : void 0;
198export default AccordionSummary;
\No newline at end of file