11import * as React from 'react' ;
22import PropTypes from 'prop-types' ;
33import clsx from 'clsx' ;
4+ import { deepmerge } from '@material-ui/utils' ;
5+ import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled' ;
6+ import capitalize from '../utils/capitalize' ;
47import Typography from '../Typography' ;
5- import withStyles from '../styles/withStyles' ;
68import FormControlContext , { useFormControl } from '../FormControl/FormControlContext' ;
9+ import experimentalStyled from '../styles/experimentalStyled' ;
10+ import inputAdornmentClasses , { getInputAdornmentUtilityClass } from './inputAdornmentClasses' ;
11+ import useThemeProps from '../styles/useThemeProps' ;
712
8- export const styles = ( theme ) => ( {
9- /* Styles applied to the root element. */
10- root : {
11- display : 'flex' ,
12- height : '0.01em' , // Fix IE11 flexbox alignment. To remove at some point.
13- maxHeight : '2em' ,
14- alignItems : 'center' ,
15- whiteSpace : 'nowrap' ,
16- color : theme . palette . action . active ,
13+ const overridesResolver = ( props , styles ) => {
14+ const { styleProps } = props ;
15+
16+ return deepmerge (
17+ {
18+ ...styles [ `position${ capitalize ( styleProps . position ) } ` ] ,
19+ ...( styleProps . disablePointerEvents === true && styles . disablePointerEvents ) ,
20+ ...( styleProps . variant === 'filled' && styles . filled ) ,
21+ } ,
22+ styles . root || { } ,
23+ ) ;
24+ } ;
25+
26+ const useUtilityClasses = ( styleProps ) => {
27+ const { classes, disablePointerEvents, position, variant } = styleProps ;
28+ const slots = {
29+ root : [
30+ 'root' ,
31+ disablePointerEvents && 'disablePointerEvents' ,
32+ position && `position${ capitalize ( position ) } ` ,
33+ variant ,
34+ 'hiddenLabel' ,
35+ 'sizeSmall' ,
36+ ] ,
37+ } ;
38+
39+ return composeClasses ( slots , getInputAdornmentUtilityClass , classes ) ;
40+ } ;
41+
42+ const InputAdornmentRoot = experimentalStyled (
43+ 'div' ,
44+ { } ,
45+ {
46+ name : 'MuiInputAdornment' ,
47+ slot : 'Root' ,
48+ overridesResolver,
1749 } ,
18- /* Styles applied to the root element if `variant="filled"`. */
19- filled : {
20- '&$positionStart:not($hiddenLabel)' : {
50+ ) ( ( { theme, styleProps } ) => ( {
51+ display : 'flex' ,
52+ height : '0.01em' , // Fix IE11 flexbox alignment. To remove at some point.
53+ maxHeight : '2em' ,
54+ alignItems : 'center' ,
55+ whiteSpace : 'nowrap' ,
56+ color : theme . palette . action . active ,
57+ ...( styleProps . variant === 'filled' && {
58+ // Styles applied to the root element if `variant="filled"`.
59+ [ `&.${ inputAdornmentClasses . positionStart } &:not(.Mui-hiddenLabel)` ] : {
2160 marginTop : 16 ,
2261 } ,
23- } ,
24- /* Styles applied to the root element if ` position=" start"`. */
25- positionStart : {
62+ } ) ,
63+ ... ( styleProps . position === ' start' && {
64+ // Styles applied to the root element if `position="start"`.
2665 marginRight : 8 ,
27- } ,
28- /* Styles applied to the root element if ` position=" end"`. */
29- positionEnd : {
66+ } ) ,
67+ ... ( styleProps . position === ' end' && {
68+ // Styles applied to the root element if `position="end"`.
3069 marginLeft : 8 ,
31- } ,
32- /* Styles applied to the root element if `disablePointerEvents={true}`. */
33- disablePointerEvents : {
70+ } ) ,
71+ ... ( styleProps . disablePointerEvents === true && {
72+ // Styles applied to the root element if `disablePointerEvents={true}`.
3473 pointerEvents : 'none' ,
35- } ,
36- /* Styles applied if the adornment is used inside <FormControl hiddenLabel />. */
37- hiddenLabel : { } ,
38- /* Styles applied if the adornment is used inside <FormControl size="small" />. */
39- sizeSmall : { } ,
40- } ) ;
74+ } ) ,
75+ } ) ) ;
4176
42- const InputAdornment = React . forwardRef ( function InputAdornment ( props , ref ) {
77+ const InputAdornment = React . forwardRef ( function InputAdornment ( inProps , ref ) {
78+ const props = useThemeProps ( { props : inProps , name : 'MuiInputAdornment' } ) ;
4379 const {
4480 children,
45- classes,
4681 className,
47- component : Component = 'div' ,
82+ component = 'div' ,
4883 disablePointerEvents = false ,
4984 disableTypography = false ,
5085 position,
5186 variant : variantProp ,
5287 ...other
5388 } = props ;
89+
90+ const styleProps = {
91+ ...props ,
92+ disablePointerEvents,
93+ position,
94+ variant : variantProp ,
95+ } ;
96+
5497 const muiFormControl = useFormControl ( ) || { } ;
5598
5699 let variant = variantProp ;
@@ -68,23 +111,16 @@ const InputAdornment = React.forwardRef(function InputAdornment(props, ref) {
68111
69112 if ( muiFormControl && ! variant ) {
70113 variant = muiFormControl . variant ;
114+ styleProps . variant = variant ;
71115 }
116+ const classes = useUtilityClasses ( styleProps ) ;
72117
73118 return (
74119 < FormControlContext . Provider value = { null } >
75- < Component
76- className = { clsx (
77- classes . root ,
78- {
79- [ classes . filled ] : variant === 'filled' ,
80- [ classes . positionStart ] : position === 'start' ,
81- [ classes . positionEnd ] : position === 'end' ,
82- [ classes . disablePointerEvents ] : disablePointerEvents ,
83- [ classes . sizeSmall ] : muiFormControl . size === 'small' ,
84- [ classes . hiddenLabel ] : muiFormControl . hiddenLabel ,
85- } ,
86- className ,
87- ) }
120+ < InputAdornmentRoot
121+ as = { component }
122+ styleProps = { styleProps }
123+ className = { clsx ( classes . root , className ) }
88124 ref = { ref }
89125 { ...other }
90126 >
@@ -101,7 +137,7 @@ const InputAdornment = React.forwardRef(function InputAdornment(props, ref) {
101137 { children }
102138 </ React . Fragment >
103139 ) }
104- </ Component >
140+ </ InputAdornmentRoot >
105141 </ FormControlContext . Provider >
106142 ) ;
107143} ) ;
@@ -143,6 +179,10 @@ InputAdornment.propTypes /* remove-proptypes */ = {
143179 * The position this adornment should appear relative to the `Input`.
144180 */
145181 position : PropTypes . oneOf ( [ 'end' , 'start' ] ) ,
182+ /**
183+ * The system prop that allows defining system overrides as well as additional CSS styles.
184+ */
185+ sx : PropTypes . object ,
146186 /**
147187 * The variant to use.
148188 * Note: If you are using the `TextField` component or the `FormControl` component
@@ -151,4 +191,4 @@ InputAdornment.propTypes /* remove-proptypes */ = {
151191 variant : PropTypes . oneOf ( [ 'filled' , 'outlined' , 'standard' ] ) ,
152192} ;
153193
154- export default withStyles ( styles , { name : 'MuiInputAdornment' } ) ( InputAdornment ) ;
194+ export default InputAdornment ;
0 commit comments