using storybook
converted to jss
This commit is contained in:
1 parent
6d4fe7749a
commit
df272e138c
33 files changed
+8944
-1650
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { FC } from "react"
|
||||
import { NODE_HEIGHT, NODE_WIDTH } from "./constants"
|
||||
import { Node } from "./types"
|
||||
|
||||
@@ -23,12 +24,39 @@ export default ({
|
||||
<div className="automation-editor--node">
|
||||
<div className={`automation-editor--node-inner top-color ${color}`}>
|
||||
<div className="automation-editor--node-inner-edge left" onClick={onXClick}>
|
||||
<div className="automation-node-side-button">X</div>
|
||||
<span className="automation-node-side-button">X</span>
|
||||
</div>
|
||||
<div className="automation-editor--node-inner-text">
|
||||
<span>{text}</span>
|
||||
</div>
|
||||
<div className="automation-editor--node-inner-text">{text}</div>
|
||||
<div className="automation-editor--node-inner-edge right" onClick={onOpenClick}>
|
||||
<div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>
|
||||
<span className="automation-node-side-button">{isOpen ? "▲" : "▼"}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</foreignObject>
|
||||
|
||||
export interface ConditionNodeProps extends NodeProp {
|
||||
conditionType: string;
|
||||
}
|
||||
export const ConditionNode: FC<ConditionNodeProps> = ({
|
||||
loc: [x,y],
|
||||
text,
|
||||
height=NODE_HEIGHT,
|
||||
width=NODE_WIDTH,
|
||||
onXClick=() => {},
|
||||
onOpenClick=() => {},
|
||||
isOpen=false,
|
||||
color,
|
||||
conditionType,
|
||||
children,
|
||||
}) => <foreignObject x={x} y={y} width={width} height={height}>
|
||||
<div className="automation-editor--condition-node">
|
||||
<div className="automation-editor--condition-node-type">
|
||||
{conditionType}
|
||||
</div>
|
||||
<div>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</foreignObject>
|
||||
@@ -6,7 +6,7 @@ import useWindowSize from "~/utils/useWindowSize";
|
||||
import AutoInfoBox from "./AutoInfoBox";
|
||||
import { NODE_HEIGHT, NODE_WIDTH } from "./constants";
|
||||
import DAGEdge from "./DAGEdge";
|
||||
import DAGNode from "./DAGNode";
|
||||
import DAGNode, { ConditionNode } from "./DAGNode";
|
||||
import { Point } from "./types";
|
||||
|
||||
interface Props {
|
||||
@@ -47,8 +47,23 @@ export default function AutomationEditor({
|
||||
lastNodeLoc = [nodeLoc[0] + NODE_WIDTH*((i - 1)*nHDF+1), nodeLoc[1] + NODE_HEIGHT/2];
|
||||
nodeLoc[0] += NODE_WIDTH*i*nHDF
|
||||
}
|
||||
let children = <></>;
|
||||
if (
|
||||
(condition.condition === 'and') ||
|
||||
(condition.condition === 'or') ||
|
||||
(condition.condition === 'not')
|
||||
) {
|
||||
// children = condition.condition_data.conditions.map((c,i) => renderMidCondition(c,i))
|
||||
}
|
||||
return <>
|
||||
<DAGNode key={`node.${i}`} loc={nodeLoc} text={getDescriptionFromAutomationNode(condition)} color="blue"/>
|
||||
<ConditionNode
|
||||
conditionType={condition.condition}
|
||||
key={`node.${i}`}
|
||||
loc={nodeLoc}
|
||||
text={getDescriptionFromAutomationNode(condition)} color="blue"
|
||||
>
|
||||
{children}
|
||||
</ConditionNode>
|
||||
<DAGEdge
|
||||
key={`edge.${i}`}
|
||||
p1={lastNodeLoc}
|
||||
@@ -81,8 +96,8 @@ export default function AutomationEditor({
|
||||
<g className="triggers">
|
||||
{automation.trigger.map(renderTrigger)}
|
||||
</g>
|
||||
<g className="conditions">
|
||||
{automation.condition.map(renderMidCondition)}
|
||||
<g className="sequence">
|
||||
{automation.sequence.map(renderMidCondition)}
|
||||
</g>
|
||||
<circle className="blue" cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2}/>
|
||||
<g className="actions">
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,28 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { usePageTheme } from "~/styles/page";
|
||||
import { ConditionEditor } from ".";
|
||||
|
||||
export default {
|
||||
title: 'ConditionEditor',
|
||||
component: ConditionEditor,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof ConditionEditor>;
|
||||
|
||||
|
||||
const Template: ComponentStory<typeof ConditionEditor> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
return <div className={classes.page}>
|
||||
<ConditionEditor {...args} />
|
||||
</div>
|
||||
}
|
||||
|
||||
export const SimpleGraph = Template.bind({})
|
||||
SimpleGraph.args = {
|
||||
condition: {
|
||||
$smType: 'condition',
|
||||
condition: 'template',
|
||||
condition_data: {
|
||||
value_template: "states('switch.light_kitchen') == 'on'"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { FC } from "react";
|
||||
import { AutomationCondition } from "~/automations/types/conditions";
|
||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||
import { useStyles } from "./style";
|
||||
|
||||
|
||||
|
||||
export const ConditionEditor: FC<{
|
||||
condition: AutomationCondition;
|
||||
onDelete: (which: 'root' | number) => void;
|
||||
onAddChild: () => void;
|
||||
}> = ({
|
||||
condition,
|
||||
onDelete,
|
||||
// onAddChild,
|
||||
}) => {
|
||||
// alias
|
||||
let children = getDescriptionFromAutomationNode(condition);
|
||||
let hasChildren = false;
|
||||
if (condition.condition === "not") {
|
||||
children = "not"
|
||||
hasChildren = true
|
||||
} else if (condition.condition ==='and') {
|
||||
children = "and"
|
||||
hasChildren = true
|
||||
} else if (condition.condition ==='or') {
|
||||
children = "or"
|
||||
hasChildren = true
|
||||
}
|
||||
|
||||
// styles
|
||||
const {classes} = useStyles({ hasChildren });
|
||||
|
||||
// components
|
||||
const DeleteButton = (p: {onClick?: () => void, isRoot?: boolean}) =>
|
||||
<button className={p.isRoot ? classes.deleteBtnRoot : classes.deleteBtn} onClick={p?.onClick}>X</button>
|
||||
|
||||
return <div className={classes.root}>
|
||||
<DeleteButton isRoot onClick={ () => onDelete('root')}/>
|
||||
<div className={classes.title}>
|
||||
{condition.condition.replace('_', '')}
|
||||
</div>
|
||||
<div className={classes.children}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Styles } from "jss";
|
||||
import { createAppUseStyles } from "~/styles/theme";
|
||||
|
||||
export const useStyles = createAppUseStyles<{
|
||||
hasChildren: boolean
|
||||
}>(theme => {
|
||||
const deleteBtn: Styles = {
|
||||
borderRadius: '10px',
|
||||
borderStyle: 'none',
|
||||
padding: '0',
|
||||
margin: '0',
|
||||
background: theme.red,
|
||||
width: '30px',
|
||||
height: '15px',
|
||||
fontSize: '10px',
|
||||
textAlign: 'center',
|
||||
cursor: 'pointer',
|
||||
"&:hover": {
|
||||
background: theme.redAccent,
|
||||
}
|
||||
}
|
||||
return {
|
||||
root: ({ hasChildren }) => ({
|
||||
background: theme.primary,
|
||||
padding: 0,
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
flexDirection: hasChildren? 'column' : 'row',
|
||||
width: hasChildren? '100%' : undefined,
|
||||
height: hasChildren? '100%' : undefined,
|
||||
}),
|
||||
title: {
|
||||
background: theme.condition.primaryColor,
|
||||
border: `1px solid ${theme.primaryAccent}`,
|
||||
borderRadius: 10,
|
||||
borderTopRightRadius: 0,
|
||||
borderBottomRightRadius: 0,
|
||||
padding: 10,
|
||||
maxWidth: 80,
|
||||
textOverflow: 'ellipsis',
|
||||
},
|
||||
deleteBtnRoot: {
|
||||
...deleteBtn,
|
||||
position: 'absolute',
|
||||
left: -35,
|
||||
top: 10,
|
||||
},
|
||||
deleteBtn,
|
||||
children: ({}) => ({
|
||||
flex: 1,
|
||||
paddingLeft: 10,
|
||||
paddingRight: 10,
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
border: `1px solid ${theme.primaryAccent}`,
|
||||
borderRadius: 10,
|
||||
borderTopLeftRadius: 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { useState } from "react";
|
||||
import { usePageTheme } from "~/styles/page";
|
||||
import InputText from "./InputText";
|
||||
|
||||
export default {
|
||||
title: 'InputText',
|
||||
component: InputText,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputText>;
|
||||
|
||||
|
||||
const Template: ComponentStory<typeof InputText> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState('')
|
||||
return <div className={classes.page}>
|
||||
<InputText {...args} value={value} onChange={setValue}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
label: "Entity ID",
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTextStyles } from "./styles";
|
||||
|
||||
export interface Props {
|
||||
textBoxFor?: string;
|
||||
@@ -15,9 +16,11 @@ export default function InputText({
|
||||
onChange,
|
||||
additionalTooltipFilters={},
|
||||
}: Props) {
|
||||
const {classes} = useInputTextStyles({});
|
||||
const tooltip = useToolTip();
|
||||
return <InputWrapper label={label}>
|
||||
return <InputWrapper label={label} labelSize={value === '' ? 'normal' : 'small'}>
|
||||
<input
|
||||
className={classes.input}
|
||||
value={value}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { CSSProperties, PropsWithChildren } from "react";
|
||||
import { PropsWithChildren } from "react";
|
||||
import { useInputWrapperStyles } from "./styles";
|
||||
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
style?: CSSProperties;
|
||||
labelSize?: 'normal' | 'small';
|
||||
}
|
||||
export default function InputWrapper({label, children, style={}}: PropsWithChildren<Props>) {
|
||||
return <div className="input-wrapper" style={style}>
|
||||
<label>{label}</label>
|
||||
export default function InputWrapper({label, children, labelSize='normal'}: PropsWithChildren<Props>) {
|
||||
const {classes} = useInputWrapperStyles({labelSize})
|
||||
return <div className={classes.wrapper}>
|
||||
<label className={classes.label}>{label}</label>
|
||||
{children}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Styles } from "jss";
|
||||
import { createAppUseStyles, AppTheme } from "~/styles/theme";
|
||||
|
||||
const commonInputStyle = (theme: AppTheme): Styles => ({
|
||||
input: {
|
||||
backgroundColor: theme.secondary,
|
||||
color: theme.secondaryAccent,
|
||||
borderColor: theme.primaryAccent,
|
||||
borderStyle: 'solid',
|
||||
borderWidth: 1,
|
||||
borderRadius: 5,
|
||||
padding: 10,
|
||||
marginLeft: 5,
|
||||
marginRight: 5,
|
||||
fontSize: 16,
|
||||
|
||||
"&:hover": {
|
||||
backgroundColor: theme.primary,
|
||||
borderColor: theme.secondaryAccent,
|
||||
},
|
||||
"&:disabled": {
|
||||
backgroundColor: '#403f3f',
|
||||
borderColor: '#403f3f',
|
||||
color: '#403f3faa',
|
||||
cursor: 'not-allowed',
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export const useInputWrapperStyles = createAppUseStyles<{
|
||||
labelSize: 'normal' | 'small',
|
||||
}>(theme => {
|
||||
return {
|
||||
wrapper: {
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
marginTop: 10,
|
||||
marginBottom: '0.25em',
|
||||
},
|
||||
label: ({ labelSize }) => ({
|
||||
fontSize: labelSize === 'normal' ? 16 : 10,
|
||||
position: 'absolute',
|
||||
left: labelSize === 'normal' ? '0.75em': '1em',
|
||||
top: labelSize === 'normal' ? '0.5em' : '0.25em',
|
||||
fontWeight: 'bold',
|
||||
transition: 'all 200ms',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const useInputTextStyles = createAppUseStyles<{}>(theme => ({
|
||||
...commonInputStyle(theme),
|
||||
}));
|
||||
Reference in new issue
Block a user