From e5b8848b8f14bb286b6326890d94770b7d4a915c Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Thu, 12 Dec 2024 13:38:02 +0800 Subject: [PATCH] feat(i18n): add LanguageSwitcher and integrate with dashboard header --- package.json | 1 + src/app/dashboard/layout.tsx | 22 ++-- src/components/language-switcher.tsx | 36 ++++++ src/components/ui/select.tsx | 159 +++++++++++++++++++++++++++ 4 files changed, 206 insertions(+), 12 deletions(-) create mode 100644 src/components/language-switcher.tsx create mode 100644 src/components/ui/select.tsx diff --git a/package.json b/package.json index 688e8e2..e4bb817 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@radix-ui/react-collapsible": "^1.1.1", "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", + "@radix-ui/react-select": "^2.1.2", "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.4", diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx index c81eed9..3798f36 100644 --- a/src/app/dashboard/layout.tsx +++ b/src/app/dashboard/layout.tsx @@ -6,16 +6,15 @@ import { import { Breadcrumb, BreadcrumbItem, - BreadcrumbLink, BreadcrumbList, BreadcrumbPage, - BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { SessionProvider } from "next-auth/react"; import { AppSidebar } from "@/components/app-sidebar"; import { Separator } from "@/components/ui/separator"; import { ModeSwitcher } from "@/components/mode-switcher"; import ConfirmationDialog from "@/dialogs/ConfirmationDialog"; +import LanguageSwitcher from "@/components/language-switcher"; export default function DashboardLayout({ children, @@ -25,25 +24,24 @@ export default function DashboardLayout({ -
-
- +
+
+ - - - Building Your Application - - - - Data Fetching + + Project Management & Task Tracking +
+
+ +
{children} diff --git a/src/components/language-switcher.tsx b/src/components/language-switcher.tsx new file mode 100644 index 0000000..9b9cdda --- /dev/null +++ b/src/components/language-switcher.tsx @@ -0,0 +1,36 @@ +import { auth } from "@/auth"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; + +const languages = [ + { value: "en-US", label: "English (United States)", flag: "🇺🇸" }, + { value: "zh-CN", label: "简体中文", flag: "🇨🇳" }, +]; + +export default async function LanguageSwitcher() { + const session = await auth(); + const defaultLanguage = session?.user?.language || "en-US"; + + return ( +
+ +
+ ); +} diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx new file mode 100644 index 0000000..0cbf77d --- /dev/null +++ b/src/components/ui/select.tsx @@ -0,0 +1,159 @@ +"use client" + +import * as React from "react" +import * as SelectPrimitive from "@radix-ui/react-select" +import { Check, ChevronDown, ChevronUp } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Select = SelectPrimitive.Root + +const SelectGroup = SelectPrimitive.Group + +const SelectValue = SelectPrimitive.Value + +const SelectTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + span]:line-clamp-1", + className + )} + {...props} + > + {children} + + + + +)) +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName + +const SelectScrollUpButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName + +const SelectScrollDownButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +SelectScrollDownButton.displayName = + SelectPrimitive.ScrollDownButton.displayName + +const SelectContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, position = "popper", ...props }, ref) => ( + + + + + {children} + + + + +)) +SelectContent.displayName = SelectPrimitive.Content.displayName + +const SelectLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectLabel.displayName = SelectPrimitive.Label.displayName + +const SelectItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + {children} + +)) +SelectItem.displayName = SelectPrimitive.Item.displayName + +const SelectSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectSeparator.displayName = SelectPrimitive.Separator.displayName + +export { + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, + SelectScrollUpButton, + SelectScrollDownButton, +}