a tool for shared writing and social publishing
1"use client";
2import { uv } from "colorjs.io/fn";
3import { Media } from "components/Media";
4import { createContext, useState } from "react";
5
6export const SidebarContext = createContext({
7 open: false,
8 setChildForceOpen: (b: boolean) => {},
9});
10
11export function Sidebar(props: {
12 children?: React.ReactNode;
13 alwaysOpen?: boolean;
14 className?: string;
15}) {
16 let [sidebarExpanded, setSidebarExpanded] = useState(false);
17 let [childForceOpen, setChildForceOpen] = useState(false);
18 let open = sidebarExpanded || childForceOpen;
19 return (
20 <Media mobile={false}>
21 <SidebarContext
22 value={{
23 open: props.alwaysOpen ? true : open,
24 setChildForceOpen,
25 }}
26 >
27 <div
28 className={`
29 actionSidebar
30 ${!props.alwaysOpen ? "absolute top-0 left-0 z-10 w-max" : "w-[192px] max-w-[192px]"}
31 h-fit p-[6px]
32 flex flex-col gap-1 justify-start border
33 rounded-md bg-bg-page ${open && !props.alwaysOpen ? "border-border-light" : "container"}
34 ${props.className}
35 `}
36 onMouseOver={() => {
37 setSidebarExpanded(true);
38 }}
39 onMouseLeave={() => {
40 !props.alwaysOpen && setSidebarExpanded(false);
41 }}
42 >
43 {props.children}
44 </div>
45 </SidebarContext>
46 </Media>
47 );
48}