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

Fix useNotify types #9529

Merged
merged 2 commits into from
Dec 15, 2023
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/useNotify.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The hook takes no argument and returns a callback. The callback takes 2 argument
- `type`: The notification type (`info`, `success`, `error` or `warning` - the default is `info`)
- `messageArgs`: options to pass to the `translate` function (because notification messages are translated if your admin has an `i18nProvider`). It is useful for inserting variables into the translation.
- `undoable`: Set it to `true` if the notification should contain an "undo" button
- `autoHideDuration`: Duration (in milliseconds) after which the notification hides. Set it to `0` if the notification should not be dismissible.
- `autoHideDuration`: Duration (in milliseconds) after which the notification hides. Set it to `null` if the notification should not be dismissible.
- `multiLine`: Set it to `true` if the notification message should be shown in more than one line.
- `anchorOrigin`: The position of the notification. The default is `{ vertical: 'top', horizontal: 'right' }`. See [the Material UI documentation](https://mui.com/material-ui/react-snackbar/) for more details.

Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/notification/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ReactNode } from 'react';
export type NotificationType = 'success' | 'info' | 'warning' | 'error';

export interface NotificationOptions {
// The duration in milliseconds the notification is shown
autoHideDuration?: number;
// The duration in milliseconds the notification is shown (pass null to disable auto hide)
autoHideDuration?: number | null;
// Arguments used to translate the message
messageArgs?: any;
// If true, the notification shows the message in multiple lines
Expand Down
14 changes: 14 additions & 0 deletions packages/ra-ui-materialui/src/layout/Notification.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ export const AutoHideDuration = () => (
</Wrapper>
);

const NoAutoHideNotification = () => {
const notify = useNotify();
React.useEffect(() => {
notify('hello, world', { autoHideDuration: null });
}, [notify]);
return null;
};

export const NoAutoHide = () => (
<Wrapper>
<NoAutoHideNotification />
</Wrapper>
);

const UndoableNotification = () => {
const notify = useNotify();
React.useEffect(() => {
Expand Down
Loading