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(ui): compact the top bar to fit narrow windows

Luis Ortiz1d48b2ca98b9
diff --git a/apps/desktop/src/renderer/GuideZoom.tsx b/apps/desktop/src/renderer/GuideZoom.tsx
index bdffc59..e75c3af 100644
--- a/apps/desktop/src/renderer/GuideZoom.tsx
+++ b/apps/desktop/src/renderer/GuideZoom.tsx
@@ -52,10 +52,11 @@ export function GuideZoom({ guideId, onDone }: { guideId: string; onDone: () =>
className="h-8 w-auto gap-1.5 rounded-lg border-border bg-card px-3 text-[13px] font-medium text-foreground hover:bg-secondary hover:text-accent"
>
<ZoomIn size={14} />
- {i18n.t('desktop_zoomGuide')}
+ <span className="@max-[960px]:hidden">{i18n.t('desktop_zoomGuide')}</span>
{current !== null && (
<span className="text-muted-foreground">
- Β· {current === 'auto' ? i18n.t('desktop_zoomAuto') : `${current}Γ—`}
+ <span className="@max-[960px]:hidden">Β· </span>
+ {current === 'auto' ? i18n.t('desktop_zoomAuto') : `${current}Γ—`}
</span>
)}
</SelectTrigger>
diff --git a/packages/ui/src/navigation/components/BarButton.tsx b/packages/ui/src/navigation/components/BarButton.tsx
new file mode 100644
index 0000000..32696d4
--- /dev/null
+++ b/packages/ui/src/navigation/components/BarButton.tsx
@@ -0,0 +1,28 @@
+import type { ComponentProps, ReactNode } from 'react';
+import { Button } from '../../components/ui/button';
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../components/ui/tooltip';
+
+type BarButtonProps = ComponentProps<typeof Button> & { icon: ReactNode; label: string; iconOnly: boolean };
+
+export function BarButton({ icon, label, iconOnly, className, ...props }: BarButtonProps) {
+ if (!iconOnly) {
+ return (
+ <Button size="sm" className={className} {...props}>
+ {icon}
+ {label}
+ </Button>
+ );
+ }
+ return (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button size="sm" aria-label={label} className={`${className ?? ''} w-8 px-0`} {...props}>
+ {icon}
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>{label}</TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+}
diff --git a/packages/ui/src/navigation/components/TopBar.tsx b/packages/ui/src/navigation/components/TopBar.tsx
index 7978f47..8dd3258 100644
--- a/packages/ui/src/navigation/components/TopBar.tsx
+++ b/packages/ui/src/navigation/components/TopBar.tsx
@@ -8,8 +8,10 @@ import { Button } from '../../components/ui/button';
import { ExportPreviewModal } from '../../export/components/ExportPreviewModal';
import { LibraryTools } from '../../library/components/LibraryTools';
import { useFullview } from '../../stores/use-fullview';
+import { useElementWidth } from '../hooks/use-element-width';
import { navigate } from '../lib/navigate';
import type { Route } from '../types';
+import { BarButton } from './BarButton';
interface TopBarProps {
route: Route;
@@ -22,6 +24,8 @@ const NAV_CONTROL =
const SEARCH_KEY = navigator.userAgent.includes('Mac') ? '⌘K' : 'Ctrl K';
const DUPLICATE_SETTLE_MS = 700;
+const COMPACT_SEARCH_PX = 960;
+const ICON_ONLY_PX = 740;
export function TopBar({ route, guideActions }: TopBarProps) {
const {
@@ -50,6 +54,9 @@ export function TopBar({ route, guideActions }: TopBarProps) {
const [exportOpen, setExportOpen] = useState(false);
const [duplicating, setDuplicating] = useState(false);
const settleTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const bar = useRef<HTMLElement>(null);
+ const barWidth = useElementWidth(bar);
+ const iconOnly = barWidth < ICON_ONLY_PX;
const routeKey = route.page === 'guide' ? `guide/${route.guideId}` : `library/${route.category}`;
const [duplicateFailedOnRoute, setDuplicateFailedOnRoute] = useState<string | null>(null);
@@ -97,15 +104,21 @@ export function TopBar({ route, guideActions }: TopBarProps) {
return (
<>
- <header className="sticky top-0 z-30 flex items-center gap-3 px-7 h-16 shrink-0 bg-card border-b border-border">
+ <header
+ ref={bar}
+ className="@container sticky top-0 z-30 flex items-center gap-3 px-7 h-16 shrink-0 bg-card border-b border-border"
+ >
<Button
size="sm"
variant="ghost"
+ aria-label={i18n.t('fullview_searchPlaceholder')}
onClick={() => setSearchOpen(true)}
- className={`w-72 justify-start ${NAV_CONTROL}`}
+ className={`${barWidth < COMPACT_SEARCH_PX ? 'w-auto' : 'w-72'} justify-start ${NAV_CONTROL}`}
>
<Search size={14} className="shrink-0 text-muted-foreground" />
- <span className="flex-1 text-left text-muted-foreground">{i18n.t('fullview_searchPlaceholder')}</span>
+ {barWidth >= COMPACT_SEARCH_PX && (
+ <span className="flex-1 text-left text-muted-foreground">{i18n.t('fullview_searchPlaceholder')}</span>
+ )}
<span className="text-[10px] font-semibold px-1.5 py-0.5 rounded-md bg-secondary text-muted-foreground">
{SEARCH_KEY}
</span>
@@ -116,42 +129,43 @@ export function TopBar({ route, guideActions }: TopBarProps) {
{route.page === 'guide' && exportData && (
<>
{guideActions}
- <Button
- size="sm"
+ <BarButton
variant="ghost"
+ iconOnly={iconOnly}
+ icon={editing ? <Check size={14} /> : <Pencil size={14} />}
+ label={editing ? i18n.t('editor.done') : i18n.t('editor.edit')}
onClick={() => toggleEditing(exportData.guideId)}
className={NAV_CONTROL}
- >
- {editing ? <Check size={14} /> : <Pencil size={14} />}
- {editing ? i18n.t('editor.done') : i18n.t('editor.edit')}
- </Button>
- <Button size="sm" variant="ghost" onClick={() => setHistoryOpen(!historyOpen)} className={NAV_CONTROL}>
- <History size={14} />
- {i18n.t('editor.versionHistory')}
- </Button>
+ />
+ <BarButton
+ variant="ghost"
+ iconOnly={iconOnly}
+ icon={<History size={14} />}
+ label={i18n.t('editor.versionHistory')}
+ onClick={() => setHistoryOpen(!historyOpen)}
+ className={NAV_CONTROL}
+ />
{hasTranscript && (
- <Button
- size="sm"
+ <BarButton
variant="ghost"
+ iconOnly={iconOnly}
+ icon={<MessageSquareQuote size={14} />}
+ label={i18n.t('transcript.title')}
onClick={() => setTranscriptOpen(!transcriptOpen)}
className={NAV_CONTROL}
- >
- <MessageSquareQuote size={14} />
- {i18n.t('transcript.title')}
- </Button>
+ />
)}
{!editing && (
<>
- <Button
- size="sm"
+ <BarButton
variant="ghost"
+ iconOnly={iconOnly}
+ icon={<Copy size={14} />}
+ label={i18n.t('library.duplicate')}
disabled={duplicating}
onClick={() => handleDuplicate(exportData.guideId)}
className={NAV_CONTROL}
- >
- <Copy size={14} />
- {i18n.t('library.duplicate')}
- </Button>
+ />
<Button size="sm" onClick={() => setExportOpen(true)} className="h-8 rounded-lg text-[13px]">
<Download size={14} />
{i18n.t('common.export')}
diff --git a/packages/ui/src/navigation/hooks/use-element-width.ts b/packages/ui/src/navigation/hooks/use-element-width.ts
new file mode 100644
index 0000000..adaac49
--- /dev/null
+++ b/packages/ui/src/navigation/hooks/use-element-width.ts
@@ -0,0 +1,14 @@
+import { type RefObject, useEffect, useState } from 'react';
+
+export function useElementWidth(ref: RefObject<HTMLElement | null>): number {
+ const [width, setWidth] = useState(Number.POSITIVE_INFINITY);
+ useEffect(() => {
+ const element = ref.current;
+ if (!element || typeof ResizeObserver === 'undefined') return;
+ setWidth(element.clientWidth);
+ const observer = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
+ observer.observe(element);
+ return () => observer.disconnect();
+ }, [ref]);
+ return width;
+}