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

Feature: Confirm Dialog's content prop can receive React.ReactNode #5954

Merged
merged 2 commits into from
Mar 15, 2021
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 @@ -404,7 +404,7 @@ export default ResetViewsButton;

**Tip**: `<Confirm>` leverages material-ui's `<Dialog>` component to implement a confirmation popup. Feel free to use it in your admins!

**Tip**: `<Confirm>` text props such as `title` and `content` are translatable. You can pass use translation keys in these props.
**Tip**: `<Confirm>` text props such as `title` and `content` are translatable. You can pass use translation keys in these props. Note: `content` is only translateable when value is `string`, otherwise it renders the content as a `ReactNode`.

**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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const sanitizeRestProps = ({
export interface BulkDeleteWithConfirmButtonProps
extends BulkActionProps,
ButtonProps {
confirmContent?: string;
confirmContent?: React.ReactNode;
confirmTitle?: string;
icon?: ReactElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interface Props {
classes?: object;
className?: string;
confirmTitle?: string;
confirmContent?: string;
confirmContent?: React.ReactNode;
icon?: ReactElement;
label?: string;
mutationMode?: MutationMode;
Expand Down
20 changes: 12 additions & 8 deletions packages/ra-ui-materialui/src/layout/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ const Confirm: FC<ConfirmProps> = props => {
{translate(title, { _: title, ...translateOptions })}
</DialogTitle>
<DialogContent>
<DialogContentText>
{translate(content, {
_: content,
...translateOptions,
})}
</DialogContentText>
{typeof content === 'string' ? (
<DialogContentText>
{translate(content, {
_: content,
...translateOptions,
})}
</DialogContentText>
) : (
content
)}
</DialogContent>
<DialogActions>
<Button disabled={loading} onClick={onClose}>
Expand Down Expand Up @@ -130,7 +134,7 @@ export interface ConfirmProps {
confirmColor?: string;
ConfirmIcon?: ReactComponentLike;
CancelIcon?: ReactComponentLike;
content: string;
content: React.ReactNode;
isOpen?: boolean;
loading?: boolean;
onClose: MouseEventHandler;
Expand All @@ -146,7 +150,7 @@ Confirm.propTypes = {
confirmColor: PropTypes.string,
ConfirmIcon: PropTypes.elementType,
CancelIcon: PropTypes.elementType,
content: PropTypes.string.isRequired,
content: PropTypes.node.isRequired,
isOpen: PropTypes.bool,
loading: PropTypes.bool,
onClose: PropTypes.func.isRequired,
Expand Down