'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { Button, Typography, cn } from '@hexclave/ui'; import { XIcon } from 'lucide-react'; import React, { ReactNode } from 'react'; import { useStackApp } from '../..'; import { suspendIfSsr } from '../../utils/react'; export type SidebarItem = { title: React.ReactNode, type: 'item' | 'divider', description?: React.ReactNode, id?: string, icon?: React.ReactNode, content?: React.ReactNode, contentTitle?: React.ReactNode, } function normalizeHash(hash: string) { return hash.startsWith("#") ? hash.slice(1) : hash; } function useHash() { suspendIfSsr(); return React.useSyncExternalStore( (onStoreChange) => { window.addEventListener("hashchange", onStoreChange); return () => window.removeEventListener("hashchange", onStoreChange); }, () => normalizeHash(window.location.hash), ); } export function SidebarLayout(props: { items: SidebarItem[], title?: ReactNode, className?: string }) { const hash = useHash(); const selectedIndex = props.items.findIndex(item => item.id && (item.id === hash)); return ( <>
); } function Items(props: { items: SidebarItem[], selectedIndex: number }) { const app = useStackApp(); const navigate = app.useNavigate(); const activeItemIndex = props.selectedIndex === -1 ? 0 : props.selectedIndex; return props.items.map((item, index) => ( item.type === 'item' ? : {item.title} )); } function DesktopLayout(props: { items: SidebarItem[], title?: ReactNode, selectedIndex: number }) { const selectedItem = props.items[props.selectedIndex === -1 ? 0 : props.selectedIndex]; return (
{props.title &&
{props.title}
}
{selectedItem.title} {selectedItem.description && {selectedItem.description}}
{selectedItem.content}
); } function MobileLayout(props: { items: SidebarItem[], title?: ReactNode, selectedIndex: number }) { const selectedItem = props.items[props.selectedIndex]; const app = useStackApp(); const navigate = app.useNavigate(); if (props.selectedIndex === -1) { return (
{props.title &&
{props.title}
}
); } else { return (
{selectedItem.title}
{selectedItem.description && {selectedItem.description}}
{selectedItem.content}
); } }