Skip to content

Commit

Permalink
feat(ui): theme switcher show in responsive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
WanQuanXie committed May 28, 2024
1 parent af9862c commit 710b72d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ui/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Clock, Edit, Share, Trash } from 'lucide-react';
import { Message } from './ChatWindow';
import { useEffect, useState } from 'react';
import { formatTimeDifference } from '@/lib/utils';
import { ThemeSwitcher } from './theme/Switcher';

const Navbar = ({ messages }: { messages: Message[] }) => {
const [title, setTitle] = useState<string>('');
Expand Down Expand Up @@ -49,6 +50,8 @@ const Navbar = ({ messages }: { messages: Message[] }) => {
</div>
<p className="hidden lg:flex">{title}</p>
<div className="flex flex-row items-center space-x-4">
<ThemeSwitcher size={17} className="lg:hidden" />

<Share
size={17}
className="active:scale-95 transition duration-100 cursor-pointer"
Expand Down
17 changes: 13 additions & 4 deletions ui/components/theme/Switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
import { useTheme } from 'next-themes';
import { SunIcon, MoonIcon, MonitorIcon } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react';
import { cn } from '@/lib/utils';

type Theme = 'dark' | 'light' | 'system';

export function ThemeSwitcher() {
interface ThemeSwitcherProps {
size?: number | string;
className?: string;
}

export function ThemeSwitcher({ size, className }: ThemeSwitcherProps) {
const [mounted, setMounted] = useState(false);

const { theme, setTheme } = useTheme();
Expand Down Expand Up @@ -46,17 +52,20 @@ export function ThemeSwitcher() {

return isTheme('dark') ? (
<SunIcon
className="cursor-pointer"
className={cn('cursor-pointer', className)}
size={size}
onClick={() => handleThemeSwitch('light')}
/>
) : isTheme('light') ? (
<MoonIcon
className="cursor-pointer"
className={cn('cursor-pointer', className)}
size={size}
onClick={() => handleThemeSwitch('dark')}
/>
) : (
<MonitorIcon
className="cursor-pointer"
className={cn('cursor-pointer', className)}
size={size}
onClick={() => handleThemeSwitch('system')}
/>
);
Expand Down

0 comments on commit 710b72d

Please sign in to comment.