@itwin/itwinui-react
Version:
A react component library for iTwinUI
53 lines (52 loc) • 1.34 kB
JavaScript
import cx from 'classnames';
import * as React from 'react';
import { Box, SoftBackgrounds, isSoftBackground } from '../../utils/index.js';
import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden.js';
let getBackground = (color) => {
if (!color) return '';
return isSoftBackground(color) ? SoftBackgrounds[color] : color;
};
export const defaultStatusTitles = {
away: 'Away',
busy: 'Busy',
offline: 'Offline',
online: 'Online',
};
export const Avatar = React.forwardRef((props, ref) => {
let {
size = 'small',
status,
abbreviation,
image,
backgroundColor,
translatedStatusTitles,
className,
style,
...rest
} = props;
let statusTitles = {
...defaultStatusTitles,
...translatedStatusTitles,
};
return React.createElement(
Box,
{
as: 'span',
className: cx('iui-avatar', className),
'data-iui-size': 'medium' !== size ? size : void 0,
'data-iui-status': status,
style: {
backgroundColor: getBackground(backgroundColor),
...style,
},
ref: ref,
...rest,
},
image ? null : abbreviation?.substring(0, 2),
image,
status
? React.createElement(VisuallyHidden, null, statusTitles[status])
: null,
);
});
if ('development' === process.env.NODE_ENV) Avatar.displayName = 'Avatar';