Files
Alex Khomenko bc98f3d139 Grafana UI: Add Avatar component (#76429)
* Grafana/UI: Add Avatar component

* Use the new component

* Add docs and story

* Update type check

* Codeformat
2023-10-16 13:59:54 +03:00

34 lines
1015 B
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2, ThemeSpacingTokens } from '@grafana/data';
import { useStyles2 } from '../../themes';
import { getResponsiveStyle, ResponsiveProp } from '../Layout/utils/responsiveness';
export interface AvatarProps {
src: string;
alt: string;
width?: ResponsiveProp<ThemeSpacingTokens>;
height?: ResponsiveProp<ThemeSpacingTokens>;
}
export const Avatar = ({ src, alt, width, height }: AvatarProps) => {
const styles = useStyles2(getStyles, width, height);
return <img className={styles.image} src={src} alt={alt} />;
};
const getStyles = (theme: GrafanaTheme2, width: AvatarProps['width'] = 3, height: AvatarProps['height'] = 3) => {
return {
image: css([
getResponsiveStyle(theme, width, (val) => ({
width: theme.spacing(val),
})),
getResponsiveStyle(theme, height, (val) => ({
height: theme.spacing(val),
})),
{ borderRadius: theme.shape.radius.circle },
]),
};
};