standardized rendering of inputs
This commit is contained in:
1 parent
32fd7f2dff
commit
53ec0d417b
10 files changed
+77
-53
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import InputWrapper from "../../components/InputWrapper";
|
||||
import InputText from "../../components/InputText";
|
||||
import { ServiceScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
@@ -12,15 +12,10 @@ export default class Generic extends BaseState<{alias: string}> {
|
||||
}
|
||||
renderOptionList(state: ServiceScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputWrapper label="Description">
|
||||
<input value={state.alias} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...state,
|
||||
alias: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
</InputWrapper>
|
||||
<InputText label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<br/>
|
||||
<b>THIS IS NOT SUPPORTED YET!</b>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import InputText from "../../components/InputText";
|
||||
import InputWrapper from "../../components/InputWrapper";
|
||||
import { ServiceScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
@@ -17,33 +18,18 @@ export default class ScriptCallServiceState extends BaseState<ServiceScript> {
|
||||
}
|
||||
renderOptionList(state: ServiceScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputWrapper label="Description">
|
||||
<input value={state.alias} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...state,
|
||||
alias: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
</InputWrapper>
|
||||
<InputWrapper label="Service">
|
||||
<input value={state.service} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...state,
|
||||
service: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
</InputWrapper>
|
||||
<InputWrapper label="Target">
|
||||
<input value={state.target} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...state,
|
||||
target: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
</InputWrapper>
|
||||
<InputText label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText label="Service"
|
||||
value={state.service}
|
||||
onChange={service => this.setState({...state, service})}
|
||||
/>
|
||||
<InputText label="Target"
|
||||
value={state.target}
|
||||
onChange={target => this.setState({...state, target})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { AutomationNodeType, NodeSubType } from "../types";
|
||||
import { BaseState } from "./BaseState";
|
||||
import Generic from "./Generic";
|
||||
@@ -24,9 +24,15 @@ export default class StateManager {
|
||||
}
|
||||
this.nodeType = nodeType;
|
||||
this.nodeSubtype = nodeSubtype;
|
||||
useEffect(() => {
|
||||
this.setState(this.baseState.defaultState());
|
||||
}, [this.nodeType, this.nodeSubtype]);
|
||||
return this.baseState;
|
||||
}
|
||||
renderOptionList() {
|
||||
return this.baseState.renderOptionList(this.state)
|
||||
}
|
||||
get isReady() {
|
||||
return this.baseState.isReady(this.state);
|
||||
}
|
||||
}
|
||||
@@ -28,14 +28,19 @@ export default function NewNodeModal<T extends AutomationNodeType>({
|
||||
<div className="new-node-modal--inner" onClick={e => e.preventDefault()}>
|
||||
<div className="new-node-modal--title">Create {node_type[0].toUpperCase()}{node_type.slice(1)}</div>
|
||||
<div className="new-node-modal--body">
|
||||
<InputWrapper label="Type:">
|
||||
<InputList options={typeList[node_type]} current={selectedSubType} onChange={n => setSubType(n as NodeSubType)}/>
|
||||
</InputWrapper>
|
||||
<InputList label="Type:"
|
||||
options={typeList[node_type]}
|
||||
current={selectedSubType}
|
||||
onChange={n => setSubType(n as NodeSubType)}
|
||||
/>
|
||||
{stateManager.renderOptionList()}
|
||||
</div>
|
||||
<div className="new-node-modal--footer">
|
||||
<button className="secondary" onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate({} as any)}>Create</button>
|
||||
<button onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate({} as any)}
|
||||
disabled={!stateManager.isReady}>
|
||||
Create
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SelectHTMLAttributes } from "react";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
|
||||
export interface Props {
|
||||
@@ -7,12 +8,15 @@ export interface Props {
|
||||
onChange: (n: string) => void;
|
||||
id?: string;
|
||||
className?: string;
|
||||
label: string;
|
||||
}
|
||||
export default function InputList({current, options, onChange, ...selattr}: Props) {
|
||||
return <select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.currentTarget.value);
|
||||
}}>
|
||||
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||
</select>
|
||||
export default function InputList({current, options, onChange, label, ...selattr}: Props) {
|
||||
return <InputWrapper label={label}>
|
||||
<select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.currentTarget.value);
|
||||
}}>
|
||||
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||
</select>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
}
|
||||
export default function InputText({
|
||||
label, value, onChange
|
||||
}: Props) {
|
||||
return <InputWrapper label={label}>
|
||||
<input value={value} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.target.value)
|
||||
}}/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -16,7 +16,6 @@ export default function AutomationNode({
|
||||
onXClick = () => {},
|
||||
}: PropsWithChildren<Props>) {
|
||||
const [isOpen, setOpen] = useState(initialOpenState);
|
||||
console.log(children);
|
||||
return <div className="automation-node">
|
||||
<div className="automation-node-inner">
|
||||
<div
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import AutomationEditor from "../components/AutomationEditor";
|
||||
import sample from "../sample/auto_01.yaml";
|
||||
|
||||
console.log(sample)
|
||||
|
||||
export function Home() {
|
||||
return (
|
||||
<div id="page--home" className="page">
|
||||
|
||||
@@ -5,5 +5,6 @@ $secondary-accent: #929191;
|
||||
|
||||
$font-color-primary: #e1e1e1;
|
||||
|
||||
$gray: #403f3f;
|
||||
$green: #68caa4;
|
||||
$blue: #68aaca;
|
||||
@@ -80,6 +80,13 @@ button {
|
||||
border-color: $secondary-accent;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
background-color: $gray;
|
||||
border-color: $gray;
|
||||
color: darken($gray, 50);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background-color: $primary;
|
||||
color: $secondary-accent;
|
||||
@@ -103,3 +110,8 @@ select {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
}
|
||||
input {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
cursor: text;
|
||||
}
|
||||
Reference in new issue
Block a user