import { $getSelectionStyleValueForProperty, $patchStyleText, } from "@lexical/selection" import { ALargeSmall, ChevronDown } from "@workspace/ui/components/icon" import { $getSelection, $isRangeSelection } from "lexical" import { Button } from "@workspace/ui/components/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@workspace/ui/components/dropdown-menu" import type { LexicalActionDefaultControlProps, LexicalActionDefinition, } from "../types" import { lexicalMessages } from "../messages" const fontSizes = ["12px", "14px", "16px", "18px", "24px", "32px"] as const function FontSizeControl({ context, label }: LexicalActionDefaultControlProps) { const fontSize = context.editor.getEditorState().read(() => { const selection = $getSelection() return $isRangeSelection(selection) ? $getSelectionStyleValueForProperty(selection, "font-size", "16px") : "16px" }) return ( event.preventDefault()} /> } > {fontSize} fontSizeAction.execute(context, value)} > {fontSizes.map((size) => ( event.preventDefault()} > {size} ))} ) } export const fontSizeAction: LexicalActionDefinition = { name: "fontSize", label: lexicalMessages.fontSize, icon: ALargeSmall, control: FontSizeControl, execute: ({ editor }, value = "16px") => { editor.update(() => { const selection = $getSelection() if ($isRangeSelection(selection)) { $patchStyleText(selection, { "font-size": value }) } }) }, }