-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
apps/nextjs-app/src/features/app/components/MenuDeleteItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Trash2 } from '@teable/icons'; | ||
import { Button, DropdownMenuItem, cn } from '@teable/ui-lib/shadcn'; | ||
import { useTranslation } from 'next-i18next'; | ||
import React, { useState } from 'react'; | ||
|
||
interface IMenuDeleteItemProps { | ||
children?: React.ReactNode | React.ReactNode[]; | ||
onConfirm?: () => void; | ||
text?: { | ||
confirmButton?: string; | ||
cancelButton?: string; | ||
}; | ||
} | ||
|
||
export const MenuDeleteItem = React.forwardRef< | ||
React.ElementRef<typeof DropdownMenuItem>, | ||
IMenuDeleteItemProps | ||
>((props, ref) => { | ||
const [deleteAlter, setDeleteAlter] = useState(false); | ||
const { onConfirm, children, text } = props; | ||
const { t } = useTranslation('common'); | ||
|
||
const { confirmButton = t('actions.yesDelete'), cancelButton = t('actions.cancel') } = text ?? {}; | ||
return ( | ||
<div className="relative overflow-hidden"> | ||
<DropdownMenuItem | ||
ref={ref} | ||
className="text-destructive focus:bg-destructive/20 focus:text-destructive dark:focus:bg-destructive dark:focus:text-foreground" | ||
onClick={(e) => { | ||
setDeleteAlter(true); | ||
e.preventDefault(); | ||
}} | ||
> | ||
{children ?? ( | ||
<> | ||
<Trash2 className="mr-1.5" /> | ||
{t('actions.delete')} | ||
</> | ||
)} | ||
</DropdownMenuItem> | ||
<div | ||
className={cn( | ||
'absolute size-full flex bottom-0 items-center gap-1 justify-between bg-background translate-y-full transition-transform', | ||
{ | ||
'translate-y-0': deleteAlter, | ||
} | ||
)} | ||
> | ||
<Button className="flex-1 px-1.5" variant={'destructive'} size={'xs'} onClick={onConfirm}> | ||
{confirmButton} | ||
</Button> | ||
<Button | ||
className="flex-1 px-1.5" | ||
variant={'outline'} | ||
size={'xs'} | ||
onClick={() => setDeleteAlter(false)} | ||
> | ||
{cancelButton} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
MenuDeleteItem.displayName = 'MenuDeleteItem'; |