-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update layout and sidebar components
- Loading branch information
1 parent
42d4b6b
commit bacd258
Showing
3 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
frontend/components/layout/ThemeToggle/dashboard-theme-switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use client"; | ||
|
||
import type { RadioGroupProps, RadioProps } from "@nextui-org/react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
import { Icon } from "@iconify/react"; | ||
import { | ||
RadioGroup, | ||
VisuallyHidden, | ||
useRadio, | ||
useRadioGroupContext, | ||
} from "@nextui-org/react"; | ||
import { useTheme } from "next-themes"; | ||
import React from "react"; | ||
|
||
const ThemeRadioItem = ({ icon, ...props }: RadioProps & { icon: string }) => { | ||
const { | ||
Component, | ||
isSelected: isSelfSelected, | ||
getBaseProps, | ||
getInputProps, | ||
getWrapperProps, | ||
} = useRadio(props); | ||
|
||
const groupContext = useRadioGroupContext(); | ||
|
||
const isSelected = | ||
isSelfSelected || | ||
Number(groupContext.groupState.selectedValue) >= Number(props.value); | ||
|
||
const wrapperProps = getWrapperProps(); | ||
|
||
return ( | ||
<Component {...getBaseProps()}> | ||
<VisuallyHidden> | ||
<input {...getInputProps()} /> | ||
</VisuallyHidden> | ||
<div | ||
{...wrapperProps} | ||
className={cn( | ||
wrapperProps?.["className"], | ||
"pointer-events-none h-8 w-8 rounded-full border-black border-opacity-10 ring-0 transition-transform group-data-[pressed=true]:scale-90", | ||
{ | ||
"bg-default-200 dark:bg-default-100": isSelected, | ||
} | ||
)} | ||
> | ||
<Icon className="text-default-500" icon={icon} width={18} /> | ||
</div> | ||
</Component> | ||
); | ||
}; | ||
|
||
const DashboardThemeSwitch = React.forwardRef< | ||
HTMLDivElement, | ||
Omit<RadioGroupProps, "children"> | ||
>(({ classNames = {}, ...props }, ref) => { | ||
const { setTheme } = useTheme(); | ||
|
||
return ( | ||
<RadioGroup | ||
ref={ref} | ||
aria-label="Select a theme" | ||
classNames={{ | ||
...classNames, | ||
wrapper: cn("gap-0 items-center", classNames?.wrapper), | ||
}} | ||
defaultValue="dark" | ||
orientation="horizontal" | ||
{...props} | ||
> | ||
<ThemeRadioItem | ||
icon="solar:moon-linear" | ||
value="dark" | ||
onClick={() => setTheme("dark")} | ||
/> | ||
<ThemeRadioItem | ||
icon="solar:sun-2-linear" | ||
value="light" | ||
onClick={() => setTheme("light")} | ||
/> | ||
<ThemeRadioItem | ||
icon="solar:monitor-linear" | ||
value="system" | ||
onClick={() => setTheme("system")} | ||
/> | ||
</RadioGroup> | ||
); | ||
}); | ||
|
||
DashboardThemeSwitch.displayName = "DashboardThemeSwitch"; | ||
|
||
export default DashboardThemeSwitch; |