-
Notifications
You must be signed in to change notification settings - Fork 186
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
Comments
You mean more nested/collapsible menu options, or something more like having access to another sidebar/drawer inside the original Sidebar? |
// 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
Can Sidebar support more than two levels?
The text was updated successfully, but these errors were encountered: