import React from 'react'; import styled from 'styled-components'; import { border, flex, layout, space } from 'styled-system'; import { customBorder } from '../../../utils/customProps'; import { Box, Image, Text } from '../../primitives'; import { usePropsConfig } from '../../../theme'; import type { IAvatarProps } from './props'; const initials = (name: string) => { const [firstName, lastName] = name.split(' '); return firstName && lastName ? `${firstName.charAt(0)}${lastName.charAt(0)}` : firstName.charAt(0); }; const StyledAvatar = styled(Box)( layout, space, border, flex, customBorder ); export const Avatar = ( props: IAvatarProps & { children?: JSX.Element[] | JSX.Element | any | undefined; } ) => { const { size, name, style, source, children, ...remainingProps } = props; const { color, fontSize, fontWeight, ...newProps } = usePropsConfig( 'Avatar', { ...remainingProps, name, size } ); const textProps = { color, fontSize, fontWeight }; const imageFitStyle = { height: '100%', width: '100%' }; return ( {source ? ( {name ) : ( {name ? initials(name) : '--'} )} {children} ); };