From cb8c2c23beb330087985441c9f16b8756b2cb23e Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sun, 20 Jul 2025 23:33:21 -0400 Subject: [PATCH] Many inputs added --- lib/component/input.ts | 14 ++- .../input/file/DragAndDropFileInput.tsx | 20 +++++ lib/component/input/file/FileInput.tsx | 85 +++++++++++++++++++ lib/component/input/number/NumberInput.tsx | 58 +++++++++++++ lib/component/input/number/NumberSlider.tsx | 36 ++++++++ .../input/{ => text}/OptionInput.tsx | 0 .../input/{ => text}/SelectInput.tsx | 0 lib/component/input/{ => text}/TextArea.tsx | 10 ++- lib/component/input/{ => text}/TextInput.tsx | 10 ++- lib/types/Input.d.ts | 44 ++++++++++ lib/util/FileUtil.ts | 9 ++ src/routes/input/index.tsx | 3 +- src/util/InputUtils.tsx | 62 +++++++++++++- 13 files changed, 335 insertions(+), 16 deletions(-) create mode 100644 lib/component/input/file/DragAndDropFileInput.tsx create mode 100644 lib/component/input/file/FileInput.tsx create mode 100644 lib/component/input/number/NumberInput.tsx create mode 100644 lib/component/input/number/NumberSlider.tsx rename lib/component/input/{ => text}/OptionInput.tsx (100%) rename lib/component/input/{ => text}/SelectInput.tsx (100%) rename lib/component/input/{ => text}/TextArea.tsx (92%) rename lib/component/input/{ => text}/TextInput.tsx (87%) create mode 100644 lib/util/FileUtil.ts diff --git a/lib/component/input.ts b/lib/component/input.ts index 69a10b3..edbe85b 100644 --- a/lib/component/input.ts +++ b/lib/component/input.ts @@ -1,10 +1,18 @@ -import OptionInput from "./input/OptionInput"; -import SelectInput from "./input/SelectInput"; -import TextInput from "./input/TextInput"; +import DragAndDropFileInput from "./input/file/DragAndDropFileInput"; +import FileInput from "./input/file/FileInput"; +import NumberInput from "./input/number/NumberInput"; +import OptionInput from "./input/text/OptionInput"; +import SelectInput from "./input/text/SelectInput"; +import TextInput from "./input/text/TextInput"; export { + DragAndDropFileInput, + FileInput, + NumberInput, + //NumberSlider, OptionInput, SelectInput, TextInput }; + diff --git a/lib/component/input/file/DragAndDropFileInput.tsx b/lib/component/input/file/DragAndDropFileInput.tsx new file mode 100644 index 0000000..bbf9790 --- /dev/null +++ b/lib/component/input/file/DragAndDropFileInput.tsx @@ -0,0 +1,20 @@ +import { useRef } from "react"; + + +export default function DragAndDropFileInput(){ + const inputRef = useRef(null); + + + return ( +
+ + Drag And Drop File Input +
+ ); +} diff --git a/lib/component/input/file/FileInput.tsx b/lib/component/input/file/FileInput.tsx new file mode 100644 index 0000000..3d79cec --- /dev/null +++ b/lib/component/input/file/FileInput.tsx @@ -0,0 +1,85 @@ +import { SecondaryButton } from "$/component/button"; +import type { FileInputProps } from "$/types/Input"; +import { humanReadableBytes } from "$/util/FileUtil"; +import clsx from "clsx"; +import { useRef, useState } from "react"; + + +export default function FileInput({ + id, + className, + name, + minSize, + maxSize, + showFileName, + showSize, + onChange, + disabled, + children +}: FileInputProps){ + const inputRef = useRef(null); + const [ file, setFile ] = useState(); + + + return ( +
+ { setFile(e.target.files?.[0]); onChange?.(e.target.files?.[0]); }} + disabled={disabled} + /> +
+ { + children && !showFileName && +
{children}
+ } + { + showFileName && +
{file?.name}
+ } + { + !children && !showFileName && + <>  + } + { + showSize && +
maxSize, + "text-green-600": minSize && !maxSize && file?.size && file?.size > minSize, + "text-green-600 ": !minSize && maxSize && file?.size && file?.size < maxSize, + " text-green-600": minSize && maxSize && file?.size && file?.size > minSize && file?.size < maxSize + } + )} + > + {humanReadableBytes(file?.size ?? 0)} +
+ } +
+
+ { inputRef.current?.click(); }} + > + Click Me + +
+
+ ); +} diff --git a/lib/component/input/number/NumberInput.tsx b/lib/component/input/number/NumberInput.tsx new file mode 100644 index 0000000..d1ff672 --- /dev/null +++ b/lib/component/input/number/NumberInput.tsx @@ -0,0 +1,58 @@ +import type { NumberInputProps } from "$/types/Input"; +import clsx from "clsx"; + + +export default function NumberInput({ + id, + className, + inputClassName, + labelClassName, + name, + min, + max, + defaultValue, + value, + onChange, + disabled, + children +}: NumberInputProps){ + return ( +
+
+ onChange?.(e.target.valueAsNumber)} + disabled={disabled} + /> + +
+
+ ); +} diff --git a/lib/component/input/number/NumberSlider.tsx b/lib/component/input/number/NumberSlider.tsx new file mode 100644 index 0000000..4b0ea45 --- /dev/null +++ b/lib/component/input/number/NumberSlider.tsx @@ -0,0 +1,36 @@ +import type { NumberSliderProps } from "$/types/Input"; +import clsx from "clsx"; + + +export default function NumberSlider({ + id, + className, + name, + min, + max, + step, + defaultValue, + value, + onChange, + disabled +}: NumberSliderProps){ + return ( + onChange?.(e.target.valueAsNumber)} + disabled={disabled} + /> + ); +} diff --git a/lib/component/input/OptionInput.tsx b/lib/component/input/text/OptionInput.tsx similarity index 100% rename from lib/component/input/OptionInput.tsx rename to lib/component/input/text/OptionInput.tsx diff --git a/lib/component/input/SelectInput.tsx b/lib/component/input/text/SelectInput.tsx similarity index 100% rename from lib/component/input/SelectInput.tsx rename to lib/component/input/text/SelectInput.tsx diff --git a/lib/component/input/TextArea.tsx b/lib/component/input/text/TextArea.tsx similarity index 92% rename from lib/component/input/TextArea.tsx rename to lib/component/input/text/TextArea.tsx index d5d0633..80314f5 100644 --- a/lib/component/input/TextArea.tsx +++ b/lib/component/input/text/TextArea.tsx @@ -7,6 +7,7 @@ export default function TextArea({ className, inputClassName, labelClassName, + name, maxLength, rows, cols, @@ -20,20 +21,21 @@ export default function TextArea({ return (