Files
OpenBB/jupyterlab/openbb-settings/src/components/FormInput.tsx
jmaslek b71abcfbf4 Updating some names (#1575)
* quick econ fix

* black

* keys and feature flags

* terminal name 👀

* some more replacements

* some more replacements

* edit pyproject

* gst -> openbb

* add example portfolios back to git

* Update api from gst

* sorry.  skipping some tests

* another round of names

* another round of test edits

* Missed some .gst refs and update timezone

* water mark stuff

* Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS

* fix more GST to OpenBB Terminal

* Logging : merge conflicts with main

* Revert wrong files

Co-authored-by: Andrew <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2022-03-29 09:46:26 -04:00

59 lines
1.4 KiB
TypeScript
Vendored

import { useState } from "react";
/**
* Generic input form
*
* @class FormInput (name)
* @param {} arg1 Arguments
* @param {} arg1.itemParent The item parent
* @param {} arg1.index The item index
* @param {} arg1.onChangeParent On change parent function
* @returns {} Gemeric input form
*/
export default function FormInput({
itemParent,
index,
onChangeParent,
}: {
itemParent: any;
index: number;
onChangeParent: any;
}): any {
const [item, setItem] = useState({
key: itemParent.key,
value: itemParent.value,
});
const onChange = (event: any) => {
const newValue =
event.target.type === "checkbox"
? event.target.checked
: event.target.value;
setItem((prevState) => {
const value = item.value;
value.value = newValue;
const newItem = { ...prevState, value: value };
onChangeParent(index, newItem);
return newItem;
});
};
return (
<>
<label className="inputFieldLabel">{item.value.title}</label>
<input
className={item.value.title}
type={item.value.form}
checked={
item.value.form === "checkbox"
? item.value.value === ""
? item.value.default
: item.value.value
: false
}
value={item.value.value === "" ? item.value.default : item.value.value}
onChange={onChange}
/>
</>
);
}