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

Can Sidebar support more than two levels? #15

Open
eukitout-qq opened this issue Sep 11, 2024 · 2 comments
Open

Can Sidebar support more than two levels? #15

eukitout-qq opened this issue Sep 11, 2024 · 2 comments

Comments

@eukitout-qq
Copy link

Can Sidebar support more than two levels?

@djowvani
Copy link

You mean more nested/collapsible menu options, or something more like having access to another sidebar/drawer inside the original Sidebar?

@eric-net
Copy link

// Sidebar.tsx
import React, { useState } from 'react';
import { Sidebar, SidebarItem, SidebarHeader } from '@shadcn/ui';

const SubMenu: React.FC<{ title: string; items: string[] }> = ({ title, items }) => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <div>
      <div onClick={() => setIsOpen(!isOpen)} style={{ cursor: 'pointer' }}>
        {title}
      </div>
      {isOpen && (
        <div style={{ paddingLeft: '20px' }}>
          {items.map((item) => (
            <SidebarItem key={item}>
              <a href={`#${item}`}>{item}</a>
            </SidebarItem>
          ))}
        </div>
      )}
    </div>
  );
};

const MySidebar: React.FC = () => {
  return (
    <Sidebar>
      <SidebarHeader>
        <h2>Mi Sidebar</h2>
      </SidebarHeader>
      <SidebarItem>
        <a href="#item1">Item 1</a>
      </SidebarItem>
      <SubMenu title="Menú 1" items={['Subitem 1', 'Subitem 2', 'Subitem 3']} />
      <SubMenu title="Menú 2" items={['Subitem A', 'Subitem B']} />
      <SidebarItem>
        <a href="#item3">Item 3</a>
      </SidebarItem>
      {/* Agrega más items según sea necesario */}
    </Sidebar>
  );
};

export default MySidebar;

// App.tsx
import React from 'react';
import MySidebar from './Sidebar';

const App: React.FC = () => {
  return (
    <div style={{ display: 'flex' }}>
      <MySidebar />
      <main style={{ padding: '20px', flexGrow: 1 }}>
        <h1>Contenido Principal</h1>
        {/* Agrega más contenido aquí */}
      </main>
    </div>
  );
};

export default App;

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

No branches or pull requests

3 participants