React-admin: Multi-line notification messages

后端 未结 1 1799
挽巷
挽巷 2021-01-22 08:28

How could i make react-admin to show a multi-line notification / error message on the snackbar?

Having the following dataProvider:



        
相关标签:
1条回答
  • 2021-01-22 08:52

    Ok, with the help of the docs I manage to do what i wanted. Defining a custom Layout component to be use by the App component and passing it a custom Notification component.

    // ./MyLayout.js
    import React from 'react';
    import { Layout } from 'react-admin';
    import MyNotification from "../MyNotification";
    
        
    const CustomLayout = props => (
        <Layout {...props} notification={MyNotification} />
    );
    
    export default CustomLayout;
    

    Then I pass a custom css class to the Notification component.

    // ./MyNotification.js
    import React from 'react';
    import {withStyles} from '@material-ui/core/styles';
    import {Notification} from 'react-admin';
    
    // Allow multi-line messages to be displayed
    const cssMsg = {
        snackbarContent: {
            whiteSpace: 'pre-wrap'
        }
    };
    
    const MyNotification = withStyles(cssMsg)(({classes, ...props}) => (
        <Notification {...props} className={classes.snackbarContent}/>
    ));
    
    export default MyNotification;
    

    error notification screenshot multi-line

    0 讨论(0)
提交回复
热议问题