2024-08-21 21:36:02 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-20 18:10:34 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
2024-08-22 22:41:29 +03:00
|
|
|
|
2025-03-12 12:04:23 +03:00
|
|
|
import { MiniButton } from '../control';
|
2025-02-22 14:03:13 +03:00
|
|
|
import { type Styling, type Titled } from '../props';
|
2024-08-21 21:36:02 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface ValueIconProps extends Styling, 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;
|
|
|
|
|
|
|
|
/** Callback to be called when the component is clicked. */
|
2025-02-22 14:03:13 +03:00
|
|
|
onClick?: (event: React.MouseEvent<Element>) => void;
|
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.
|
|
|
|
*/
|
2025-02-07 10:53:49 +03:00
|
|
|
export function ValueIcon({
|
2024-08-21 21:36:02 +03:00
|
|
|
id,
|
|
|
|
dense,
|
|
|
|
icon,
|
2024-08-23 12:35:05 +03:00
|
|
|
value,
|
2024-08-21 21:36:02 +03:00
|
|
|
disabled = true,
|
|
|
|
title,
|
|
|
|
titleHtml,
|
|
|
|
hideTitle,
|
|
|
|
className,
|
|
|
|
onClick,
|
|
|
|
...restProps
|
2024-08-23 12:35:05 +03:00
|
|
|
}: ValueIconProps) {
|
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',
|
2025-03-13 01:14:47 +03:00
|
|
|
dense ? 'gap-1' : 'justify-between gap-6',
|
2024-08-23 12:35:05 +03:00
|
|
|
className
|
|
|
|
)}
|
2024-08-21 21:36:02 +03:00
|
|
|
{...restProps}
|
2025-02-20 18:10:34 +03:00
|
|
|
data-tooltip-id={!!title || !!titleHtml ? globalIDs.tooltip : undefined}
|
2024-08-22 22:41:29 +03:00
|
|
|
data-tooltip-html={titleHtml}
|
|
|
|
data-tooltip-content={title}
|
|
|
|
data-tooltip-hidden={hideTitle}
|
2025-03-20 14:41:48 +03:00
|
|
|
aria-label={title}
|
2024-08-21 21:36:02 +03:00
|
|
|
>
|
2025-03-20 14:41:48 +03:00
|
|
|
{onClick ? <MiniButton noHover noPadding icon={icon} onClick={onClick} disabled={disabled} /> : icon}
|
|
|
|
<span id={id}>{value}</span>
|
2024-08-21 21:36:02 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|