feat(playground): add ligatures checkbox component and update translations in PlaygroundPage

This commit is contained in:
ngc2207 2024-12-15 21:54:39 +08:00
parent f590d77578
commit 40f273f5a2
8 changed files with 101 additions and 1 deletions

View File

@ -2,6 +2,16 @@
"Page": { "Page": {
"DashboardPage": { "DashboardPage": {
"title": "Welcome to Judge4c!" "title": "Welcome to Judge4c!"
},
"PlaygroundPage": {
"Components": {
"playgroundSidebar": {
"title": "Files"
},
"ligaturesCheckbox": {
"label": "Font Ligatures"
}
}
} }
}, },
"Components": { "Components": {

View File

@ -2,6 +2,16 @@
"Page": { "Page": {
"DashboardPage": { "DashboardPage": {
"title": "欢迎使用Judge4c" "title": "欢迎使用Judge4c"
},
"PlaygroundPage": {
"Components": {
"playgroundSidebar": {
"title": "文件"
},
"ligaturesCheckbox": {
"label": "连字"
}
}
} }
}, },
"Components": { "Components": {

View File

@ -13,9 +13,11 @@
"@monaco-editor/react": "^4.6.0", "@monaco-editor/react": "^4.6.0",
"@radix-ui/react-alert-dialog": "^1.1.2", "@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-avatar": "^1.1.1", "@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-collapsible": "^1.1.1", "@radix-ui/react-collapsible": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-select": "^2.1.2", "@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-slot": "^1.1.0",

View File

@ -0,0 +1,18 @@
"use client";
import { useTranslations } from "next-intl";
import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import { useCodeEditorStore } from "@/store/codeEditorStore";
export default function LigaturesCheckbox() {
const t = useTranslations("Page.PlaygroundPage.Components.ligaturesCheckbox");
const { setIsLigature } = useCodeEditorStore();
return (
<div className="flex items-center gap-2">
<Checkbox onCheckedChange={setIsLigature} />
<Label>{t("label")}</Label>
</div>
);
}

View File

@ -20,6 +20,7 @@ import {
CollapsibleTrigger, CollapsibleTrigger,
} from "@/components/ui/collapsible"; } from "@/components/ui/collapsible";
import * as actions from "@/actions"; import * as actions from "@/actions";
import { useTranslations } from "next-intl";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
import { COriginal, JavaOriginal } from "devicons-react"; import { COriginal, JavaOriginal } from "devicons-react";
import { useCodeEditorStore } from "@/store/codeEditorStore"; import { useCodeEditorStore } from "@/store/codeEditorStore";
@ -89,6 +90,7 @@ export function PlaygroundSidebar({
}); });
const username = session?.user?.name ?? ""; const username = session?.user?.name ?? "";
const t = useTranslations("Page.PlaygroundPage.Components.playgroundSidebar");
React.useEffect(() => { React.useEffect(() => {
async function fetchFileTree() { async function fetchFileTree() {
@ -109,7 +111,7 @@ export function PlaygroundSidebar({
<Sidebar {...props}> <Sidebar {...props}>
<SidebarContent> <SidebarContent>
<SidebarGroup> <SidebarGroup>
<SidebarGroupLabel>Files</SidebarGroupLabel> <SidebarGroupLabel>{t("title")}</SidebarGroupLabel>
<SidebarGroupContent> <SidebarGroupContent>
<SidebarMenu> <SidebarMenu>
{fileTree.children && {fileTree.children &&

View File

@ -8,6 +8,7 @@ import { Separator } from "@/components/ui/separator";
import ThemeSelector from "./components/theme-selector"; import ThemeSelector from "./components/theme-selector";
import { ModeSwitcher } from "@/components/mode-switcher"; import { ModeSwitcher } from "@/components/mode-switcher";
import LanguageSwitcher from "@/components/language-switcher"; import LanguageSwitcher from "@/components/language-switcher";
import LigaturesCheckbox from "./components/ligatures-checkbox";
import { PlaygroundSidebar } from "@/app/playground/components/playground-sidebar"; import { PlaygroundSidebar } from "@/app/playground/components/playground-sidebar";
export default function PlaygroundLayout({ export default function PlaygroundLayout({
@ -24,6 +25,7 @@ export default function PlaygroundLayout({
<ModeSwitcher /> <ModeSwitcher />
<Separator orientation="vertical" className="mr-2 h-4" /> <Separator orientation="vertical" className="mr-2 h-4" />
<ThemeSelector /> <ThemeSelector />
<LigaturesCheckbox />
</div> </div>
<div className="ml-auto px-3"> <div className="ml-auto px-3">
<LanguageSwitcher /> <LanguageSwitcher />

View File

@ -0,0 +1,30 @@
"use client"
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"
import { cn } from "@/lib/utils"
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
>
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName
export { Checkbox }

View File

@ -0,0 +1,26 @@
"use client"
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
)
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName
export { Label }