new text area + editable template
This commit is contained in:
1 parent
fed45e1d78
commit
b683cbb65e
9 files changed
+86
-28
No files matched your search
@@ -2,6 +2,7 @@ import { FC } from "react";
|
||||
import { AutomationCondition, TemplateCondition } from "~/automations/types/conditions";
|
||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||
import InputText from "../Inputs/InputText";
|
||||
import InputTextArea from "../Inputs/InputTextArea";
|
||||
|
||||
|
||||
interface Editor<C extends AutomationCondition> extends FC<{
|
||||
@@ -31,12 +32,12 @@ export const TemplateEditor: Editor<TemplateCondition> = ({
|
||||
alias
|
||||
}
|
||||
})}/>
|
||||
<InputText label="Template" value={condition.condition_data.value_template} onChange={value_template => onChange({
|
||||
<InputTextArea label="Template" value={condition.condition_data.value_template} onChange={value_template => onChange({
|
||||
...condition,
|
||||
condition_data: {
|
||||
...condition.condition_data,
|
||||
value_template
|
||||
}
|
||||
})}/>
|
||||
})} resizable/>
|
||||
</div>
|
||||
}
|
||||
@@ -27,5 +27,4 @@ SimpleGraph.args = {
|
||||
value_template: "states('switch.light_kitchen') == 'on'"
|
||||
}
|
||||
},
|
||||
displayMode: true,
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import { useStyles } from "./style";
|
||||
|
||||
export const ConditionEditor: FC<{
|
||||
condition: AutomationCondition;
|
||||
displayMode?: boolean;
|
||||
onDelete: (which: 'root' | number) => void;
|
||||
onAddChild: () => void;
|
||||
onUpdate: (data: AutomationCondition) => void;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { usePageTheme } from "~/styles/page";
|
||||
import InputText from "./InputText";
|
||||
|
||||
export default {
|
||||
title: 'InputText',
|
||||
title: 'Inputs/InputText',
|
||||
component: InputText,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputText>;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTextStyles } from "./styles";
|
||||
@@ -18,7 +19,8 @@ export default function InputText({
|
||||
}: Props) {
|
||||
const {classes} = useInputTextStyles({});
|
||||
const tooltip = useToolTip();
|
||||
return <InputWrapper label={label} labelSize={value === '' ? 'normal' : 'small'}>
|
||||
const [isFocused, setIsFocused] = useState(false)
|
||||
return <InputWrapper label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
|
||||
<input
|
||||
className={classes.input}
|
||||
value={value}
|
||||
@@ -26,15 +28,23 @@ export default function InputText({
|
||||
e.preventDefault();
|
||||
onChange(e.target.value)
|
||||
}}
|
||||
onFocus={e => textBoxFor && tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
searchText: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChange
|
||||
)}
|
||||
onBlur={e => {
|
||||
setIsFocused(false)
|
||||
}}
|
||||
onFocus={e => {
|
||||
setIsFocused(true)
|
||||
if(textBoxFor) {
|
||||
tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
searchText: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChange
|
||||
)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { useState } from "react";
|
||||
import { usePageTheme } from "~/styles/page";
|
||||
import InputTextArea from "./InputTextArea";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputTextArea',
|
||||
component: InputTextArea,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputTextArea>;
|
||||
|
||||
|
||||
const Template: ComponentStory<typeof InputTextArea> = args => {
|
||||
const {classes} = usePageTheme({});
|
||||
const [value, setValue] = useState('')
|
||||
return <div className={classes.page}>
|
||||
<InputTextArea {...args} value={value} onChange={setValue}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
label: "Entity ID",
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useToolTip } from "~/tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTextAreaStyles } from "./styles";
|
||||
|
||||
export interface Props {
|
||||
textBoxFor?: string;
|
||||
@@ -7,6 +9,7 @@ export interface Props {
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
additionalTooltipFilters?: Record<string, string>;
|
||||
resizable?: boolean;
|
||||
}
|
||||
export default function InputTextArea({
|
||||
label,
|
||||
@@ -14,24 +17,36 @@ export default function InputTextArea({
|
||||
value="",
|
||||
onChange,
|
||||
additionalTooltipFilters={},
|
||||
resizable=false,
|
||||
}: Props) {
|
||||
const {classes} = useInputTextAreaStyles({ resizable });
|
||||
const tooltip = useToolTip();
|
||||
return <InputWrapper label={label}>
|
||||
const [isFocused, setIsFocused] = useState(false)
|
||||
return <InputWrapper label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
|
||||
<textarea
|
||||
className={classes.input}
|
||||
value={value}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.target.value)
|
||||
}}
|
||||
onFocus={e => textBoxFor && tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
searchText: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChange
|
||||
)}
|
||||
onBlur={e => {
|
||||
setIsFocused(false)
|
||||
}}
|
||||
onFocus={e => {
|
||||
setIsFocused(true)
|
||||
if(textBoxFor) {
|
||||
tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
searchText: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChange
|
||||
)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { usePageTheme } from "~/styles/page";
|
||||
import InputViewEdit from "./InputViewEdit";
|
||||
|
||||
export default {
|
||||
title: 'InputViewEdit',
|
||||
title: 'Inputs/InputViewEdit',
|
||||
component: InputViewEdit,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputViewEdit>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Styles } from "jss";
|
||||
import { createAppUseStyles, AppTheme } from "~/styles/theme";
|
||||
|
||||
const commonInputStyle = (theme: AppTheme): Styles => ({
|
||||
const commonInputStyle = (theme: AppTheme) => ({
|
||||
input: {
|
||||
backgroundColor: theme.secondary,
|
||||
color: theme.secondaryAccent,
|
||||
@@ -9,7 +9,7 @@ const commonInputStyle = (theme: AppTheme): Styles => ({
|
||||
borderStyle: 'solid',
|
||||
borderWidth: 1,
|
||||
borderRadius: 5,
|
||||
padding: 10,
|
||||
padding: 15,
|
||||
marginLeft: 5,
|
||||
marginRight: 5,
|
||||
fontSize: 16,
|
||||
@@ -53,6 +53,16 @@ export const useInputTextStyles = createAppUseStyles<{}>(theme => ({
|
||||
...commonInputStyle(theme),
|
||||
}));
|
||||
|
||||
export const useInputTextAreaStyles = createAppUseStyles<{ resizable: boolean }>(theme => {
|
||||
const styles = commonInputStyle(theme);
|
||||
return {
|
||||
input: ({resizable}) => ({
|
||||
...styles.input,
|
||||
resize: resizable ? 'both' : 'none'
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
export const useInputViewEditStyles = createAppUseStyles<{
|
||||
isEditing: boolean;
|
||||
}>(theme => ({
|
||||
|
||||
Reference in new issue
Block a user