2024-07-29 07:45:59 -07:00
|
|
|
import { ReactElement } from 'react';
|
|
|
|
|
import {
|
2024-07-29 19:25:36 -04:00
|
|
|
OGDialog,
|
|
|
|
|
OGDialogTrigger,
|
2024-07-29 07:45:59 -07:00
|
|
|
Label,
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from '~/components/ui';
|
2024-07-29 19:25:36 -04:00
|
|
|
import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
|
2024-07-29 07:45:59 -07:00
|
|
|
import { CrossIcon } from '~/components/svg';
|
|
|
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
|
|
|
|
|
|
export default function TooltipIcon({
|
|
|
|
|
disabled,
|
|
|
|
|
appendLabel = false,
|
|
|
|
|
title,
|
|
|
|
|
className = '',
|
|
|
|
|
confirm,
|
|
|
|
|
confirmMessage,
|
|
|
|
|
icon,
|
2024-07-29 19:25:36 -04:00
|
|
|
tabIndex,
|
|
|
|
|
onFocus,
|
|
|
|
|
onBlur,
|
2024-07-29 07:45:59 -07:00
|
|
|
}: {
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
title: string;
|
|
|
|
|
appendLabel?: boolean;
|
|
|
|
|
className?: string;
|
|
|
|
|
confirm?: () => void;
|
|
|
|
|
confirmMessage?: ReactElement;
|
|
|
|
|
icon?: ReactElement;
|
2024-07-29 19:25:36 -04:00
|
|
|
tabIndex?: number;
|
|
|
|
|
onFocus?: () => void;
|
|
|
|
|
onBlur?: () => void;
|
2024-07-29 07:45:59 -07:00
|
|
|
}) {
|
|
|
|
|
const localize = useLocalize();
|
|
|
|
|
|
|
|
|
|
const renderDeleteButton = () => {
|
|
|
|
|
if (appendLabel) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{icon} {localize('com_ui_delete')}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<TooltipProvider delayDuration={250}>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<span>{icon}</span>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="top" sideOffset={0}>
|
|
|
|
|
{localize('com_ui_delete')}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!confirmMessage) {
|
|
|
|
|
return (
|
2024-07-29 19:25:36 -04:00
|
|
|
<button
|
|
|
|
|
className={className}
|
|
|
|
|
onClick={confirm}
|
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
|
onFocus={onFocus}
|
|
|
|
|
onBlur={onBlur}
|
|
|
|
|
>
|
2024-07-29 07:45:59 -07:00
|
|
|
{disabled ? <CrossIcon /> : renderDeleteButton()}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
2024-07-29 19:25:36 -04:00
|
|
|
<OGDialog>
|
|
|
|
|
<OGDialogTrigger asChild>
|
|
|
|
|
<button className={className} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur}>
|
|
|
|
|
{disabled ? <CrossIcon /> : renderDeleteButton()}
|
|
|
|
|
</button>
|
|
|
|
|
</OGDialogTrigger>
|
|
|
|
|
<OGDialogTemplate
|
2024-07-29 07:45:59 -07:00
|
|
|
showCloseButton={false}
|
|
|
|
|
title={title}
|
|
|
|
|
className="max-w-[450px]"
|
2024-07-29 19:25:36 -04:00
|
|
|
main={<Label className="text-left text-sm font-medium">{confirmMessage}</Label>}
|
2024-07-29 07:45:59 -07:00
|
|
|
selection={{
|
|
|
|
|
selectHandler: confirm,
|
|
|
|
|
selectClasses:
|
|
|
|
|
'bg-red-700 dark:bg-red-600 hover:bg-red-800 dark:hover:bg-red-800 text-white',
|
|
|
|
|
selectText: localize('com_ui_delete'),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-07-29 19:25:36 -04:00
|
|
|
</OGDialog>
|
2024-07-29 07:45:59 -07:00
|
|
|
);
|
|
|
|
|
}
|