Skip to content

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Jul 18, 2023
1 parent 8388c93 commit 84165d2
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 35 deletions.
4 changes: 4 additions & 0 deletions crates/compiler/checkmate/www/.vim/coc-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tsserver.useLocalTsdk": true,
"tsserver.tsdk": "${workspaceFolder}/node_modules/typescript/lib"
}
82 changes: 68 additions & 14 deletions crates/compiler/checkmate/www/src/components/Common/Variable.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,83 @@
import { ComponentProps } from "react";
import clsx from "clsx";
import { QuerySubs, TypeDescriptor } from "../../engine/subs";
import { Variable } from "../../schema";
import { ContentStyles } from "./../Content";
import DrawHeadConstructor from "../Content/HeadConstructor";
import { contentStyles } from "./../Content";

export function VariableElHelp({
variable,
styles,
onClick,
}: {
interface VariableElProps {
variable: Variable;
styles: ContentStyles;
onClick?: () => void;
}): JSX.Element {
const { name, bg } = styles;
subs: QuerySubs;
onClick?: (variable: Variable) => void;
nested?: boolean;
raw?: boolean;
}

export function VariableElPretty(props: VariableElProps): JSX.Element {
const { variable, subs } = props;
const desc = subs.get_root(variable);
const content = (
<DrawHeadConstructor
desc={desc}
drawVariablePretty={(variable) => (
<VariableElPretty {...props} variable={variable} nested />
)}
drawVariableRaw={(variable) => (
<VariableElRaw {...props} variable={variable} nested raw />
)}
/>
);
return (
<span className={clsx("py-0 pl-0 pr-1 rounded-md", bg)}>
<Helper {...props} desc={desc}>
{content}
</Helper>
);
}

function VariableElRaw(props: VariableElProps): JSX.Element {
const desc = props.subs.get_root(props.variable);
return <Helper {...props} desc={desc}></Helper>;
}

function Helper({
children,
variable,
desc,
onClick,
nested,
raw,
}: VariableElProps &
Pick<ComponentProps<"div">, "children"> & {
desc: TypeDescriptor | undefined;
}): JSX.Element {
const { bg } = contentStyles(desc);
const varHeader =
!nested || raw ? (
<span
className="ring-1 ring-inset ring-black-100 mr-1 px-1 bg-white rounded-md cursor"
className={clsx(
"ring-1 ring-inset ring-black-100 px-1 bg-white rounded-md cursor",
nested ? "text-md" : "p-0.5"
)}
onClick={(e) => {
e.stopPropagation();
onClick?.();
onClick?.(variable);
}}
>
{variable}
</span>
{name}
) : (
<></>
);
return (
<span
className={clsx(
"rounded-md whitespace-nowrap",
bg,
nested ? "text-sm" : "p-0.5 pl-0 text-base"
)}
>
{varHeader}
{children ? <span className="px-1">{children}</span> : <></>}
</span>
);
}
Loading

0 comments on commit 84165d2

Please sign in to comment.