Search code examples
reactjsadmin-on-rest

Custom title with image in admin on rest


I'm using admin-on-rest to build our next dashboard. I'd like to be able to add a logo/image in the header in front of the title. Would this involve a custom theme, or is there a less invasive way of doing this?


Solution

  • I found the answer to this and thought I'd share it on stackoverflow for the next developer facing this question.

    The title prop on <Admin /> accepts a node. So this works:

    import {Admin} from 'admin-on-rest';
    
    const App = () => (
      <Admin title={<AppTitle />}>
        // Resources
      </Admin>
    );
    
    // Default styles
    const appTitleStyles = {
      whiteSpace        : 'nowrap',
      overflow          : 'hidden',
      WebkitTextOverflow: 'ellipsis',
      textOverflow      : 'ellipsis',
      margin            : 0,
      letterSpacing     : 0,
      fontSize          : 24,
      fontWeight        : '400',
      color             : 'rgb(255, 255, 255)',
      height            : 44,
      paddingTop        : 10,
      paddingBottom     : 10,
      WebkitFlex        : '1 1 0%',
      MsFlex            : '1 1 0%',
      flex              : '1 1 0%'
    };
    
    const AppTitle = () => (
      <img style={appTitleStyles} src="./my-cool-logo.png" />
    );
    
    export default App;