Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Refactor annotation config UI and remove presets dropdown
Richie McIlroy97ad9ead7b3a
diff --git a/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx b/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsxindex e32d30a19..129104c0a 100644--- a/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx+++ b/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx@@ -1,12 +1,12 @@import { Popover } from "@kobalte/core/popover";-import { createMemo, For, Show } from "solid-js";-import { Portal } from "solid-js/web";+import { cx } from "cva";+import { createMemo, For, type JSX, Show } from "solid-js";import Tooltip from "~/components/Tooltip";import { BACKGROUND_COLORS, hexToRgb, RgbInput, rgbToHex } from "./ColorPicker";import { type Annotation, useScreenshotEditorContext } from "./context";import { Slider } from "./ui";-export function AnnotationConfig() {+export function AnnotationConfigBar() {const {annotations,selectedAnnotationId,@@ -35,154 +35,156 @@ export function AnnotationConfig() {const maskType = () => ann().maskType ?? "blur";const maskLevel = () => ann().maskLevel ?? 16;return (- <Portal>- <div class="fixed left-1/2 -translate-x-1/2 top-20 z-50 overflow-hidden rounded-xl border border-gray-3 bg-gray-1 shadow-xl animate-in fade-in zoom-in-95">- <div class="flex items-center gap-4 p-4">- <Show when={!isMask}>- <div class="flex flex-col gap-1">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">- {type === "text" ? "Color" : "Stroke"}- </span>- <ColorPickerButton- value={ann().strokeColor}- onChange={(c) => update("strokeColor", c)}- />- </div>- </Show>+ <div class="w-full border-b border-gray-3 bg-gray-1 dark:bg-gray-2 animate-in fade-in slide-in-from-top-1 duration-150">+ <div class="flex items-center justify-center gap-6 px-4 h-11">+ <Show when={!isMask}>+ <ConfigItem label={type === "text" ? "Color" : "Stroke"}>+ <ColorPickerButton+ value={ann().strokeColor}+ onChange={(c) => update("strokeColor", c)}+ />+ </ConfigItem>+ </Show>- <Show when={type !== "text" && !isMask}>- <div class="flex flex-col gap-1 w-24">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">- Width <span>{ann().strokeWidth}px</span>- </span>- <Slider- value={[ann().strokeWidth]}- onChange={(v) => update("strokeWidth", v[0])}- minValue={1}- maxValue={20}- step={1}- class="w-full"- />- </div>- </Show>+ <Show when={type !== "text" && !isMask}>+ <ConfigItem label="Width" value={`${ann().strokeWidth}px`}>+ <Slider+ value={[ann().strokeWidth]}+ onChange={(v) => update("strokeWidth", v[0])}+ minValue={1}+ maxValue={20}+ step={1}+ class="w-20"+ />+ </ConfigItem>+ </Show>- <Show when={type === "rectangle" || type === "circle"}>- <div class="flex flex-col gap-1">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">- Fill- </span>- <ColorPickerButton- value={ann().fillColor}- onChange={(c) => update("fillColor", c)}- allowTransparent- />- </div>- </Show>+ <Show when={type === "rectangle" || type === "circle"}>+ <ConfigItem label="Fill">+ <ColorPickerButton+ value={ann().fillColor}+ onChange={(c) => update("fillColor", c)}+ allowTransparent+ />+ </ConfigItem>+ </Show>- <Show when={!isMask}>- <div class="flex flex-col gap-1 w-24">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">- Opacity <span>{Math.round(ann().opacity * 100)}%</span>- </span>- <Slider- value={[ann().opacity]}- onChange={(v) => update("opacity", v[0])}- minValue={0.1}- maxValue={1}- step={0.1}- class="w-full"- />- </div>- </Show>+ <Show when={!isMask}>+ <ConfigItem+ label="Opacity"+ value={`${Math.round(ann().opacity * 100)}%`}+ >+ <Slider+ value={[ann().opacity]}+ onChange={(v) => update("opacity", v[0])}+ minValue={0.1}+ maxValue={1}+ step={0.1}+ class="w-20"+ />+ </ConfigItem>+ </Show>- <Show when={type === "mask"}>- <div class="flex flex-col gap-1">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">- Style- </span>- <div class="flex gap-1">- <button- type="button"- class={`px-3 h-8 rounded-lg border ${- maskType() === "blur"- ? "border-blue-7 bg-blue-3 text-blue-11"- : "border-gray-4 bg-gray-2 text-gray-11"- }`}- onClick={() => update("maskType", "blur")}- >- Blur- </button>- <button- type="button"- class={`px-3 h-8 rounded-lg border ${- maskType() === "pixelate"- ? "border-blue-7 bg-blue-3 text-blue-11"- : "border-gray-4 bg-gray-2 text-gray-11"- }`}- onClick={() => update("maskType", "pixelate")}- >- Pixelate- </button>- </div>+ <Show when={type === "mask"}>+ <ConfigItem label="Style">+ <div class="flex gap-1">+ <button+ type="button"+ class={cx(+ "px-2.5 h-6 rounded-md text-xs font-medium transition-colors",+ maskType() === "blur"+ ? "bg-blue-9 text-white"+ : "bg-gray-3 text-gray-11 hover:bg-gray-4",+ )}+ onClick={() => update("maskType", "blur")}+ >+ Blur+ </button>+ <button+ type="button"+ class={cx(+ "px-2.5 h-6 rounded-md text-xs font-medium transition-colors",+ maskType() === "pixelate"+ ? "bg-blue-9 text-white"+ : "bg-gray-3 text-gray-11 hover:bg-gray-4",+ )}+ onClick={() => update("maskType", "pixelate")}+ >+ Pixelate+ </button></div>- </Show>+ </ConfigItem>+ </Show>- <Show when={type === "mask"}>- <div class="flex flex-col gap-1 w-28">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">- Intensity <span>{Math.round(maskLevel())}</span>- </span>- <Slider- value={[maskLevel()]}- onChange={(v) => update("maskLevel", v[0])}- minValue={4}- maxValue={50}- step={1}- class="w-full"- />- </div>- </Show>+ <Show when={type === "mask"}>+ <ConfigItem+ label="Intensity"+ value={`${Math.round(maskLevel())}`}+ >+ <Slider+ value={[maskLevel()]}+ onChange={(v) => update("maskLevel", v[0])}+ minValue={4}+ maxValue={50}+ step={1}+ class="w-24"+ />+ </ConfigItem>+ </Show>- <Show when={type === "text"}>- <div class="flex flex-col gap-1 w-24">- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">- Size <span>{ann().height}px</span>- </span>- <Slider- value={[ann().height]}- onChange={(v) => update("height", v[0])}- minValue={12}- maxValue={100}- step={1}- class="w-full"- />- </div>- </Show>+ <Show when={type === "text"}>+ <ConfigItem label="Size" value={`${ann().height}px`}>+ <Slider+ value={[ann().height]}+ onChange={(v) => update("height", v[0])}+ minValue={12}+ maxValue={100}+ step={1}+ class="w-20"+ />+ </ConfigItem>+ </Show>- <div class="w-px h-8 bg-gray-4 mx-1" />+ <div class="w-px h-5 bg-gray-4" />- <button- type="button"- class="text-xs text-blue-11 font-medium hover:text-blue-9 px-2 h-full"- onClick={() => setSelectedAnnotationId(null)}- >- Done- </button>- </div>+ <button+ type="button"+ class="text-xs text-blue-11 font-medium hover:text-blue-9 transition-colors"+ onClick={() => setSelectedAnnotationId(null)}+ >+ Done+ </button></div>- </Portal>+ </div>);}}</Show>);}+function ConfigItem(props: {+ label: string;+ value?: string;+ children: JSX.Element;+}) {+ return (+ <div class="flex items-center gap-2">+ <span class="text-[11px] text-gray-10 font-medium whitespace-nowrap">+ {props.label}+ {props.value && (+ <span class="text-gray-11 ml-1 tabular-nums">{props.value}</span>+ )}+ </span>+ {props.children}+ </div>+ );+}+function ColorPickerButton(props: {value: string;onChange: (value: string) => void;allowTransparent?: boolean;}) {- // Helper to handle RGB <-> Hexconst rgbValue = createMemo(() => {if (props.value === "transparent")return [0, 0, 0] as [number, number, number];@@ -194,24 +196,24 @@ function ColorPickerButton(props: {const isTransparent = createMemo(() => props.value === "transparent");return (- <Popover placement="bottom">+ <Popover placement="bottom" gutter={8}><Popover.Trigger class="outline-none group">- <div class="size-6 rounded-full border border-gray-4 p-0.5 bg-white dark:bg-gray-2 transition-transform group-hover:scale-105 group-active:scale-95 shadow-sm">+ <div class="size-5 rounded-full border border-gray-5 transition-all group-hover:scale-110 group-hover:border-gray-7 group-active:scale-95 overflow-hidden"><div- class="w-full h-full rounded-full border border-black/5"+ class="w-full h-full"style={{background: isTransparent()? "linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)": props.value,- "background-size": isTransparent() ? "4px 4px" : "auto",+ "background-size": isTransparent() ? "3px 3px" : "auto","background-color": isTransparent() ? "white" : props.value,}}/></div></Popover.Trigger><Popover.Portal>- <Popover.Content class="z-[200] w-[240px] overflow-hidden rounded-xl border border-gray-3 bg-gray-1 shadow-xl animate-in fade-in zoom-in-95 p-3">- <div class="flex flex-col gap-3">+ <Popover.Content class="z-[200] w-[220px] overflow-hidden rounded-lg border border-gray-4 bg-gray-1 dark:bg-gray-2 shadow-lg animate-in fade-in zoom-in-95 p-2.5">+ <div class="flex flex-col gap-2.5"><RgbInputvalue={rgbValue()}onChange={(rgb) => {@@ -219,17 +221,17 @@ function ColorPickerButton(props: {}}/>- <div class="grid grid-cols-6 gap-2">+ <div class="grid grid-cols-6 gap-1.5"><Show when={props.allowTransparent}><Tooltip content="Transparent"><buttontype="button"onClick={() => props.onChange("transparent")}- class="size-6 rounded-full border border-gray-3 relative overflow-hidden hover:scale-110 transition-transform"+ class="size-5 rounded-full border border-gray-4 relative overflow-hidden hover:scale-110 transition-transform"style={{background:"linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)",- "background-size": "4px 4px",+ "background-size": "3px 3px","background-color": "white",}}>@@ -243,14 +245,14 @@ function ColorPickerButton(props: {{(color: string) => (<buttontype="button"- class="size-6 rounded-full border border-black/10 hover:scale-110 transition-transform relative"+ class="size-5 rounded-full border border-black/10 hover:scale-110 transition-transform relative"style={{ "background-color": color }}onClick={() => props.onChange(color)}><Showwhen={props.value.toLowerCase() === color.toLowerCase()}>- <div class="absolute inset-0 ring-2 ring-white/50 rounded-full shadow-sm" />+ <div class="absolute inset-0 ring-2 ring-white/50 rounded-full" /></Show></button>)}diff --git a/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx b/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsxindex 41927cc45..c4eeacacf 100644--- a/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx+++ b/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx@@ -7,52 +7,43 @@ import IconLucideEyeOff from "~icons/lucide/eye-off";import IconLucideMousePointer2 from "~icons/lucide/mouse-pointer-2";import IconLucideSquare from "~icons/lucide/square";import IconLucideType from "~icons/lucide/type";-import { AnnotationConfig } from "./AnnotationConfig";import { type AnnotationType, useScreenshotEditorContext } from "./context";export function AnnotationTools() {return (- <>- <div class="flex items-center gap-1">- <ToolButton- tool="select"- icon={IconLucideMousePointer2}- label="Select"- shortcut="V"- />- <ToolButton- tool="arrow"- icon={IconLucideArrowUpRight}- label="Arrow"- shortcut="A"- />- <ToolButton- tool="rectangle"- icon={IconLucideSquare}- label="Rectangle"- shortcut="R"- />- <ToolButton- tool="mask"- icon={IconLucideEyeOff}- label="Mask"- shortcut="M"- />- <ToolButton- tool="circle"- icon={IconLucideCircle}- label="Circle"- shortcut="C"- />- <ToolButton- tool="text"- icon={IconLucideType}- label="Text"- shortcut="T"- />- </div>- <AnnotationConfig />- </>+ <div class="flex items-center gap-1">+ <ToolButton+ tool="select"+ icon={IconLucideMousePointer2}+ label="Select"+ shortcut="V"+ />+ <ToolButton+ tool="arrow"+ icon={IconLucideArrowUpRight}+ label="Arrow"+ shortcut="A"+ />+ <ToolButton+ tool="rectangle"+ icon={IconLucideSquare}+ label="Rectangle"+ shortcut="R"+ />+ <ToolButton+ tool="mask"+ icon={IconLucideEyeOff}+ label="Mask"+ shortcut="M"+ />+ <ToolButton+ tool="circle"+ icon={IconLucideCircle}+ label="Circle"+ shortcut="C"+ />+ <ToolButton tool="text" icon={IconLucideType} label="Text" shortcut="T" />+ </div>);}diff --git a/apps/desktop/src/routes/screenshot-editor/Header.tsx b/apps/desktop/src/routes/screenshot-editor/Header.tsxindex cfa497ab9..e1e26f713 100644--- a/apps/desktop/src/routes/screenshot-editor/Header.tsx+++ b/apps/desktop/src/routes/screenshot-editor/Header.tsx@@ -15,7 +15,6 @@ import IconLucideMoreHorizontal from "~icons/lucide/more-horizontal";import IconLucideSave from "~icons/lucide/save";import { AnnotationTools } from "./AnnotationTools";import { useScreenshotEditorContext } from "./context";-import PresetsSubMenu from "./PresetsDropdown";import { AspectRatioSelect } from "./popovers/AspectRatioSelect";import { BackgroundSettingsPopover } from "./popovers/BackgroundSettingsPopover";import { BorderPopover } from "./popovers/BorderPopover";@@ -32,8 +31,9 @@ import {import { useScreenshotExport } from "./useScreenshotExport";export function Header() {- const { path, setDialog, project, latestFrame } =- useScreenshotEditorContext();+ const ctx = useScreenshotEditorContext();+ const { setDialog, project, latestFrame } = ctx;+ const path = () => ctx.editorInstance()?.path ?? "";const { exportImage, isExporting } = useScreenshotExport();@@ -149,7 +149,7 @@ export function Header() {><DropdownItemonSelect={() => {- revealItemInDir(path);+ revealItemInDir(path());}}><IconLucideFolder class="size-4 text-gray-11" />@@ -162,7 +162,7 @@ export function Header() {"Are you sure you want to delete this screenshot?",)) {- await remove(path);+ await remove(path());await getCurrentWindow().close();}}}@@ -171,15 +171,6 @@ export function Header() {<span>Delete</span></DropdownItem></MenuItemList>-- <DropdownMenu.Separator class="h-px bg-gray-4 mx-1 my-1" />-- <MenuItemList<typeof DropdownMenu.Group>- as={DropdownMenu.Group}- class="p-1"- >- <PresetsSubMenu />- </MenuItemList></PopperContent></Suspense></DropdownMenu.Portal>diff --git a/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx b/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsxdeleted file mode 100644index 7f212b772..000000000--- a/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx+++ /dev/null@@ -1,57 +0,0 @@-import { DropdownMenu as KDropdownMenu } from "@kobalte/core/dropdown-menu";-import { cx } from "cva";-import { Suspense } from "solid-js";-import IconCapCirclePlus from "~icons/cap/circle-plus";-import IconCapPresets from "~icons/cap/presets";-import IconLucideChevronRight from "~icons/lucide/chevron-right";-import {- DropdownItem,- MenuItemList,- PopperContent,- topSlideAnimateClasses,-} from "./ui";--export function PresetsSubMenu() {- return (- <KDropdownMenu.Sub gutter={8}>- <KDropdownMenu.SubTrigger- as={DropdownItem}- class="justify-between cursor-default"- >- <div class="flex items-center gap-2">- <IconCapPresets />- <span>Presets</span>- </div>- <IconLucideChevronRight class="size-3 text-gray-10" />- </KDropdownMenu.SubTrigger>- <KDropdownMenu.Portal>- <Suspense>- <PopperContent<typeof KDropdownMenu.SubContent>- as={KDropdownMenu.SubContent}- class={cx("w-72 max-h-56", topSlideAnimateClasses)}- >- <MenuItemList<typeof KDropdownMenu.Group>- as={KDropdownMenu.Group}- class="overflow-y-auto flex-1 scrollbar-none"- >- <div class="py-1 w-full text-sm text-center text-gray-11">- No Presets- </div>- </MenuItemList>- <MenuItemList<typeof KDropdownMenu.Group>- as={KDropdownMenu.Group}- class="border-t shrink-0"- >- <DropdownItem disabled>- <span>Create new preset</span>- <IconCapCirclePlus class="ml-auto" />- </DropdownItem>- </MenuItemList>- </PopperContent>- </Suspense>- </KDropdownMenu.Portal>- </KDropdownMenu.Sub>- );-}--export default PresetsSubMenu;