First Commit

This commit is contained in:
Benjamin Toby
2024-12-09 16:36:17 +01:00
parent f24b493566
commit b037cec100
128 changed files with 3281 additions and 193 deletions
+22
View File
@@ -0,0 +1,22 @@
type Props = {
size?: number;
};
export default function Logo({ size }: Props) {
const sizeRatio = 50 / 100;
const width = size || 50;
const height = width * sizeRatio;
return (
<a href="/">
<img
src="/images/logo-white.svg"
alt="Main Logo"
width={width}
height={height}
style={{
minWidth: width + "px",
}}
/>
</a>
);
}
+136
View File
@@ -0,0 +1,136 @@
import { AceEditorAcceptedModes } from "@/components/general/data/partials/EditDataListButton";
import React, { MutableRefObject } from "react";
import { twMerge } from "tailwind-merge";
export type AceEditorComponentType = {
editorRef?: MutableRefObject<AceAjax.Editor>;
readOnly?: boolean;
/** Function to call when Ctrl+Enter is pressed */
ctrlEnterFn?: (editor: AceAjax.Editor) => void;
content?: string;
placeholder?: string;
mode?: AceEditorAcceptedModes;
fontSize?: string;
previewMode?: boolean;
onChange?: (value: string) => void;
delay?: number;
};
let timeout: any;
/**
* # Powerful Ace Editor
* @note **NOTE** head scripts required
* @script `https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ace.min.js`
* @script `https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ext-language_tools.min.js`
*/
export default function AceEditor({
editorRef,
readOnly,
ctrlEnterFn,
content = "",
placeholder,
mode,
fontSize,
previewMode,
onChange,
delay = 500,
}: AceEditorComponentType) {
try {
const editorElementRef = React.useRef<HTMLDivElement>();
const editorRefInstance = React.useRef<AceAjax.Editor>();
const [refresh, setRefresh] = React.useState(0);
const [darkMode, setDarkMode] = React.useState(false);
const [ready, setReady] = React.useState(false);
React.useEffect(() => {
if (!ready) return;
if (!ace?.edit || !editorElementRef.current) {
setTimeout(() => {
setRefresh((prev) => prev + 1);
}, 1000);
return;
}
const editor = ace.edit(editorElementRef.current);
editor.setOptions({
mode: `ace/mode/${mode ? mode : "javascript"}`,
theme: darkMode
? "ace/theme/tomorrow_night_bright"
: "ace/theme/ace_light",
value: content,
placeholder: placeholder ? placeholder : "",
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
readOnly: readOnly ? true : false,
fontSize: fontSize ? fontSize : null,
showLineNumbers: previewMode ? false : true,
wrap: true,
wrapMethod: "code",
// onchange: (e) => {
// console.log(e);
// },
});
editor.commands.addCommand({
name: "myCommand",
bindKey: { win: "Ctrl-Enter", mac: "Command-Enter" },
exec: function (editor) {
if (ctrlEnterFn) ctrlEnterFn(editor);
},
readOnly: true,
});
editor.getSession().on("change", function (e) {
if (onChange) {
clearTimeout(timeout);
setTimeout(() => {
onChange(editor.getValue());
console.log(editor.getValue());
}, delay);
}
});
editorRefInstance.current = editor;
if (editorRef) editorRef.current = editor;
}, [refresh, darkMode, ready]);
React.useEffect(() => {
const htmlClassName = document.documentElement.className;
if (htmlClassName.match(/dark/i)) setDarkMode(true);
setTimeout(() => {
setReady(true);
}, 200);
}, []);
return (
<React.Fragment>
<div
className={twMerge(
"w-full h-[400px] block rounded-md overflow-hidden",
"border border-slate-200 border-solid",
"dark:border-white/20"
)}
>
<div
ref={editorElementRef as any}
className="w-full h-full"
></div>
</div>
</React.Fragment>
);
} catch (error: any) {
return (
<React.Fragment>
<span className="text-sm m-0">
Editor Error:{" "}
<b className="text-red-600">{error.message}</b>
</span>
</React.Fragment>
);
}
}
+36
View File
@@ -0,0 +1,36 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
export type TWUI_BORDER_PROPS = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> & {
spacing?: "normal" | "loose" | "tight" | "wide" | "tightest";
};
/**
* # Toggle Component
* @className_wrapper twui-border
*/
export default function Border({ spacing, ...props }: TWUI_BORDER_PROPS) {
return (
<div
{...props}
className={twMerge(
"relative flex items-center gap-2 border rounded",
"border-slate-300 dark:border-white/20",
spacing
? spacing == "normal"
? "px-3 py-2"
: spacing == "tight"
? "px-2 py-1"
: ""
: "px-3 py-2",
"twui-border",
props.className
)}
>
{props.children}
</div>
);
}
+94
View File
@@ -0,0 +1,94 @@
import React from "react";
import Link from "../layout/Link";
import Divider from "../layout/Divider";
import Row from "../layout/Row";
import lowerToTitleCase from "@/server-client-shared/utils/lower-to-title-case";
type LinkObject = {
title: string;
path: string;
};
export default function Breadcrumbs() {
const [links, setLinks] = React.useState<LinkObject[] | null>(null);
React.useEffect(() => {
let pathname = window.location.pathname;
let pathLinks = pathname.split("/");
let validPathLinks = [];
validPathLinks.push({
title: "Home",
path: pathname.match(/admin/) ? "/admin" : "/",
});
pathLinks.forEach((linkText, index, array) => {
if (!linkText?.match(/./) || index == 1) {
return;
}
validPathLinks.push({
title: lowerToTitleCase(linkText),
path: (() => {
let path = "";
for (let i = 0; i < array.length; i++) {
const lnText = array[i];
if (i > index || !lnText.match(/./)) continue;
path += `/${lnText}`;
}
return path;
})(),
});
});
setLinks(validPathLinks);
return function () {
setLinks(null);
};
}, []);
if (!links?.[1]) {
return <React.Fragment></React.Fragment>;
}
return (
<Row className="gap-4">
{links.map((linkObject, index, array) => {
if (index === links.length - 1) {
return (
<Link
key={index}
href={linkObject.path}
className="text-slate-400 dark:text-slate-500 pointer-events-none text-xs"
>
{linkObject.title}
</Link>
);
} else {
return (
<React.Fragment key={index}>
<Link href={linkObject.path} className="text-xs">
{linkObject.title}
</Link>
<Divider vertical />
</React.Fragment>
);
}
})}
</Row>
);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
+45
View File
@@ -0,0 +1,45 @@
import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General Card
* @className_wrapper twui-card
*/
export default function Card({
href,
variant,
linkProps,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
variant?: "normal";
href?: string;
linkProps?: DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>;
}) {
const component = (
<div
{...props}
className={twMerge(
"flex flex-row items-center p-4 rounded bg-white dark:bg-white/10",
"border border-slate-200 dark:border-white/10 border-solid",
href ? "hover:bg-slate-100 dark:hover:bg-white/30" : "",
"twui-card",
props.className
)}
>
{props.children}
</div>
);
if (href) {
return (
<a href={href} {...linkProps}>
{component}
</a>
);
}
return component;
}
@@ -0,0 +1,39 @@
import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
import Toggle, { TWUI_TOGGLE_PROPS } from "./Toggle";
/**
* # Color Scheme Loader
* @className_wrapper twui-color-scheme-selector
*/
export default function ColorSchemeSelector({
active,
setActive,
toggleProps,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
toggleProps?: TWUI_TOGGLE_PROPS;
active: boolean;
setActive: React.Dispatch<React.SetStateAction<boolean>>;
}) {
React.useEffect(() => {
if (active) {
document.documentElement.className = "dark";
} else {
document.documentElement.className = "";
}
}, [active]);
return (
<div
{...props}
className={twMerge(
"flex flex-row items-center",
"twui-color-scheme-selector",
props.className
)}
>
<Toggle active={active} setActive={setActive} {...toggleProps} />
</div>
);
}
+58
View File
@@ -0,0 +1,58 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
type Props = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> & {
size?: "small" | "normal" | "medium" | "large" | "smaller";
svgClassName?: string;
};
/**
* # Loading Component
* @className_wrapper twui-loading
*/
export default function Loading({ size, svgClassName, ...props }: Props) {
const sizeClassName = (() => {
switch (size) {
case "smaller":
return "w-4 h-4";
case "small":
return "w-5 h-5";
case "normal":
return "w-6 h-6";
case "large":
return "w-7 h-7";
default:
return "w-6 h-6";
}
})();
return (
<div role="status" {...props}>
<svg
aria-hidden="true"
className={twMerge(
"text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",
"twui-loading",
sizeClassName,
svgClassName
)}
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
</div>
);
}
+24
View File
@@ -0,0 +1,24 @@
import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General paper
* @className_wrapper twui-loading-block
*/
export default function LoadingBlock({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) {
return (
<div
{...props}
className={twMerge(
"bg-slate-200 dark:bg-white/10",
"rounded animate-pulse w-full h-[60px]",
"twui-loading-block",
props.className
)}
>
{props.children}
</div>
);
}
+71
View File
@@ -0,0 +1,71 @@
import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
import { createRoot } from "react-dom/client";
import Paper from "./Paper";
type Props = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> & {
target: React.ReactNode;
};
/**
* # Modal Component
* @className_wrapper twui-modal-root
* @className_wrapper twui-modal
*/
export default function Modal({ target, ...props }: Props) {
const [wrapper, setWrapper] = React.useState<HTMLDivElement | null>(null);
React.useEffect(() => {
const wrapperEl = document.createElement("div");
wrapperEl.className = twMerge(
"fixed z-[200000] top-0 left-0 w-screen h-screen",
"flex flex-col items-center justify-center",
"twui-modal-root"
);
setWrapper(wrapperEl);
}, []);
const modalEl = (
<React.Fragment>
<div
className={twMerge(
"absolute top-0 left-0 bg-slate-900/80 z-0",
"w-screen h-screen"
)}
onClick={(e) => {
closeModal({ wrapperEl: wrapper });
}}
></div>
<Paper
{...props}
className={twMerge("z-10 max-w-[500px]", props.className)}
>
{props.children}
</Paper>
</React.Fragment>
);
const targetEl = (
<div
onClick={(e) => {
if (!wrapper) return;
document.body.appendChild(wrapper);
const root = createRoot(wrapper);
root.render(modalEl);
}}
>
{target}
</div>
);
return targetEl;
}
function closeModal({ wrapperEl }: { wrapperEl: HTMLDivElement | null }) {
if (!wrapperEl) return;
wrapperEl.parentElement?.removeChild(wrapperEl);
}
+32
View File
@@ -0,0 +1,32 @@
import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General paper
* @className_wrapper twui-paper
*/
export default function Paper({
variant,
linkProps,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
variant?: "normal";
linkProps?: DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>;
}) {
return (
<div
{...props}
className={twMerge(
"flex flex-row items-center p-4 rounded bg-white dark:bg-white/10",
"border border-slate-200 dark:border-white/10 border-solid w-full",
"twui-paper",
props.className
)}
>
{props.children}
</div>
);
}
+110
View File
@@ -0,0 +1,110 @@
import { twMerge } from "tailwind-merge";
import Input from "../form/Input";
import Button from "../layout/Button";
import Row from "../layout/Row";
import { Search as SearchIcon } from "lucide-react";
import React, {
DetailedHTMLProps,
InputHTMLAttributes,
TextareaHTMLAttributes,
} from "react";
let timeout: any;
export type SearchProps = DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> & {
dispatch?: (value?: string) => void;
delay?: number;
inputProps?: DetailedHTMLProps<
InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> &
DetailedHTMLProps<
TextareaHTMLAttributes<HTMLTextAreaElement>,
HTMLTextAreaElement
>;
buttonProps?: DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>;
};
/**
* # Search Component
* @className_wrapper twui-search-wrapper
* @className_circle twui-search-input
* @className_circle twui-search-button
*/
export default function Search({
dispatch,
delay = 500,
inputProps,
buttonProps,
...props
}: SearchProps) {
const [input, setInput] = React.useState("");
React.useEffect(() => {
clearTimeout(timeout);
timeout = setTimeout(() => {
dispatch?.(input);
}, delay);
}, [input]);
const inputRef = React.useRef<HTMLInputElement>();
React.useEffect(() => {
if (props.autoFocus) {
inputRef.current?.focus();
}
}, []);
return (
<Row
{...props}
className={twMerge(
"relative xl:flex-nowrap items-stretch gap-0",
"twui-search-wrapper",
props?.className
)}
>
<Input
type="search"
placeholder="Search"
{...inputProps}
value={input}
onChange={(e) => setInput(e.target.value)}
className={twMerge(
"rounded-r-none",
"twui-search-input",
inputProps?.className
)}
wrapperProps={{
className: "rounded-r-none",
}}
componentRef={inputRef}
/>
<Button
{...buttonProps}
variant="outlined"
color="gray"
className={twMerge(
"rounded-l-none my-[1px]",
"twui-search-button",
buttonProps?.className
)}
onClick={() => {
dispatch?.(input);
}}
>
<SearchIcon
className="text-slate-800 dark:text-white"
size={20}
/>
</Button>
</Row>
);
}
+52
View File
@@ -0,0 +1,52 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
export type TWUI_TOGGLE_PROPS = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> & {
active?: boolean;
setActive?: React.Dispatch<React.SetStateAction<boolean>>;
circleProps?: DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
};
/**
* # Toggle Component
* @className_wrapper twui-toggle-wrapper
* @className_circle twui-toggle-circle
*/
export default function Toggle({
circleProps,
active,
setActive,
...props
}: TWUI_TOGGLE_PROPS) {
return (
<div
{...props}
className={twMerge(
"flex flex-row items-center w-[40px] p-[3px] transition-all",
"border border-slate-300 dark:border-white/30 border-solid rounded-full",
active ? "justify-end" : "justify-start",
"twui-toggle-wrapper",
props.className
)}
onClick={() => setActive?.(!active)}
>
<div
{...circleProps}
className={twMerge(
"w-3.5 h-3.5 rounded-full ",
active
? "bg-blue-600 dark:bg-blue-500"
: "bg-slate-300 dark:bg-white/40",
"twui-toggle-circle",
circleProps?.className
)}
></div>
</div>
);
}
+23
View File
@@ -0,0 +1,23 @@
import { DetailedHTMLProps, FormHTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Form Element
* @className twui-form
*/
export default function Form({
...props
}: DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>) {
return (
<form
{...props}
className={twMerge(
"flex flex-col items-stretch gap-2 w-full bg-transparent",
"twui-form",
props.className
)}
>
{props.children}
</form>
);
}
+109
View File
@@ -0,0 +1,109 @@
import Button from "@/components/lib/layout/Button";
import Stack from "@/components/lib/layout/Stack";
import { ImagePlus, X } from "lucide-react";
import React, { DetailedHTMLProps } from "react";
import Card from "@/components/lib/elements/Card";
import Span from "@/components/lib/layout/Span";
import Center from "@/components/lib/layout/Center";
import imageInputToBase64, {
ImageInputToBase64FunctionReturn,
} from "../utils/form/imageInputToBase64";
import { twMerge } from "tailwind-merge";
type ImageUploadProps = {
onChange?: (imgData: ImageInputToBase64FunctionReturn | undefined) => any;
fileInputProps?: DetailedHTMLProps<
React.InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
>;
wrapperProps?: DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
placeHolderWrapper?: DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
previewImageWrapperProps?: DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
previewImageProps?: DetailedHTMLProps<
React.ImgHTMLAttributes<HTMLImageElement>,
HTMLImageElement
>;
};
export default function ImageUpload({
onChange,
fileInputProps,
wrapperProps,
placeHolderWrapper,
previewImageWrapperProps,
previewImageProps,
}: ImageUploadProps) {
const [src, setSrc] = React.useState<string | undefined>(undefined);
const inputRef = React.useRef<HTMLInputElement>();
return (
<Stack
className={twMerge("w-full", wrapperProps?.className)}
{...wrapperProps}
>
<input
type="file"
className={twMerge("hidden", fileInputProps?.className)}
{...fileInputProps}
onChange={(e) => {
imageInputToBase64({ imageInput: e.target }).then((res) => {
setSrc(res.imageBase64Full);
onChange?.(res);
fileInputProps?.onChange?.(e);
});
}}
ref={inputRef as any}
/>
{src ? (
<Card className="w-full relative" {...previewImageWrapperProps}>
<img
src={src}
className="w-full h-[300px] object-contain"
{...previewImageProps}
/>
<Button
variant="ghost"
className="absolute p-2 top-2 right-2 z-20"
onClick={(e) => {
setSrc(undefined);
onChange?.(undefined);
}}
>
<X className="text-slate-950" />
</Button>
</Card>
) : (
<Card
className={twMerge(
"w-full h-[300px] cursor-pointer hover:bg-slate-100 dark:hover:bg-white/20",
placeHolderWrapper?.className
)}
onClick={(e) => {
inputRef.current?.click();
placeHolderWrapper?.onClick?.(e);
}}
{...placeHolderWrapper}
>
<Center>
<Stack className="items-center gap-2">
<ImagePlus className="text-slate-400" />
<Span size="smaller" variant="faded">
Click to Upload Image
</Span>
</Stack>
</Center>
</Card>
)}
</Stack>
);
}
+136
View File
@@ -0,0 +1,136 @@
import React, {
DetailedHTMLProps,
InputHTMLAttributes,
LabelHTMLAttributes,
RefObject,
TextareaHTMLAttributes,
} from "react";
import { twMerge } from "tailwind-merge";
export type InputProps = DetailedHTMLProps<
InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> &
DetailedHTMLProps<
TextareaHTMLAttributes<HTMLTextAreaElement>,
HTMLTextAreaElement
> & {
label?: string;
variant?: "normal" | "warning" | "error" | "inactive";
prefix?: string | React.ReactNode;
suffix?: string | React.ReactNode;
showLabel?: boolean;
istextarea?: boolean;
wrapperProps?: DetailedHTMLProps<
InputHTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
labelProps?: DetailedHTMLProps<
LabelHTMLAttributes<HTMLLabelElement>,
HTMLLabelElement
>;
componentRef?: RefObject<any>;
};
/**
* # Input Element
* @className twui-input
*/
export default function Input({
label,
variant,
prefix,
suffix,
componentRef,
labelProps,
wrapperProps,
showLabel,
istextarea,
...props
}: InputProps) {
const [focus, setFocus] = React.useState(false);
const targetComponent = istextarea ? (
<textarea
{...props}
className={twMerge(
"w-full outline-none bg-transparent",
"twui-textarea",
props.className
)}
ref={componentRef}
onFocus={(e) => {
setFocus(true);
props?.onFocus?.(e);
}}
onBlur={(e) => {
setFocus(false);
props?.onBlur?.(e);
}}
/>
) : (
<input
{...props}
className={twMerge(
"w-full outline-none bg-transparent",
"twui-input",
props.className
)}
ref={componentRef}
onFocus={(e) => {
setFocus(true);
props?.onFocus?.(e);
}}
onBlur={(e) => {
setFocus(false);
props?.onBlur?.(e);
}}
/>
);
return (
<div
{...wrapperProps}
className={twMerge(
"relative flex items-center gap-2 border rounded-md px-3 py-2 outline outline-1",
focus
? "border-slate-700 dark:border-white/50"
: "border-slate-300 dark:border-white/20",
focus
? "outline-slate-700 dark:outline-white/50"
: "outline-transparent",
variant == "warning" &&
"border-yellow-500 dark:border-yellow-300 outline-yellow-500 dark:outline-yellow-300",
variant == "error" &&
"border-red-500 dark:border-red-300 outline-red-500 dark:outline-red-300",
variant == "inactive" && "opacity-40 pointer-events-none",
"bg-white dark:bg-black",
wrapperProps?.className
)}
>
{showLabel && (
<label
htmlFor={props.name}
{...labelProps}
className={twMerge(
"text-xs absolute -top-2.5 left-2 text-slate-500 bg-white px-1.5 rounded-t",
"dark:text-white/60 dark:bg-black",
labelProps?.className
)}
>
{label || props.placeholder || props.name}
</label>
)}
{prefix && (
<div className="opacity-60 pointer-events-none">{prefix}</div>
)}
{targetComponent}
{suffix && (
<div className="opacity-60 pointer-events-none">{suffix}</div>
)}
</div>
);
}
+117
View File
@@ -0,0 +1,117 @@
import { ChevronDown, LucideProps } from "lucide-react";
import {
DetailedHTMLProps,
ForwardRefExoticComponent,
InputHTMLAttributes,
LabelHTMLAttributes,
RefAttributes,
RefObject,
SelectHTMLAttributes,
} from "react";
import { twMerge } from "tailwind-merge";
type SelectOptionObject = {
title: string;
value: string;
default?: boolean;
};
type SelectOption = SelectOptionObject | SelectOptionObject[];
/**
* # Select Element
* @className twui-select-wrapper
* @className twui-select
* @className twui-select-dropdown-icon
*/
export default function Select({
label,
options,
componentRef,
labelProps,
wrapperProps,
showLabel,
iconProps,
...props
}: DetailedHTMLProps<
SelectHTMLAttributes<HTMLSelectElement>,
HTMLSelectElement
> & {
options: SelectOptionObject[];
label?: string;
showLabel?: boolean;
wrapperProps?: DetailedHTMLProps<
InputHTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
labelProps?: DetailedHTMLProps<
LabelHTMLAttributes<HTMLLabelElement>,
HTMLLabelElement
>;
componentRef?: RefObject<HTMLSelectElement>;
iconProps?: LucideProps;
}) {
return (
<div
{...wrapperProps}
className={twMerge(
"relative w-full flex items-center",
wrapperProps?.className
)}
>
{showLabel && (
<label
htmlFor={props.name}
{...labelProps}
className={twMerge(
"text-xs absolute -top-2 left-4 text-slate-600 bg-white px-2",
"dark:text-white/60 dark:bg-black",
labelProps?.className
)}
>
{label || props.name}
</label>
)}
<select
{...props}
className={twMerge(
"w-full pl-3 py-2 border rounded-md appearance-none pr-8",
"border-slate-300 dark:border-white/20",
"focus:border-slate-700 dark:focus:border-white/50",
"outline-slate-300 dark:outline-white/20",
"focus:outline-slate-700 dark:focus:outline-white/50",
"bg-white dark:bg-black",
"twui-select",
props.className
)}
ref={componentRef}
defaultValue={
options.flat().find((opt) => opt.default)?.value ||
undefined
}
>
{options.flat().map((option, index) => {
return (
<option
key={index}
value={option.value}
// selected={option.default || undefined}
>
{option.title}
</option>
);
})}
</select>
<ChevronDown
size={20}
{...iconProps}
className={twMerge(
"absolute right-2 pointer-events-none",
iconProps?.className
)}
/>
</div>
);
}
+9
View File
@@ -0,0 +1,9 @@
import Input, { InputProps } from "./Input";
/**
* # Textarea Component
* @className twui-textarea
*/
export default function Textarea({ componentRef, ...props }: InputProps) {
return <Input istextarea {...props} componentRef={componentRef} />;
}
+204
View File
@@ -0,0 +1,204 @@
import {
AnchorHTMLAttributes,
ButtonHTMLAttributes,
DetailedHTMLProps,
HTMLAttributeAnchorTarget,
HTMLAttributes,
} from "react";
import { twMerge } from "tailwind-merge";
import Loading from "../elements/Loading";
/**
* # Buttons
* @className twui-button-general
* @className twui-button-content-wrapper
* @className twui-button-primary
* @className twui-button-primary-outlined
* @className twui-button-primary-ghost
* @className twui-button-secondary
* @className twui-button-secondary-outlined
* @className twui-button-secondary-ghost
* @className twui-button-accent
* @className twui-button-accent-outlined
* @className twui-button-accent-ghost
* @className twui-button-gray
* @className twui-button-gray-outlined
* @className twui-button-gray-ghost
*/
export default function Button({
href,
target,
variant,
color,
size,
buttonContentProps,
linkProps,
beforeIcon,
afterIcon,
loading,
...props
}: DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> & {
variant?: "normal" | "ghost" | "outlined";
color?:
| "primary"
| "secondary"
| "accent"
| "gray"
| "error"
| "warning"
| "success";
size?: "small" | "smaller" | "normal" | "large" | "larger";
href?: string;
target?: HTMLAttributeAnchorTarget;
loading?: boolean;
linkProps?: DetailedHTMLProps<
AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>;
beforeIcon?: React.ReactNode;
afterIcon?: React.ReactNode;
buttonContentProps?: DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
}) {
const finalClassName: string = (() => {
if (variant == "normal" || !variant) {
if (color == "primary" || !color)
return twMerge(
"bg-blue-500 hover:bg-blue-600 text-white",
"twui-button-primary"
);
if (color == "secondary")
return twMerge(
"bg-emerald-500 hover:bg-emerald-600 text-white",
"twui-button-secondary"
);
if (color == "accent")
return twMerge(
"bg-violet-500 hover:bg-violet-600 text-white",
"twui-button-accent"
);
if (color == "gray")
return twMerge(
"bg-slate-300 hover:bg-slate-200 text-slate-800",
"twui-button-gray"
);
} else if (variant == "outlined") {
if (color == "primary" || !color)
return twMerge(
"bg-transparent outline outline-1 outline-blue-500",
"text-blue-500 dark:text-blue-400 dark:outline-blue-300",
"twui-button-primary-outlined"
);
if (color == "secondary")
return twMerge(
"bg-transparent outline outline-1 outline-emerald-500",
"text-emerald-500",
"twui-button-secondary-outlined"
);
if (color == "accent")
return twMerge(
"bg-transparent outline outline-1 outline-violet-500",
"text-violet-500",
"twui-button-accent-outlined"
);
if (color == "gray")
return twMerge(
"bg-transparent outline outline-1 outline-slate-300",
"text-slate-600 dark:text-white/60 dark:outline-white/30",
"twui-button-gray-outlined"
);
} else if (variant == "ghost") {
if (color == "primary" || !color)
return twMerge(
"bg-transparent outline-none p-2",
"text-blue-500",
"twui-button-primary-ghost"
);
if (color == "secondary")
return twMerge(
"bg-transparent outline-none p-2",
"text-emerald-500",
"twui-button-secondary-ghost"
);
if (color == "accent")
return twMerge(
"bg-transparent outline-none p-2",
"text-violet-500",
"twui-button-accent-ghost"
);
if (color == "gray")
return twMerge(
"bg-transparent outline-none p-2",
"text-slate-600 dark:text-white/70",
"twui-button-gray-ghost"
);
if (color == "error")
return twMerge(
"bg-transparent outline-none p-2",
"text-red-600 dark:text-red-400",
"twui-button-error-ghost"
);
if (color == "warning")
return twMerge(
"bg-transparent outline-none p-2",
"text-yellow-600",
"twui-button-warning-ghost"
);
if (color == "success")
return twMerge(
"bg-transparent outline-none p-2",
"text-emerald-600",
"twui-button-success-ghost"
);
}
return "";
})();
const buttonComponent = (
<button
{...props}
className={twMerge(
"bg-blue-600 text-white text-base font-medium px-4 py-2 rounded",
"flex items-center justify-center relative transition-all",
"twui-button-general",
size == "small" && "px-3 py-1.5 text-sm",
size == "smaller" && "px-2 py-1 text-xs",
size == "large" && "text-lg",
size == "larger" && "px-5 py-3 text-xl",
finalClassName,
props.className,
loading ? "pointer-events-none opacity-80" : "l"
)}
>
<div
{...buttonContentProps}
className={twMerge(
"flex flex-row items-center gap-2",
loading ? "opacity-0" : "",
"twui-button-content-wrapper",
buttonContentProps?.className
)}
>
{beforeIcon && beforeIcon}
{props.children}
{afterIcon && afterIcon}
</div>
{loading && <Loading className="absolute" />}
</button>
);
if (href)
return (
<a {...linkProps} href={href} target={target}>
{buttonComponent}
</a>
);
return buttonComponent;
}
+23
View File
@@ -0,0 +1,23 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Flexbox Column
* @className twui-center
*/
export default function Center({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) {
return (
<div
{...props}
className={twMerge(
"flex flex-col items-center justify-center gap-4 p-2 w-full",
"twui-center",
props.className
)}
>
{props.children}
</div>
);
}
+24
View File
@@ -0,0 +1,24 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Default Container
* @className twui-container
*/
export default function Container({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) {
return (
<div
{...props}
className={twMerge(
"flex w-full max-w-[1200px] gap-4 justify-between",
"flex-wrap flex-col xl:flex-row items-start xl:items-center",
"twui-container",
props.className
)}
>
{props.children}
</div>
);
}
+30
View File
@@ -0,0 +1,30 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Vertical and Horizontal Divider
* @className twui-divider
* @className twui-divider-horizontal
* @className twui-divider-vertical
*/
export default function Divider({
vertical,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
vertical?: boolean;
}) {
return (
<div
{...props}
className={twMerge(
"border-slate-200 dark:border-white/10",
vertical
? "border-0 border-l h-full min-h-5"
: "border-0 border-t w-full",
"twui-divider",
vertical ? "twui-divider-vertical" : "twui-divider-horizontal",
props.className
)}
/>
);
}
+25
View File
@@ -0,0 +1,25 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General Footer
* @className twui-footer
*/
export default function Footer({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>) {
return (
<footer
{...props}
className={twMerge(
"flex flex-col items-center justify-center",
"px-4 sm:px-10 py-2",
"border-0 border-b border-slate-200 border-solid",
"twui-footer",
props.className
)}
>
{props.children}
</footer>
);
}
+19
View File
@@ -0,0 +1,19 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # H1 Headers
* @className twui-h1
*/
export default function H1({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<h1
{...props}
className={twMerge("text-5xl mb-4", "twui-h1", props.className)}
>
{props.children}
</h1>
);
}
+19
View File
@@ -0,0 +1,19 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # H2 Headers
* @className twui-h2
*/
export default function H2({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<h2
{...props}
className={twMerge("text-3xl mb-4", "twui-h2", props.className)}
>
{props.children}
</h2>
);
}
+19
View File
@@ -0,0 +1,19 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # H3 Headers
* @className twui-h3
*/
export default function H3({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<h3
{...props}
className={twMerge("text-xl mb-4", "twui-h3", props.className)}
>
{props.children}
</h3>
);
}
+19
View File
@@ -0,0 +1,19 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # H4 Headers
* @className twui-h4
*/
export default function H4({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<h4
{...props}
className={twMerge("text-base mb-4", "twui-h4", props.className)}
>
{props.children}
</h4>
);
}
+19
View File
@@ -0,0 +1,19 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # H5 Headers
* @className twui-h5
*/
export default function H5({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<h5
{...props}
className={twMerge("text-sm mb-4", "twui-h5", props.className)}
>
{props.children}
</h5>
);
}
+21
View File
@@ -0,0 +1,21 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Horizonta Rule (hr)
* @className twui-hr
*/
export default function HR({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHRElement>, HTMLHRElement>) {
return (
<hr
{...props}
className={twMerge(
"border-slate-200 dark:border-white/20 w-full my-4",
"twui-hr",
props.className
)}
/>
);
}
+25
View File
@@ -0,0 +1,25 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Default Header
* @className twui-header
*/
export default function Header({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>) {
return (
<header
{...props}
className={twMerge(
"flex flex-col items-center justify-center",
"px-4 sm:px-10 py-3 flex-wrap",
"border-0 border-b border-slate-200 dark:border-white/10 border-solid",
"twui-header",
props.className
)}
>
{props.children}
</header>
);
}
+30
View File
@@ -0,0 +1,30 @@
import { AnchorHTMLAttributes, DetailedHTMLProps } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General Anchor Elements
* @className twui-a | twui-anchor
*/
export default function Link({
...props
}: DetailedHTMLProps<
AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>) {
return (
<a
{...props}
className={twMerge(
"text-base text-link-500 no-underline hover:text-link-500/50",
"text-blue-600 dark:text-blue-400 hover:opacity-60 transition-all",
"border-0 border-b border-blue-300 dark:border-blue-200/30 border-solid leading-4",
// "focus:text-red-600",
"twui-anchor",
"twui-a",
props.className
)}
>
{props.children}
</a>
);
}
+54
View File
@@ -0,0 +1,54 @@
import {
AnchorHTMLAttributes,
DetailedHTMLProps,
HTMLAttributes,
OlHTMLAttributes,
} from "react";
import { twMerge } from "tailwind-merge";
/**
* # Ordered and unorder Lists
* @className twui-ol
* @className twui-ul
*/
export default function List({
ordered,
items,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement> &
DetailedHTMLProps<OlHTMLAttributes<HTMLOListElement>, HTMLOListElement> & {
items: {
content: React.ReactNode | string;
}[];
ordered?: boolean;
}) {
const listContent = (
<>
{items.map((item, index) => (
<li key={index}>{item.content}</li>
))}
</>
);
const className = "flex flex-col items-start gap-4";
if (ordered) {
return (
<ol
{...props}
className={twMerge(className, "twui-ol", props.className)}
>
{listContent}
</ol>
);
}
return (
<ul
{...props}
className={twMerge(className, "twui-ul", props.className)}
>
{listContent}
</ul>
);
}
@@ -0,0 +1,28 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
export type LoadingRectangleBlockProps = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;
/**
* # A loading Rectangle block
* @className twui-loading-rectangle-block
*/
export default function LoadingRectangleBlock({
...props
}: LoadingRectangleBlockProps) {
return (
<div
{...props}
className={twMerge(
"flex items-center w-full h-10 animate-pulse bg-slate-200 rounded",
"twui-loading-rectangle-block",
props.className
)}
>
{props.children}
</div>
);
}
+23
View File
@@ -0,0 +1,23 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Main Wrapper
* @className twui-h1
*/
export default function Main({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>) {
return (
<main
{...props}
className={twMerge(
"flex flex-col items-center w-full",
"twui-main",
props.className
)}
>
{props.children}
</main>
);
}
+24
View File
@@ -0,0 +1,24 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Paragraph Tag
* @className twui-p | twui-paragraph
*/
export default function P({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) {
return (
<p
{...props}
className={twMerge(
"text-base py-4",
"twui-p",
"twui-paragraph",
props.className
)}
>
{props.children}
</p>
);
}
+23
View File
@@ -0,0 +1,23 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Flexbox Row
* @className twui-row
*/
export default function Row({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) {
return (
<div
{...props}
className={twMerge(
"flex flex-row items-center gap-2 flex-wrap",
"twui-row",
props.className
)}
>
{props.children}
</div>
);
}
+24
View File
@@ -0,0 +1,24 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # General Section
* @className twui-section
*/
export default function Section({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>) {
return (
<section
{...props}
className={twMerge(
"flex flex-col items-center w-full",
"px-4 sm:px-10 py-10",
"twui-section",
props.className
)}
>
{props.children}
</section>
);
}
+33
View File
@@ -0,0 +1,33 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Span element
* @className twui-span
*/
export default function Span({
size,
variant,
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement> & {
size?: "normal" | "small" | "smaller" | "large" | "larger";
variant?: "normal" | "faded";
}) {
return (
<span
{...props}
className={twMerge(
"text-base",
size == "small" && "text-sm",
size == "smaller" && "text-xs",
size == "large" && "text-lg",
size == "larger" && "text-xl",
variant == "faded" && "opacity-50",
"twui-span",
props.className
)}
>
{props.children}
</span>
);
}
+23
View File
@@ -0,0 +1,23 @@
import { DetailedHTMLProps, HTMLAttributes } from "react";
import { twMerge } from "tailwind-merge";
/**
* # Flexbox Column
* @className twui-stack
*/
export default function Stack({
...props
}: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>) {
return (
<div
{...props}
className={twMerge(
"flex flex-col items-start gap-4",
"twui-stack",
props.className
)}
>
{props.children}
</div>
);
}
+106
View File
@@ -0,0 +1,106 @@
import { AuthCsrfHeaderName } from "@/server-client-shared/types/admin/auth";
import _ from "lodash";
type FetchApiOptions = {
method:
| "POST"
| "GET"
| "DELETE"
| "PUT"
| "PATCH"
| "post"
| "get"
| "delete"
| "put"
| "patch";
body?: object | string;
headers?: FetchHeader;
};
type FetchHeader = HeadersInit & {
[key in AuthCsrfHeaderName]?: string | null;
};
export type FetchApiReturn = {
success: boolean;
payload: any;
msg?: string;
[key: string]: any;
};
export default async function fetchApi(
url: string,
options?: FetchApiOptions,
csrf?: boolean
): Promise<any> {
let data;
if (typeof options === "string") {
try {
let fetchData;
const csrfValue = localStorage.getItem("csrf");
switch (options) {
case "post":
fetchData = await fetch(url, {
method: options,
headers: {
"Content-Type": "application/json",
"x-csrf-auth": csrf ? csrfValue : "",
} as FetchHeader,
} as RequestInit);
data = fetchData.json();
break;
default:
fetchData = await fetch(url);
data = fetchData.json();
break;
}
} catch (error: any) {
console.log("FetchAPI error #1:", error.message);
data = null;
}
} else if (typeof options === "object") {
try {
let fetchData;
const csrfValue = localStorage.getItem("csrf");
if (options.body && typeof options.body === "object") {
let oldOptionsBody = _.cloneDeep(options.body);
options.body = JSON.stringify(oldOptionsBody);
}
if (options.headers) {
options.headers["x-csrf-auth"] = csrf ? csrfValue : "";
const finalOptions: any = { ...options };
fetchData = await fetch(url, finalOptions);
} else {
fetchData = await fetch(url, {
...options,
headers: {
"Content-Type": "application/json",
"x-csrf-auth": csrf ? csrfValue : "",
} as FetchHeader,
} as RequestInit);
}
data = fetchData.json();
} catch (error: any) {
console.log("FetchAPI error #2:", error.message);
data = null;
}
} else {
try {
let fetchData = await fetch(url);
data = fetchData.json();
} catch (error: any) {
console.log("FetchAPI error #3:", error.message);
data = null;
}
}
return data;
}
@@ -0,0 +1,93 @@
export type ImageInputToBase64FunctionReturn = {
imageBase64?: string;
imageBase64Full?: string;
imageName?: string;
};
export type ImageInputToBase64FunctioParam = {
imageInput: HTMLInputElement;
maxWidth?: number;
mimeType?: string;
};
export default async function imageInputToBase64({
imageInput,
maxWidth,
mimeType,
}: ImageInputToBase64FunctioParam): Promise<ImageInputToBase64FunctionReturn> {
try {
if (!imageInput.files?.[0]) {
throw new Error("No Files found in this image input");
}
let imagePreviewNode = document.querySelector(
`[data-imagepreview='image']`
);
let imageName = imageInput.files[0].name.replace(/\..*/, "");
let imageDataBase64: string | undefined;
const MIME_TYPE = mimeType ? mimeType : "image/jpeg";
const QUALITY = 0.95;
const MAX_WIDTH = maxWidth ? maxWidth : null;
const file = imageInput.files[0];
const blobURL = URL.createObjectURL(file);
const img = new Image();
img.src = blobURL;
imageDataBase64 = await new Promise((res, rej) => {
img.onerror = function () {
URL.revokeObjectURL(this.src);
window.alert("Cannot load image!");
};
img.onload = function () {
URL.revokeObjectURL(img.src);
const canvas = document.createElement("canvas");
if (MAX_WIDTH) {
const scaleSize = MAX_WIDTH / img.naturalWidth;
canvas.width =
img.naturalWidth < MAX_WIDTH
? img.naturalWidth
: MAX_WIDTH;
canvas.height =
img.naturalWidth < MAX_WIDTH
? img.naturalHeight
: img.naturalHeight * scaleSize;
} else {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
}
const ctx = canvas.getContext("2d");
ctx?.drawImage(img, 0, 0, canvas.width, canvas.height);
const srcEncoded = canvas.toDataURL(MIME_TYPE, QUALITY);
res(srcEncoded);
};
});
return {
imageBase64: imageDataBase64?.replace(/.*?base64,/, ""),
imageBase64Full: imageDataBase64,
imageName: imageName,
};
} catch (error: any) {
console.log("Image Processing Error! =>", error.message);
return {
imageBase64: undefined,
imageBase64Full: undefined,
imageName: undefined,
};
}
}
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
+167
View File
@@ -0,0 +1,167 @@
export const skills = {
Devops: {
description: "Server management, deployment, and automation",
href: "/work/devops",
portfolio: [
{
title: "Server Management",
description: "Server management, deployment, and automation",
href: "/work/devops/server-management",
image: "/images/work/devops/server-management.png",
technologies: [
"Linux",
"Docker",
"Shell Scripting",
"Kubernetes",
"Terraform",
"AWS",
"Hetzner",
"Azure",
"Google Cloud",
"Debian",
"Ubuntu",
"Alpine",
"...",
],
},
{
title: "Email Server Setup",
description:
"Self Hosted Email solution. Setup and Deployment.",
href: "/work/devops/server-management",
image: "/images/work/devops/server-management.png",
technologies: ["Linux", "Docker", "Mailinabox", "Hetzner"],
},
{
title: "DNS Configuration",
description: "Domain names setup, configuration, and security.",
image: "/images/work/devops/server-management.png",
technologies: [
"Cloudflare DNS",
"Cloudflare Zero Trust",
"Cloudflare Registry",
],
},
{
title: "Web Servers and Reverse Proxies",
description:
"Web Server Configuration and deployment. Plus SSL Certificates provisioning.",
image: "/images/work/devops/server-management.png",
technologies: [
"NGINX",
"Node JS",
"Bun JS",
"Certbot",
"Let's Encrypt",
],
},
{
title: "Continuous Integration and Deployment",
description:
"Self hosted and managed solutions for deployment and continuous integration",
image: "/images/work/devops/server-management.png",
technologies: [
"Coolify",
"Vercel",
"Github Runners",
"Gitea Runners",
"Dokploy",
],
},
{
title: "Customer Service",
description:
"Self hosted and managed solutions for handling customers",
image: "/images/work/devops/server-management.png",
technologies: ["Chatwoot", "Tidio"],
},
],
},
"Full Stack": {
description: "Frontend and Backend development",
href: "/work/devops",
portfolio: [
{
title: "Server Development",
description:
"Easy development and development of Web servers and APIs",
image: "/images/work/devops/server-management.png",
technologies: ["Node JS", "Bun JS", "Shell Script", "Python"],
},
{
title: "React JS",
description: "Development of React JS applications for the web",
image: "/images/work/devops/server-management.png",
technologies: [
"React",
"Next JS",
"Vite",
"React Hooks",
"Functional Components",
],
},
{
title: "HTML & CSS",
description: "HTML and CSS Development for the web",
image: "/images/work/devops/server-management.png",
technologies: [
"HTML 5",
"CSS 3",
"SCSS",
"Less",
"Tailwind CSS",
],
},
{
title: "Database",
description: "Database Development and Management",
image: "/images/work/devops/server-management.png",
technologies: [
"MySQL",
"Mariadb",
"PostgreSQL",
"MongoDB",
"Redis",
"SQLite",
"Firebase",
"Supabase",
"Prisma",
"Mongoose",
],
},
{
title: "User Authentication",
description: "User Authentication and Authorization",
image: "/images/work/devops/server-management.png",
technologies: [
"Google Login",
"Github Login",
"Next Auth",
"Firebase",
"Cloudflare Zero Trust",
"Clerk",
],
},
],
},
"Software Development": {
description: "Application development for server, desktop, and web",
href: "/work/devops",
portfolio: [
{
title: "Node Modules Development",
description:
"Development of Node Modules for server, desktop, and web. Deployed on NPM package registry.",
image: "/images/work/devops/server-management.png",
technologies: ["Node JS", "Bun JS", "Shell Scripting", "Rsync"],
},
{
title: "Shell Scripting",
description:
"Development of shell scripts for automation and task execution",
image: "/images/work/devops/server-management.png",
technologies: ["Shell Script", "Bash Scripting", "GNU/Linux"],
},
],
},
};
+92
View File
@@ -0,0 +1,92 @@
export const work = {
Fullstack: {
href: "/work/full-stack",
portfolio: [
{
title: "Datasquirel",
description: "Clould-based SQL data management system.",
href: "https://datasquirel.com",
image: "/images/work/devops/server-management.png",
technologies: [
"Node JS",
"SQL",
"Mariadb",
"Shell Scripting",
"Docker",
"Docker Compose",
"Next JS",
"Tailwind CSS",
"Cloudflare Zero Trust",
],
},
{
title: "Summit Lending",
description: "Mortgage Broker in Utah",
href: "https://summitlending.com",
image: "/images/work/devops/server-management.png",
technologies: [
"Next JS",
"Tailwind CSS",
"Zapier",
"Google APIs",
"SQL",
"Spreadsheet to JSON",
],
},
{
title: "Coderank",
description: "A new age of remote work. Targeted at developers",
href: "https://summitlending.com",
image: "/images/work/devops/server-management.png",
technologies: [
"Next JS",
"Docker",
"VSCode Web Editor",
"NGINX Reverse Proxy",
],
},
],
},
Devops: {
href: "/work/devops",
portfolio: [
{
title: "Personal Mail Server",
description:
"Self Hosted Email solution for all my personal projects",
href: "https://box.mailben.xyz/mail",
image: "/images/work/devops/server-management.png",
technologies: ["Linux", "Docker", "Mailinabox"],
},
{
title: "Git, Packge, Container repository",
description:
"Self Hosted repository for Git projects, NPM modules, Docker images, and more",
href: "https://git.tben.me/tben",
image: "/images/work/devops/server-management.png",
technologies: ["Gitea", "Linux"],
},
],
},
Software: {
description: "Application development for server, desktop, and web",
href: "/work/devops",
portfolio: [
{
title: "Turbo Sync NPM Module",
description:
"The easiest way to synchronize local and remote directories in real time",
href: "https://git.tben.me/Moduletrace/-/packages/npm/turbosync",
image: "/images/work/devops/server-management.png",
technologies: ["Node JS", "Bun JS", "Shell Scripting", "Rsync"],
},
{
title: "Batchrun",
description: "Run multiple concurrent processes",
href: "https://git.tben.me/Moduletrace/-/packages/npm/@moduletrace%2Fbatchrun",
image: "/images/work/devops/server-management.png",
technologies: ["Node JS"],
},
],
},
};
@@ -0,0 +1,18 @@
import H2 from "@/components/lib/layout/H2";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
export default function AboutSection() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<H2 className="leading-snug">About Me</H2>
<Span>
I'm passionate and dedicated to solving problems using the
best technologies available.
</Span>
</Stack>
</Section>
);
}
@@ -0,0 +1,159 @@
import Card from "@/components/lib/elements/Card";
import H2 from "@/components/lib/layout/H2";
import H3 from "@/components/lib/layout/H3";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
import { skills } from "../(data)/skills";
import React from "react";
import Row from "@/components/lib/layout/Row";
import { twMerge } from "tailwind-merge";
import Divider from "@/components/lib/layout/Divider";
type Props = {
noTitle?: boolean;
expand?: boolean;
};
export default function MySkillsSection({ noTitle, expand }: Props) {
const [category, setCategory] =
React.useState<keyof typeof skills>("Devops");
const categories = Object.keys(skills) as (keyof typeof skills)[];
if (expand) {
return (
<Section>
<Stack className="w-full">
{!noTitle && (
<React.Fragment>
<H2 className="leading-snug m-0">My Skills</H2>
<Span>
A summary of the vast array of tools I've
mastered over the years
</Span>
<Divider className="opacity-0 my-2" />
</React.Fragment>
)}
<Stack className="items-stretch gap-20 flex-row xl:flex-col flex-wrap md:flex-nowrap">
{categories.map((ctgr, i) => {
return (
<Stack key={i}>
<Stack className="gap-6">
<Stack className="gap-2">
<H3 className="m-0 text-lg">
{ctgr}
</H3>
<Span className="text-sm !leading-5">
{skills[ctgr].description}
</Span>
</Stack>
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 w-full">
{skills[ctgr].portfolio.map(
(portfolio, index) => {
return (
<MySkillsCard
portfolio={
portfolio
}
key={index}
/>
);
}
)}
</div>
</Stack>
</Stack>
);
})}
</Stack>
</Stack>
</Section>
);
}
return (
<Section>
<Stack className="w-full">
{!noTitle && (
<React.Fragment>
<H2 className="leading-snug m-0">My Skills</H2>
<Span>
A summary of the vast array of tools I've mastered
over the years
</Span>
<Divider className="opacity-0 my-2" />
</React.Fragment>
)}
<Row className="flex-nowrap items-start gap-x-10 flex-col xl:flex-row gap-y-10">
<Stack className="xl:max-w-[200px] items-stretch gap-10 flex-row xl:flex-col flex-wrap md:flex-nowrap">
{categories.map((ctgr, i) => {
const isActive = category === ctgr;
return (
<Stack
key={i}
className={twMerge(
"cursor-pointer",
isActive
? ""
: "opacity-40 hover:opacity-70"
)}
onClick={() => setCategory(ctgr)}
>
<Stack className="gap-1">
<H3 className="m-0 text-lg">{ctgr}</H3>
<Span className="text-sm !leading-5">
{skills[ctgr].description}
</Span>
</Stack>
</Stack>
);
})}
</Stack>
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 w-full">
{skills[category].portfolio.map((portfolio, index) => {
return (
<MySkillsCard
portfolio={portfolio}
key={index}
/>
);
})}
</div>
</Row>
</Stack>
</Section>
);
}
export function MySkillsCard({
portfolio,
}: {
portfolio: (typeof skills.Devops.portfolio)[number];
}) {
return (
<Card className="grow w-full items-start">
<Stack className="gap-4">
<H3 className="m-0">{portfolio.title}</H3>
<Span>{portfolio.description}</Span>
{portfolio.technologies?.[0] && (
<Row className="gap-4">
{portfolio.technologies.map((tch, _i) => (
<React.Fragment key={_i}>
<Span className="text-sm dark:text-white/40">
{tch}
</Span>
{_i < portfolio.technologies.length - 1 && (
<Divider vertical />
)}
</React.Fragment>
))}
</Row>
)}
</Stack>
</Card>
);
}
@@ -0,0 +1,154 @@
import Card from "@/components/lib/elements/Card";
import H2 from "@/components/lib/layout/H2";
import H3 from "@/components/lib/layout/H3";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
import { work } from "../(data)/work";
import Link from "@/components/lib/layout/Link";
import React from "react";
import Row from "@/components/lib/layout/Row";
import Divider from "@/components/lib/layout/Divider";
import { twMerge } from "tailwind-merge";
type Props = {
noTitle?: boolean;
expand?: boolean;
};
export default function MyWorkSection({ noTitle, expand }: Props) {
const categories = Object.keys(work) as (keyof typeof work)[];
const [category, setCategory] = React.useState<keyof typeof work>(
categories[0]
);
if (expand) {
return (
<Section>
<Stack className="w-full">
{!noTitle && (
<React.Fragment>
<H2 className="leading-snug m-0">My Work</H2>
<Span>Some work I've done in the past</Span>
<Divider className="opacity-0 my-2" />
</React.Fragment>
)}
<Stack className="items-stretch gap-20 flex-row xl:flex-col flex-wrap md:flex-nowrap">
{categories.map((ctgr, i) => {
const isActive = category === ctgr;
return (
<Stack key={i}>
<Stack className="gap-6">
<H3 className="m-0 text-lg">{ctgr}</H3>
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 w-full">
{work[ctgr].portfolio.map(
(portfolio, index) => {
return (
<MyWorkPortfolioCard
portfolio={
portfolio
}
key={index}
/>
);
}
)}
</div>
</Stack>
</Stack>
);
})}
</Stack>
</Stack>
</Section>
);
}
return (
<Section>
<Stack className="w-full">
{!noTitle && (
<React.Fragment>
<H2 className="leading-snug m-0">My Work</H2>
<Span>Some work I've done in the past</Span>
<Divider className="opacity-0 my-2" />
</React.Fragment>
)}
<Row className="flex-nowrap items-start gap-x-14 flex-col xl:flex-row gap-y-10">
<Stack className="xl:max-w-[200px] items-stretch gap-6 flex-row xl:flex-col flex-wrap md:flex-nowrap">
{categories.map((ctgr, i) => {
const isActive = category === ctgr;
return (
<Stack
key={i}
className={twMerge(
"cursor-pointer",
isActive
? ""
: "opacity-40 hover:opacity-70"
)}
onClick={() => setCategory(ctgr)}
>
<Stack className="gap-1">
<H3 className="m-0 text-lg">{ctgr}</H3>
</Stack>
</Stack>
);
})}
</Stack>
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 w-full">
{work[category].portfolio.map((portfolio, index) => {
return (
<MyWorkPortfolioCard
portfolio={portfolio}
key={index}
/>
);
})}
</div>
</Row>
</Stack>
</Section>
);
}
export function MyWorkPortfolioCard({
portfolio,
}: {
portfolio: (typeof work.Devops.portfolio)[number];
}) {
return (
<Card className="grow w-full items-start">
<Stack className="gap-4">
<H3 className="m-0">{portfolio.title}</H3>
<Link
target="_blank"
href={portfolio.href}
className="text-sm text-wrap break-all border-none"
>
{portfolio.href}
</Link>
<Span>{portfolio.description}</Span>
{portfolio.technologies?.[0] && (
<Row className="gap-4">
{portfolio.technologies.map((tch, _i) => (
<React.Fragment key={_i}>
<Span className="text-sm dark:text-white/40">
{tch}
</Span>
{_i < portfolio.technologies.length - 1 && (
<Divider vertical />
)}
</React.Fragment>
))}
</Row>
)}
</Stack>
</Card>
);
}
+42
View File
@@ -0,0 +1,42 @@
import Button from "@/components/lib/layout/Button";
import H1 from "@/components/lib/layout/H1";
import Row from "@/components/lib/layout/Row";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
import { Contact, ScrollText } from "lucide-react";
export default function Main() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<Span>Howdy Tech Enthusiasts! I'm Benjamin Toby</Span>
<H1 className="leading-snug">
Software Engineer, DevOps Engineer, Full Stack Developer,
Software Architect, Philosopher, Solar Energy Enthusiast.
</H1>
<Row className="items-stretch flex-col md:flex-row w-full md:w-auto">
<Button
beforeIcon={
<Contact size={17} className="font-normal" />
}
href="/contact"
className="grow w-full"
>
Contact Me
</Button>
<Button
beforeIcon={
<ScrollText size={17} className="font-normal" />
}
href="/contact"
variant="outlined"
className="grow w-full"
>
Resume
</Button>
</Row>
</Stack>
</Section>
);
}
+22
View File
@@ -0,0 +1,22 @@
import H1 from "@/components/lib/layout/H1";
import Link from "@/components/lib/layout/Link";
import Row from "@/components/lib/layout/Row";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
import { Mail } from "lucide-react";
export default function Main() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<H1 className="leading-snug">About Me</H1>
<Span>
I'm a man of few words. My{" "}
<Link href="/skills">Skills</Link> and{" "}
<Link href="/work">Work</Link> speaks for themselves.
</Span>
</Stack>
</Section>
);
}
+28
View File
@@ -0,0 +1,28 @@
import H1 from "@/components/lib/layout/H1";
import Link from "@/components/lib/layout/Link";
import Row from "@/components/lib/layout/Row";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
import { Mail } from "lucide-react";
export default function Main() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<H1 className="leading-snug">Contact Me</H1>
<Span>
Have a great idea? Want to collaborate? Let's make it
happen.
</Span>
<Link href="mailto:ben@tben.me" className="border-none">
<Row className="items-center">
<Mail size={20} className="mt-1" />
<Span className="text-2xl">ben@tben.me</Span>
</Row>
</Link>
</Stack>
</Section>
);
}
+18
View File
@@ -0,0 +1,18 @@
import H1 from "@/components/lib/layout/H1";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
export default function Main() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<H1 className="leading-snug">My Skills</H1>
<Span>
A summary of the vast array of tools I've mastered over the
years
</Span>
</Stack>
</Section>
);
}
+15
View File
@@ -0,0 +1,15 @@
import H1 from "@/components/lib/layout/H1";
import Section from "@/components/lib/layout/Section";
import Span from "@/components/lib/layout/Span";
import Stack from "@/components/lib/layout/Stack";
export default function Main() {
return (
<Section>
<Stack className="w-full max-w-full xl:max-w-[50vw]">
<H1 className="leading-snug">My Work</H1>
<Span>Some of My Work</Span>
</Stack>
</Section>
);
}