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

Any example of adding Side Menu using recursion. #48

Open
duttarnab opened this issue May 10, 2021 · 0 comments
Open

Any example of adding Side Menu using recursion. #48

duttarnab opened this issue May 10, 2021 · 0 comments

Comments

@duttarnab
Copy link

duttarnab commented May 10, 2021

I have parent-child menus for example:

{
            icon: 'fa-gears', label: 'Services', children: [
                { label: 'Acrs', component: AcrsPage, path: '/config/acrs' },
                { label: 'Cache', component: CachePage, path: '/config/cache' },
                { label: 'Jwks', component: JwksPage, path: '/config/jwks' },
                {
                    icon: 'fa-database', label: 'Persistence', children: [
                        { label: 'Ldap Edit', component: LdapEditPage, path: '/config/ldap/edit:configId' },
                        { label: 'Ldap Add', component: LdapAddPage, path: '/config/ldap/new' },
                        { label: 'Ldap', component: LdapListPage, path: '/config/ldap' },
                        { label: 'Couchbase', component: CouchbasePage, path: '/config/couchbase' }
                    ]
                }
            ]
        }

Is there any example where we can arrange the menus using recursion?
I tried with the below component, although it arranges menu but shows every item as parent menu (even if there is no child item to it.)

import React from 'react'
import { SidebarMenu, Divider } from '../'

export const SidebarMenusRecursiveWrapper = ({ item }) => {

    const { label, path, children = [], icon = '' } = item;

    function getIcon(name) {
        let fullName = ''
        if (name) {
            fullName = 'fa fa-fw ' + name
            return <i className={fullName}></i>
        }
        return ''
    }
    return (
        !!label &&
        <SidebarMenu>
            {children.length > 0 ? (
                <SidebarMenu.Item
                    icon={getIcon(icon)}
                    title={label}>
                    {children.map((child, i) => {
                        return (
                            <SidebarMenusRecursiveWrapper key={i} item={child} />
                        );
                    })}
                </SidebarMenu.Item>
            ) : (
                    <SidebarMenu.Item
                        icon={getIcon(icon)}
                        title={label}
                        to={path}
                    />
                )
            }
        </SidebarMenu>
    );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant