-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 #6433 from marmelab/simple-form-iterator-reorder
Add support for reordering items in SimpleFormIterator
- Loading branch information
Showing
11 changed files
with
370 additions
and
154 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
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
51 changes: 51 additions & 0 deletions
51
packages/ra-ui-materialui/src/button/IconButtonWithTooltip.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,51 @@ | ||
import * as React from 'react'; | ||
import { MouseEvent } from 'react'; | ||
import { IconButton, IconButtonProps, Tooltip } from '@material-ui/core'; | ||
import { useTranslate } from 'ra-core'; | ||
|
||
/** | ||
* An IconButton with a tooltip which ensures the tooltip is closed on click to avoid ghost tooltips | ||
* when the button position changes. | ||
*/ | ||
export const IconButtonWithTooltip = ({ | ||
label, | ||
onClick, | ||
...props | ||
}: IconButtonWithTooltipProps) => { | ||
const translate = useTranslate(); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
|
||
const translatedLabel = translate(label, { _: label }); | ||
|
||
const handleClick = (event: MouseEvent<HTMLButtonElement>) => { | ||
handleClose(); | ||
onClick(event); | ||
}; | ||
|
||
return ( | ||
<Tooltip | ||
title={translatedLabel} | ||
open={open} | ||
onOpen={handleOpen} | ||
onClose={handleClose} | ||
> | ||
<IconButton | ||
aria-label={translatedLabel} | ||
onClick={handleClick} | ||
{...props} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export interface IconButtonWithTooltipProps extends IconButtonProps { | ||
label: string; | ||
} |
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
Oops, something went wrong.