mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 06:52:13 +08:00

* Grafana/UI: Add Avatar component * Use the new component * Add docs and story * Update type check * Codeformat
34 lines
1015 B
TypeScript
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 },
|
|
]),
|
|
};
|
|
};
|