114 lines
3.0 KiB
TypeScript
114 lines
3.0 KiB
TypeScript
import { number } from '@lumina/tools/format';
|
|
import NextLink from 'next/link';
|
|
|
|
import { Avatar } from '../../atoms/avatar';
|
|
import { FlexBox } from '../../atoms/flex-box';
|
|
import { GridBox } from '../../atoms/grid-box';
|
|
import { Icon } from '../../atoms/icon';
|
|
import { Typography } from '../../atoms/typography';
|
|
import { cn } from '../../tools/cn';
|
|
import type { AvatarStackProps } from './types';
|
|
import { avatarStackFaceVariants, avatarStackVariants } from './variants';
|
|
|
|
/**
|
|
* Overlapping 32px avatars with «+N» for the rest (DS AvatarStack). With a `title` it is the strip
|
|
* on خانه, «تحلیلگران منتخب», and with `href` the whole strip is a link.
|
|
*/
|
|
export function AvatarStack({
|
|
avatars,
|
|
max = 4,
|
|
title,
|
|
subtitle,
|
|
href,
|
|
label,
|
|
className,
|
|
}: AvatarStackProps) {
|
|
const shown = avatars.slice(0, max);
|
|
const rest = avatars.length - shown.length;
|
|
const strip = title != null;
|
|
|
|
const faces = (
|
|
<FlexBox
|
|
tag="span"
|
|
display="inline-flex"
|
|
alignItems="items-center"
|
|
role={!strip && label ? 'img' : undefined}
|
|
aria-label={!strip ? label : undefined}
|
|
aria-hidden={strip || !label ? true : undefined}
|
|
className={cn('flex-none', !strip && className)}
|
|
>
|
|
{shown.map((avatar, index) => (
|
|
<Avatar
|
|
key={avatar.name}
|
|
name={avatar.name}
|
|
src={avatar.src}
|
|
size="sm"
|
|
className={avatarStackFaceVariants({ overlap: index > 0 })}
|
|
/>
|
|
))}
|
|
{rest > 0 && (
|
|
<GridBox
|
|
tag="span"
|
|
justifyItems="justify-items-center"
|
|
alignItems="items-center"
|
|
className={cn(
|
|
avatarStackFaceVariants({ overlap: shown.length > 0 }),
|
|
'size-8 bg-surface-sunken text-text-secondary',
|
|
)}
|
|
>
|
|
<Typography
|
|
tag="bdi"
|
|
dir="ltr"
|
|
variant="micro"
|
|
color="inherit"
|
|
className="font-semibold"
|
|
>
|
|
{`+${number(rest)}`}
|
|
</Typography>
|
|
</GridBox>
|
|
)}
|
|
</FlexBox>
|
|
);
|
|
|
|
if (!strip) return faces;
|
|
|
|
const content = (
|
|
<>
|
|
{faces}
|
|
<FlexBox tag="span" direction="flex-col" className="min-w-0 flex-1">
|
|
<Typography tag="span" className="font-semibold">
|
|
{title}
|
|
</Typography>
|
|
{subtitle != null && (
|
|
<Typography tag="span" variant="caption" color="secondary">
|
|
{subtitle}
|
|
</Typography>
|
|
)}
|
|
</FlexBox>
|
|
{href && (
|
|
<Icon name="chevron-left" size={20} className="text-text-tertiary" />
|
|
)}
|
|
</>
|
|
);
|
|
const classes = cn(
|
|
avatarStackVariants({ strip: true, link: href != null }),
|
|
className,
|
|
);
|
|
|
|
return href ? (
|
|
<FlexBox
|
|
tag={NextLink}
|
|
href={href}
|
|
alignItems="items-center"
|
|
gap="gap-3"
|
|
className={classes}
|
|
>
|
|
{content}
|
|
</FlexBox>
|
|
) : (
|
|
<FlexBox alignItems="items-center" gap="gap-3" className={classes}>
|
|
{content}
|
|
</FlexBox>
|
|
);
|
|
}
|