soapbox/src/components/verification-badge.tsx

34 lines
1008 B
TypeScript
Raw Normal View History

2023-02-06 19:01:03 +01:00
import clsx from 'clsx';
2020-03-27 21:59:38 +01:00
import React from 'react';
2022-03-05 20:16:11 +01:00
import { useIntl, defineMessages } from 'react-intl';
2020-03-27 21:59:38 +01:00
import { Icon } from 'soapbox/components/ui';
2022-04-05 19:32:41 +02:00
import { useSoapboxConfig } from 'soapbox/hooks';
2022-03-05 20:16:11 +01:00
const messages = defineMessages({
verified: { id: 'account.verified', defaultMessage: 'Verified Account' },
});
interface IVerificationBadge {
className?: string
}
2022-04-05 19:32:41 +02:00
const VerificationBadge: React.FC<IVerificationBadge> = ({ className }) => {
2022-03-05 20:16:11 +01:00
const intl = useIntl();
2022-04-05 19:32:41 +02:00
const soapboxConfig = useSoapboxConfig();
2022-03-05 20:16:11 +01:00
2022-03-05 20:55:41 +01:00
// Prefer a custom icon if found
const icon = soapboxConfig.verifiedIcon || require('soapbox/assets/icons/verified.svg');
2022-03-05 20:55:41 +01:00
// Render component based on file extension
2022-03-21 19:09:01 +01:00
const Element = icon.endsWith('.svg') ? Icon : 'img';
2022-03-05 20:55:41 +01:00
2022-03-05 20:16:11 +01:00
return (
2022-05-17 19:10:40 +02:00
<span className='verified-icon' data-testid='verified-badge'>
2023-02-06 19:01:03 +01:00
<Element className={clsx('w-4 text-accent-500', className)} src={icon} alt={intl.formatMessage(messages.verified)} />
2022-03-05 20:16:11 +01:00
</span>
);
};
2020-03-27 21:59:38 +01:00
export default VerificationBadge;