2022-11-25 20:25:03 +00:00
|
|
|
import type { IconDefinition } from '@fortawesome/free-solid-svg-icons';
|
2022-06-20 21:26:47 +00:00
|
|
|
import classNames from 'classnames';
|
2022-11-25 20:25:03 +00:00
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
import { useFitText } from '@flyyer/use-fit-text';
|
|
|
|
|
2022-06-27 23:18:58 +00:00
|
|
|
import CopyOnClick from '@/components/elements/CopyOnClick';
|
2022-11-25 20:25:03 +00:00
|
|
|
import Icon from '@/components/elements/Icon';
|
|
|
|
|
|
|
|
import styles from './style.module.css';
|
2022-06-20 21:26:47 +00:00
|
|
|
|
|
|
|
interface StatBlockProps {
|
|
|
|
title: string;
|
2022-06-27 23:18:58 +00:00
|
|
|
copyOnClick?: string;
|
2022-06-20 21:26:47 +00:00
|
|
|
color?: string | undefined;
|
|
|
|
icon: IconDefinition;
|
2022-11-25 20:25:03 +00:00
|
|
|
children: ReactNode;
|
2022-06-21 22:43:59 +00:00
|
|
|
className?: string;
|
2022-06-20 21:26:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
function StatBlock({ title, copyOnClick, icon, color, className, children }: StatBlockProps) {
|
2022-06-26 01:27:18 +00:00
|
|
|
const { fontSize, ref } = useFitText({ minFontSize: 8, maxFontSize: 500 });
|
|
|
|
|
2022-06-20 21:26:47 +00:00
|
|
|
return (
|
2022-06-28 00:14:55 +00:00
|
|
|
<CopyOnClick text={copyOnClick}>
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={classNames(styles.stat_block, 'bg-slate-600', className)}>
|
|
|
|
<div className={classNames(styles.status_bar, color || 'bg-slate-700')} />
|
|
|
|
<div className={classNames(styles.icon, color || 'bg-slate-700')}>
|
2022-06-27 23:56:26 +00:00
|
|
|
<Icon
|
|
|
|
icon={icon}
|
|
|
|
className={classNames({
|
2022-12-16 02:06:14 +00:00
|
|
|
'text-slate-100': !color || color === 'bg-slate-700',
|
|
|
|
'text-slate-50': color && color !== 'bg-slate-700',
|
2022-06-27 23:56:26 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-01-12 19:31:47 +00:00
|
|
|
<div className={'flex w-full flex-col justify-center overflow-hidden'}>
|
|
|
|
<p className={'font-header text-xs leading-tight text-slate-200 md:text-sm'}>{title}</p>
|
2022-06-28 00:14:55 +00:00
|
|
|
<div
|
|
|
|
ref={ref}
|
2023-01-12 19:31:47 +00:00
|
|
|
className={'h-[1.75rem] w-full truncate font-semibold text-slate-50'}
|
2022-06-28 00:14:55 +00:00
|
|
|
style={{ fontSize }}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
2022-06-20 21:26:47 +00:00
|
|
|
</div>
|
2022-06-27 23:56:26 +00:00
|
|
|
</div>
|
2022-06-28 00:14:55 +00:00
|
|
|
</CopyOnClick>
|
2022-06-20 21:26:47 +00:00
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default StatBlock;
|