MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / PageSidebarLayout

Function PageSidebarLayout

ui/src/components/PageSidebarLayout.tsx:67–213  ·  view source on GitHub ↗
({
  storageKey,
  title,
  actions,
  sidebar,
  children,
  defaultWidth = 260,
}: PageSidebarLayoutProps)

Source from the content-addressed store, hash-verified

65 * local navigator, and owns its width + mobile drawer behavior.
66 */
67export function PageSidebarLayout({
68 storageKey,
69 title,
70 actions,
71 sidebar,
72 children,
73 defaultWidth = 260,
74}: PageSidebarLayoutProps) {
75 const isDesktop = useIsDesktop()
76 const rootRef = useRef<HTMLDivElement | null>(null)
77 const [drawerOpen, setDrawerOpen] = useState(false)
78 const [preferredWidth, setPreferredWidth] = useState(() =>
79 readStoredWidth(storageKey, clampWidth(defaultWidth, defaultWidth)),
80 )
81 const [containerWidth, setContainerWidth] = useState(() =>
82 typeof window !== 'undefined' ? window.innerWidth : 0,
83 )
84 const maxWidth = responsiveMaxWidth(containerWidth)
85 const width = Math.min(preferredWidth, maxWidth)
86
87 const persistWidth = useCallback((next: number) => {
88 window.localStorage.setItem(storageName(storageKey), String(next))
89 }, [storageKey])
90
91 const beginResize = useCallback((event: ReactPointerEvent<HTMLDivElement>) => {
92 event.preventDefault()
93 event.stopPropagation()
94
95 const startX = event.clientX
96 const startWidth = width
97 let nextWidth = startWidth
98
99 const onPointerMove = (moveEvent: PointerEvent) => {
100 nextWidth = Math.max(MIN_WIDTH, Math.min(maxWidth, Math.round(startWidth + moveEvent.clientX - startX)))
101 setPreferredWidth(nextWidth)
102 }
103
104 const onPointerUp = () => {
105 persistWidth(nextWidth)
106 document.body.style.cursor = ''
107 document.body.style.userSelect = ''
108 window.removeEventListener('pointermove', onPointerMove)
109 window.removeEventListener('pointerup', onPointerUp)
110 window.removeEventListener('pointercancel', onPointerUp)
111 }
112
113 document.body.style.cursor = 'col-resize'
114 document.body.style.userSelect = 'none'
115 window.addEventListener('pointermove', onPointerMove)
116 window.addEventListener('pointerup', onPointerUp)
117 window.addEventListener('pointercancel', onPointerUp)
118 }, [maxWidth, persistWidth, width])
119
120 useEffect(() => {
121 if (isDesktop) setDrawerOpen(false)
122 }, [isDesktop])
123
124 useEffect(() => {

Callers

nothing calls this directly

Calls 8

readStoredWidthFunction · 0.85
clampWidthFunction · 0.85
responsiveMaxWidthFunction · 0.85
storageNameFunction · 0.85
useIsDesktopFunction · 0.70
measureFunction · 0.70
addEventListenerMethod · 0.65
disconnectMethod · 0.45

Tested by

no test coverage detected