Skip to content

Commit ee2b3e4

Browse files
Refactor UI styles & configurations (#324)
* Refactor UI styles & configurations - Modify button styles and their color schemes to create a consistent user experience when interacting with buttons. - Adjust the design of the search bar to a more user-friendly layout by changing its background color and styling. - Create a responsive mobile behavior for the navigation bar to hide it behind a menu icon instead of permanently displaying it. * Update .gitignore to exclude unnecessary files for Meilisearch Update .gitignore to exclude meilisearch.exe and data.ms/*, which are not necessary for Meilisearch. * feat: Add getCurrentBreakpoint function to get current breakpoint This commit adds a getCurrentBreakpoint function to determine the current breakpoint of the viewport. The function uses fullConfig to determine the biggest breakpoint value of the window, and returns the corresponding breakpoint. It also updates the useEffect function to use getCurrentBreakpoint instead of checking if the userAgent matches a mobile regex. * Update tailwind import path in Nav component The import path for the tailwind config was updated in the Nav component to match the new project structure. This ensures that the correct Tailwind styles are applied to the component and improves maintainability. * Add ThemeContext and cn utility function to Nav component This commit adds the ThemeContext and cn utility function to the Nav component's dependencies with useContext and import respectively. It also modifies a class name with a ternary operator that toggles based on the theme value passed via ThemeContext. * Update Nav button styles for better visibility Changed the button styles for the Nav close and open buttons to enhance visibility. The text color for both buttons will now change when hovering to gray and gray-600 respectively. * Improve message header styles and add transition effects This commit updates the MessageHeader component styles by adjusting the text color, as well as adding transition effects to enhance the hover experience. The commit also tweaks mobile styles by adding a transition effect to `.nav` when resizing the window to mobile size. * Refactor the message header component styling for better visual contrast The message header component was refactored to improve its visual contrast by changing the text color for better readability. The styles of the component were modified to improve hover behavior as well as transition effects. The setSaveAsDialogShow method was shifted to the onClick prop to only execute when the endpoint is not 'chatGPTBrowser'. * refactor: Update styling of MessageHeader and Nav buttons The commit message describes changes made to the MessageHeader and Nav components. It summarizes the code changes as a refactor of the CSS styling for the buttons in both components, specifically updating the text and hover colors for the dark and light themes.
1 parent 67716f0 commit ee2b3e4

File tree

9 files changed

+161
-108
lines changed

9 files changed

+161
-108
lines changed

client/src/components/Messages/MessageHeader.jsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@ import React, { useState } from 'react';
22
import { useRecoilValue } from 'recoil';
33
import EndpointOptionsDialog from '../Endpoints/EndpointOptionsDialog';
44
import { cn } from '~/utils/';
5-
import { Button } from '../ui/Button.tsx';
65

76
import store from '~/store';
87

9-
const clipPromptPrefix = (str) => {
10-
if (typeof str !== 'string') {
11-
return null;
12-
} else if (str.length > 10) {
13-
return str.slice(0, 10) + '...';
14-
} else {
15-
return str;
16-
}
17-
};
18-
198
const MessageHeader = ({ isSearchView = false }) => {
209
const [saveAsDialogShow, setSaveAsDialogShow] = useState(false);
2110
const conversation = useRecoilValue(store.conversation);
@@ -56,7 +45,7 @@ const MessageHeader = ({ isSearchView = false }) => {
5645
<>
5746
<div
5847
className={cn(
59-
'dark:text-gray-450 w-full gap-1 border-b border-black/10 bg-gray-50 text-sm text-gray-500 transition-all hover:bg-gray-100 hover:bg-opacity-30 dark:border-gray-900/50 dark:bg-gray-700 dark:hover:bg-gray-600 dark:hover:bg-opacity-100',
48+
'dark:text-gray-450 w-full gap-1 border-b border-black/10 bg-gray-50 text-sm text-gray-600 transition-all hover:bg-gray-100 hover:bg-opacity-30 dark:border-gray-900/50 dark:bg-gray-700 dark:hover:bg-gray-600 dark:hover:bg-opacity-100 dark:text-gray-500',
6049
endpoint === 'chatGPTBrowser' ? '' : 'cursor-pointer '
6150
)}
6251
onClick={() => (endpoint === 'chatGPTBrowser' ? null : setSaveAsDialogShow(true))}

client/src/components/Nav/SearchBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function SearchBar({ clearSearch }) {
1919
};
2020

2121
return (
22-
<div className="flex cursor-pointer items-center gap-3 rounded-md px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10">
22+
<div className="flex w-full cursor-pointer items-center gap-3 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700">
2323
{<Search className="h-4 w-4" />}
2424
<input
2525
type="text"

client/src/components/Nav/index.jsx

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useRef } from 'react';
1+
import { useState, useEffect, useRef, useContext } from 'react';
22
import NewChat from './NewChat';
33
import Spinner from '../svg/Spinner';
44
import Pages from '../Conversations/Pages';
@@ -9,10 +9,33 @@ import { useGetConversationsQuery, useSearchQuery } from '~/data-provider';
99
import useDebounce from '~/hooks/useDebounce';
1010
import store from '~/store';
1111
import { useAuthContext } from '~/hooks/AuthContext';
12+
import { ThemeContext } from '~/hooks/ThemeContext';
13+
import { cn } from '~/utils/';
14+
15+
import resolveConfig from 'tailwindcss/resolveConfig';
16+
const tailwindConfig = import('../../../tailwind.config.cjs');
17+
const fullConfig = resolveConfig(tailwindConfig);
18+
19+
export const getBreakpointValue = (value) =>
20+
+fullConfig.theme.screens[value].slice(0, fullConfig.theme.screens[value].indexOf('px'));
21+
22+
export const getCurrentBreakpoint = () => {
23+
let currentBreakpoint;
24+
let biggestBreakpointValue = 0;
25+
for (const breakpoint of Object.keys(fullConfig.theme.screens)) {
26+
const breakpointValue = getBreakpointValue(breakpoint);
27+
if (breakpointValue > biggestBreakpointValue && window.innerWidth >= breakpointValue) {
28+
biggestBreakpointValue = breakpointValue;
29+
currentBreakpoint = breakpoint;
30+
}
31+
}
32+
return currentBreakpoint;
33+
};
1234

1335
export default function Nav({ navVisible, setNavVisible }) {
1436
const [isHovering, setIsHovering] = useState(false);
1537
const { isAuthenticated } = useAuthContext();
38+
const { theme, } = useContext(ThemeContext);
1639
const containerRef = useRef(null);
1740
const scrollPositionRef = useRef(null);
1841

@@ -75,6 +98,13 @@ export default function Nav({ navVisible, setNavVisible }) {
7598
}
7699
};
77100

101+
const moveToTop = () => {
102+
const container = containerRef.current;
103+
if (container) {
104+
scrollPositionRef.current = container.scrollTop;
105+
}
106+
};
107+
78108
const nextPage = async () => {
79109
moveToTop();
80110
setPageNumber(pageNumber + 1);
@@ -111,19 +141,17 @@ export default function Nav({ navVisible, setNavVisible }) {
111141
}
112142
}, [pageNumber, conversationId, refreshConversationsHint]);
113143

114-
const moveToTop = () => {
115-
const container = containerRef.current;
116-
if (container) {
117-
scrollPositionRef.current = container.scrollTop;
118-
}
119-
};
120-
121144
const toggleNavVisible = () => {
122145
setNavVisible((prev) => !prev);
123146
};
124147

125148
useEffect(() => {
126-
setNavVisible(false);
149+
let currentBreakpoint = getCurrentBreakpoint();
150+
if (currentBreakpoint === 'sm') {
151+
setNavVisible(false);
152+
} else {
153+
setNavVisible(true);
154+
}
127155
}, [conversationId, setNavVisible]);
128156

129157
const containerClasses =
@@ -133,12 +161,7 @@ export default function Nav({ navVisible, setNavVisible }) {
133161

134162
return (
135163
<>
136-
<div
137-
className={
138-
'nav dark bg-gray-900 md:fixed md:inset-y-0 md:flex md:w-[260px] md:flex-col' +
139-
(navVisible ? ' active' : '')
140-
}
141-
>
164+
<div className={'nav dark bg-gray-900 md:inset-y-0' + (navVisible ? ' active' : '')}>
142165
<div className="flex h-full min-h-0 flex-col ">
143166
<div className="scrollbar-trigger relative flex h-full w-full flex-1 items-start border-white/20">
144167
<nav className="relative flex h-full flex-1 flex-col space-y-1 p-2">
@@ -175,27 +198,65 @@ export default function Nav({ navVisible, setNavVisible }) {
175198
</div>
176199
<button
177200
type="button"
178-
className="nav-close-button -ml-0.5 -mt-0.5 inline-flex h-10 w-10 items-center justify-center rounded-md text-white hover:text-gray-900 hover:text-white focus:outline-none focus:ring-white"
201+
className={cn('nav-close-button -ml-0.5 -mt-2.5 inline-flex h-10 w-10 items-center justify-center rounded-md focus:outline-none focus:ring-white md:-ml-1 md:-mt-2.5', theme === 'dark' ? 'text-gray-500 hover:text-gray-400' : 'text-gray-900 hover:text-gray-600')}
179202
onClick={toggleNavVisible}
180203
>
181-
<span className="sr-only">Open sidebar</span>
204+
<span className="sr-only">Close sidebar</span>
182205
<svg
183206
stroke="currentColor"
184207
fill="none"
185208
strokeWidth="1.5"
186209
viewBox="0 0 24 24"
187210
strokeLinecap="round"
188211
strokeLinejoin="round"
189-
className="h-6 w-6"
212+
className="block h-6 w-6 md:hidden"
190213
height="1em"
191214
width="1em"
192215
xmlns="http://www.w3.org/2000/svg"
193216
>
194217
<line x1="3" y1="6" x2="15" y2="18" />
195218
<line x1="3" y1="18" x2="15" y2="6" />
196219
</svg>
220+
<svg
221+
xmlns="http://www.w3.org/2000/svg"
222+
fill="none"
223+
viewBox="0 0 24 24"
224+
strokeWidth={1.5}
225+
stroke="currentColor"
226+
className="hidden h-[26px] w-[26px] md:block"
227+
>
228+
<path
229+
strokeLinecap="round"
230+
strokeLinejoin="round"
231+
d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75"
232+
/>
233+
</svg>
197234
</button>
198235
</div>
236+
{!navVisible && (
237+
<button
238+
type="button"
239+
className="nav-open-button fixed left-2 top-0.5 z-10 inline-flex h-10 w-10 items-center justify-center rounded-md text-gray-900 hover:text-gray-600 focus:outline-none focus:ring-white dark:text-gray-500 dark:hover:text-gray-400"
240+
onClick={toggleNavVisible}
241+
>
242+
<span className="sr-only">Open sidebar</span>
243+
<svg
244+
xmlns="http://www.w3.org/2000/svg"
245+
fill="none"
246+
viewBox="0 0 24 24"
247+
strokeWidth={1.5}
248+
stroke="currentColor"
249+
className="h-6 w-6"
250+
>
251+
<path
252+
strokeLinecap="round"
253+
strokeLinejoin="round"
254+
d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15m3 0l3-3m0 0l-3-3m3 3H9"
255+
/>
256+
</svg>
257+
</button>
258+
)}
259+
199260
<div className={'nav-mask' + (navVisible ? ' active' : '')} onClick={toggleNavVisible}></div>
200261
</>
201262
);

client/src/components/ui/AlertDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const AlertDialogAction = React.forwardRef<
100100
<AlertDialogPrimitive.Action
101101
ref={ref}
102102
className={cn(
103-
'inline-flex h-10 items-center justify-center rounded-md bg-slate-900 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-slate-200 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900',
103+
'inline-flex h-10 items-center justify-center rounded-md bg-slate-900 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-slate-200 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900',
104104
className
105105
)}
106106
{...props}
@@ -115,7 +115,7 @@ const AlertDialogCancel = React.forwardRef<
115115
<AlertDialogPrimitive.Cancel
116116
ref={ref}
117117
className={cn(
118-
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-slate-700 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
118+
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-gray-900 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
119119
className
120120
)}
121121
{...props}

client/src/components/ui/Button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const buttonVariants = cva(
88
{
99
variants: {
1010
variant: {
11-
default: 'bg-slate-900 text-white hover:bg-slate-700 dark:bg-slate-50 dark:text-slate-900',
11+
default: 'bg-slate-900 text-white hover:bg-gray-900 dark:bg-slate-50 dark:text-slate-900',
1212
destructive: 'bg-red-500 text-white hover:bg-red-600 dark:hover:bg-red-600',
1313
outline:
1414
'bg-transparent border border-slate-200 hover:bg-slate-100 dark:border-slate-700 dark:text-slate-100',
1515
subtle:
16-
'bg-slate-100 text-slate-900 hover:bg-slate-200 dark:bg-slate-700 dark:text-slate-100',
16+
'bg-slate-100 text-slate-900 hover:bg-slate-200 dark:bg-gray-900 dark:text-slate-100',
1717
ghost:
1818
'bg-transparent hover:bg-slate-100 dark:hover:bg-slate-800 dark:text-slate-100 dark:hover:text-slate-100 data-[state=open]:bg-transparent dark:data-[state=open]:bg-transparent',
1919
link: 'bg-transparent underline-offset-4 hover:underline text-slate-900 dark:text-slate-100 hover:bg-transparent dark:hover:bg-transparent'

client/src/components/ui/Dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const DialogClose = React.forwardRef<
102102
<DialogPrimitive.Close
103103
ref={ref}
104104
className={cn(
105-
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-slate-700 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
105+
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-gray-900 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
106106
className
107107
)}
108108
{...props}
@@ -118,7 +118,7 @@ const DialogButton = React.forwardRef<
118118
ref={ref}
119119
variant="outline"
120120
className={cn(
121-
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-slate-700 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
121+
'mt-2 inline-flex h-10 items-center justify-center rounded-md border border-slate-200 bg-transparent px-4 py-2 text-sm font-semibold text-slate-900 transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-gray-900 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 sm:mt-0',
122122
className
123123
)}
124124
{...props}

client/src/components/ui/DropdownMenu.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
2727
<DropdownMenuPrimitive.SubTrigger
2828
ref={ref}
2929
className={cn(
30-
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100 dark:focus:bg-slate-700 dark:data-[state=open]:bg-slate-700',
30+
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100 dark:focus:bg-gray-900 dark:data-[state=open]:bg-gray-900',
3131
inset && 'pl-8',
3232
className
3333
)}
@@ -81,7 +81,7 @@ const DropdownMenuItem = React.forwardRef<
8181
<DropdownMenuPrimitive.Item
8282
ref={ref}
8383
className={cn(
84-
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-slate-700',
84+
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-900',
8585
inset && 'pl-8',
8686
className
8787
)}
@@ -97,7 +97,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
9797
<DropdownMenuPrimitive.CheckboxItem
9898
ref={ref}
9999
className={cn(
100-
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-slate-700',
100+
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-900',
101101
className
102102
)}
103103
checked={checked}
@@ -120,7 +120,7 @@ const DropdownMenuRadioItem = React.forwardRef<
120120
<DropdownMenuPrimitive.RadioItem
121121
ref={ref}
122122
className={cn(
123-
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-slate-700',
123+
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-900',
124124
className
125125
)}
126126
{...props}
@@ -159,7 +159,7 @@ const DropdownMenuSeparator = React.forwardRef<
159159
>(({ className, ...props }, ref) => (
160160
<DropdownMenuPrimitive.Separator
161161
ref={ref}
162-
className={cn('-mx-1 my-1 h-px bg-slate-100 dark:bg-slate-700', className)}
162+
className={cn('-mx-1 my-1 h-px bg-slate-100 dark:bg-gray-900', className)}
163163
{...props}
164164
/>
165165
));

0 commit comments

Comments
 (0)