aboutsummaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/components/fields
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-10-27 15:13:35 -0300
committerSebastian <sebasjm@gmail.com>2021-10-27 15:13:35 -0300
commit32318a80f48bf52ca7823a0c055164f43bdaf1d6 (patch)
tree08ef42e65d1db93f3958dd75d39f4bff1d03d2b6 /packages/anastasis-webui/src/components/fields
parent21b60c8f6ff69bf114779a767a3ac3355f69a34f (diff)
working version with improved ui
Diffstat (limited to 'packages/anastasis-webui/src/components/fields')
-rw-r--r--packages/anastasis-webui/src/components/fields/DateInput.tsx4
-rw-r--r--packages/anastasis-webui/src/components/fields/NumberInput.tsx41
-rw-r--r--packages/anastasis-webui/src/components/fields/TextInput.tsx (renamed from packages/anastasis-webui/src/components/fields/LabeledInput.tsx)4
3 files changed, 46 insertions, 3 deletions
diff --git a/packages/anastasis-webui/src/components/fields/DateInput.tsx b/packages/anastasis-webui/src/components/fields/DateInput.tsx
index c45acc6d2..e1c354f7b 100644
--- a/packages/anastasis-webui/src/components/fields/DateInput.tsx
+++ b/packages/anastasis-webui/src/components/fields/DateInput.tsx
@@ -8,6 +8,7 @@ export interface DateInputProps {
grabFocus?: boolean;
tooltip?: string;
error?: string;
+ years?: Array<number>;
bind: [string, (x: string) => void];
}
@@ -19,7 +20,7 @@ export function DateInput(props: DateInputProps): VNode {
}
}, [props.grabFocus]);
const [opened, setOpened2] = useState(false)
- function setOpened(v: boolean) {
+ function setOpened(v: boolean): void {
console.log('dale', v)
setOpened2(v)
}
@@ -50,6 +51,7 @@ export function DateInput(props: DateInputProps): VNode {
{showError && <p class="help is-danger">{props.error}</p>}
<DatePicker
opened={opened}
+ years={props.years}
closeFunction={() => setOpened(false)}
dateReceiver={(d) => {
setDirty(true)
diff --git a/packages/anastasis-webui/src/components/fields/NumberInput.tsx b/packages/anastasis-webui/src/components/fields/NumberInput.tsx
new file mode 100644
index 000000000..af9bbe66b
--- /dev/null
+++ b/packages/anastasis-webui/src/components/fields/NumberInput.tsx
@@ -0,0 +1,41 @@
+import { h, VNode } from "preact";
+import { useLayoutEffect, useRef, useState } from "preact/hooks";
+
+export interface TextInputProps {
+ label: string;
+ grabFocus?: boolean;
+ error?: string;
+ tooltip?: string;
+ bind: [string, (x: string) => void];
+}
+
+export function NumberInput(props: TextInputProps): VNode {
+ const inputRef = useRef<HTMLInputElement>(null);
+ useLayoutEffect(() => {
+ if (props.grabFocus) {
+ inputRef.current?.focus();
+ }
+ }, [props.grabFocus]);
+ const value = props.bind[0];
+ const [dirty, setDirty] = useState(false)
+ const showError = dirty && props.error
+ return (<div class="field">
+ <label class="label">
+ {props.label}
+ {props.tooltip && <span class="icon has-tooltip-right" data-tooltip={props.tooltip}>
+ <i class="mdi mdi-information" />
+ </span>}
+ </label>
+ <div class="control has-icons-right">
+ <input
+ value={value}
+ type="number"
+ class={showError ? 'input is-danger' : 'input'}
+ onChange={(e) => {setDirty(true); props.bind[1]((e.target as HTMLInputElement).value)}}
+ ref={inputRef}
+ style={{ display: "block" }} />
+ </div>
+ {showError && <p class="help is-danger">{props.error}</p>}
+ </div>
+ );
+}
diff --git a/packages/anastasis-webui/src/components/fields/LabeledInput.tsx b/packages/anastasis-webui/src/components/fields/TextInput.tsx
index 96d634a4f..fa6fd9792 100644
--- a/packages/anastasis-webui/src/components/fields/LabeledInput.tsx
+++ b/packages/anastasis-webui/src/components/fields/TextInput.tsx
@@ -1,7 +1,7 @@
import { h, VNode } from "preact";
import { useLayoutEffect, useRef, useState } from "preact/hooks";
-export interface LabeledInputProps {
+export interface TextInputProps {
label: string;
grabFocus?: boolean;
error?: string;
@@ -9,7 +9,7 @@ export interface LabeledInputProps {
bind: [string, (x: string) => void];
}
-export function LabeledInput(props: LabeledInputProps): VNode {
+export function TextInput(props: TextInputProps): VNode {
const inputRef = useRef<HTMLInputElement>(null);
useLayoutEffect(() => {
if (props.grabFocus) {