import type { FC, ReactNode } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import classNames from 'classnames'; import AdminIcon from '@/images/icons/icon_admin.svg?react'; import IconVerified from '@/images/icons/icon_verified.svg?react'; import type { OnAttributeHandler } from '@/mastodon/utils/html'; import BlockIcon from '@/material-icons/400-24px/block.svg?react'; import GroupsIcon from '@/material-icons/400-24px/group.svg?react'; import PersonIcon from '@/material-icons/400-24px/person.svg?react'; import SmartToyIcon from '@/material-icons/400-24px/smart_toy.svg?react'; import VolumeOffIcon from '@/material-icons/400-24px/volume_off.svg?react'; import { EmojiHTML } from '../emoji/html'; import { Icon } from '../icon'; import classes from './styles.module.scss'; interface BadgeProps extends React.ComponentPropsWithoutRef<'div'> { label: ReactNode; icon?: ReactNode; domain?: ReactNode; roleId?: string; variant?: | 'default' | 'subtle' | 'inverted' | 'success' | 'warning' | 'danger'; } export const Badge: FC = ({ icon = , variant = 'default', label, className, domain, roleId, ...otherProps }) => (
{icon} {label} {domain && {domain}}
); export const AdminBadge: FC> = ({ label, ...props }) => ( } label={ label ?? ( ) } {...props} /> ); export const GroupBadge: FC> = ({ label, ...props }) => ( } label={ label ?? ( ) } {...props} /> ); export const AutomatedBadge: FC<{ className?: string }> = ({ className }) => ( } label={ } className={className} /> ); export const MutedBadge: FC< Partial & { expiresAt?: string | null } > = ({ expiresAt, label, ...props }) => { // Format the date, only showing the year if it's different from the current year. const intl = useIntl(); let formattedDate: string | null = null; if (expiresAt) { const expiresDate = new Date(expiresAt); const isCurrentYear = expiresDate.getFullYear() === new Date().getFullYear(); formattedDate = intl.formatDate(expiresDate, { month: 'short', day: 'numeric', ...(isCurrentYear ? {} : { year: 'numeric' }), }); } return ( } variant='inverted' label={ label ?? (formattedDate ? ( ) : ( )) } {...props} /> ); }; export const BlockedBadge: FC> = ({ label, ...props }) => ( } variant='danger' label={ label ?? ( ) } {...props} /> ); const onAttribute: OnAttributeHandler = (name, value, tagName) => { if (name === 'rel' && tagName === 'a') { if (value === 'me') { return null; } return [ name, value .split(' ') .filter((x) => x !== 'me') .join(' '), ]; } return undefined; }; export const VerifiedBadge: React.FC<{ link: string; className?: string }> = ({ link, className, }) => ( } label={} className={className} /> );