Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tree node styling. #592

Merged
merged 10 commits into from
Oct 27, 2022
17 changes: 13 additions & 4 deletions src/components/TreeReactFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function flavorLabel(flavor: NodeFlavor): string {
}

const primerNodeTypeName = "primer";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the lack of line breaks were intentional. This is all part of defining a "primer node", and I like to group related definitions (though maybe it's a bit odd that there is then a blank line within PrimerNode.

Anyway, it really doesn't matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it hard to read and follow, personally.

type PrimerNodePropsNode = {
label?: string;
contents?: string;
Expand All @@ -154,12 +155,22 @@ type PrimerNodePropsNode = {
color: string;
selected: boolean;
};

type PrimerNodePropsTree = {
// Invariant: these will be the same for all nodes in a single tree.
def: GlobalName;
nodeType: NodeType;
};

type PrimerNodeProps = PrimerNodePropsTree & PrimerNodePropsNode;

const primerNodeClasses = (selected: boolean) =>
classNames({
"outline outline-4 outline-offset-4": selected,
"flex items-center justify-center rounded border-4 text-grey-tertiary bg-white-primary":
true,
});

const PrimerNode = (p: NodeProps<PrimerNodeProps>) => {
// these properties are necessary due to an upstream bug: https://github.com/wbkd/react-flow/issues/2193
const handleStyle = "absolute border-[2px] border-solid border-grey-tertiary";
Expand All @@ -168,10 +179,7 @@ const PrimerNode = (p: NodeProps<PrimerNodeProps>) => {
<>
<Handle type="target" position={Position.Top} className={handleStyle} />
<div
className={classNames(
"flex items-center justify-center rounded border-4 text-grey-tertiary bg-white-primary",
p.data.selected && "outline outline-4 outline-offset-4"
)}
className={primerNodeClasses(p.data.selected)}
style={{
width: p.data.width,
height: p.data.height,
Expand All @@ -195,6 +203,7 @@ const PrimerNode = (p: NodeProps<PrimerNodeProps>) => {
</>
);
};

const nodeTypes = { [primerNodeTypeName]: PrimerNode };

const convertTree = (
Expand Down