1
1
import * as React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { unstable_composeClasses as composeClasses } from '@mui/base' ;
4
- import { useSlotProps } from '@mui/base/utils' ;
5
4
import { OverridableComponent } from '@mui/types' ;
6
5
import { unstable_capitalize as capitalize } from '@mui/utils' ;
7
- import { useThemeProps } from '../styles' ;
6
+ import useThemeProps from '../styles/useThemeProps' ;
7
+ import useSlot from '../utils/useSlot' ;
8
8
import styled from '../styles/styled' ;
9
9
import { getAspectRatioUtilityClass } from './aspectRatioClasses' ;
10
10
import { AspectRatioProps , AspectRatioOwnerState , AspectRatioTypeMap } from './AspectRatioProps' ;
@@ -91,7 +91,6 @@ const AspectRatio = React.forwardRef(function AspectRatio(inProps, ref) {
91
91
const {
92
92
component = 'div' ,
93
93
children,
94
- componentsProps = { } ,
95
94
ratio = '16 / 9' ,
96
95
minHeight,
97
96
maxHeight,
@@ -114,35 +113,33 @@ const AspectRatio = React.forwardRef(function AspectRatio(inProps, ref) {
114
113
115
114
const classes = useUtilityClasses ( ownerState ) ;
116
115
117
- const rootProps = useSlotProps ( {
116
+ const externalForwardedProps = { ...other , component } ;
117
+
118
+ const [ SlotRoot , rootProps ] = useSlot ( 'root' , {
119
+ ref,
120
+ className : classes . root ,
118
121
elementType : AspectRatioRoot ,
122
+ externalForwardedProps,
119
123
ownerState,
120
- externalSlotProps : componentsProps . root ,
121
- externalForwardedProps : other ,
122
- additionalProps : {
123
- ref,
124
- as : component ,
125
- } ,
126
- className : classes . root ,
127
124
} ) ;
128
125
129
- const contentProps = useSlotProps ( {
126
+ const [ SlotContent , contentProps ] = useSlot ( 'content' , {
127
+ className : classes . content ,
130
128
elementType : AspectRatioContent ,
129
+ externalForwardedProps,
131
130
ownerState,
132
- externalSlotProps : componentsProps . content ,
133
- className : classes . content ,
134
131
} ) ;
135
132
136
133
return (
137
- < AspectRatioRoot { ...rootProps } >
138
- < AspectRatioContent { ...contentProps } >
134
+ < SlotRoot { ...rootProps } >
135
+ < SlotContent { ...contentProps } >
139
136
{ React . Children . map ( children , ( child , index ) =>
140
137
index === 0 && React . isValidElement ( child )
141
138
? React . cloneElement ( child , { 'data-first-child' : '' } as Record < string , string > )
142
139
: child ,
143
140
) }
144
- </ AspectRatioContent >
145
- </ AspectRatioRoot >
141
+ </ SlotContent >
142
+ </ SlotRoot >
146
143
) ;
147
144
} ) as OverridableComponent < AspectRatioTypeMap > ;
148
145
@@ -166,14 +163,6 @@ AspectRatio.propTypes /* remove-proptypes */ = {
166
163
* Either a string to use a HTML element or a component.
167
164
*/
168
165
component : PropTypes . elementType ,
169
- /**
170
- * The props used for each slot inside the component.
171
- * @default {}
172
- */
173
- componentsProps : PropTypes . shape ( {
174
- content : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
175
- root : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
176
- } ) ,
177
166
/**
178
167
* The maximum calculated height of the element (not the CSS height).
179
168
*/
@@ -204,6 +193,21 @@ AspectRatio.propTypes /* remove-proptypes */ = {
204
193
* @default '16 / 9'
205
194
*/
206
195
ratio : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
196
+ /**
197
+ * The props used for each slot inside the component.
198
+ * @default {}
199
+ */
200
+ slotProps : PropTypes . shape ( {
201
+ content : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
202
+ root : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
203
+ } ) ,
204
+ /**
205
+ * Replace the default slots.
206
+ */
207
+ slots : PropTypes . shape ( {
208
+ content : PropTypes . elementType ,
209
+ root : PropTypes . elementType ,
210
+ } ) ,
207
211
/**
208
212
* The system prop that allows defining system overrides as well as additional CSS styles.
209
213
*/
0 commit comments