added input text view + moved things

This commit is contained in:
Ari Sosnovsky committed 2021-11-12 14:09:00 -05:00
1 parent 9694ffb238
commit 54c1edba0c
17 files changed
+166 -121

No files matched your search

@@ -0,0 +1,26 @@
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: boolean;
onChange: (v: boolean) => void;
}
export default function InputBoolean({
label,
value=false,
onChange,
}: Props) {
return <InputWrapper label={label} style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: '3%',
marginBottom: '3%'
}}>
<span className="checkbox" onClick={e => {
e.preventDefault()
onChange(!value)
}}>
{value ? '✔️' : ' '}
</span>
</InputWrapper>
}
+24
View File
@@ -0,0 +1,24 @@
import InputWrapper from "./InputWrapper";
export interface Props<T extends string> {
current: T;
options: readonly T[];
onChange: (n: string) => void;
id?: string;
className?: string;
label: string;
}
export default function InputList<T extends string>({
current, options, onChange, label,
...selattr
}: Props<T>) {
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>
}
+23
View File
@@ -0,0 +1,23 @@
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: number;
onChange: (v: number) => void;
}
export default function InputNumber({
label,
value=0,
onChange,
}: Props) {
return <InputWrapper label={label}>
<input
type="number"
value={value}
onChange={e => {
e.preventDefault();
onChange(Number(e.target.value))
}}
/>
</InputWrapper>
}
+37
View File
@@ -0,0 +1,37 @@
import { useToolTip } from "~/tooltip/context";
import InputWrapper from "./InputWrapper";
export interface Props {
textBoxFor?: string;
label: string;
value: string;
onChange: (v: string) => void;
additionalTooltipFilters?: Record<string, string>;
}
export default function InputText({
label,
textBoxFor,
value="",
onChange,
additionalTooltipFilters={},
}: Props) {
const tooltip = useToolTip();
return <InputWrapper label={label}>
<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
)}
/>
</InputWrapper>
}
@@ -0,0 +1,56 @@
import { useRef, useState, useEffect } from "react";
import CheckMarkIcon from "~/icons/checkmark";
import PencilIcon from "~/icons/pencil";
import { useToolTip } from "~/tooltip/context";
import InputWrapper from "./InputWrapper";
export interface Props {
textBoxFor?: string;
label: string;
value: string;
onChange: (v: string) => void;
additionalTooltipFilters?: Record<string, string>;
}
export default function InputViewEdit({
label,
textBoxFor,
value="",
onChange,
additionalTooltipFilters={},
}: Props) {
const tooltip = useToolTip();
const [isEditing, setIsEditing] = useState(false);
const onChangeWrapped = (t: string) => {
onChange(t);
setIsEditing(false);
}
const inputRef = useRef<HTMLInputElement | null>(null);
useEffect(() => {
if (isEditing && inputRef.current) {
inputRef.current.focus()
}
}, [inputRef.current, isEditing])
return <InputWrapper label={label}>
{isEditing ? <input
ref={inputRef}
value={value}
onChange={e => {
e.preventDefault();
onChangeWrapped(e.target.value)
}}
onFocus={e => textBoxFor && tooltip.setFocus(
e.target.getBoundingClientRect(),
{
searchObject: textBoxFor,
searchText: value,
filterObjects: additionalTooltipFilters,
},
onChangeWrapped
)}
/>:<div className="input-view">
{value}
</div>}
<PencilIcon onClick={() => setIsEditing(!isEditing)} className={`icon pencil ${isEditing ? 'opened' : ''}`}/>
<CheckMarkIcon onClick={() => setIsEditing(!isEditing)} className={`icon checkmark ${isEditing ? 'opened' : ''}`}/>
</InputWrapper>
}
@@ -0,0 +1,13 @@
import { CSSProperties, PropsWithChildren } from "react";
export interface Props {
label: string;
style?: CSSProperties;
}
export default function InputWrapper({label, children, style={}}: PropsWithChildren<Props>) {
return <div className="input-wrapper" style={style}>
<label>{label}</label>
{children}
</div>
}
+39
View File
@@ -0,0 +1,39 @@
import InputWrapper from "./InputWrapper";
import * as yaml from "js-yaml";
import { useEffect, useRef, useState } from "react";
export interface Props<T> {
label: string;
value: T;
onChange: (v: T) => void;
}
export default function InputYaml<T>({
label,
value={} as any,
onChange,
}: Props<T>) {
const [text, setText] = useState("");
useEffect(() => {
setText(yaml.dump(value));
}, [value]);
const delayId = useRef<null | number>(null);
const delayedUpdate = (update: string) => {
if (delayId.current) {
window.clearTimeout(delayId.current);
delayId.current = null;
}
delayId.current = window.setTimeout(() => {
onChange(yaml.load(update) as any)
}, 1000);
}
return <InputWrapper label={label}>
<textarea
value={text}
onChange={e => {
e.preventDefault();
setText(e.target.value);
delayedUpdate(e.target.value);
}}
/>
</InputWrapper>
}
View File
Whitespace-only changes.