Files
ServerKit/frontend/src/contexts/LayoutContext.jsx
T
Juan DenisandClaude Opus 4.8 e738f3d509 feat(ui): add topbar layout variant to the layout switcher
- Add 'topbar' to LayoutContext and a third switcher button (Sidebar |
  Compact | Top bar).
- Topbar: the sidebar becomes a horizontal bar pinned to the top; top-level
  items lay out in a horizontally-scrollable row with an underline active
  indicator. Category headers, expand chevrons, and sub-items are hidden
  (sub-nav is reached from each page's in-page navigation), which sidesteps
  the horizontal-overflow vs. dropdown clipping trap. Desktop-only; the
  mobile drawer is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 03:05:39 -04:00

44 lines
1.5 KiB
React

import { createContext, useContext, useState, useEffect, useCallback } from 'react';
const LayoutContext = createContext(null);
// Shell geometry options, kept in sync with the switcher in Sidebar and the
// [data-layout="..."] rules in styles/layout/_sidebar.scss. 'topbar' is reserved
// for a later phase; any unknown or stale stored value falls back to 'sidebar'.
const LAYOUTS = ['sidebar', 'rail', 'topbar'];
const DEFAULT_LAYOUT = 'sidebar';
const normalize = (value) => (LAYOUTS.includes(value) ? value : DEFAULT_LAYOUT);
export function LayoutProvider({ children }) {
const [layout, setLayoutState] = useState(() => normalize(localStorage.getItem('layout')));
const setLayout = useCallback((next) => {
const value = normalize(next);
setLayoutState(value);
localStorage.setItem('layout', value);
document.documentElement.setAttribute('data-layout', value);
}, []);
// Mirror the persisted choice onto the document (matches ThemeContext).
useEffect(() => {
document.documentElement.setAttribute('data-layout', layout);
}, [layout]);
return (
<LayoutContext.Provider value={{ layout, setLayout }}>
{children}
</LayoutContext.Provider>
);
}
export function useLayout() {
const context = useContext(LayoutContext);
if (!context) {
throw new Error('useLayout must be used within a LayoutProvider');
}
return context;
}
export default LayoutContext;