UNPKG

@amsterdam/design-system-react

Version:

All React components from the Amsterdam Design System. Use it to compose pages in your website or application.

25 lines (24 loc) 1.36 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { PersonFillIcon } from '@amsterdam/design-system-react-icons'; import { clsx } from 'clsx'; import { forwardRef } from 'react'; import { Icon } from '../Icon'; export const avatarColors = ['azure', 'green', 'lime', 'magenta', 'orange', 'yellow']; const AvatarContent = ({ imageSrc, initials }) => { if (imageSrc) { return _jsx("img", { alt: "", src: imageSrc }); } if (initials.length) { return _jsx("span", { "aria-hidden": true, children: initials }); } return _jsx(Icon, { size: "small", svg: PersonFillIcon }); }; /** * @see {@link https://designsystem.amsterdam/?path=/docs/components-feedback-avatar--docs Avatar docs at Amsterdam Design System} */ export const Avatar = forwardRef(({ className, color, imageSrc, label, ...restProps }, ref) => { const initials = label.slice(0, 2).toUpperCase(); const a11yLabel = initials.length === 0 ? 'Gebruiker' : `Initialen gebruiker: ${initials}`; return (_jsxs("span", { ...restProps, className: clsx('ams-avatar', color && `ams-avatar--${color}`, imageSrc && 'ams-avatar--has-image', className), ref: ref, children: [_jsx("span", { className: "ams-visually-hidden", children: a11yLabel }), _jsx(AvatarContent, { imageSrc: imageSrc, initials: initials })] })); }); Avatar.displayName = 'Avatar';