From 442ad5aa32cf58797b20534b20a881a5f20fdc70 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Tue, 4 Feb 2025 13:21:44 +0100 Subject: [PATCH] Updates --- bun.lockb | Bin 76129 -> 76129 bytes components/lib/editors/AceEditor.tsx | 0 components/lib/elements/Border.tsx | 2 +- components/lib/elements/Breadcrumbs.tsx | 0 components/lib/elements/Card.tsx | 27 +++++--- components/lib/elements/Dropdown.tsx | 3 + components/lib/elements/Tag.tsx | 17 ++++- components/lib/form/Form.tsx | 1 + components/lib/form/ImageUpload.tsx | 13 ++-- components/lib/form/Input.tsx | 21 +++++- components/lib/form/Select.tsx | 49 ++++++++------ components/lib/hooks/useWebSocket.tsx | 9 +-- .../lib/hooks/useWebSocketEventHandler.tsx | 39 +++++++++++ components/lib/layout/Button.tsx | 61 ++++++++++-------- components/lib/utils/fetch/fetchApi.ts | 26 +++++--- components/pages/Home/(data)/skills.ts | 11 ++++ components/pages/Home/(data)/work.ts | 7 ++ 17 files changed, 207 insertions(+), 79 deletions(-) mode change 100755 => 100644 components/lib/editors/AceEditor.tsx mode change 100755 => 100644 components/lib/elements/Breadcrumbs.tsx create mode 100644 components/lib/hooks/useWebSocketEventHandler.tsx mode change 100755 => 100644 components/lib/utils/fetch/fetchApi.ts diff --git a/bun.lockb b/bun.lockb index ae27f9d0352637f95d56e34dff86b915b2da0f19..ee0571ee7298c7a45706781876ed3970fd8aa18e 100755 GIT binary patch delta 571 zcmWO0xi3Qj9KiAScqA5a)pK_cN43h+RvoJl#bOhQr2hk!4i;yqBhP(C!bGA;Th}6p zzSdyq;E1brhOi?NzQZTK?{E3#7Y$3%u;lRtoPB~I^r918=*ArS;l?-yFp5bGVGv`O zz%-^X0~Pa_#R7&gqUyB#o=hqOxyVBnvY|%~WTYSsIwT<-sYt{rPH>DM0@%SW_OS&o z*02r_ma&K>9&>31HKLiE3VSK4Q3)&TsDcf(s6h$JP!1z3sDJ@xm{5pf6rmZdXi-;# zva&(Nih>Xa3HR(bxWzRhxWhRvaH;x(#IJWe;hKma`VYTIhK4KFm&2w?|)?7;&! z*07EhEMZwjG+S>g)q-Z^A`fO*kPj;gP>3SfP>d3kq73DzKqabB4LfR3iw(pWgisKR zEA}-aLZpZr;ud!}!#OTwhptM$Zmw@&HKGoih~xP?_XpnaiYV@J2_Fuyj~+C^A?-nv t(Ck*^(#5etmAH3ihNzky1Rea*h;|h9}cq93LJkArf?GMNBTD<@O diff --git a/components/lib/editors/AceEditor.tsx b/components/lib/editors/AceEditor.tsx old mode 100755 new mode 100644 diff --git a/components/lib/elements/Border.tsx b/components/lib/elements/Border.tsx index 88290fe..01dd3cf 100644 --- a/components/lib/elements/Border.tsx +++ b/components/lib/elements/Border.tsx @@ -17,7 +17,7 @@ export default function Border({ spacing, ...props }: TWUI_BORDER_PROPS) {
, + HTMLDivElement +> & { + variant?: "normal"; + href?: string; + linkProps?: DetailedHTMLProps< + React.AnchorHTMLAttributes, + HTMLAnchorElement + >; + noHover?: boolean; +}; + /** * # General Card * @className twui-card @@ -13,22 +26,18 @@ export default function Card({ href, variant, linkProps, + noHover, ...props -}: DetailedHTMLProps, HTMLDivElement> & { - variant?: "normal"; - href?: string; - linkProps?: DetailedHTMLProps< - React.AnchorHTMLAttributes, - HTMLAnchorElement - >; -}) { +}: Props) { const component = (
; debounce?: number; hoverOpen?: boolean; + above?: boolean; position?: (typeof TWUIDropdownContentPositions)[number]; topOffset?: number; externalSetOpen?: React.Dispatch>; @@ -41,6 +42,7 @@ export default function Dropdown({ contentWrapperProps, targetWrapperProps, hoverOpen, + above, debounce = 500, target, position = "center", @@ -122,6 +124,7 @@ export default function Dropdown({ : position == "right" ? "right-0" : "", + above ? "-translate-y-[120%]" : "", open ? "flex" : "hidden", "twui-dropdown-content", contentWrapperProps?.className diff --git a/components/lib/elements/Tag.tsx b/components/lib/elements/Tag.tsx index fae2eff..6bd6f23 100644 --- a/components/lib/elements/Tag.tsx +++ b/components/lib/elements/Tag.tsx @@ -15,6 +15,7 @@ export type TWUI_TOGGLE_PROPS = PropsWithChildren & > & { color?: "normal" | "secondary" | "error" | "success" | "gray"; variant?: "normal" | "outlined" | "ghost"; + href?: string; }; /** @@ -25,13 +26,15 @@ export default function Tag({ color, variant, children, + href, ...props }: TWUI_TOGGLE_PROPS) { - return ( + const mainComponent = (
); + + if (href) { + return ( + + {mainComponent} + + ); + } + + return mainComponent; } diff --git a/components/lib/form/Form.tsx b/components/lib/form/Form.tsx index 4baecd1..dce0147 100644 --- a/components/lib/form/Form.tsx +++ b/components/lib/form/Form.tsx @@ -27,6 +27,7 @@ export default function Form({ const formData = new FormData(formEl); const data = Object.fromEntries(formData.entries()) as T; props.submitHandler?.(e, data); + props.onSubmit?.(e); }} > {props.children} diff --git a/components/lib/form/ImageUpload.tsx b/components/lib/form/ImageUpload.tsx index f87f096..ec3d290 100644 --- a/components/lib/form/ImageUpload.tsx +++ b/components/lib/form/ImageUpload.tsx @@ -14,7 +14,9 @@ type ImageUploadProps = DetailedHTMLProps< React.HTMLAttributes, HTMLDivElement > & { - onChange?: (imgData: ImageInputToBase64FunctionReturn | undefined) => any; + onChangeHandler?: ( + imgData: ImageInputToBase64FunctionReturn | undefined + ) => any; fileInputProps?: DetailedHTMLProps< React.InputHTMLAttributes, HTMLInputElement @@ -35,8 +37,11 @@ type ImageUploadProps = DetailedHTMLProps< disablePreview?: boolean; }; +/** + * @note use the `onChangeHandler` prop to grab the parsed base64 image object + */ export default function ImageUpload({ - onChange, + onChangeHandler, fileInputProps, placeHolderWrapper, previewImageWrapperProps, @@ -60,7 +65,7 @@ export default function ImageUpload({ onChange={(e) => { imageInputToBase64({ imageInput: e.target }).then((res) => { setSrc(res.imageBase64Full); - onChange?.(res); + onChangeHandler?.(res); fileInputProps?.onChange?.(e); }); }} @@ -88,7 +93,7 @@ export default function ImageUpload({ className="absolute p-2 top-2 right-2 z-20" onClick={(e) => { setSrc(undefined); - onChange?.(undefined); + onChangeHandler?.(undefined); }} > diff --git a/components/lib/form/Input.tsx b/components/lib/form/Input.tsx index 7e145de..84b1516 100644 --- a/components/lib/form/Input.tsx +++ b/components/lib/form/Input.tsx @@ -107,6 +107,7 @@ export type InputProps = DetailedHTMLProps< validationFunction?: (value: string) => Promise; autoComplete?: (typeof autocompleteOptions)[number]; name?: KeyType; + valueUpdate?: string; }; /** @@ -130,11 +131,16 @@ export default function Input({ autoComplete, validationFunction, validationRegex, + valueUpdate, ...props }: InputProps) { const [focus, setFocus] = React.useState(false); const [value, setValue] = React.useState( - props.defaultValue ? String(props.defaultValue) : "" + props.value + ? String(props.value) + : props.defaultValue + ? String(props.defaultValue) + : "" ); delete props.defaultValue; @@ -163,6 +169,11 @@ export default function Input({ } }, [value]); + React.useEffect(() => { + if (!props.value) return; + setValue(String(props.value)); + }, [props.value]); + const targetComponent = istextarea ? (