UNPKG

3.04 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { Theme } from '../styles';
5import { OverridableComponent, OverrideProps } from '../OverridableComponent';
6import { AvatarClasses } from './avatarClasses';
7import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
8
9export interface AvatarSlots {
10 /**
11 * The component that renders the transition.
12 * [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
13 * @default Collapse
14 */
15 img: React.JSXElementConstructor<React.ImgHTMLAttributes<HTMLImageElement>>;
16}
17
18export interface AvatarPropsVariantOverrides {}
19
20export type AvatarSlotsAndSlotProps = CreateSlotsAndSlotProps<
21 AvatarSlots,
22 {
23 img: SlotProps<
24 React.ElementType<React.ImgHTMLAttributes<HTMLImageElement>>,
25 {},
26 AvatarOwnProps
27 >;
28 }
29>;
30
31export interface AvatarOwnProps {
32 /**
33 * Used in combination with `src` or `srcSet` to
34 * provide an alt attribute for the rendered `img` element.
35 */
36 alt?: string;
37 /**
38 * Used to render icon or text elements inside the Avatar if `src` is not set.
39 * This can be an element, or just a string.
40 */
41 children?: React.ReactNode;
42 /**
43 * Override or extend the styles applied to the component.
44 */
45 classes?: Partial<AvatarClasses>;
46 /**
47 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes) applied to the `img` element if the component is used to display an image.
48 * It can be used to listen for the loading error event.
49 */
50 imgProps?: React.ImgHTMLAttributes<HTMLImageElement> & {
51 sx?: SxProps<Theme>;
52 };
53 /**
54 * The `sizes` attribute for the `img` element.
55 */
56 sizes?: string;
57 /**
58 * The `src` attribute for the `img` element.
59 */
60 src?: string;
61 /**
62 * The `srcSet` attribute for the `img` element.
63 * Use this attribute for responsive image display.
64 */
65 srcSet?: string;
66 /**
67 * The system prop that allows defining system overrides as well as additional CSS styles.
68 */
69 sx?: SxProps<Theme>;
70 /**
71 * The shape of the avatar.
72 * @default 'circular'
73 */
74 variant?: OverridableStringUnion<'circular' | 'rounded' | 'square', AvatarPropsVariantOverrides>;
75}
76
77export interface AvatarTypeMap<
78 AdditionalProps = {},
79 RootComponent extends React.ElementType = 'div',
80> {
81 props: AdditionalProps & AvatarOwnProps & AvatarSlotsAndSlotProps;
82 defaultComponent: RootComponent;
83}
84
85/**
86 *
87 * Demos:
88 *
89 * - [Avatar](https://mui.com/material-ui/react-avatar/)
90 *
91 * API:
92 *
93 * - [Avatar API](https://mui.com/material-ui/api/avatar/)
94 */
95declare const Avatar: OverridableComponent<AvatarTypeMap>;
96
97export type AvatarProps<
98 RootComponent extends React.ElementType = AvatarTypeMap['defaultComponent'],
99 AdditionalProps = {},
100> = OverrideProps<AvatarTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
101 component?: React.ElementType;
102};
103
104export default Avatar;