/* eslint-disable no-nested-ternary */ import React, { ReactNode } from 'react'; import styled from 'styled-components'; import { space } from 'styled-system'; import { SocialEmail, SocialGithub, SocialLinkedin, SocialTwitter, SocialXing, } from '@t3n/icons'; import { ThemeProps } from '@t3n/theme'; import Avatar from '../Avatar'; import Badge from '../Badge'; import Box from '../Box'; import Button from '../Button'; import Card from '../Card'; import Link from '../Link'; import Text from '../Text'; export type SocialLinkType = | 'TWITTER' | 'GITHUB' | 'XING' | 'HOMEPAGE' | 'LINKEDIN'; export type SocialLink = { url: string; type: SocialLinkType }; export type UserCardProps = { user: { id: number; name: string; avatarUrl: string; email?: string; position?: string; flag?: string; phone?: string; socialLinks: SocialLink[]; }; optimizeAvatar?: boolean; link?: { fullCard?: boolean; url?: string; target?: string; title?: string; }; compact: boolean; secondary?: boolean; children?: ReactNode; }; export type SocialLinksProps = { links: SocialLink[]; cardLinked?: boolean; }; const StyledCard = styled(Card)` position: relative; height: 100%; ${({ theme }: ThemeProps) => space({ pt: [4, 5], theme })}; `; const StyledBadge = styled(Badge)` position: absolute; top: 8px; right: 8px; `; const SocialButton = styled(Button)` border-radius: 50%; border: 0; background-color: ${({ theme }: ThemeProps) => theme.colors.background.secondary}; width: 32px; height: 32px; align-items: center; margin: 0 0.5rem 0 0; padding: 5px; &:hover:not(:disabled) { transform: scale(1); background-color: ${({ theme }: ThemeProps) => theme.colors.background.inverse}; } &:hover > svg { fill: #fff; } `; const StyledDefaultBox = styled(Box)` @media screen and (max-width: ${(props: ThemeProps) => props.theme.breakpoints[0]}) { display: grid; justify-content: center; text-align: center; } `; const StyledCompactBox = styled(Box)` text-align: center; `; const StyledLink = styled(Link)` background-image: unset; &:hover, &:visited, &:focus { background-image: unset; } `; const SocialLinksBox = styled(Box)` @media screen and (max-width: ${(props: ThemeProps) => props.theme.breakpoints[0]}) { justify-content: center; } `; const SocialLinks: React.FC = ({ links }) => { return ( {links.map((link) => ( {link.type === 'XING' ? ( ) : link.type === 'LINKEDIN' ? ( ) : link.type === 'TWITTER' ? ( ) : link.type === 'GITHUB' ? ( ) : ( )} ))} ); }; const CompactUserCard: React.FC< Pick > = ({ user, link, optimizeAvatar, children }) => { return ( {!link?.fullCard && link?.url ? ( ) : ( )} {children} ); }; const DefaultUserCard: React.FC< Pick > = ({ user, link, optimizeAvatar, children }) => { return ( {!link?.fullCard && link?.url ? ( ) : ( )} {children} ); }; const UserCardContent: React.FC< Pick > = ({ user, link, secondary }) => { return ( <> {!link?.fullCard && link?.url ? ( {user.name} ) : ( user.name )} {user.position} {user.flag && {user.flag}} {!link?.fullCard && user.email ? ( {user.email} ) : ( {user.email} )} {!link?.fullCard && user.phone ? ( {user.phone} ) : ( {user.phone} )} {!link?.fullCard && user.socialLinks.length > 0 && ( )} ); }; const UserCard: React.FC = ({ user, optimizeAvatar, link, compact, secondary, children, }) => { return ( {compact ? ( {children} ) : ( {children} )} ); }; export default UserCard;