mirror of
https://github.com/bendtherules/completion-viz.git
synced 2026-08-18 13:42:51 +00:00
feat(completion): Comp SourceSnippet - add compact layout for one-line related code
This commit is contained in:
@@ -8,18 +8,31 @@ import { getCodeTextFromCompletion } from "./utils";
|
||||
export function CompletionCardSourceSnippet() {
|
||||
const { completionDetail, code } = useCompletionCardContext();
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<div className="my-1">
|
||||
From source
|
||||
const relatedCode = getCodeTextFromCompletion(code, completionDetail);
|
||||
|
||||
const hasNewline = relatedCode.includes("\n");
|
||||
|
||||
const directionEmojiJSX = hasNewline ? (
|
||||
<span role="img" aria-label="See below">
|
||||
⤵️
|
||||
</span>
|
||||
|
||||
</div>
|
||||
) : (
|
||||
<span role="img" aria-label="See to the right" className="pr-1">
|
||||
👉
|
||||
</span>
|
||||
);
|
||||
|
||||
const parentClassname = hasNewline ? "" : "flex flex-row items-center";
|
||||
const inlineCodeExtraClassName = hasNewline
|
||||
? "py-2 lg:pl-3 lg:pr-8 lg:py-3"
|
||||
: "";
|
||||
|
||||
return (
|
||||
<div className={parentClassname}>
|
||||
<div className="my-1">From source {directionEmojiJSX} </div>
|
||||
<InlineResultViewer
|
||||
className="px-1 py-1 my-1 rounded md:w-fit-content"
|
||||
code={getCodeTextFromCompletion(code, completionDetail)}
|
||||
className={`px-1 my-1 rounded md:w-fit-content ${inlineCodeExtraClassName}`}
|
||||
code={relatedCode}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user