2022-06-20 21:26:47 +00:00
|
|
|
import React from 'react';
|
|
|
|
import Icon from '@/components/elements/Icon';
|
|
|
|
import { IconDefinition } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
2022-06-21 22:43:59 +00:00
|
|
|
import styles from './style.module.css';
|
2022-06-26 01:27:18 +00:00
|
|
|
import useFitText from 'use-fit-text';
|
2022-06-20 21:26:47 +00:00
|
|
|
|
|
|
|
interface StatBlockProps {
|
|
|
|
title: string;
|
|
|
|
description?: string;
|
|
|
|
color?: string | undefined;
|
|
|
|
icon: IconDefinition;
|
|
|
|
children: React.ReactNode;
|
2022-06-21 22:43:59 +00:00
|
|
|
className?: string;
|
2022-06-20 21:26:47 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 22:43:59 +00:00
|
|
|
export default ({ title, icon, color, description, 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 (
|
|
|
|
<Tooltip arrow placement={'top'} disabled={!description} content={description || ''}>
|
2022-06-21 22:43:59 +00:00
|
|
|
<div className={classNames(styles.stat_block, 'bg-gray-600', className)}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<div className={classNames(styles.status_bar, color || 'bg-gray-700')} />
|
2022-06-21 22:43:59 +00:00
|
|
|
<div className={classNames(styles.icon, color || 'bg-gray-700')}>
|
2022-06-20 21:26:47 +00:00
|
|
|
<Icon
|
|
|
|
icon={icon}
|
2022-06-21 22:43:59 +00:00
|
|
|
className={classNames({
|
|
|
|
'text-gray-100': !color || color === 'bg-gray-700',
|
|
|
|
'text-gray-50': color && color !== 'bg-gray-700',
|
|
|
|
})}
|
2022-06-20 21:26:47 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-06-26 01:27:18 +00:00
|
|
|
<div className={'flex flex-col justify-center overflow-hidden w-full'}>
|
2022-06-21 22:43:59 +00:00
|
|
|
<p className={'font-header leading-tight text-xs md:text-sm text-gray-200'}>{title}</p>
|
2022-06-26 01:27:18 +00:00
|
|
|
<div
|
|
|
|
ref={ref}
|
|
|
|
className={'h-[1.75rem] w-full font-semibold text-gray-50 truncate'}
|
|
|
|
style={{ fontSize }}
|
|
|
|
>
|
2022-06-20 21:26:47 +00:00
|
|
|
{children}
|
2022-06-26 01:27:18 +00:00
|
|
|
</div>
|
2022-06-20 21:26:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|