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() {
|
export function CompletionCardSourceSnippet() {
|
||||||
const { completionDetail, code } = useCompletionCardContext();
|
const { completionDetail, code } = useCompletionCardContext();
|
||||||
|
|
||||||
|
const relatedCode = getCodeTextFromCompletion(code, completionDetail);
|
||||||
|
|
||||||
|
const hasNewline = relatedCode.includes("\n");
|
||||||
|
|
||||||
|
const directionEmojiJSX = hasNewline ? (
|
||||||
|
<span role="img" aria-label="See below">
|
||||||
|
⤵️
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<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 (
|
return (
|
||||||
<div className="">
|
<div className={parentClassname}>
|
||||||
<div className="my-1">
|
<div className="my-1">From source {directionEmojiJSX} </div>
|
||||||
From source
|
|
||||||
<span role="img" aria-label="See below">
|
|
||||||
⤵️
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<InlineResultViewer
|
<InlineResultViewer
|
||||||
className="px-1 py-1 my-1 rounded md:w-fit-content"
|
className={`px-1 my-1 rounded md:w-fit-content ${inlineCodeExtraClassName}`}
|
||||||
code={getCodeTextFromCompletion(code, completionDetail)}
|
code={relatedCode}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user