fix(mobile): Tabs UI for Input/Output + compact FormatPicker on small viewports (#47)
After v1.4.1 user retested and reported the UI still breaks below ~400x700: panels overlap below 600h, become nearly invisible below 500h. Root cause is the grid-rows-2 mobile stack still gives each panel only half the available height, and when the workspace toolbar wraps 2-3 rows (FormatPicker's 12 chips) plus header / Home hero / Footer / StatusBar chrome, each row drops below CodeMirror's minimum rendered content height and the two panels visually overlap. Tabs UI on mobile (<md) - Add shadcn Tabs primitive (@radix-ui/react-tabs, MIT) - ConverterWorkspace renders Tabs on mobile (Input | Output, full-height active tab) and the side-by-side grid on md+. Both layouts render in parallel so CodeMirror state survives viewport resize without a remount. - Output tab shows a 6px dot when output changes while the user is on the Input tab; the dot clears when they switch over. No auto-switch — user controls. Compact FormatPicker on mobile - Mobile: a single "Target format: CSV" button opens a bottom Sheet listing all 12 chips in a 2-3 column grid (reuses the Sheet primitive already shipped with BatchPanel / SettingsPanel). Saves ~50-80px of toolbar height that would otherwise be eaten by the chip flex-wrap. - Desktop: unchanged — 12 chips inline. Minimum viewport documented - README EN + VI now state "designed for viewports ≥ 360 × 640; smaller screens still work but may feel cramped". THIRD-PARTY.md adds @radix-ui/react-tabs. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
71b7ba2837
commit
e91af0f676
12 files changed
+367
-43
No files matched your search
@@ -42,6 +42,7 @@ JSONPrism is a refracting tool for developers. It takes a single JSON input and
|
||||
- **Smart shape detection** — recognizes flat objects, arrays of objects, scalars; suggests the best target format.
|
||||
- **Per-format options** — pretty-print, indentation, dialect (for SQL), alignment (for Markdown), and more.
|
||||
- **Dark + light themes** — Prism Spectrum palette with violet / cyan / amber / rose accents.
|
||||
- **Responsive — designed for viewports ≥ 360 × 640.** Smaller screens still work but may feel cramped; on mobile, Input and Output use a Tabs UI to give each panel full height.
|
||||
- **EN + VI** — bilingual interface out of the box. More languages welcome.
|
||||
- **Tauri desktop build** — drag-and-drop file workflow, offline-first (Phase 2 milestone).
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ JSONPrism là công cụ "tán sắc" cho developer. Nhận một JSON đầu v
|
||||
- **Phát hiện shape thông minh** — nhận diện flat object, mảng object, scalar; gợi ý format đích phù hợp.
|
||||
- **Tuỳ chọn theo từng format** — pretty-print, indentation, dialect (SQL), alignment (Markdown), v.v.
|
||||
- **Theme sáng/tối** — bảng màu Prism Spectrum với violet / cyan / amber / rose.
|
||||
- **Responsive — tối ưu cho viewport ≥ 360 × 640.** Màn hình nhỏ hơn vẫn dùng được nhưng có thể chật; trên mobile, Input và Output dùng Tabs UI để mỗi panel có toàn bộ chiều cao.
|
||||
- **Đa ngôn ngữ EN + VI** — sẵn sàng từ ngày đầu. Hoan nghênh thêm ngôn ngữ khác.
|
||||
- **Bản desktop Tauri** — drag-and-drop file, hoạt động offline (mốc Phase 2).
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ the relevant notices. This file is a starting point.
|
||||
| `@radix-ui/react-dialog` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) |
|
||||
| `@radix-ui/react-slot` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) |
|
||||
| `@radix-ui/react-switch` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) |
|
||||
| `@radix-ui/react-tabs` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) |
|
||||
| `lucide-react` | ^0.460.0 | ISC | [lucide.dev](https://lucide.dev/) |
|
||||
| `sonner` | ^1.7.0 | MIT | [sonner.emilkowal.ski](https://sonner.emilkowal.ski/) |
|
||||
| `react-dropzone` | ^14.3.0 | MIT | [react-dropzone.js.org](https://react-dropzone.js.org/) |
|
||||
|
||||
Generated
+121
@@ -24,6 +24,7 @@
|
||||
"@radix-ui/react-dialog": "^1.1.0",
|
||||
"@radix-ui/react-slot": "^1.1.0",
|
||||
"@radix-ui/react-switch": "^1.1.0",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"@tauri-apps/api": "^2.0.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.0.0",
|
||||
"@tauri-apps/plugin-fs": "^2.0.0",
|
||||
@@ -1145,6 +1146,50 @@
|
||||
"integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@radix-ui/react-collection": {
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.1.7.tgz",
|
||||
"integrity": "sha512-Fh9rGN0MoI4ZFUNyfFVNU4y9LUz93u9/0K+yLgA2bwRojxM8JU1DyvvMBabnZPBgMWREAJvU2jjVzq+LrFUglw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-compose-refs": "1.1.2",
|
||||
"@radix-ui/react-context": "1.1.2",
|
||||
"@radix-ui/react-primitive": "2.1.3",
|
||||
"@radix-ui/react-slot": "1.2.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-collection/node_modules/@radix-ui/react-slot": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz",
|
||||
"integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-compose-refs": "1.1.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-compose-refs": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.2.tgz",
|
||||
@@ -1229,6 +1274,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-direction": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-direction/-/react-direction-1.1.1.tgz",
|
||||
"integrity": "sha512-1UEWRX6jnOA2y4H5WczZ44gOOjTEmlqv1uNW4GAJEO5+bauCBhv8snY65Iw5/VOS/ghKN9gr2KjnLKxrsvoMVw==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-dismissable-layer": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.11.tgz",
|
||||
@@ -1403,6 +1463,37 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-roving-focus": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-roving-focus/-/react-roving-focus-1.1.11.tgz",
|
||||
"integrity": "sha512-7A6S9jSgm/S+7MdtNDSb+IU859vQqJ/QAtcYQcfFC6W8RS4IxIZDldLR0xqCFZ6DCyrQLjLPsxtTNch5jVA4lA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/primitive": "1.1.3",
|
||||
"@radix-ui/react-collection": "1.1.7",
|
||||
"@radix-ui/react-compose-refs": "1.1.2",
|
||||
"@radix-ui/react-context": "1.1.2",
|
||||
"@radix-ui/react-direction": "1.1.1",
|
||||
"@radix-ui/react-id": "1.1.1",
|
||||
"@radix-ui/react-primitive": "2.1.3",
|
||||
"@radix-ui/react-use-callback-ref": "1.1.1",
|
||||
"@radix-ui/react-use-controllable-state": "1.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-slot": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.4.tgz",
|
||||
@@ -1450,6 +1541,36 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-tabs": {
|
||||
"version": "1.1.13",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.1.13.tgz",
|
||||
"integrity": "sha512-7xdcatg7/U+7+Udyoj2zodtI9H/IIopqo+YOIcZOq1nJwXWBZ9p8xiu5llXlekDbZkca79a/fozEYQXIA4sW6A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/primitive": "1.1.3",
|
||||
"@radix-ui/react-context": "1.1.2",
|
||||
"@radix-ui/react-direction": "1.1.1",
|
||||
"@radix-ui/react-id": "1.1.1",
|
||||
"@radix-ui/react-presence": "1.1.5",
|
||||
"@radix-ui/react-primitive": "2.1.3",
|
||||
"@radix-ui/react-roving-focus": "1.1.11",
|
||||
"@radix-ui/react-use-controllable-state": "1.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-use-callback-ref": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"@radix-ui/react-dialog": "^1.1.0",
|
||||
"@radix-ui/react-slot": "^1.1.0",
|
||||
"@radix-ui/react-switch": "^1.1.0",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"@tauri-apps/api": "^2.0.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.0.0",
|
||||
"@tauri-apps/plugin-fs": "^2.0.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { toast } from '@/components/ui/sonner';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { getConverter } from '@/converters/registry';
|
||||
import type { FormatId } from '@/converters/types';
|
||||
import { parseJsonInput } from '@/lib/detect';
|
||||
@@ -36,6 +37,11 @@ export function ConverterWorkspace() {
|
||||
const actionsRef = useRef<{ copy: () => void; download: () => void } | null>(null);
|
||||
const [batchOpen, setBatchOpen] = useState(false);
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
// Mobile tab state — desktop ignores this and renders both panels side-by-side.
|
||||
const [activeTab, setActiveTab] = useState<'input' | 'output'>('input');
|
||||
// Badge dot on Output tab when output changes while user is on Input tab.
|
||||
const [hasUnreadOutput, setHasUnreadOutput] = useState(false);
|
||||
const prevOutputRef = useRef('');
|
||||
const addBatchFiles = useBatchStore((s) => s.addFiles);
|
||||
|
||||
const handleMultiFileDrop = useCallback(
|
||||
@@ -179,6 +185,21 @@ export function ConverterWorkspace() {
|
||||
{ key: ',', mod: true, handler: () => setSettingsOpen((v) => !v) },
|
||||
]);
|
||||
|
||||
// Flip the badge dot on the Output tab whenever output changes while the
|
||||
// user is on the Input tab. Clearing happens once the user navigates over.
|
||||
useEffect(() => {
|
||||
if (output !== prevOutputRef.current) {
|
||||
prevOutputRef.current = output;
|
||||
if (output && activeTab !== 'output') {
|
||||
setHasUnreadOutput(true);
|
||||
}
|
||||
}
|
||||
}, [output, activeTab]);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab === 'output') setHasUnreadOutput(false);
|
||||
}, [activeTab]);
|
||||
|
||||
const inputBytes = useMemo(() => new TextEncoder().encode(input).length, [input]);
|
||||
const outputBytes = useMemo(() => new TextEncoder().encode(output).length, [output]);
|
||||
|
||||
@@ -215,8 +236,54 @@ export function ConverterWorkspace() {
|
||||
</div>
|
||||
|
||||
<div className="border-border bg-card/40 flex min-h-0 flex-1 flex-col overflow-hidden rounded-lg border">
|
||||
<div className="grid min-h-0 flex-1 grid-rows-2 md:grid-cols-2 md:grid-rows-1">
|
||||
<div className="md:border-border/60 min-h-0 border-b md:border-r md:border-b-0">
|
||||
{/* Mobile: Tabs UI — each tab gets the full workspace height so panels
|
||||
never overlap on short viewports. */}
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(v) => setActiveTab(v as 'input' | 'output')}
|
||||
className="flex min-h-0 flex-1 flex-col md:hidden"
|
||||
>
|
||||
<TabsList className="border-border/60 w-full justify-start gap-0 rounded-none border-b px-2">
|
||||
<TabsTrigger value="input">{t('home.tab_input')}</TabsTrigger>
|
||||
<TabsTrigger value="output" className="relative">
|
||||
{t('home.tab_output')}
|
||||
{hasUnreadOutput && (
|
||||
<span
|
||||
aria-hidden
|
||||
className="bg-primary absolute top-1 right-1 h-1.5 w-1.5 rounded-full"
|
||||
/>
|
||||
)}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="input" className="min-h-0 flex-1">
|
||||
<InputPanel
|
||||
value={input}
|
||||
onChange={setInput}
|
||||
error={inputError}
|
||||
format={format}
|
||||
direction={direction}
|
||||
onMultiFileDrop={handleMultiFileDrop}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent value="output" className="min-h-0 flex-1">
|
||||
<OutputPanel
|
||||
format={format}
|
||||
content={output}
|
||||
error={outputError}
|
||||
options={currentOptions}
|
||||
direction={direction}
|
||||
registerActions={(a) => {
|
||||
actionsRef.current = a;
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
{/* Desktop: side-by-side grid (≥ md). Rendered in parallel with the
|
||||
Tabs above so neither remounts on viewport resize and CodeMirror
|
||||
state survives the swap. */}
|
||||
<div className="hidden min-h-0 flex-1 md:grid md:grid-cols-2">
|
||||
<div className="border-border/60 min-h-0 border-r">
|
||||
<InputPanel
|
||||
value={input}
|
||||
onChange={setInput}
|
||||
@@ -239,6 +306,7 @@ export function ConverterWorkspace() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<StatusBar inputBytes={inputBytes} outputBytes={outputBytes} parseMs={parseMs} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ChevronDown } from 'lucide-react';
|
||||
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
|
||||
import { ALL_FORMATS, getConverter } from '@/converters/registry';
|
||||
import type { FormatId } from '@/converters/types';
|
||||
import type { JsonShape } from '@/lib/detect';
|
||||
@@ -17,51 +20,121 @@ interface FormatPickerProps {
|
||||
|
||||
export function FormatPicker({ value, onChange, shape, direction = 'forward' }: FormatPickerProps) {
|
||||
const { t } = useTranslation();
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const current = getConverter(value);
|
||||
|
||||
const handlePick = (id: FormatId) => {
|
||||
onChange(id);
|
||||
setSheetOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{ALL_FORMATS.map((id) => {
|
||||
const c = getConverter(id);
|
||||
const active = value === id;
|
||||
const suggested = direction === 'forward' && shape ? isFormatSuggested(id, shape) : false;
|
||||
const noReverse = direction === 'reverse' && typeof c.reverse !== 'function';
|
||||
const enabled = c.meta.ready && !noReverse;
|
||||
const dimmed = direction === 'forward' && shape && !suggested && c.meta.ready;
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Mobile: compact Sheet trigger — saves ~50-80px of toolbar height when
|
||||
the 12 chip grid would otherwise wrap to 2-3 rows on narrow viewports. */}
|
||||
<Sheet open={sheetOpen} onOpenChange={setSheetOpen}>
|
||||
<SheetTrigger asChild>
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
onClick={() => onChange(id)}
|
||||
disabled={!enabled}
|
||||
className={cn(
|
||||
'group relative inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-[11px] font-medium transition sm:px-2.5 sm:py-1 sm:text-xs',
|
||||
active
|
||||
? 'border-primary/60 bg-primary/10 text-foreground'
|
||||
: 'border-border bg-card/40 text-muted-foreground hover:text-foreground hover:border-border',
|
||||
!enabled && 'cursor-not-allowed opacity-50',
|
||||
dimmed && !active && 'opacity-50',
|
||||
suggested && !active && 'ring-primary/30 ring-offset-background ring-1 ring-offset-1',
|
||||
)}
|
||||
title={
|
||||
!c.meta.ready
|
||||
? t('format_status.planned', { phase: c.meta.phase })
|
||||
: noReverse
|
||||
? t('format_status.no_reverse')
|
||||
: suggested
|
||||
? t('format_status.suggested')
|
||||
: t('format_status.ready')
|
||||
}
|
||||
className="border-border bg-card/40 text-muted-foreground hover:border-primary/40 hover:text-foreground inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs font-medium transition md:hidden"
|
||||
aria-label={t('home.format_picker_label')}
|
||||
>
|
||||
<span className="font-mono">{t(c.meta.labelKey)}</span>
|
||||
{!c.meta.ready && (
|
||||
<span className="border-border text-muted-foreground rounded border px-1 text-[10px] tracking-wide">
|
||||
P{c.meta.phase}
|
||||
</span>
|
||||
)}
|
||||
<span className="tracking-wider uppercase opacity-70">
|
||||
{t('home.format_picker_label')}
|
||||
</span>
|
||||
<span className="text-foreground font-mono">{t(current.meta.labelKey)}</span>
|
||||
<ChevronDown className="h-3 w-3" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="bottom" className="max-h-[80vh] w-full overflow-y-auto">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{t('home.format_picker_label')}</SheetTitle>
|
||||
</SheetHeader>
|
||||
<div className="grid grid-cols-2 gap-1.5 p-4 pt-2 sm:grid-cols-3">
|
||||
{ALL_FORMATS.map((id) => (
|
||||
<FormatChip
|
||||
key={id}
|
||||
id={id}
|
||||
value={value}
|
||||
onChange={handlePick}
|
||||
shape={shape}
|
||||
direction={direction}
|
||||
expanded
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
|
||||
{/* Desktop: 12 chips inline. */}
|
||||
<div className="hidden flex-wrap gap-1.5 md:flex">
|
||||
{ALL_FORMATS.map((id) => (
|
||||
<FormatChip
|
||||
key={id}
|
||||
id={id}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
shape={shape}
|
||||
direction={direction}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface FormatChipProps {
|
||||
id: FormatId;
|
||||
value: FormatId;
|
||||
onChange: (id: FormatId) => void;
|
||||
shape: JsonShape | null | undefined;
|
||||
direction: Direction;
|
||||
/** Expanded layout (fills the Sheet grid cell), vs the compact inline chip. */
|
||||
expanded?: boolean;
|
||||
}
|
||||
|
||||
function FormatChip({ id, value, onChange, shape, direction, expanded }: FormatChipProps) {
|
||||
const { t } = useTranslation();
|
||||
const c = getConverter(id);
|
||||
const active = value === id;
|
||||
const suggested = direction === 'forward' && shape ? isFormatSuggested(id, shape) : false;
|
||||
const noReverse = direction === 'reverse' && typeof c.reverse !== 'function';
|
||||
const enabled = c.meta.ready && !noReverse;
|
||||
const dimmed = direction === 'forward' && shape && !suggested && c.meta.ready;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(id)}
|
||||
disabled={!enabled}
|
||||
className={cn(
|
||||
'group relative inline-flex items-center gap-1.5 rounded-md border font-medium transition',
|
||||
expanded
|
||||
? 'justify-between px-3 py-2 text-sm'
|
||||
: 'px-2 py-0.5 text-[11px] sm:px-2.5 sm:py-1 sm:text-xs',
|
||||
active
|
||||
? 'border-primary/60 bg-primary/10 text-foreground'
|
||||
: 'border-border bg-card/40 text-muted-foreground hover:text-foreground hover:border-border',
|
||||
!enabled && 'cursor-not-allowed opacity-50',
|
||||
dimmed && !active && 'opacity-50',
|
||||
suggested && !active && 'ring-primary/30 ring-offset-background ring-1 ring-offset-1',
|
||||
)}
|
||||
title={
|
||||
!c.meta.ready
|
||||
? t('format_status.planned', { phase: c.meta.phase })
|
||||
: noReverse
|
||||
? t('format_status.no_reverse')
|
||||
: suggested
|
||||
? t('format_status.suggested')
|
||||
: t('format_status.ready')
|
||||
}
|
||||
>
|
||||
<span className="font-mono">{t(c.meta.labelKey)}</span>
|
||||
{!c.meta.ready && (
|
||||
<span className="border-border text-muted-foreground rounded border px-1 text-[10px] tracking-wide">
|
||||
P{c.meta.phase}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import * as React from 'react';
|
||||
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Tabs = TabsPrimitive.Root;
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'text-muted-foreground inline-flex items-center justify-center gap-1',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsList.displayName = TabsPrimitive.List.displayName;
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'text-muted-foreground hover:text-foreground data-[state=active]:text-foreground data-[state=active]:border-primary inline-flex items-center justify-center gap-1.5 border-b-2 border-transparent px-3 py-1.5 text-xs font-medium tracking-wider uppercase transition focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn('focus-visible:outline-none', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
||||
@@ -14,6 +14,8 @@
|
||||
"input_label_format": "Input {{format}}",
|
||||
"input_placeholder": "Paste your JSON here, drop files, or load a sample…",
|
||||
"input_placeholder_format": "Paste your {{ext}} here, drop files, or load a sample…",
|
||||
"tab_input": "Input",
|
||||
"tab_output": "Output",
|
||||
"output_label": "Output",
|
||||
"output_empty": "Output will appear here once you provide valid JSON.",
|
||||
"output_empty_format": "Output will appear here once you provide valid {{ext}}.",
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"input_label_format": "{{format}} 入力",
|
||||
"input_placeholder": "ここに JSON を貼り付け、ファイルをドロップ、またはサンプルを読み込み…",
|
||||
"input_placeholder_format": "ここに {{ext}} を貼り付け、ファイルをドロップ、またはサンプルを読み込み…",
|
||||
"tab_input": "入力",
|
||||
"tab_output": "出力",
|
||||
"output_label": "出力",
|
||||
"output_empty": "有効な JSON を入力すると、ここに出力が表示されます。",
|
||||
"output_empty_format": "有効な {{ext}} を入力すると、ここに出力が表示されます。",
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"input_label_format": "Đầu vào {{format}}",
|
||||
"input_placeholder": "Dán JSON vào đây, thả file, hoặc nạp mẫu…",
|
||||
"input_placeholder_format": "Dán {{ext}} vào đây, thả file, hoặc nạp mẫu…",
|
||||
"tab_input": "Đầu vào",
|
||||
"tab_output": "Kết quả",
|
||||
"output_label": "Kết quả",
|
||||
"output_empty": "Kết quả sẽ hiện ở đây khi bạn cung cấp JSON hợp lệ.",
|
||||
"output_empty_format": "Kết quả sẽ hiện ở đây khi bạn cung cấp {{ext}} hợp lệ.",
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"input_label_format": "{{format}} 输入",
|
||||
"input_placeholder": "在此处粘贴 JSON、拖入文件或加载示例…",
|
||||
"input_placeholder_format": "在此处粘贴 {{ext}}、拖入文件或加载示例…",
|
||||
"tab_input": "输入",
|
||||
"tab_output": "输出",
|
||||
"output_label": "输出",
|
||||
"output_empty": "提供有效的 JSON 后,输出将显示在此处。",
|
||||
"output_empty_format": "提供有效的 {{ext}} 后,输出将显示在此处。",
|
||||
|
||||
Reference in new issue
Block a user