-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add types for button components #4071
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,13 +1,13 @@ | ||
import React from 'react'; | ||
import React, { FC, ReactElement } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import onlyUpdateForKeys from 'recompose/onlyUpdateForKeys'; | ||
import { Fab, makeStyles, useMediaQuery } from '@material-ui/core'; | ||
import { Fab, makeStyles, useMediaQuery, Theme } from '@material-ui/core'; | ||
import ContentAdd from '@material-ui/icons/Add'; | ||
import classnames from 'classnames'; | ||
import { Link } from 'react-router-dom'; | ||
import { useTranslate } from 'ra-core'; | ||
|
||
import Button from './Button'; | ||
import Button, { ButtonProps } from './Button'; | ||
|
||
const useStyles = makeStyles( | ||
theme => ({ | ||
|
@@ -28,7 +28,7 @@ const useStyles = makeStyles( | |
{ name: 'RaCreateButton' } | ||
); | ||
|
||
const CreateButton = ({ | ||
const CreateButton: FC<CreateButtonProps> = ({ | ||
basePath = '', | ||
className, | ||
classes: classesOverride, | ||
|
@@ -38,15 +38,17 @@ const CreateButton = ({ | |
}) => { | ||
const classes = useStyles({ classes: classesOverride }); | ||
const translate = useTranslate(); | ||
const isSmall = useMediaQuery(theme => theme.breakpoints.down('sm')); | ||
const isSmall = useMediaQuery((theme: Theme) => | ||
theme.breakpoints.down('sm') | ||
); | ||
return isSmall ? ( | ||
<Fab | ||
component={Link} | ||
color="primary" | ||
className={classnames(classes.floating, className)} | ||
to={`${basePath}/create`} | ||
aria-label={label && translate(label)} | ||
{...rest} | ||
{...rest as any} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to disable type checking here because of a material-ui bug: |
||
> | ||
{icon} | ||
</Fab> | ||
|
@@ -56,20 +58,26 @@ const CreateButton = ({ | |
to={`${basePath}/create`} | ||
className={className} | ||
label={label} | ||
{...rest} | ||
{...rest as any} | ||
> | ||
{icon} | ||
</Button> | ||
); | ||
}; | ||
|
||
interface Props { | ||
basePath: string; | ||
icon?: ReactElement; | ||
} | ||
|
||
export type CreateButtonProps = Props & ButtonProps; | ||
|
||
CreateButton.propTypes = { | ||
basePath: PropTypes.string, | ||
className: PropTypes.string, | ||
classes: PropTypes.object, | ||
label: PropTypes.string, | ||
size: PropTypes.string, | ||
className: PropTypes.string, | ||
icon: PropTypes.element, | ||
label: PropTypes.string, | ||
}; | ||
|
||
const enhance = onlyUpdateForKeys(['basePath', 'label', 'translate']); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { FC, ReactElement, SyntheticEvent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Record, RedirectionSideEffect } from 'ra-core'; | ||
|
||
import { ButtonProps } from './Button'; | ||
import DeleteWithUndoButton from './DeleteWithUndoButton'; | ||
import DeleteWithConfirmButton from './DeleteWithConfirmButton'; | ||
|
||
const DeleteButton: FC<DeleteButtonProps> = ({ undoable, ...props }) => | ||
undoable ? ( | ||
<DeleteWithUndoButton {...props} /> | ||
) : ( | ||
<DeleteWithConfirmButton {...props} /> | ||
); | ||
|
||
interface Props { | ||
basePath: string; | ||
classes?: object; | ||
className?: string; | ||
icon?: ReactElement; | ||
label?: string; | ||
onClick?: (e: MouseEvent) => void; | ||
record?: Record; | ||
redirect?: RedirectionSideEffect; | ||
resource?: string; | ||
// May be injected by Toolbar - sanitized in DeleteWithUndoButtonutton | ||
handleSubmit?: (event?: SyntheticEvent<HTMLFormElement>) => Promise<Object>; | ||
handleSubmitWithRedirect?: (redirect?: RedirectionSideEffect) => void; | ||
invalid?: boolean; | ||
pristine?: boolean; | ||
saving?: boolean; | ||
submitOnEnter?: boolean; | ||
undoable?: boolean; | ||
} | ||
|
||
export type DeleteButtonProps = Props & ButtonProps; | ||
|
||
DeleteButton.propTypes = { | ||
basePath: PropTypes.string, | ||
label: PropTypes.string, | ||
record: PropTypes.any, | ||
// @ts-ignore | ||
redirect: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.bool, | ||
PropTypes.func, | ||
]), | ||
resource: PropTypes.string, | ||
undoable: PropTypes.bool, | ||
icon: PropTypes.element, | ||
}; | ||
|
||
DeleteButton.defaultProps = { | ||
undoable: true, | ||
}; | ||
|
||
export default DeleteButton; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably extract the two first properties in a reusable interface for all our components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code is hard enough to read like that, I prefer a bit of duplication to a lot of indirection.