mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-31 17:03:24 +00:00
* inital Tooltip implementation and test * style(tooltip): L/R sidePanel and Nav * style(tooltip): unarchive button; refactor: `useArchiveHandler` and `ArchiveButton` * style(tooltip): Delete button * refactor: remove unused className prop in DeleteButton component * style(tooltip): finish final tooltip and fix bookmark edit and delete button * refactor(ui): remove TooltipTest and DropDownMenu component and unused imports * style: update mobile UI * fix: sidePanel icon not showing * feat(AttachFile): add tooltip * fix(NavToggle): remove button without this button, kb users don't have to manually press 2 times to change the focus Also, tooltips with buttons focus don't trigger * fix: right side panel issue with double button * fix: merge issues * fix: sharedLink table issue * chore: update ariakit and framer-motion version * a11y: kb toggle for sidebar * feat: tooltip for some buttons
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import { useCallback, useState } from 'react';
|
|
import type { FC } from 'react';
|
|
import { Label, OGDialog, OGDialogTrigger, TooltipAnchor } from '~/components/ui';
|
|
import { useDeleteConversationTagMutation } from '~/data-provider';
|
|
import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
|
|
import { NotificationSeverity } from '~/common';
|
|
import { useToastContext } from '~/Providers';
|
|
import { TrashIcon } from '~/components/svg';
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
const DeleteBookmarkButton: FC<{
|
|
bookmark: string;
|
|
tabIndex?: number;
|
|
onFocus?: () => void;
|
|
onBlur?: () => void;
|
|
}> = ({ bookmark, tabIndex = 0, onFocus, onBlur }) => {
|
|
const localize = useLocalize();
|
|
const { showToast } = useToastContext();
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const deleteBookmarkMutation = useDeleteConversationTagMutation({
|
|
onSuccess: () => {
|
|
showToast({
|
|
message: localize('com_ui_bookmarks_delete_success'),
|
|
});
|
|
},
|
|
onError: () => {
|
|
showToast({
|
|
message: localize('com_ui_bookmarks_delete_error'),
|
|
severity: NotificationSeverity.ERROR,
|
|
});
|
|
},
|
|
});
|
|
|
|
const confirmDelete = useCallback(async () => {
|
|
await deleteBookmarkMutation.mutateAsync(bookmark);
|
|
}, [bookmark, deleteBookmarkMutation]);
|
|
|
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
setOpen(!open);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<OGDialog open={open} onOpenChange={setOpen}>
|
|
<OGDialogTrigger asChild>
|
|
<TooltipAnchor
|
|
description={localize('com_ui_delete')}
|
|
className="flex size-7 cursor-pointer items-center justify-center rounded-lg transition-colors duration-200 hover:bg-surface-hover"
|
|
tabIndex={tabIndex}
|
|
onFocus={onFocus}
|
|
onBlur={onBlur}
|
|
onClick={() => setOpen(!open)}
|
|
onKeyDown={handleKeyDown}
|
|
>
|
|
<TrashIcon className="size-4" />
|
|
</TooltipAnchor>
|
|
</OGDialogTrigger>
|
|
<OGDialogTemplate
|
|
showCloseButton={false}
|
|
title={localize('com_ui_bookmarks_delete')}
|
|
className="max-w-[450px]"
|
|
main={
|
|
<Label className="text-left text-sm font-medium">
|
|
{localize('com_ui_bookmark_delete_confirm')} {bookmark}
|
|
</Label>
|
|
}
|
|
selection={{
|
|
selectHandler: confirmDelete,
|
|
selectClasses:
|
|
'bg-red-700 dark:bg-red-600 hover:bg-red-800 dark:hover:bg-red-800 text-white',
|
|
selectText: localize('com_ui_delete'),
|
|
}}
|
|
/>
|
|
</OGDialog>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default DeleteBookmarkButton;
|