fixed up styling for choose

This commit is contained in:
ari committed 2022-07-12 18:47:18 -04:00
1 parent 084a3585d0
commit 0c5ef76f4b
11 files changed
+283 -61

No files matched your search

@@ -1,7 +1,10 @@
.collection-nodes--wrap {
--padding: 1.5em;
--child-height: calc(var(--node-height) - 2*var(--padding));
--child-width: calc(var(--node-width) - 2*var(--padding));
--padding-left: 1.5em;
--padding-right: 3em;
--padding-top: 2.25em;
--padding-bottom: 0.25em;
--child-height: calc(var(--node-height) - var(--padding-top) - var(--padding-bottom));
--child-width: calc(var(--node-width) - var(--padding-left) - var(--padding-right));
min-width: var(--node-width);
min-height: var(--node-height);
@@ -18,20 +21,34 @@
.collection-nodes {
position: relative;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
gap: 0em 1em;
max-width: var(--child-width);
max-height: var(--child-height);
border-color: var(--node-color);
border-style: solid;
border-width: 1px;
border-radius: 10px;
max-width: max-content;
max-height: max-content;
padding-right: var(--padding-right);
}
.collection-nodes--inner {
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
justify-content: space-around;
gap: 0 1em;
max-width: var(--child-width);
max-height: var(--child-height);
min-height: calc(var(--child-height) / 4);
min-width: var(--child-width);
padding-left: var(--padding-left);
padding-top: var(--padding-top);
padding-bottom: var(--padding-bottom);
overflow: auto;
padding: var(--padding);
}
.collection-nodes .react-flow__handle {
@@ -43,4 +60,16 @@
bottom: 0.25em;
right: 0.25em;
font-size: 0.5em;
}
.collection-nodes .add {
position: absolute;
bottom: calc(50% - var(--padding-bottom));
right: 0.25em;
}
.collection-nodes--title {
position: absolute;
top: 0.5em;
left: calc(var(--child-width)/2);
}
@@ -7,6 +7,7 @@ import { SequenceNodeElement } from "../SequenceNode/SequenceNodeElement";
import { CollectionNodeProps } from "./types";
import { Handle, Position } from "react-flow-renderer";
import { useSequenceNodeColor } from "../SequenceNode/util";
import { prettyName } from "utils/formatting";
export const CollectionNode: FC<CollectionNodeProps> = ({
onAddNode,
@@ -17,6 +18,7 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
flipped,
color,
hasInput = false,
collectionType,
}) => {
const nodeColor = useSequenceNodeColor(color);
@@ -32,22 +34,29 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
}
>
<div className="collection-nodes">
{nodes.map((n, i) => (
<SequenceNodeElement
{...n}
{...sequenceNode}
key={i}
color={color}
flipped={flipped}
/>
))}
<ButtonIcon icon={<Add />} onClick={onAddNode} />
<span className="collection-nodes--title">
{prettyName(collectionType)}s
</span>
<div className="collection-nodes--inner">
{nodes.map((n, i) => (
<SequenceNodeElement
{...n}
{...sequenceNode}
key={i}
color={color}
flipped={flipped}
/>
))}
</div>
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
<Handle
key="source"
type="source"
position={flipped ? Position.Bottom : Position.Right}
/>
{hasInput && (
<Handle
key="target"
type="target"
position={flipped ? Position.Top : Position.Left}
/>
@@ -0,0 +1,126 @@
import React, { FC } from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { Page } from "components/Page";
import { CollectionNode } from "./CollectionNode";
import { DAGGraphBoard } from "components/DAGGraph/board";
import { CollectionNodeMaker } from "./index";
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
const Demo: FC<{
height: number;
width: number;
totalChildNodes: number;
onAddNode: () => void;
enabledChild: boolean;
}> = (args) => {
return (
<Page>
<DAGGraphBoard
closeModal={() => {}}
state={{
ready: true,
data: {
elements: {
edges: [],
nodes: ["trogger", "sequence", "condition"].map(
(collectionType: any, i: number) =>
CollectionNodeMaker.makeElement(
{
id: collectionType,
position: {
x: 50 + args.width * (i % 3 === 0 ? 1 : 0),
y: 50 + args.height * ((i + 1) % 2 === 0 ? 1 : 0),
},
},
DEFAULT_DIMS,
{
hasInput: false,
onAddNode: args.onAddNode,
width: args.width,
height: args.height,
nodes: [
{
enabled: args.enabledChild,
label: collectionType,
},
...Array.from(Array(args.totalChildNodes)).map(
(_, i) => ({
enabled: true,
label: `Dummy Node #${i + 1}`,
})
),
],
collectionType,
}
)
),
},
},
}}
/>
</Page>
);
};
export default {
title: "DAGGraph/Nodes/Collection",
component: Demo,
parameters: { actions: { argTypesRegex: "^on.*" } },
args: {
...DEFAULT_DIMS.condition,
totalChildNodes: 1,
enabledChild: true,
},
} as ComponentMeta<typeof Demo>;
export const Colors: ComponentStory<typeof Demo> = (args) => <Demo {...args} />;
export const Empty: ComponentStory<typeof Demo> = (args) => {
return (
<Page>
<DAGGraphBoard
closeModal={() => {}}
state={{
ready: true,
data: {
elements: {
edges: [],
nodes: [
CollectionNodeMaker.makeElement(
{
id: "only-one",
position: {
x: 50,
y: 50,
},
},
DEFAULT_DIMS,
{
hasInput: false,
onAddNode: args.onAddNode,
width: args.width,
height: args.height,
nodes: [
...Array.from(Array(args.totalChildNodes)).map(
(_, i) => ({
enabled: true,
label: `Dummy Node #${i + 1}`,
})
),
],
collectionType: "condition",
}
),
],
},
},
}}
/>
</Page>
);
};
Empty.args = {
...Empty.args,
totalChildNodes: 0,
};
@@ -1,12 +1,18 @@
import { NodeManager } from "components/DAGGraph/nodes/NodeManager";
import { CollectionNode } from "./CollectionNode";
import { CollectionNodeDataProps } from "./types";
import { SequenceNodeColor } from "../SequenceNode/types";
export const CollectionNodeMaker = NodeManager.register(
"CollectionNode",
CollectionNode,
(pre: CollectionNodeDataProps, { node, flipped }) => ({
...pre,
color: (pre.collectionType === "condition"
? "blue"
: pre.collectionType === "sequence"
? "green"
: "red") as SequenceNodeColor,
sequenceNode: node,
flipped,
})
@@ -1,6 +1,7 @@
import { Size } from "components/DAGGraph/elements/types";
import { ReactNode } from "react";
import { SequenceNodeActions, SequenceNodeColor } from "../SequenceNode/types";
import { AutomationActionData } from "types/automations";
export type CollectionNodeChildProps = Partial<SequenceNodeActions> & {
enabled: boolean;
@@ -9,11 +10,12 @@ export type CollectionNodeChildProps = Partial<SequenceNodeActions> & {
export type CollectionNodeDataProps = Size & {
nodes: CollectionNodeChildProps[];
onAddNode: () => void;
color: SequenceNodeColor;
hasInput?: boolean;
collectionType: keyof AutomationActionData;
};
export type CollectionNodeProps = CollectionNodeDataProps & {
sequenceNode: Size;
flipped: boolean;
color: SequenceNodeColor;
};