cleaned up styles for node display
This commit is contained in:
1 parent
9a43330501
commit
4d9afbe26b
10 files changed
+173
-68
No files matched your search
@@ -1,3 +1,59 @@
|
||||
.dagnode {
|
||||
font-size: 0.9em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.dagnode--inner {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
padding: 1.5em 0.5em;
|
||||
/* width: calc(100% - 0.5em);
|
||||
height: calc(100% - 0.5em); */
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
|
||||
.dagnode--label {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dagnode .dagnode--inner .speed-dial {
|
||||
height: 2em;
|
||||
width: 2em;
|
||||
min-height: 2em;
|
||||
max-height: 2em;
|
||||
position: absolute;
|
||||
top: -1em;
|
||||
left: -1em;
|
||||
background-color: var(--primary);
|
||||
border-color: var(--primary-accent);
|
||||
border-style: solid;
|
||||
border-width: 0.5px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.open>.dagnode--actions-btn, .dagnode--actions-btn:hover {
|
||||
color: var(--primary);
|
||||
background-color: var(--primary-accent);
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.dagnode--actions--move.right {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
Whitespace-only changes.
@@ -1,7 +1,6 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { DAGAutomationFlow } from ".";
|
||||
import { useState } from "react";
|
||||
import * as dgconst from "components/DAGFlow/constants";
|
||||
import ReactFlow, { Controls } from "react-flow-renderer";
|
||||
import { DAGNode } from "./DAGNode";
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import "./DAGNode.css";
|
||||
import { PencilIcon } from "components/Icons";
|
||||
import "./DAGNode.flipped.css";
|
||||
|
||||
import { NodeColor } from "types/graphs";
|
||||
import { useNodeStyles } from "./styles";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { FC, ReactNode, useState } from "react";
|
||||
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
||||
import { FC, ReactNode } from "react";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
|
||||
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
||||
import { createToNodeMakerFunction } from "./helpers";
|
||||
import { SpeedDial } from "components/SpeedDial";
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import { useTheme } from "@mui/material";
|
||||
|
||||
export type DAGNodeOnMove<Direction extends string> = Record<
|
||||
Direction,
|
||||
@@ -26,7 +27,6 @@ export interface DAGNodeDataProps {
|
||||
color: NodeColor;
|
||||
label: ReactNode;
|
||||
hasInput?: boolean;
|
||||
accentBackground?: boolean;
|
||||
}
|
||||
export interface DAGNodeProps extends DAGNodeDataProps {
|
||||
height: number;
|
||||
@@ -36,16 +36,13 @@ export interface DAGNodeProps extends DAGNodeDataProps {
|
||||
|
||||
export const makeConditionPoint = createToNodeMakerFunction<
|
||||
{
|
||||
totalConditions: number;
|
||||
label: ReactNode;
|
||||
onEditClick: () => void;
|
||||
},
|
||||
DAGNodeProps
|
||||
>((pre, { conditionWidth, conditionHeight, flipped }) => ({
|
||||
color: "lblue",
|
||||
accentBackground: true,
|
||||
label: `${pre.totalConditions} Condition${
|
||||
pre.totalConditions !== 1 ? "s" : ""
|
||||
}`,
|
||||
label: pre.label,
|
||||
height: conditionHeight,
|
||||
width: conditionWidth,
|
||||
hasInput: true,
|
||||
@@ -72,38 +69,48 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
onMove = {},
|
||||
color,
|
||||
hasInput = false,
|
||||
accentBackground = false,
|
||||
flipped,
|
||||
}) => {
|
||||
const { classes, theme } = useNodeStyles({
|
||||
color,
|
||||
nodeHeight: height,
|
||||
nodeWidth: width,
|
||||
accentBackground,
|
||||
});
|
||||
const [open, setOpen] = useState(false);
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<>
|
||||
{hasInput && (
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<div className={classes.root}>
|
||||
<div className={classes.inner}>
|
||||
<div
|
||||
className={["dagnode", flipped ? "flipped" : ""].join(" ")}
|
||||
style={{
|
||||
height,
|
||||
width,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="dagnode--inner"
|
||||
style={{
|
||||
maxHeight: height,
|
||||
maxWidth: width,
|
||||
minWidth: Math.max(width / 2, height / 2),
|
||||
borderBottomColor: theme.palette.grey[500],
|
||||
borderLeftColor: theme.palette.grey[700],
|
||||
borderRightColor: theme.palette.grey[700],
|
||||
borderTopColor:
|
||||
color === "blue"
|
||||
? theme.palette.info.main
|
||||
: color === "green"
|
||||
? theme.palette.success.light
|
||||
: color === "lblue"
|
||||
? theme.palette.info.light
|
||||
: color === "red"
|
||||
? theme.palette.error.dark
|
||||
: "none",
|
||||
backgroundColor: theme.palette.background.default,
|
||||
}}
|
||||
>
|
||||
<SpeedDial
|
||||
icon={<SettingsOutlinedIcon className="dagnode--actions" />}
|
||||
icon={<SettingsOutlinedIcon className="dagnode--actions-btn" />}
|
||||
>
|
||||
<IconButton onClick={onXClick} size="small">
|
||||
<DeleteForeverIcon fontSize="inherit" color="warning" />
|
||||
</IconButton>
|
||||
<IconButton onClick={onEditClick} size="small">
|
||||
<PencilIcon color={theme.green} size={0.8} />
|
||||
<Edit color="success" fontSize="inherit" />
|
||||
</IconButton>
|
||||
<IconButton onClick={onXClick} size="small">
|
||||
<DeleteForeverIcon fontSize="inherit" color="error" />
|
||||
</IconButton>
|
||||
{Object.entries(onMove).map(([key, action]) => (
|
||||
<IconButton
|
||||
@@ -116,10 +123,18 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
</IconButton>
|
||||
))}
|
||||
</SpeedDial>
|
||||
<div className={classes.textWrap}>
|
||||
<span className={classes.text}>{label}</span>
|
||||
</div>
|
||||
<div className={classes.rightEdge} onClick={onEditClick}></div>
|
||||
|
||||
{hasInput && (
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<div className="dagnode--label">{label}</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -2,8 +2,8 @@ import { DAGAutomationFlowDims } from "components/DAGFlow/types";
|
||||
|
||||
export const NODE_WIDTH = 150 as const;
|
||||
export const NODE_HEIGHT = 60 as const;
|
||||
export const CONDITION_HEIGHT = 30 as const;
|
||||
export const CONDITION_WIDTH = 120 as const;
|
||||
export const CONDITION_HEIGHT = 100 as const;
|
||||
export const CONDITION_WIDTH = 200 as const;
|
||||
export const CIRCLE_SIZE = 40 as const;
|
||||
export const DISTANCE_FACTOR = 1.5 as const;
|
||||
export const PADDING = 50 as const;
|
||||
@@ -20,4 +20,4 @@ export const DEFAULT_DIMS = {
|
||||
y: PADDING,
|
||||
},
|
||||
flipped: false,
|
||||
} as DAGAutomationFlowDims
|
||||
} as DAGAutomationFlowDims;
|
||||
@@ -21,6 +21,7 @@ import { AutomationCondition } from "types/automations/conditions";
|
||||
import { convertToFlowNode } from "./helpers";
|
||||
import { DAGErrorNode } from "./DAGErrorNode";
|
||||
import { useHA } from "haService";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
|
||||
const nodeTypes = {
|
||||
dagnode: convertToFlowNode(DAGNode),
|
||||
@@ -101,14 +102,21 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
||||
dims.flipped
|
||||
? {
|
||||
y: dims.padding.y + dims.nodeHeight * dims.distanceFactor,
|
||||
x: dims.padding.x + dims.nodeWidth * 0.25,
|
||||
x: dims.padding.x + (dims.nodeWidth - dims.conditionWidth) / 2,
|
||||
}
|
||||
: {
|
||||
x: dims.padding.x + dims.nodeWidth * dims.distanceFactor,
|
||||
y: dims.padding.y + dims.nodeHeight * 0.25,
|
||||
y: dims.padding.y + (dims.nodeHeight - dims.conditionHeight) / 2,
|
||||
},
|
||||
{
|
||||
totalConditions: condition.length,
|
||||
label: getDescriptionFromAutomationNode(
|
||||
{
|
||||
condition: "and",
|
||||
conditions: condition,
|
||||
},
|
||||
namer,
|
||||
true
|
||||
),
|
||||
onEditClick: makeOnEditAutomationConditions(
|
||||
condition,
|
||||
onConditionUpdate,
|
||||
@@ -154,11 +162,11 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
||||
...dims,
|
||||
padding: dims.flipped
|
||||
? {
|
||||
y: condPoint.position.y - dims.nodeHeight - dims.conditionHeight,
|
||||
y: condPoint.position.y - dims.nodeHeight,
|
||||
x: dims.padding.x,
|
||||
}
|
||||
: {
|
||||
x: condPoint.position.x - dims.nodeWidth - dims.conditionWidth,
|
||||
x: condPoint.position.x - dims.nodeWidth,
|
||||
y: dims.padding.y,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -231,11 +231,17 @@ const addChooseNode = (
|
||||
dims.flipped
|
||||
? {
|
||||
y: position.y + dims.nodeHeight * dims.distanceFactor,
|
||||
x: lastPos.x + dims.nodeWidth * dims.distanceFactor,
|
||||
x:
|
||||
lastPos.x +
|
||||
Math.max(dims.nodeWidth, dims.conditionWidth) *
|
||||
dims.distanceFactor,
|
||||
}
|
||||
: {
|
||||
x: position.x + dims.nodeWidth * dims.distanceFactor,
|
||||
y: lastPos.y + dims.nodeHeight * dims.distanceFactor,
|
||||
y:
|
||||
lastPos.y +
|
||||
Math.max(dims.nodeHeight, dims.conditionHeight) *
|
||||
dims.distanceFactor,
|
||||
},
|
||||
{
|
||||
flipped: dims.flipped,
|
||||
@@ -254,14 +260,21 @@ const addChooseNode = (
|
||||
dims.flipped
|
||||
? {
|
||||
y: circle.position.y + dims.circleSize * dims.distanceFactor,
|
||||
x: circle.position.x - dims.circleSize,
|
||||
x: circle.position.x - (dims.conditionWidth - dims.circleSize) / 2,
|
||||
}
|
||||
: {
|
||||
x: circle.position.x + dims.circleSize * dims.distanceFactor,
|
||||
y: circle.position.y + dims.circleSize / 8,
|
||||
y: circle.position.y - (dims.conditionHeight - dims.circleSize) / 2,
|
||||
},
|
||||
{
|
||||
totalConditions: conditions.length,
|
||||
label: getDescriptionFromAutomationNode(
|
||||
{
|
||||
condition: "and",
|
||||
conditions,
|
||||
},
|
||||
namer,
|
||||
true
|
||||
),
|
||||
onEditClick: updater.makeOnEditConditionsForChooseNode(i, j),
|
||||
},
|
||||
dims
|
||||
@@ -278,12 +291,16 @@ const addChooseNode = (
|
||||
...dims,
|
||||
padding: dims.flipped
|
||||
? {
|
||||
y: condNode.position.y - dims.nodeHeight * dims.distanceFactor,
|
||||
x: condNode.position.x - dims.conditionHeight / 2,
|
||||
y: condNode.position.y - dims.nodeHeight,
|
||||
x:
|
||||
condNode.position.x -
|
||||
(dims.nodeWidth - dims.conditionWidth) / 2,
|
||||
}
|
||||
: {
|
||||
x: condNode.position.x - (dims.nodeWidth + dims.conditionWidth),
|
||||
y: condNode.position.y - dims.conditionHeight / 2,
|
||||
x: condNode.position.x - dims.nodeWidth,
|
||||
y:
|
||||
condNode.position.y -
|
||||
(dims.nodeHeight - dims.conditionHeight) / 2,
|
||||
},
|
||||
},
|
||||
namer,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.speed-dial, .speed-dial--button {
|
||||
.speed-dial, .speed-dial--icon {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
@@ -8,7 +8,7 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.speed-dial .speed-dial--button {
|
||||
.speed-dial .speed-dial--icon {
|
||||
max-height: 2em;
|
||||
max-width: 2em;
|
||||
overflow: hidden;
|
||||
@@ -16,13 +16,12 @@
|
||||
}
|
||||
|
||||
.speed-dial--list.close {
|
||||
display: none;
|
||||
width: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.speed-dial--list {
|
||||
position: absolute;
|
||||
bottom: -3em;
|
||||
left: 0em;
|
||||
background: var(--secondary);
|
||||
z-index: 10;
|
||||
height: fit-content;
|
||||
@@ -30,15 +29,17 @@
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.speed-dial--list.open.row {
|
||||
.speed-dial--list.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
top: 0;
|
||||
left: 2em;
|
||||
}
|
||||
|
||||
.speed-dial--list.open.column {
|
||||
.speed-dial--list.column {
|
||||
display: flex;
|
||||
top: 2em;
|
||||
flex-direction: column;
|
||||
gap: 0.25em;
|
||||
top: 2em;
|
||||
left: 0.25em;
|
||||
}
|
||||
@@ -16,9 +16,12 @@ export const SpeedDial: FC<SpeedDialProps> = (props) => {
|
||||
<div
|
||||
className={["speed-dial", props.className ?? ""].join(" ")}
|
||||
onClick={() => setOpen(!open)}
|
||||
onMouseEnter={() => setOpen(true)}
|
||||
>
|
||||
<div className="speed-dial--button">{props.icon}</div>
|
||||
<div
|
||||
className={["speed-dial--icon", open ? "open" : "close"].join(" ")}
|
||||
>
|
||||
{props.icon}
|
||||
</div>
|
||||
<div
|
||||
className={[
|
||||
"speed-dial--list",
|
||||
|
||||
@@ -77,7 +77,13 @@ export const getDescriptionFromAutomationNode = <
|
||||
node.condition === "or" ||
|
||||
node.condition === "not"
|
||||
) {
|
||||
return "Logic";
|
||||
if (node.conditions.length === 0) {
|
||||
return `None`;
|
||||
}
|
||||
const childConditions = node.conditions.map((c) =>
|
||||
getDescriptionFromAutomationNode(c, namer, allowJs)
|
||||
);
|
||||
return childConditions.join(` ${node.condition} `).trim() ?? "None";
|
||||
} else {
|
||||
switch (node.condition) {
|
||||
case "numeric_state":
|
||||
|
||||
Reference in new issue
Block a user