From b7191c09bba419db8f547fbac89194585da8c1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= <2712495353@qq.com> Date: Mon, 13 Jul 2026 23:31:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(json-tools):=20=E4=BC=98=E5=8C=96=20Js?= =?UTF-8?q?onDiffPanel=20=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20TextInputArea=20=E7=81=B5=E6=B4=BB?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TextInputArea.tsx | 11 ++- .../JsonTools/components/JsonDiffPanel.tsx | 87 +++++++++++-------- src/pages/JsonTools/components/JsonTree.tsx | 2 +- .../__tests__/JsonDiffPanel.test.tsx | 3 +- 4 files changed, 63 insertions(+), 40 deletions(-) diff --git a/src/components/TextInputArea.tsx b/src/components/TextInputArea.tsx index 9e92015..22eebba 100644 --- a/src/components/TextInputArea.tsx +++ b/src/components/TextInputArea.tsx @@ -48,6 +48,9 @@ export interface TextInputAreaProps extends Omit< * 用于需要固定高度 + 内部滚动的卡片面板。 */ fill?: boolean; + + /** 是否无边框、无阴影、无圆角(适用于嵌套在其他有边框的容器中) */ + borderless?: boolean; } function ActionButton({ @@ -113,6 +116,7 @@ const TextInputArea = forwardRef((props externalError, onClear, fill = false, + borderless = false, ...restProps } = props; @@ -241,9 +245,12 @@ const TextInputArea = forwardRef((props
diff --git a/src/pages/JsonTools/components/JsonDiffPanel.tsx b/src/pages/JsonTools/components/JsonDiffPanel.tsx index dc995ca..0c627cf 100644 --- a/src/pages/JsonTools/components/JsonDiffPanel.tsx +++ b/src/pages/JsonTools/components/JsonDiffPanel.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ChevronDown, ChevronRight } from 'lucide-react'; +import { ChevronRight } from 'lucide-react'; import TextInputArea from '@/components/TextInputArea'; import { cn } from '@/lib/utils'; @@ -10,7 +10,7 @@ export interface JsonDiffPanelProps extends Omit void; error?: string | null; - /** 是否处于折叠态(Accordion 收起) */ + /** 是否处于折叠态 */ collapsed: boolean; onToggleCollapse: () => void; /** 折叠态展示的单行缩略预览文本 */ @@ -32,45 +32,60 @@ export default function JsonDiffPanel({ return (
- {collapsed ? ( - - ) : ( - <> -
- {title} - -
- - - )} + {preview} + + + + +
+ +
); } diff --git a/src/pages/JsonTools/components/JsonTree.tsx b/src/pages/JsonTools/components/JsonTree.tsx index abb3450..a96b7f1 100644 --- a/src/pages/JsonTools/components/JsonTree.tsx +++ b/src/pages/JsonTools/components/JsonTree.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef, useState } from 'react'; +import React, { useEffect, useMemo, useRef } from 'react'; import { ChevronDown, ChevronRight } from 'lucide-react'; import type { DiffNode, DiffType } from '../types'; import { cn } from '@/lib/utils'; diff --git a/src/pages/JsonTools/components/__tests__/JsonDiffPanel.test.tsx b/src/pages/JsonTools/components/__tests__/JsonDiffPanel.test.tsx index 66009cb..59240d8 100644 --- a/src/pages/JsonTools/components/__tests__/JsonDiffPanel.test.tsx +++ b/src/pages/JsonTools/components/__tests__/JsonDiffPanel.test.tsx @@ -33,7 +33,8 @@ describe('JsonDiffPanel', () => { />, ); expect(screen.getByText('abc(点击展开)')).toBeInTheDocument(); - expect(screen.queryByPlaceholderText('x')).not.toBeInTheDocument(); + const input = screen.getByPlaceholderText('x'); + expect(input.closest('.opacity-0')).toBeInTheDocument(); }); it('点击标题可切换折叠', async () => {