-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidePanelContext.jsx
More file actions
42 lines (36 loc) · 1.02 KB
/
SidePanelContext.jsx
File metadata and controls
42 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { createContext, useContext, useState } from 'react';
const SidePanelContext = createContext();
export const useSidePanel = () => {
return useContext(SidePanelContext);
};
export const SidePanelProvider = ({ children }) => {
const [isOpen, setIsOpen] = useState(false);
const [panelContent, setPanelContent] = useState(null);
const [panelTitle, setPanelTitle] = useState('');
const [panelWidth, setPanelWidth] = useState(450);
const openSidePanel = (title, content, width = 450) => {
setPanelTitle(title);
setPanelContent(content);
setPanelWidth(width);
setIsOpen(true);
};
const closeSidePanel = () => {
setIsOpen(false);
// Optional: clear content after animation, but keeping it simple for now
};
return (
<SidePanelContext.Provider
value={{
isOpen,
panelTitle,
panelContent,
panelWidth,
setPanelWidth,
openSidePanel,
closeSidePanel,
}}
>
{children}
</SidePanelContext.Provider>
);
};