feat: collapsed codeblock by default
This commit is contained in:
parent
dae6770a89
commit
979c2473c6
3 changed files with 40 additions and 11 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import {
|
||||
ToCoreFromWebviewProtocol,
|
||||
ToWebviewFromCoreProtocol,
|
||||
} from "./coreWebview.js";
|
||||
import { ToWebviewOrCoreFromIdeProtocol } from "./ide.js";
|
||||
import { ToCoreFromIdeProtocol, ToIdeFromCoreProtocol } from "./ideCore.js";
|
||||
} from "./coreWebview";
|
||||
import { ToWebviewOrCoreFromIdeProtocol } from "./ide";
|
||||
import { ToCoreFromIdeProtocol, ToIdeFromCoreProtocol } from "./ideCore";
|
||||
import {
|
||||
ToIdeFromWebviewProtocol,
|
||||
ToWebviewFromIdeProtocol,
|
||||
} from "./ideWebview.js";
|
||||
} from "./ideWebview";
|
||||
|
||||
export type IProtocol = Record<string, [any, any]>;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
CommandLineIcon,
|
||||
PlayIcon,
|
||||
XMarkIcon,
|
||||
ChevronDownIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { getBasename } from "core/util";
|
||||
import { useContext, useRef, useState } from "react";
|
||||
|
|
@ -87,6 +88,8 @@ interface CodeBlockToolBarProps {
|
|||
language: string | undefined;
|
||||
isNextCodeBlock: boolean;
|
||||
filepath?: string;
|
||||
isExpanded: boolean;
|
||||
onToggleExpand: () => void;
|
||||
}
|
||||
|
||||
const terminalLanguages = ["bash", "sh"];
|
||||
|
|
@ -260,12 +263,27 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
|
||||
return (
|
||||
<ToolbarDiv>
|
||||
<div
|
||||
className="flex max-w-[50%] cursor-pointer items-center gap-1"
|
||||
onClick={onClickHeader}
|
||||
>
|
||||
<FileIcon height="20px" width="20px" filename={props.filepath} />
|
||||
<span className="truncate">{getBasename(props.filepath)}</span>
|
||||
<div className="flex max-w-[50%] items-center">
|
||||
<div
|
||||
onClick={props.onToggleExpand}
|
||||
className="flex cursor-pointer items-center justify-center"
|
||||
>
|
||||
<ChevronDownIcon
|
||||
className={`h-4 w-4 text-gray-400 ${
|
||||
props.isExpanded ? "rotate-0" : "-rotate-90"
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{props.filepath && (
|
||||
<div
|
||||
className="flex cursor-pointer items-center gap-1"
|
||||
onClick={onClickHeader}
|
||||
>
|
||||
<FileIcon height="20px" width="20px" filename={props.filepath} />
|
||||
<span className="truncate">{getBasename(props.filepath)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ function PreWithToolbar(props: {
|
|||
|
||||
const [hovering, setHovering] = useState(false);
|
||||
const [copyValue, setCopyValue] = useState("");
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
|
||||
const nextCodeBlockIndex = useSelector(
|
||||
(state: RootState) => state.uiState.nextCodeBlockToApplyIndex,
|
||||
|
|
@ -76,6 +77,8 @@ function PreWithToolbar(props: {
|
|||
bottom={toolbarBottom}
|
||||
language={props.language}
|
||||
filepath={props.filepath}
|
||||
isExpanded={isExpanded}
|
||||
onToggleExpand={() => setIsExpanded(!isExpanded)}
|
||||
/>
|
||||
) : (
|
||||
hovering && (
|
||||
|
|
@ -84,11 +87,19 @@ function PreWithToolbar(props: {
|
|||
text={copyValue}
|
||||
bottom={toolbarBottom}
|
||||
language={props.language}
|
||||
isExpanded={isExpanded}
|
||||
onToggleExpand={() => setIsExpanded(!isExpanded)}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
{props.children}
|
||||
<div
|
||||
className={`overflow-hidden ${
|
||||
isExpanded ? "max-h-[400px] opacity-100" : "max-h-0 opacity-0"
|
||||
}`}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
</TopDiv>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue