generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #557 from captain-Akshay/master
feat(button): action button
- Loading branch information
Showing
10 changed files
with
136 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Grow as MuiGrow, GrowProps as MuiGrowProps } from '@mui/material'; | ||
|
||
export function Grow(props: MuiGrowProps): JSX.Element { | ||
return <MuiGrow {...props} />; | ||
} |
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 @@ | ||
export { Grow } from './Grow'; |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as React from 'react'; | ||
import { | ||
Button, | ||
ButtonGroup, | ||
ClickAwayListener, | ||
MenuItem, | ||
MenuList, | ||
Paper, | ||
Popper | ||
} from '../../base'; | ||
import { DropDownIcon } from '../../icons'; | ||
interface Option { | ||
icon: React.ReactNode; | ||
label: string; | ||
onClick: (event: React.MouseEvent<HTMLLIElement, MouseEvent>, index: number) => void; | ||
} | ||
|
||
interface ActionButtonProps { | ||
defaultActionClick: () => void; | ||
options: Option[]; | ||
label: string; | ||
} | ||
|
||
export default function ActionButton({ | ||
defaultActionClick, | ||
options, | ||
label | ||
}: ActionButtonProps): JSX.Element { | ||
const [open, setOpen] = React.useState(false); | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
const handleMenuItemClick = () => { | ||
setOpen(false); | ||
}; | ||
|
||
const handleToggle = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
event.stopPropagation(); | ||
setAnchorEl(event.currentTarget); | ||
setOpen((prevOpen) => !prevOpen); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<ButtonGroup | ||
variant="contained" | ||
style={{ boxShadow: 'none' }} | ||
aria-label="Button group with a nested menu" | ||
> | ||
<Button onClick={defaultActionClick} variant="contained"> | ||
{label} | ||
</Button> | ||
<Button size="small" onClick={handleToggle} variant="contained"> | ||
<DropDownIcon /> | ||
</Button> | ||
</ButtonGroup> | ||
<Popper | ||
sx={{ | ||
zIndex: 1 | ||
}} | ||
open={open} | ||
anchorEl={anchorEl} | ||
role={undefined} | ||
> | ||
<Paper> | ||
<ClickAwayListener onClickAway={handleClose}> | ||
<MenuList id="split-button-menu" autoFocusItem> | ||
{options.map((option, index) => ( | ||
<MenuItem | ||
key={index} | ||
onClick={(event) => { | ||
handleMenuItemClick(); | ||
option.onClick(event, index); | ||
}} | ||
> | ||
<div style={{ marginRight: '1rem' }}>{option.icon}</div> | ||
{option.label} | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</ClickAwayListener> | ||
</Paper> | ||
</Popper> | ||
</React.Fragment> | ||
); | ||
} |
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,3 @@ | ||
import ActionButton from './ActionButton'; | ||
|
||
export { ActionButton }; |
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
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,23 @@ | ||
import { DEFAULT_HEIGHT, DEFAULT_WIDTH } from '../../constants/constants'; | ||
import { IconProps } from '../types'; | ||
|
||
export const DropDownIcon = ({ | ||
width = DEFAULT_WIDTH, | ||
height = DEFAULT_HEIGHT, | ||
...props | ||
}: IconProps): JSX.Element => { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="-6.5 0 32 32" | ||
width={width} | ||
height={height} | ||
fill={props.fill || 'currentColor'} | ||
{...props} | ||
> | ||
<path d="M18.813 11.406l-7.906 9.906c-0.75 0.906-1.906 0.906-2.625 0l-7.906-9.906c-0.75-0.938-0.375-1.656 0.781-1.656h16.875c1.188 0 1.531 0.719 0.781 1.656z"></path> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default DropDownIcon; |
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 @@ | ||
export { default as DropDownIcon } from './DropDownIcon'; |
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