+ added bubble editor
+ initial numeric editor + entity id input
This commit is contained in:
1 parent
6be9f1ba12
commit
60ec7c3f29
7 files changed
+237
-8
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { FC } from "react";
|
||||
import { AutomationCondition, LogicCondition, TemplateCondition } from "~/automations/types/conditions";
|
||||
import { AutomationCondition, LogicCondition, NumericCondition, TemplateCondition } from "~/automations/types/conditions";
|
||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||
import InputText from "../Inputs/InputText";
|
||||
import InputTextArea from "../Inputs/InputTextArea";
|
||||
import { InputEntity } from "../Inputs/InputTextBubble";
|
||||
import { ConditionNode } from "./ConditionNode";
|
||||
|
||||
|
||||
@@ -22,6 +23,8 @@ export const getEditor = (condition: AutomationCondition): Editor<any> => {
|
||||
return LogicViewer;
|
||||
case 'not':
|
||||
return LogicViewer;
|
||||
case 'numeric_state':
|
||||
return NumericStateEditor;
|
||||
default:
|
||||
return () => <div>Not Ready</div>
|
||||
}
|
||||
@@ -50,6 +53,39 @@ export const TemplateEditor: Editor<TemplateCondition> = ({
|
||||
}
|
||||
|
||||
|
||||
export const NumericStateEditor: Editor<NumericCondition> = ({
|
||||
onChange,
|
||||
condition,
|
||||
}) => {
|
||||
return <div>
|
||||
<InputText label="Alias" value={condition.condition_data.alias ?? getDescriptionFromAutomationNode(condition)} onChange={alias => onChange({
|
||||
...condition,
|
||||
condition_data: {
|
||||
...condition.condition_data,
|
||||
alias
|
||||
}
|
||||
})}/>
|
||||
<InputEntity
|
||||
value={condition.condition_data.entity_id}
|
||||
onChange={entity_id => onChange({
|
||||
...condition,
|
||||
condition_data: {
|
||||
...condition.condition_data,
|
||||
entity_id
|
||||
}
|
||||
})}
|
||||
/>
|
||||
<InputTextArea label="Template" value={condition.condition_data.value_template ?? ""} onChange={value_template => onChange({
|
||||
...condition,
|
||||
condition_data: {
|
||||
...condition.condition_data,
|
||||
value_template
|
||||
}
|
||||
})} resizable/>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
export const LogicViewer: Editor<LogicCondition> = ({
|
||||
condition,
|
||||
onChange,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { PropsWithChildren, useState } from "react";
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTextStyles } from "./styles";
|
||||
@@ -8,6 +8,7 @@ export interface Props {
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
onEnter?: () => void;
|
||||
additionalTooltipFilters?: Record<string, string>;
|
||||
}
|
||||
export default function InputText({
|
||||
@@ -15,8 +16,10 @@ export default function InputText({
|
||||
textBoxFor,
|
||||
value="",
|
||||
onChange,
|
||||
onEnter=()=>{},
|
||||
additionalTooltipFilters={},
|
||||
}: Props) {
|
||||
children,
|
||||
}: PropsWithChildren<Props>) {
|
||||
const {classes} = useInputTextStyles({});
|
||||
const tooltip = useToolTip();
|
||||
const [isFocused, setIsFocused] = useState(false)
|
||||
@@ -24,6 +27,11 @@ export default function InputText({
|
||||
<input
|
||||
className={classes.input}
|
||||
value={value}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
onEnter();
|
||||
}
|
||||
}}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.target.value)
|
||||
@@ -46,5 +54,6 @@ export default function InputText({
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{children}
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { useState } from "react";
|
||||
import { usePageTheme } from "~/styles/page";
|
||||
import InputTextBubble, { InputEntity } from "./InputTextBubble";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputTextBubble',
|
||||
component: InputTextBubble,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {
|
||||
label: {
|
||||
defaultValue: 'Sample Title'
|
||||
}
|
||||
}
|
||||
} as ComponentMeta<typeof InputTextBubble>;
|
||||
|
||||
|
||||
export const ArrayText: ComponentStory<typeof InputTextBubble> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState<string | string[]>(['wow','lots of bubbles', 'itchen', 'bathroom'])
|
||||
return <div className={classes.page}>
|
||||
<div style={{maxWidth: '200px', overflow: 'hidden'}}>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue}/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
export const JustText: ComponentStory<typeof InputTextBubble> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState<string | string[]>('hello')
|
||||
return <div className={classes.page}>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
export const EntityId: ComponentStory<typeof InputTextBubble> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState<string | string[]>(['sensor.bathroom'])
|
||||
return <div className={classes.page}>
|
||||
<InputEntity value={value} onChange={setValue}/>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { FC, useState } from "react";
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputText from "./InputText";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputBubblesStyles, useInputTextStyles } from "./styles";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
textBoxFor?: string;
|
||||
value: string | string[];
|
||||
onChange: (v: string[]) => void;
|
||||
additionalTooltipFilters?: Record<string, string>;
|
||||
}
|
||||
export default function InputTextBubble({
|
||||
value="",
|
||||
label,
|
||||
textBoxFor,
|
||||
onChange,
|
||||
additionalTooltipFilters={},
|
||||
}: Props) {
|
||||
const {classes} = useInputBubblesStyles({});
|
||||
let selected: string[];
|
||||
if (typeof value === 'string') {
|
||||
selected = [value]
|
||||
} else {
|
||||
selected = value
|
||||
}
|
||||
const [text, setText] = useState('');
|
||||
const addNew = () => {
|
||||
if(text) {
|
||||
onChange([text].concat(selected))
|
||||
setText("")
|
||||
}
|
||||
};
|
||||
|
||||
return <InputText
|
||||
label={label}
|
||||
value={text}
|
||||
textBoxFor={textBoxFor}
|
||||
onChange={t => setText(t)}
|
||||
onEnter={() => addNew()}
|
||||
additionalTooltipFilters={additionalTooltipFilters}
|
||||
>
|
||||
<div className={classes.bubbles}>
|
||||
{selected.map((s, i) => <div className={classes.bubble} onClick={() => onChange([
|
||||
...selected.slice(0, i),
|
||||
...selected.slice(i+1),
|
||||
])}>
|
||||
{s}
|
||||
<span className={classes.deleteIcon}>X</span>
|
||||
</div>)}
|
||||
</div>
|
||||
<button className={classes.addBtn} onClick={() => addNew()}>+</button>
|
||||
</InputText>
|
||||
}
|
||||
|
||||
export const InputEntity: FC<{
|
||||
value: string | string[];
|
||||
onChange: (v: string[]) => void;
|
||||
}> = ({
|
||||
value,
|
||||
onChange,
|
||||
}) => <InputTextBubble
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
label="Entity ID"
|
||||
textBoxFor="entity_id"
|
||||
/>
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Styles } from "jss";
|
||||
import { createAppUseStyles, AppTheme } from "~/styles/theme";
|
||||
import Color from 'chroma-js';
|
||||
|
||||
const commonInputStyle = (theme: AppTheme) => ({
|
||||
input: {
|
||||
@@ -76,4 +76,67 @@ export const useInputViewEditStyles = createAppUseStyles<{
|
||||
pencil: {
|
||||
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({
|
||||
bubbles: {
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
maxHeight: 50,
|
||||
maxWidth: '100%',
|
||||
overflowX: 'auto',
|
||||
overflowY: 'hidden',
|
||||
scrollbarWidth: 'thin',
|
||||
},
|
||||
bubble: {
|
||||
position: 'relative',
|
||||
border: `1px solid ${theme.primaryAccent}`,
|
||||
borderRadius: 10,
|
||||
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||
color: Color(theme.primary).brighten(5).hex(),
|
||||
fontSize: 16,
|
||||
|
||||
marginLeft: 1,
|
||||
padding: 5,
|
||||
width: 'fit-content',
|
||||
whiteSpace: 'nowrap',
|
||||
|
||||
cursor: 'pointer',
|
||||
"&:hover": {
|
||||
backgroundColor: Color(theme.primary).set('rgb.r', 150).alpha(0.35).hex(),
|
||||
color: Color(theme.primary).brighten(5).alpha(0.35).hex(),
|
||||
},
|
||||
|
||||
"&:hover $deleteIcon": {
|
||||
display: 'block',
|
||||
}
|
||||
},
|
||||
deleteIcon: {
|
||||
display: 'none',
|
||||
position: "absolute",
|
||||
left: "48%",
|
||||
top: 5,
|
||||
color: "white",
|
||||
},
|
||||
addBtn: {
|
||||
position: "absolute",
|
||||
top: 10,
|
||||
right: 10,
|
||||
fontSize: 20,
|
||||
cursor: 'pointer',
|
||||
borderStyle: 'solid',
|
||||
borderWidth: 1,
|
||||
borderColor: theme.secondary,
|
||||
backgroundColor: theme.secondary,
|
||||
color: theme.secondaryAccent,
|
||||
padding: "3px 7px",
|
||||
transition: "200ms ease-out",
|
||||
"&:hover": {
|
||||
borderRadius: 100,
|
||||
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||
borderColor: theme.secondaryAccent,
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user