LibreChat/client/src/components/ui/Dialog.tsx

140 lines
5.4 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import * as DialogPrimitive from '@radix-ui/react-dialog';
2023-04-03 12:54:15 +08:00
import { Button } from '../ui/Button';
import { X } from 'lucide-react';
2023-03-03 15:52:06 -05:00
import { cn } from '../../utils';
2023-03-03 15:52:06 -05:00
const Dialog = DialogPrimitive.Root;
2023-03-03 15:52:06 -05:00
const DialogTrigger = DialogPrimitive.Trigger;
2023-03-03 15:52:06 -05:00
const DialogPortal = ({ className, children, ...props }: DialogPrimitive.DialogPortalProps) => (
2023-03-03 15:52:06 -05:00
<DialogPrimitive.Portal className={cn(className)} {...props}>
<div className="fixed inset-0 z-[999] flex items-start justify-center sm:items-center">
2023-03-03 15:52:06 -05:00
{children}
</div>
</DialogPrimitive.Portal>
);
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
2023-03-03 15:52:06 -05:00
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, children, ...props }, ref) => (
<DialogPrimitive.Overlay
className={cn(
'data-[state=closed]:animate-out data-[state=open]:fade-in data-[state=closed]:fade-out fixed inset-0 z-[999] bg-black/50 backdrop-blur-sm transition-all duration-100',
2023-03-03 15:52:06 -05:00
className
)}
{...props}
ref={ref}
/>
));
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
2023-03-03 15:52:06 -05:00
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'animate-in data-[state=open]:fade-in-90 data-[state=open]:slide-in-from-bottom-10 sm:zoom-in-90 data-[state=open]:sm:slide-in-from-bottom-0 fixed z-[999] grid w-full gap-4 rounded-b-lg bg-white p-6 sm:max-w-lg sm:rounded-lg',
'dark:bg-slate-900',
2023-03-03 15:52:06 -05:00
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-slate-100 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 dark:data-[state=open]:bg-slate-800">
2023-04-02 04:15:07 +08:00
<X className="h-4 w-4 text-black dark:text-white" />
2023-03-03 15:52:06 -05:00
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
));
DialogContent.displayName = DialogPrimitive.Content.displayName;
2023-03-03 15:52:06 -05:00
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} />
);
DialogHeader.displayName = 'DialogHeader';
2023-03-03 15:52:06 -05:00
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
2023-03-03 15:52:06 -05:00
<div
className={cn('flex flex-col-reverse sm:flex-row sm:justify-between sm:space-x-2', className)}
2023-03-03 15:52:06 -05:00
{...props}
/>
);
DialogFooter.displayName = 'DialogFooter';
2023-03-03 15:52:06 -05:00
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn('text-lg font-semibold text-slate-900', 'dark:text-slate-50', className)}
2023-03-03 15:52:06 -05:00
{...props}
/>
));
DialogTitle.displayName = DialogPrimitive.Title.displayName;
2023-03-03 15:52:06 -05:00
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn('text-sm text-slate-500', 'dark:text-slate-400', className)}
2023-03-03 15:52:06 -05:00
{...props}
/>
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;
2023-03-03 15:52:06 -05:00
const DialogClose = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Close>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Close
ref={ref}
className={cn(
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.
2023-05-19 20:21:34 +05:30
'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',
2023-03-03 15:52:06 -05:00
className
)}
{...props}
/>
));
DialogClose.displayName = DialogPrimitive.Title.displayName;
2023-03-03 15:52:06 -05:00
2023-04-03 12:54:15 +08:00
const DialogButton = React.forwardRef<
React.ElementRef<typeof Button>,
React.ComponentPropsWithoutRef<typeof Button>
>(({ className, ...props }, ref) => (
<Button
ref={ref}
variant="outline"
className={cn(
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.
2023-05-19 20:21:34 +05:30
'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',
2023-04-03 12:54:15 +08:00
className
)}
{...props}
/>
));
DialogButton.displayName = DialogPrimitive.Title.displayName;
2023-04-03 12:54:15 +08:00
2023-03-03 15:52:06 -05:00
export {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
DialogClose,
DialogButton
};