From d476ffb613a1dda9b76a2f68f0c415b17ca219fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Sun, 1 Mar 2026 16:14:56 +0100 Subject: [PATCH] refactor: extract MobileTabs shared component, replace in all 8 tools Co-Authored-By: Claude Sonnet 4.6 --- components/animate/AnimationEditor.tsx | 23 +++++------------ components/ascii/ASCIIConverter.tsx | 23 +++++------------ components/calculate/Calculator.tsx | 23 +++++------------ components/color/ColorManipulation.tsx | 23 +++++------------ components/favicon/FaviconGenerator.tsx | 23 +++++------------ components/media/FileConverter.tsx | 23 +++++------------ components/qrcode/QRCodeGenerator.tsx | 23 +++++------------ components/ui/code-snippet.tsx | 2 +- components/ui/mobile-tabs.tsx | 33 +++++++++++++++++++++++++ components/units/MainConverter.tsx | 23 +++++------------ 10 files changed, 82 insertions(+), 137 deletions(-) create mode 100644 components/ui/mobile-tabs.tsx diff --git a/components/animate/AnimationEditor.tsx b/components/animate/AnimationEditor.tsx index 10afc35..8aad902 100644 --- a/components/animate/AnimationEditor.tsx +++ b/components/animate/AnimationEditor.tsx @@ -9,6 +9,7 @@ import { PresetLibrary } from './PresetLibrary'; import { ExportPanel } from './ExportPanel'; import { DEFAULT_CONFIG, newKeyframe } from '@/lib/animate/defaults'; import { cn } from '@/lib/utils/cn'; +import { MobileTabs } from '@/components/ui/mobile-tabs'; import type { AnimationConfig, KeyframeProperties as KFProps, PreviewElement } from '@/types/animate'; type MobileTab = 'edit' | 'preview'; @@ -75,23 +76,11 @@ export function AnimationEditor() { return (
- {/* ── Mobile tab switcher ─────────────────────────────── */} -
- {(['edit', 'preview'] as MobileTab[]).map((t) => ( - - ))} -
+ setMobileTab(v as MobileTab)} + /> {/* ── Main layout ─────────────────────────────────────── */}
- {/* ── Mobile tab switcher ────────────────────────────────── */} -
- {(['editor', 'preview'] as Tab[]).map((t) => ( - - ))} -
+ setTab(v as Tab)} + /> {/* ── Main layout ────────────────────────────────────────── */}
- {/* Mobile tab switcher — hidden on lg+ */} -
- {(['calc', 'graph'] as Tab[]).map((t) => ( - - ))} -
+ setTab(v as Tab)} + /> {/* Main layout — side-by-side on lg, tabbed on mobile */}
- {/* ── Mobile tab switcher ────────────────────────────────── */} -
- {(['pick', 'explore'] as MobileTab[]).map((t) => ( - - ))} -
+ setMobileTab(v as MobileTab)} + /> {/* ── Main layout ────────────────────────────────────────── */}
- {/* ── Mobile tab switcher ─────────────────────────────── */} -
- {(['setup', 'results'] as MobileTab[]).map((t) => ( - - ))} -
+ setMobileTab(v as MobileTab)} + /> {/* ── Main layout ─────────────────────────────────────── */}
- {/* ── Mobile tab switcher ─────────────────────────────── */} -
- {(['upload', 'convert'] as MobileTab[]).map((t) => ( - - ))} -
+ setMobileTab(v as MobileTab)} + /> {/* ── Main layout ─────────────────────────────────────── */}
- {/* ── Mobile tab switcher ─────────────────────────────── */} -
- {(['configure', 'preview'] as MobileTab[]).map((t) => ( - - ))} -
+ setMobileTab(v as MobileTab)} + /> {/* ── Main layout ─────────────────────────────────────── */}
         {code}
diff --git a/components/ui/mobile-tabs.tsx b/components/ui/mobile-tabs.tsx
new file mode 100644
index 0000000..e72d371
--- /dev/null
+++ b/components/ui/mobile-tabs.tsx
@@ -0,0 +1,33 @@
+import { cn } from '@/lib/utils/cn';
+
+interface Tab {
+  value: string;
+  label: string;
+}
+
+interface MobileTabsProps {
+  tabs: Tab[];
+  active: string;
+  onChange: (value: string) => void;
+}
+
+export function MobileTabs({ tabs, active, onChange }: MobileTabsProps) {
+  return (
+    
+ {tabs.map(({ value, label }) => ( + + ))} +
+ ); +} diff --git a/components/units/MainConverter.tsx b/components/units/MainConverter.tsx index 2e1fa73..9a83dc6 100644 --- a/components/units/MainConverter.tsx +++ b/components/units/MainConverter.tsx @@ -14,6 +14,7 @@ import { type ConversionResult, } from '@/lib/units/units'; import { parseNumberInput, formatNumber, cn } from '@/lib/utils'; +import { MobileTabs } from '@/components/ui/mobile-tabs'; type Tab = 'category' | 'convert'; @@ -87,23 +88,11 @@ export default function MainConverter() { return (
- {/* ── Mobile tab switcher ────────────────────────────────── */} -
- {(['category', 'convert'] as Tab[]).map((t) => ( - - ))} -
+ setTab(v as Tab)} + /> {/* ── Main layout ────────────────────────────────────────── */}