UNPKG

2.95 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3const _excluded = ["className"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import ListContext from '../List/ListContext';
9import styled from '../styles/styled';
10import useThemeProps from '../styles/useThemeProps';
11import { getListItemAvatarUtilityClass } from './listItemAvatarClasses';
12import { jsx as _jsx } from "react/jsx-runtime";
13
14const useUtilityClasses = ownerState => {
15 const {
16 alignItems,
17 classes
18 } = ownerState;
19 const slots = {
20 root: ['root', alignItems === 'flex-start' && 'alignItemsFlexStart']
21 };
22 return composeClasses(slots, getListItemAvatarUtilityClass, classes);
23};
24
25const ListItemAvatarRoot = styled('div', {
26 name: 'MuiListItemAvatar',
27 slot: 'Root',
28 overridesResolver: (props, styles) => {
29 const {
30 ownerState
31 } = props;
32 return [styles.root, ownerState.alignItems === 'flex-start' && styles.alignItemsFlexStart];
33 }
34})(({
35 ownerState
36}) => _extends({
37 minWidth: 56,
38 flexShrink: 0
39}, ownerState.alignItems === 'flex-start' && {
40 marginTop: 8
41}));
42/**
43 * A simple wrapper to apply `List` styles to an `Avatar`.
44 */
45
46const ListItemAvatar = /*#__PURE__*/React.forwardRef(function ListItemAvatar(inProps, ref) {
47 const props = useThemeProps({
48 props: inProps,
49 name: 'MuiListItemAvatar'
50 });
51
52 const {
53 className
54 } = props,
55 other = _objectWithoutPropertiesLoose(props, _excluded);
56
57 const context = React.useContext(ListContext);
58
59 const ownerState = _extends({}, props, {
60 alignItems: context.alignItems
61 });
62
63 const classes = useUtilityClasses(ownerState);
64 return /*#__PURE__*/_jsx(ListItemAvatarRoot, _extends({
65 className: clsx(classes.root, className),
66 ownerState: ownerState,
67 ref: ref
68 }, other));
69});
70process.env.NODE_ENV !== "production" ? ListItemAvatar.propTypes
71/* remove-proptypes */
72= {
73 // ----------------------------- Warning --------------------------------
74 // | These PropTypes are generated from the TypeScript type definitions |
75 // | To update them edit the d.ts file and run "yarn proptypes" |
76 // ----------------------------------------------------------------------
77
78 /**
79 * The content of the component, normally an `Avatar`.
80 */
81 children: PropTypes.node,
82
83 /**
84 * Override or extend the styles applied to the component.
85 */
86 classes: PropTypes.object,
87
88 /**
89 * @ignore
90 */
91 className: PropTypes.string,
92
93 /**
94 * The system prop that allows defining system overrides as well as additional CSS styles.
95 */
96 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
97} : void 0;
98export default ListItemAvatar;
\No newline at end of file