Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(editor): reduce the editor chrome to a single icon toolbar

Luis Ortiz0515648506b6
diff --git a/src/ui/shared/AnnotationEditor.tsx b/src/ui/shared/AnnotationEditor.tsx
index f13fb1d..942300b 100644
--- a/src/ui/shared/AnnotationEditor.tsx
+++ b/src/ui/shared/AnnotationEditor.tsx
@@ -1,6 +1,5 @@
import {
ArrowUpRight,
- Check,
ChevronDown,
Circle as CircleIcon,
CopyPlus,
@@ -9,7 +8,6 @@ import {
EyeOff,
Minus,
MoveVertical,
- Pencil,
PenTool,
Redo2,
RotateCcw,
@@ -18,7 +16,6 @@ import {
Trash2,
Type,
Undo2,
- X,
} from 'lucide-react';
import type { ComponentType, ReactNode } from 'react';
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
@@ -65,7 +62,7 @@ import {
} from '@/ui/components/ui/dropdown-menu';
type EditorMode = 'crop' | 'annotate' | 'redact';
-type EditorTool = 'eraser' | 'line' | 'arrow' | 'box' | 'ellipse' | 'text' | 'freehand';
+type EditorTool = 'crop' | 'box' | 'ellipse' | 'arrow' | 'line' | 'freehand' | 'text' | 'redact' | 'eraser';
interface AnnotationEditorProps {
screenshot: Screenshot;
@@ -150,25 +147,21 @@ const SELECTION_GAP = 6;
const DRAFT_ID = 'draft';
const TARGET_ID = 'click-target';
-const MODES: { id: EditorMode; icon: ComponentType<{ size?: number }>; labelKey: string }[] = [
- { id: 'crop', icon: Crop, labelKey: 'annotationEditor.toolCrop' },
- { id: 'annotate', icon: Pencil, labelKey: 'annotationEditor.modeAnnotate' },
- { id: 'redact', icon: EyeOff, labelKey: 'annotationEditor.toolRedact' },
-];
-
const TOOLS: { id: EditorTool; icon: ComponentType<{ size?: number }>; labelKey: string }[] = [
- { id: 'eraser', icon: Eraser, labelKey: 'annotationEditor.toolEraser' },
- { id: 'line', icon: Minus, labelKey: 'annotationEditor.toolLine' },
- { id: 'arrow', icon: ArrowUpRight, labelKey: 'annotationEditor.toolArrow' },
+ { id: 'crop', icon: Crop, labelKey: 'annotationEditor.toolCrop' },
{ id: 'box', icon: Square, labelKey: 'annotationEditor.toolBox' },
{ id: 'ellipse', icon: CircleIcon, labelKey: 'annotationEditor.toolEllipse' },
- { id: 'text', icon: Type, labelKey: 'annotationEditor.toolText' },
+ { id: 'arrow', icon: ArrowUpRight, labelKey: 'annotationEditor.toolArrow' },
+ { id: 'line', icon: Minus, labelKey: 'annotationEditor.toolLine' },
{ id: 'freehand', icon: PenTool, labelKey: 'annotationEditor.toolFreehand' },
+ { id: 'text', icon: Type, labelKey: 'annotationEditor.toolText' },
+ { id: 'redact', icon: EyeOff, labelKey: 'annotationEditor.toolRedact' },
+ { id: 'eraser', icon: Eraser, labelKey: 'annotationEditor.toolEraser' },
];
-function initialModeFor(tool: 'annotate' | 'redact' | 'crop' | 'target'): EditorMode {
- if (tool === 'redact') return 'redact';
+function modeForTool(tool: EditorTool): EditorMode {
if (tool === 'crop') return 'crop';
+ if (tool === 'redact') return 'redact';
return 'annotate';
}
@@ -208,7 +201,9 @@ function hitHandle(b: ScreenshotBounds, x: number, y: number, radius: number): H
}
export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }: AnnotationEditorProps) {
- const [activeTool, setActiveTool] = useState<EditorTool>('box');
+ const [activeTool, setActiveTool] = useState<EditorTool>(
+ tool === 'crop' ? 'crop' : tool === 'redact' ? 'redact' : 'box',
+ );
const [annotations, setAnnotations] = useState<Annotation[]>(() => {
const existing = screenshot.edits?.annotations ?? [];
const t = resolveTarget(screenshot);
@@ -232,11 +227,11 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:
const [anchor, setAnchor] = useState<{ x: number; y: number } | null>(null);
const [hue, setHue] = useState(0);
const [grabbing, setGrabbing] = useState(false);
- const [mode, setMode] = useState<EditorMode>(initialModeFor(tool));
- const [fill, setFill] = useState('transparent');
- const [lineWidth, setLineWidth] = useState<LineWidth>('ms');
- const [radius, setRadius] = useState(0);
- const [arrowEnd, setArrowEnd] = useState<ArrowEnd>('arrow-solid');
+
+ const [fill] = useState('transparent');
+ const [lineWidth] = useState<LineWidth>('ms');
+ const [radius] = useState(0);
+ const [arrowEnd] = useState<ArrowEnd>('arrow-solid');
const [fontFamily, setFontFamily] = useState<FontFamily>('sans-serif');
const [bold, setBold] = useState(false);
const [italic, setItalic] = useState(false);
@@ -267,6 +262,7 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:
setFuture((f) => f.slice(1));
};
+ const mode = modeForTool(activeTool);
const selected = annotations.find((a) => a.id === selectedId);
const selectedTarget = selected?.type === 'target' ? selected : null;
@@ -744,192 +740,87 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:
return (
<div className="fixed inset-0 z-50 bg-black/80 flex flex-col">
- <div className="shrink-0 bg-card border-b border-border px-4 py-2.5 flex flex-col gap-2">
- <div className="flex items-center gap-3 w-full justify-between">
- <div className="flex items-center gap-1">
- <button
- type="button"
- onClick={undo}
- disabled={past.length === 0}
- title={i18n.t('annotationEditor.undo')}
- className="flex items-center justify-center w-8 h-8 rounded-lg text-foreground hover:bg-secondary disabled:opacity-30"
- >
- <Undo2 size={15} />
- </button>
- <button
- type="button"
- onClick={redo}
- disabled={future.length === 0}
- title={i18n.t('annotationEditor.redo')}
- className="flex items-center justify-center w-8 h-8 rounded-lg text-foreground hover:bg-secondary disabled:opacity-30"
- >
- <Redo2 size={15} />
- </button>
- </div>
- <div className="flex items-center gap-2">
- {MODES.map(({ id, icon: Icon, labelKey }) => (
- <button
- key={id}
- type="button"
- onClick={() => {
- setMode(id);
- setSelectedId(null);
- }}
- className={`flex flex-col items-center justify-center gap-1 w-[74px] h-[60px] rounded-xl border transition-colors ${
- mode === id
- ? 'bg-secondary border-accent text-accent'
- : 'bg-card border-border text-foreground hover:bg-secondary/50'
- }`}
- >
- <Icon size={17} />
- <span className="text-[11px] font-semibold">{i18n.t(labelKey)}</span>
- </button>
- ))}
- </div>
- <div className="flex items-center gap-1.5">
+ <div className="shrink-0 bg-primary px-3 h-12 flex items-center justify-between gap-4">
+ <div className="flex items-center gap-1">
+ <button
+ type="button"
+ onClick={undo}
+ disabled={past.length === 0}
+ title={i18n.t('annotationEditor.undo')}
+ className="flex items-center justify-center w-8 h-8 rounded-lg text-primary-foreground hover:bg-primary-foreground/15 disabled:opacity-25"
+ >
+ <Undo2 size={15} />
+ </button>
+ <button
+ type="button"
+ onClick={redo}
+ disabled={future.length === 0}
+ title={i18n.t('annotationEditor.redo')}
+ className="flex items-center justify-center w-8 h-8 rounded-lg text-primary-foreground hover:bg-primary-foreground/15 disabled:opacity-25"
+ >
+ <Redo2 size={15} />
+ </button>
+ </div>
+
+ <div className="flex items-center gap-0.5">
+ {TOOLS.map(({ id, icon: Icon, labelKey }) => (
<button
+ key={id}
type="button"
- onClick={onCancel}
- className="flex items-center gap-1 px-3 h-8 text-[12px] font-semibold text-foreground rounded-lg border border-border hover:bg-secondary"
+ onClick={() => {
+ setActiveTool(id);
+ setSelectedId(null);
+ }}
+ title={i18n.t(labelKey)}
+ aria-pressed={activeTool === id}
+ className={`flex items-center justify-center w-9 h-8 rounded-lg transition-colors ${
+ activeTool === id
+ ? 'bg-primary-foreground/20 text-primary-foreground'
+ : 'text-primary-foreground/60 hover:bg-primary-foreground/10 hover:text-primary-foreground'
+ }`}
>
- <X size={13} />
- {i18n.t('common.cancel')}
+ <Icon size={16} />
</button>
+ ))}
+ <span className="w-px h-5 bg-primary-foreground/20 mx-1.5" />
+ <input
+ type="color"
+ value={color}
+ onChange={(e) => handleColorSelect(e.target.value)}
+ title={i18n.t('annotationEditor.lineColor')}
+ className="w-7 h-7 rounded-full border-2 border-primary-foreground/25 bg-transparent p-0 cursor-pointer"
+ />
+ </div>
+
+ <div className="flex items-center gap-1.5">
+ {mode === 'crop' && viewport && (
<button
type="button"
- onClick={handleDone}
- disabled={saving}
- className="flex items-center gap-1 px-3.5 h-8 text-[12px] font-bold text-primary-foreground bg-accent rounded-lg hover:bg-accent/90 disabled:opacity-50"
+ onClick={() => {
+ setViewport(undefined);
+ setCropDraft(null);
+ }}
+ className="flex items-center gap-1.5 px-2.5 h-8 rounded-lg text-[12px] font-semibold text-primary-foreground/80 hover:bg-primary-foreground/15"
>
- <Check size={13} />
- {i18n.t('annotationEditor.done')}
+ <RotateCcw size={13} />
+ {i18n.t('annotationEditor.resetCrop')}
</button>
- </div>
- </div>
- <div className="flex items-center justify-center gap-4 flex-wrap min-h-[38px]">
- {mode === 'annotate' && (
- <div className="flex items-center gap-1">
- {TOOLS.map(({ id, icon: Icon, labelKey }) => (
- <button
- key={id}
- type="button"
- onClick={() => setActiveTool(id)}
- className={`flex items-center gap-1.5 px-3 h-8 rounded-lg text-[12px] font-medium transition-colors ${
- activeTool === id ? 'bg-secondary text-accent' : 'text-foreground hover:bg-secondary/60'
- }`}
- >
- <Icon size={14} />
- {i18n.t(labelKey)}
- </button>
- ))}
- </div>
- )}
-
- {mode === 'annotate' && (
- <div className="flex items-end gap-5 min-h-[46px]">
- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">
- {i18n.t('annotationEditor.lineColor')}
- <input
- type="color"
- value={color}
- onChange={(e) => handleColorSelect(e.target.value)}
- className="w-7 h-7 rounded-full border border-border bg-transparent p-0 cursor-pointer"
- />
- </label>
- {(activeTool === 'box' || activeTool === 'ellipse') && (
- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">
- {i18n.t('annotationEditor.fillColor')}
- <select
- value={fill}
- onChange={(e) => {
- setFill(e.target.value);
- setProp('fill', e.target.value);
- }}
- className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"
- style={{ color: fill === 'transparent' ? undefined : fill }}
- >
- {SHAPE_COLORS.map((c) => (
- <option key={c} value={c}>
- {c === 'transparent' ? i18n.t('annotationEditor.noFill') : c}
- </option>
- ))}
- </select>
- </label>
- )}
- {activeTool !== 'text' && (
- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">
- {i18n.t('annotationEditor.lineWidth')}
- <select
- value={lineWidth}
- onChange={(e) => {
- setLineWidth(e.target.value as LineWidth);
- setProp('lineWidth', e.target.value);
- }}
- className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none capitalize"
- >
- {LINE_WIDTH_ORDER.map((w) => (
- <option key={w} value={w}>
- {i18n.t(`annotationEditor.width_${w}`)}
- </option>
- ))}
- </select>
- </label>
- )}
- {activeTool === 'box' && (
- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">
- {i18n.t('annotationEditor.cornerRadius')}
- <input
- type="range"
- min={0}
- max={60}
- value={radius}
- onChange={(e) => {
- setRadius(Number(e.target.value));
- setProp('radius', Number(e.target.value));
- }}
- className="w-24 h-7 accent-accent"
- />
- </label>
- )}
- {activeTool === 'arrow' && (
- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">
- {i18n.t('annotationEditor.arrowEnd')}
- <select
- value={arrowEnd}
- onChange={(e) => {
- setArrowEnd(e.target.value as ArrowEnd);
- setProp('end', e.target.value);
- }}
- className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"
- >
- {ARROW_ENDS.map((end) => (
- <option key={end} value={end}>
- {i18n.t(`annotationEditor.end_${end.replace('-', '_')}`)}
- </option>
- ))}
- </select>
- </label>
- )}
- </div>
- )}
-
- {mode === 'crop' && (
- <div className="flex items-center gap-3 min-h-[46px]">
- <span className="text-[11px] text-muted-foreground">{i18n.t('annotationEditor.cropHint')}</span>
- <button
- type="button"
- onClick={() => {
- setViewport(undefined);
- setCropDraft(null);
- }}
- disabled={!viewport}
- className="flex items-center gap-1.5 px-3 h-8 rounded-lg border border-border text-[12px] font-semibold text-foreground hover:bg-secondary disabled:opacity-40"
- >
- <RotateCcw size={13} />
- {i18n.t('annotationEditor.resetCrop')}
- </button>
- </div>
)}
+ <button
+ type="button"
+ onClick={onCancel}
+ className="px-3 h-8 text-[12px] font-semibold text-primary-foreground/80 rounded-lg hover:bg-primary-foreground/15"
+ >
+ {i18n.t('common.cancel')}
+ </button>
+ <button
+ type="button"
+ onClick={handleDone}
+ disabled={saving}
+ className="px-4 h-8 text-[12px] font-bold text-primary bg-primary-foreground rounded-lg hover:bg-primary-foreground/90 disabled:opacity-50"
+ >
+ {i18n.t('annotationEditor.done')}
+ </button>
</div>
</div>
<div className="flex-1 flex overflow-hidden">
@@ -1017,6 +908,59 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:
<CopyPlus size={14} />
</button>
)}
+ {(selected.type === 'box' || selected.type === 'ellipse') && (
+ <select
+ value={selected.fill ?? 'transparent'}
+ onChange={(e) => setProp('fill', e.target.value)}
+ title={i18n.t('annotationEditor.fillColor')}
+ className="h-6 rounded-md bg-primary-foreground/10 px-1 text-[10px] text-primary-foreground outline-none"
+ >
+ {SHAPE_COLORS.map((c) => (
+ <option key={c} value={c}>
+ {c === 'transparent' ? i18n.t('annotationEditor.noFill') : c}
+ </option>
+ ))}
+ </select>
+ )}
+ {selected.type !== 'text' && selected.type !== 'redact' && (
+ <select
+ value={selected.type === 'target' ? 'ms' : (selected.lineWidth ?? 'ms')}
+ onChange={(e) => setProp('lineWidth', e.target.value)}
+ title={i18n.t('annotationEditor.lineWidth')}
+ className="h-6 rounded-md bg-primary-foreground/10 px-1 text-[10px] text-primary-foreground outline-none"
+ >
+ {LINE_WIDTH_ORDER.map((w) => (
+ <option key={w} value={w}>
+ {i18n.t(`annotationEditor.width_${w}`)}
+ </option>
+ ))}
+ </select>
+ )}
+ {selected.type === 'box' && (
+ <Stepper
+ title={i18n.t('annotationEditor.cornerRadius')}
+ value={Math.round(selected.radius ?? 0)}
+ min={0}
+ max={60}
+ step={4}
+ width="w-6"
+ onChange={(v) => setProp('radius', v)}
+ />
+ )}
+ {selected.type === 'arrow' && (
+ <select
+ value={selected.end ?? 'arrow-solid'}
+ onChange={(e) => setProp('end', e.target.value)}
+ title={i18n.t('annotationEditor.arrowEnd')}
+ className="h-6 rounded-md bg-primary-foreground/10 px-1 text-[10px] text-primary-foreground outline-none"
+ >
+ {ARROW_ENDS.map((end) => (
+ <option key={end} value={end}>
+ {i18n.t(`annotationEditor.end_${end.replace('-', '_')}`)}
+ </option>
+ ))}
+ </select>
+ )}
{selected.type === 'text' && (
<>
<DropdownMenu>