-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: restructure component layers for kebab button on groupcard (#…
…389) * refactor: move DialogRoot * refactor: change the name of components * docs: add to interfaces * refactor: restructure the directories * refactor: delete unnecessary code * feat: focust kebab button using useAutoFocus * docs: add docs to interface * docs: doc:fix the TSDoc * fix: typo
- Loading branch information
Showing
6 changed files
with
130 additions
and
161 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ardList/GroupCard/GroupCardContent/GroupCardDropdownMenu/GroupCardDropdownMenuContent.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,46 @@ | ||
import { IconDelete, IconPen } from '@/assets/images/icons'; | ||
import { | ||
DropdownMenuButton, | ||
DropdownMenuButtonIcon, | ||
DropdownMenuButtonText, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
Icon, | ||
} from '@/components/ui'; | ||
|
||
interface IGroupCardDropdownMenuContentProps { | ||
/** | ||
* Function to handle the rename button click. | ||
*/ | ||
handleRenameClick: () => void; | ||
/** | ||
* The function to close the dropdown menu. | ||
*/ | ||
handleDeleteClick: () => void; | ||
} | ||
|
||
export const GroupCardDropdownMenuContent = ({ | ||
handleRenameClick, | ||
handleDeleteClick, | ||
}: IGroupCardDropdownMenuContentProps) => { | ||
return ( | ||
<DropdownMenuContent> | ||
<DropdownMenuItem asChild> | ||
<DropdownMenuButton onClick={handleRenameClick}> | ||
<DropdownMenuButtonIcon> | ||
<Icon icon={IconPen} size={5} color="primary" /> | ||
</DropdownMenuButtonIcon> | ||
<DropdownMenuButtonText>Rename</DropdownMenuButtonText> | ||
</DropdownMenuButton> | ||
</DropdownMenuItem> | ||
<DropdownMenuItem asChild> | ||
<DropdownMenuButton onClick={handleDeleteClick}> | ||
<DropdownMenuButtonIcon> | ||
<Icon icon={IconDelete} size={5} color="danger" /> | ||
</DropdownMenuButtonIcon> | ||
<DropdownMenuButtonText>Delete</DropdownMenuButtonText> | ||
</DropdownMenuButton> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
...roups/components/GroupCardList/GroupCard/GroupCardContent/GroupCardDropdownMenu/index.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,63 @@ | ||
'use client'; | ||
import { IconMenuKebab } from '@/assets/images/icons'; | ||
import { Button, DialogRoot, DropdownMenu, DropdownMenuTrigger, Icon } from '@/components/ui'; | ||
import { DeleteGroupDialogContent } from '@/features/groups/components/DeleteGroupDialogContent'; | ||
import { useAutoFocus } from '@/hooks'; | ||
import { IGroup } from '@/types/definition'; | ||
|
||
import { useState } from 'react'; | ||
|
||
import { GroupCardDropdownMenuContent } from './GroupCardDropdownMenuContent'; | ||
|
||
interface IGroupCardMenuButtonProps { | ||
/** | ||
* The ID of the group to be deleted. | ||
*/ | ||
groupId: IGroup['id']; | ||
/** | ||
* Function to handle the rename button click. | ||
*/ | ||
handleRenameClick: () => void; | ||
/** | ||
* A state of renaming input field to be opened (=true) or closed(=false) | ||
*/ | ||
isRenameFormOpen: boolean; | ||
} | ||
|
||
export const GroupCardDropdownMenu = ({ | ||
groupId, | ||
handleRenameClick, | ||
isRenameFormOpen, | ||
}: IGroupCardMenuButtonProps) => { | ||
const [isDropdownMenuOpen, setIsDropdownMenuOpen] = useState(false); | ||
const [isDeleteGroupDialogOpen, setIsDeleteGroupDialogOpen] = useState(false); | ||
|
||
const kebabRef = useAutoFocus<HTMLButtonElement>(!isDeleteGroupDialogOpen && !isRenameFormOpen); | ||
|
||
const handleDeleteClick = () => { | ||
setIsDropdownMenuOpen(false); | ||
setIsDeleteGroupDialogOpen(true); | ||
}; | ||
return ( | ||
<> | ||
<DropdownMenu open={isDropdownMenuOpen} onOpenChange={setIsDropdownMenuOpen}> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="ghost" className="w-12" ref={kebabRef}> | ||
<Icon icon={IconMenuKebab} size={4.5} /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<GroupCardDropdownMenuContent | ||
handleRenameClick={handleRenameClick} | ||
handleDeleteClick={handleDeleteClick} | ||
/> | ||
</DropdownMenu> | ||
<DialogRoot open={isDeleteGroupDialogOpen} onOpenChange={setIsDeleteGroupDialogOpen}> | ||
<DeleteGroupDialogContent | ||
groupId={groupId} | ||
onParentClose={() => setIsDropdownMenuOpen(false)} | ||
onDialogClose={() => setIsDeleteGroupDialogOpen(false)} | ||
/> | ||
</DialogRoot> | ||
</> | ||
); | ||
}; |
51 changes: 0 additions & 51 deletions
51
...wnMenuTriggerButton/GroupCardDropdownMenuContent/DeleteGroupDialogTriggerButton/index.tsx
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
...roupCardContent/GroupCardDropdownMenuTriggerButton/GroupCardDropdownMenuContent/index.tsx
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...nts/GroupCardList/GroupCard/GroupCardContent/GroupCardDropdownMenuTriggerButton/index.tsx
This file was deleted.
Oops, something went wrong.
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