materialuiupgraded
Version:
Material-UI's workspace package
104 lines (97 loc) • 2.67 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Typography from '../Typography';
import withStyles from '../styles/withStyles';
export const styles = {
/* Styles applied to the root element. */
root: {
display: 'flex',
height: '0.01em', // Fix IE 11 flexbox alignment. To remove at some point.
maxHeight: '2em',
alignItems: 'center',
},
/* Styles applied to the root element if `variant="filled"` */
filled: {
'&$positionStart': {
marginTop: 16,
},
},
/* Styles applied to the root element if `position="start"`. */
positionStart: {
marginRight: 8,
},
/* Styles applied to the root element if `position="end"`. */
positionEnd: {
marginLeft: 8,
},
};
function InputAdornment(props) {
const {
children,
component: Component,
classes,
className,
disableTypography,
position,
variant,
...other
} = props;
return (
<Component
className={classNames(
classes.root,
{
[]: variant === 'filled',
[]: position === 'start',
[]: position === 'end',
},
className,
)}
{...other}
>
{typeof children === 'string' && !disableTypography ? (
<Typography color="textSecondary">{children}</Typography>
) : (
children
)}
</Component>
);
}
InputAdornment.propTypes = {
/**
* The content of the component, normally an `IconButton` or string.
*/
children: PropTypes.node.isRequired,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
/**
* If children is a string then disable wrapping in a Typography component.
*/
disableTypography: PropTypes.bool,
/**
* The position this adornment should appear relative to the `Input`.
*/
position: PropTypes.oneOf(['start', 'end']),
/**
* The variant to use.
*/
variant: PropTypes.oneOf(['standard', 'outlined', 'filled']),
};
InputAdornment.defaultProps = {
component: 'div',
disableTypography: false,
};
export default withStyles(styles, { name: 'MuiInputAdornment' })(InputAdornment);