-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Button that allows the user to switch the side where the sidebar is displayed #340
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,11 @@ import { | |
AtSymbolIcon, | ||
RectangleStackIcon, | ||
QuestionMarkCircleIcon, | ||
ArrowsRightLeftIcon, | ||
} from '@heroicons/react/24/outline' | ||
import { LogoNIAEFEUPImage } from '../../images' | ||
import { getPath, config } from '../../utils' | ||
import { useSidebarContext } from './SidebarPosition' | ||
|
||
const navigation = [ | ||
{ | ||
|
@@ -34,6 +36,8 @@ type Props = { | |
} | ||
|
||
const Header = ({ siteTitle, location }: Props) => { | ||
const { toggleSidebarPosition } = useSidebarContext(); | ||
|
||
return ( | ||
<Disclosure | ||
as="nav" | ||
|
@@ -80,10 +84,20 @@ const Header = ({ siteTitle, location }: Props) => { | |
))} | ||
</div> | ||
|
||
<div className="hidden self-center md:inline-flex"> | ||
<div className='flex items-center space-x-2 relative top-1'> | ||
<button | ||
onClick={toggleSidebarPosition} | ||
className="hidden md:inline-flex items-center justify-center w-8 h-8 bg-primary text-white rounded hover:text-opacity-75" | ||
> | ||
<ArrowsRightLeftIcon className='h-4 w-4' /> | ||
</button> | ||
|
||
Comment on lines
+88
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the button to switch sides should be here on the navbar because not all pages have the sidebar and it looks weird for the about page and the FAQ page to have such button. Can you move it to some place inside the sidebar? For example, near the download button or on the bottom of the sidebar. |
||
|
||
<div className="hidden self-center md:inline-flex"> | ||
|
||
<DarkModeSwitch /> | ||
|
||
<DarkModeSwitch /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createCheckboxScope } from "@radix-ui/react-checkbox"; | ||
import { Children, createContext, useContext, useState } from "react"; | ||
|
||
type SidebarContextType = { | ||
sidebarPosition: 'left' | 'right'; | ||
toggleSidebarPosition: () => void; | ||
}; | ||
|
||
const SidebarContext = createContext<SidebarContextType | undefined>(undefined); | ||
|
||
export const SidebarProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [sidebarPosition, setSidebarPosition] = useState<'left' | 'right'>('right'); | ||
|
||
const toggleSidebarPosition = () => { | ||
setSidebarPosition((prev) => (prev === 'right' ? 'left' : 'right')); | ||
}; | ||
|
||
return ( | ||
<SidebarContext.Provider value={{ sidebarPosition, toggleSidebarPosition }}> | ||
{children} | ||
</SidebarContext.Provider> | ||
); | ||
}; | ||
|
||
export const useSidebarContext = () => { | ||
const context = useContext(SidebarContext); | ||
if (!context) { | ||
throw new Error('useSidebarContext must be used within a SidebarProvider') | ||
} | ||
return context | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the same light as the previous comment, since the sidebar button to change sides should not be global, it does not really make sense to render the
SidebarProvider
here.It should be inside the
TimeTableScheduler.tsx
page