From e13fff0be400f2ee51c9979c797ed1ca32ca5850 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Tue, 31 Dec 2024 20:23:57 +0800 Subject: [PATCH] feat(header): add LanguageSelector component for selecting programming languages --- package.json | 1 + .../(main)/components/language-selector.tsx | 29 ++++ src/components/ui/select.tsx | 159 ++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/app/(main)/components/language-selector.tsx create mode 100644 src/components/ui/select.tsx diff --git a/package.json b/package.json index 3fd7b97..12a1a58 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@prisma/client": "^6.1.0", "@radix-ui/react-avatar": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.4", + "@radix-ui/react-select": "^2.1.4", "@radix-ui/react-slot": "^1.1.1", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", diff --git a/src/app/(main)/components/language-selector.tsx b/src/app/(main)/components/language-selector.tsx new file mode 100644 index 0000000..f1a9424 --- /dev/null +++ b/src/app/(main)/components/language-selector.tsx @@ -0,0 +1,29 @@ +import { + Select, + SelectItem, + SelectValue, + SelectContent, + SelectTrigger, +} from "@/components/ui/select"; +import { SUPPORTED_LANGUAGES } from "@/constants/languages"; +import { useCodeEditorStore } from "@/store/useCodeEditorStore"; + +export default function LanguageSelector() { + const { language, setLanguage } = useCodeEditorStore(); + + 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, +}