feat(theme-switcher): move to settings menu

This commit is contained in:
ItzCrazyKns 2024-06-02 12:19:53 +05:30
parent 32cc430b1b
commit 7c676479d4
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
3 changed files with 23 additions and 32 deletions

View File

@ -8,6 +8,7 @@ import React, {
useState, useState,
type SelectHTMLAttributes, type SelectHTMLAttributes,
} from 'react'; } from 'react';
import ThemeSwitcher from './theme/Switcher';
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {} interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
@ -27,7 +28,7 @@ interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
options: { value: string; label: string; disabled?: boolean }[]; options: { value: string; label: string; disabled?: boolean }[];
} }
const Select = ({ className, options, ...restProps }: SelectProps) => { export const Select = ({ className, options, ...restProps }: SelectProps) => {
return ( return (
<select <select
{...restProps} {...restProps}
@ -209,6 +210,12 @@ const SettingsDialog = ({
</Dialog.Title> </Dialog.Title>
{config && !isLoading && ( {config && !isLoading && (
<div className="flex flex-col space-y-4 mt-6"> <div className="flex flex-col space-y-4 mt-6">
<div className="flex flex-col space-y-1">
<p className="text-black/70 dark:text-white/70 text-sm">
Theme
</p>
<ThemeSwitcher />
</div>
{config.chatModelProviders && ( {config.chatModelProviders && (
<div className="flex flex-col space-y-1"> <div className="flex flex-col space-y-1">
<p className="text-black/70 dark:text-white/70 text-sm"> <p className="text-black/70 dark:text-white/70 text-sm">

View File

@ -68,14 +68,10 @@ const Sidebar = ({ children }: { children: React.ReactNode }) => {
))} ))}
</VerticalIconContainer> </VerticalIconContainer>
<VerticalIconContainer>
<ThemeSwitcher />
<Settings <Settings
onClick={() => setIsSettingsOpen(!isSettingsOpen)} onClick={() => setIsSettingsOpen(!isSettingsOpen)}
className="cursor-pointer" className="cursor-pointer"
/> />
</VerticalIconContainer>
<SettingsDialog <SettingsDialog
isOpen={isSettingsOpen} isOpen={isSettingsOpen}

View File

@ -3,15 +3,11 @@ import { useTheme } from 'next-themes';
import { SunIcon, MoonIcon, MonitorIcon } from 'lucide-react'; import { SunIcon, MoonIcon, MonitorIcon } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { Select } from '../SettingsDialog';
type Theme = 'dark' | 'light' | 'system'; type Theme = 'dark' | 'light' | 'system';
interface ThemeSwitcherProps { const ThemeSwitcher = ({ className }: { className?: string }) => {
size?: number | string;
className?: string;
}
const ThemeSwitcher = ({ size, className }: ThemeSwitcherProps) => {
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme(); const { theme, setTheme } = useTheme();
@ -50,23 +46,15 @@ const ThemeSwitcher = ({ size, className }: ThemeSwitcherProps) => {
return null; return null;
} }
return isTheme('dark') ? ( return (
<SunIcon <Select
className={cn('cursor-pointer', className)} className={className}
size={size} value={theme}
onClick={() => handleThemeSwitch('light')} onChange={(e) => handleThemeSwitch(e.target.value as Theme)}
/> options={[
) : isTheme('light') ? ( { value: 'light', label: 'Light' },
<MoonIcon { value: 'dark', label: 'Dark' }
className={cn('cursor-pointer', className)} ]}
size={size}
onClick={() => handleThemeSwitch('dark')}
/>
) : (
<MonitorIcon
className={cn('cursor-pointer', className)}
size={size}
onClick={() => handleThemeSwitch('system')}
/> />
); );
}; };