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