Skip to content
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 custom icons for Confirm action buttons. #3812

Merged
merged 3 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export default ResetViewsButton;

**Tip**: `<Confirm>` text props such as `title` and `content` are translatable. You can pass use translation keys in these props.

**Tip**: You can customize the text of the two `<Confirm>` component buttons using the `cancel` and `confirm` prop which accepts translation keys too.
**Tip**: You can customize the text of the two `<Confirm>` component buttons using the `cancel` and `confirm` props which accept translation keys. You can customize the icons by setting the `ConfirmIcon` and `CancelIcon` props, which accept a SvgIcon type.

**Tip**: React-admin doesn't use the `<Confirm>` component internally, because deletes and updates are applied locally immediately, then dispatched to the server after a few seconds, unless the user chooses to undo the modification. That's what we call optimistic rendering. You can do the same for the `ResetViewsButton` by setting `undoable: true` in the last argument of `useUpdateMany()`, as follows:

Expand Down
12 changes: 10 additions & 2 deletions packages/ra-ui-materialui/src/layout/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const useStyles = makeStyles(theme => ({
* content="Are you sure you want to delete this item?"
* confirm="Yes"
* confirmColor="primary"
* ConfirmIcon=ActionCheck
* CancelIcon=AlertError
* cancel="Cancel"
* onConfirm={() => { // do something }}
* onClose={() => { // do something }}
Expand All @@ -58,6 +60,8 @@ const Confirm = ({
confirm,
cancel,
confirmColor,
ConfirmIcon,
CancelIcon,
onClose,
onConfirm,
classes: classesOverride,
Expand Down Expand Up @@ -98,7 +102,7 @@ const Confirm = ({
</DialogContent>
<DialogActions>
<Button disabled={loading} onClick={onClose}>
<AlertError className={classes.iconPaddingStyle} />
<CancelIcon className={classes.iconPaddingStyle} />
{translate(cancel, { _: cancel })}
</Button>
<Button
Expand All @@ -110,7 +114,7 @@ const Confirm = ({
})}
autoFocus
>
<ActionCheck className={classes.iconPaddingStyle} />
<ConfirmIcon className={classes.iconPaddingStyle} />
{translate(confirm, { _: confirm })}
</Button>
</DialogActions>
Expand All @@ -123,6 +127,8 @@ Confirm.propTypes = {
classes: PropTypes.object,
confirm: PropTypes.string.isRequired,
confirmColor: PropTypes.string.isRequired,
ConfirmIcon: PropTypes.elementType.isRequired,
CancelIcon: PropTypes.elementType.isRequired,
content: PropTypes.string.isRequired,
isOpen: PropTypes.bool,
loading: PropTypes.bool,
Expand All @@ -136,6 +142,8 @@ Confirm.defaultProps = {
classes: {},
confirm: 'ra.action.confirm',
confirmColor: 'primary',
ConfirmIcon: ActionCheck,
CancelIcon: AlertError,
isOpen: false,
};

Expand Down