npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dougley/ra-treemenu

v1.0.4

Published

A tree-like menu implementation for react-admin applications.

Downloads

8

Readme

ra-treemenu

A tree-like menu implementation for react-admin.

Inspired from the official react-admin demo application, this package facilitates quick and easy integration of the menu tree in any new or existing react-admin app.

Supported react-admin versions:

  • React-Admin 3.x

Installation

Install using npm:

npm install --save @bb-tech/ra-treemenu

Basic Usage

To use ra-treemenu in your react-admin application:

  1. Create a parent resource (non-routing) with the following key in the options prop: isMenuParent = true. Remember to pass the mandatory name prop in this resource as this will be used to map the child resource to it's specified parent in the tree.
<Resource name="users" options={{ "label": "Users", "isMenuParent": true }} />
  1. Now create a child resource under this parent by mapping the menuParent option in the options props to the name of your parent resource.
<Resource name="posts" options={{ "label": "Posts", "menuParent": "users" }} />

This should give you a menu structure like below:

Examples

Here's a simple example of organising the menu into a tree-like structure:

// In App.js
import * as React from 'react';
import { Admin, Resource, Layout } from 'react-admin';
/* Import TreeMenu from the package */
import TreeMenu from '@bb-tech/ra-treemenu';

const App = () => (
    <Admin layout={(props) => <Layout {...props} menu={TreeMenu} />} >
        {/* Dummy parent resource with isMenuParent options as true */}
        <Resource name="users" options={{ "label": "Users", "isMenuParent": true }} />
        {/* Children menu items under parent */}
        <Resource name="posts" options={{ "label": "Posts", "menuParent": "users" }} />
        <Resource name="comments" options={{ "label": "Comments", "menuParent": "users" }} />
        {/* Dummy parent resource with isMenuParent options as true */}
        <Resource name="groups" options={{ "label": "Groups", "isMenuParent": true }} />
        {/* Children menu items under parent */}
        <Resource name="members" options={{ "label": "Members", "menuParent": "groups" }} />
    </Admin>
);

export default App;

You can find an example application implementing this tree menu in the examples directory.

Advanced Recipes

Using a Custom Layout

It is completely possible to use ra-treemenu inside your custom app layout.

// In App.js
/* Import CustomLayout */
import CustomLayout from './CustomLayout';
 
const App = () => (
    <Admin layout={CustomLayout}>
        ...
    </Admin>
);

export default App;
// In CustomLayout.js
/* Import TreeMenu from the package */
import TreeMenu from '@bb-tech/ra-treemenu';
 
const CustomLayout = (props) => (
    <Layout {...props} menu={TreeMenu} />
);

export default CustomLayout;

Using Custom Icons for Resources

For icons, ra-treemenu depends upon material-ui and the defaults for the resources are:

  1. ViewListIcon: For all child resources.
  2. Label: For all parent resources (non-routing).

To use a custom icon (for a parent or a child), pass it as a prop to the <Resource> like:

<Resource name="posts" icon={CustomIcon} options={{ "label": "Posts", "menuParent": "users" }} />

License

ra-treemenu is licensed under MIT License, sponsored and supported by BigBasket Tech.