-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add type props to share and edit buttons (#676)
* feat: add type props to share and edit buttons * fix: import expect from storybook/jest * feat: add classname and id to edit button * fix: use ActionButton.icon for icon type --------- Co-authored-by: Kim Lan Phan Hoang <pyphilia@gmail.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
33 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,41 +1,59 @@ | ||
import EditIcon from '@mui/icons-material/Edit'; | ||
import { ListItemIcon, ListItemText, MenuItem } from '@mui/material'; | ||
import IconButton, { IconButtonProps } from '@mui/material/IconButton'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
|
||
import { FC, MouseEventHandler } from 'react'; | ||
|
||
import { ActionButton, ActionButtonVariant } from '../../types'; | ||
|
||
export type Props = { | ||
id?: string; | ||
className?: string; | ||
ariaLabel?: string; | ||
onClick?: MouseEventHandler; | ||
tooltip?: string; | ||
title?: string; | ||
size?: IconButtonProps['size']; | ||
type?: ActionButtonVariant; | ||
}; | ||
|
||
const EditButton: FC<Props> = ({ | ||
id, | ||
className, | ||
ariaLabel, | ||
onClick, | ||
tooltip = 'edit', | ||
title = 'Edit', | ||
size = 'small', | ||
type = ActionButton.ICON_BUTTON, | ||
}) => { | ||
return ( | ||
<Tooltip title={tooltip}> | ||
<span> | ||
<IconButton | ||
id={id} | ||
aria-label={ariaLabel} | ||
className={className} | ||
onClick={onClick} | ||
size={size} | ||
> | ||
<EditIcon /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
); | ||
switch (type) { | ||
case ActionButton.MENU_ITEM: | ||
return ( | ||
<MenuItem key={title} onClick={onClick} id={id} className={className}> | ||
<ListItemIcon> | ||
<EditIcon /> | ||
</ListItemIcon> | ||
<ListItemText>{title}</ListItemText> | ||
</MenuItem> | ||
); | ||
case ActionButton.ICON_BUTTON: | ||
default: | ||
return ( | ||
<Tooltip title={title}> | ||
<span> | ||
<IconButton | ||
id={id} | ||
aria-label={ariaLabel} | ||
className={className} | ||
onClick={onClick} | ||
size={size} | ||
> | ||
<EditIcon /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
); | ||
} | ||
}; | ||
|
||
export default EditButton; |
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
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