2024-08-21 21:36:02 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-01-28 23:23:03 +03:00
|
|
|
import { CProps } from '@/components/props';
|
2024-08-22 22:41:29 +03:00
|
|
|
import { globals } from '@/utils/constants';
|
|
|
|
|
2024-08-21 21:36:02 +03:00
|
|
|
import MiniButton from './MiniButton';
|
|
|
|
|
2024-08-23 12:35:05 +03:00
|
|
|
interface ValueIconProps extends CProps.Styling, CProps.Titled {
|
2024-11-21 15:09:31 +03:00
|
|
|
/** Id of the component. */
|
2024-08-21 21:36:02 +03:00
|
|
|
id?: string;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Value to display. */
|
2024-08-21 21:36:02 +03:00
|
|
|
value: string | number;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Icon to display. */
|
|
|
|
icon: React.ReactNode;
|
|
|
|
|
|
|
|
/** Classname for the text. */
|
2024-08-23 12:35:05 +03:00
|
|
|
textClassName?: string;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Callback to be called when the component is clicked. */
|
2024-08-21 21:36:02 +03:00
|
|
|
onClick?: (event: CProps.EventMouse) => void;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Number of symbols to display in a small size. */
|
2024-08-23 12:35:05 +03:00
|
|
|
smallThreshold?: number;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Indicates that padding should be minimal. */
|
2024-08-21 21:36:02 +03:00
|
|
|
dense?: boolean;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Disable interaction. */
|
2024-08-21 21:36:02 +03:00
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:31 +03:00
|
|
|
/**
|
|
|
|
* Displays a value with an icon that can be clicked.
|
|
|
|
*/
|
2024-08-23 12:35:05 +03:00
|
|
|
function ValueIcon({
|
2024-08-21 21:36:02 +03:00
|
|
|
id,
|
|
|
|
dense,
|
|
|
|
icon,
|
2024-08-23 12:35:05 +03:00
|
|
|
value,
|
|
|
|
textClassName,
|
2024-08-21 21:36:02 +03:00
|
|
|
disabled = true,
|
|
|
|
title,
|
|
|
|
titleHtml,
|
|
|
|
hideTitle,
|
|
|
|
className,
|
2024-08-23 12:35:05 +03:00
|
|
|
smallThreshold,
|
2024-08-21 21:36:02 +03:00
|
|
|
onClick,
|
|
|
|
...restProps
|
2024-08-23 12:35:05 +03:00
|
|
|
}: ValueIconProps) {
|
2024-12-13 21:30:49 +03:00
|
|
|
// TODO: use CSS instead of threshold
|
|
|
|
const isSmall = !smallThreshold || String(value).length < smallThreshold;
|
2024-08-21 21:36:02 +03:00
|
|
|
return (
|
|
|
|
<div
|
2024-08-23 12:35:05 +03:00
|
|
|
className={clsx(
|
|
|
|
'flex items-center',
|
|
|
|
'text-right',
|
|
|
|
'hover:cursor-default',
|
|
|
|
{ 'justify-between gap-6': !dense, 'gap-1': dense },
|
|
|
|
className
|
|
|
|
)}
|
2024-08-21 21:36:02 +03:00
|
|
|
{...restProps}
|
2024-08-22 22:41:29 +03:00
|
|
|
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
|
|
|
|
data-tooltip-html={titleHtml}
|
|
|
|
data-tooltip-content={title}
|
|
|
|
data-tooltip-hidden={hideTitle}
|
2024-08-21 21:36:02 +03:00
|
|
|
>
|
2024-08-22 22:41:29 +03:00
|
|
|
<MiniButton noHover noPadding icon={icon} disabled={disabled} onClick={onClick} />
|
2024-08-23 12:35:05 +03:00
|
|
|
<span id={id} className={clsx({ 'text-xs': !isSmall }, textClassName)}>
|
2024-08-22 21:38:59 +03:00
|
|
|
{value}
|
|
|
|
</span>
|
2024-08-21 21:36:02 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-23 12:35:05 +03:00
|
|
|
export default ValueIcon;
|