feat(completion): Comp SourceSnippet - add compact layout for one-line related code

This commit is contained in:
2020-09-28 20:24:41 +05:30
parent 05a5278244
commit 7937b6b2d6
@@ -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&nbsp;{directionEmojiJSX}&nbsp;</div>
From source&nbsp;
<span role="img" aria-label="See below">
</span>
&nbsp;
</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>
); );