feat: tab bar

This commit is contained in:
OpenSquared
2026-06-29 08:56:10 +02:00
parent 97077af369
commit 45e5504256
5 changed files with 196 additions and 45 deletions

View File

@@ -0,0 +1,27 @@
import { createContext, useContext, useCallback, useState, ReactNode } from 'react'
interface TabsCtx {
kept: ReadonlySet<string>
keepRoute: (r: string) => void
forgetRoute: (r: string) => void
}
const Ctx = createContext<TabsCtx>({
kept: new Set(),
keepRoute: () => {},
forgetRoute: () => {},
})
export function TabsProvider({ children }: { children: ReactNode }) {
const [kept, setKept] = useState<Set<string>>(new Set())
const keepRoute = useCallback((r: string) =>
setKept(p => p.has(r) ? p : new Set([...p, r])), [])
const forgetRoute = useCallback((r: string) =>
setKept(p => { const n = new Set(p); n.delete(r); return n }), [])
return <Ctx.Provider value={{ kept, keepRoute, forgetRoute }}>{children}</Ctx.Provider>
}
export const useTabs = () => useContext(Ctx)