Radio Button and Checkbox Created

This commit is contained in:
2025-07-30 23:10:17 -04:00
parent cb8c2c23be
commit f6f77c9d42
29 changed files with 892 additions and 18 deletions

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function DangerCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-red-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-red-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function DarkCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-black group-data-checked:stroke-white": box,
"group-data-checked:stroke-black": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function InfoCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-cyan-500 group-data-checked:stroke-white": box,
"group-data-checked:stroke-cyan-500": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function LightCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-white group-data-checked:stroke-black": box,
"group-data-checked:stroke-white": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,71 @@
import type { CheckboxProps } from "$/types/Input";
import { Checkbox } from "@headlessui/react";
import clsx from "clsx";
export default function MattrixwvCheckbox({
id,
className,
labelClassName,
name,
size = "sm",
box = true,
onChange,
checked,
defaultChecked,
strokeWidth = 2,
value,
children
}: CheckboxProps){
return (
<Checkbox
id={id}
className={clsx(
"group cursor-pointer",
"flex flex-row items-center justify-center gap-x-2"
)}
name={name}
checked={checked}
defaultChecked={defaultChecked}
onChange={onChange}
value={value}
>
<div
className={clsx(
className,
{
"rounded border": box
},
{
"": size === "none",
"size-3": size === "xs",
"size-4": size === "sm",
"size-5": size === "md",
"size-6": size === "lg",
"size-7": size === "xl"
}
)}
>
<svg
viewBox="0 0 14 14"
fill="none"
>
<path
d="M3 8L6 11L11 3.5"
strokeWidth={strokeWidth}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</div>
{
children &&
<div
className={labelClassName}
>
{children}
</div>
}
</Checkbox>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function MoltenCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-orange-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-orange-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function PrimaryCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-blue-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-blue-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function SecondaryCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-neutral-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-neutral-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,25 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function SuccessCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-green-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-green-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function TertiaryCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-purple-600 group-data-checked:stroke-white": box,
"group-data-checked:stroke-purple-600": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -0,0 +1,24 @@
import type { CheckboxProps } from "$/types/Input";
import clsx from "clsx";
import MattrixwvCheckbox from "./MattrixwvCheckbox";
export default function WarningCheckbox({
className,
box = true,
...props
}: CheckboxProps){
return (
<MattrixwvCheckbox
className={clsx(
className,
{
"group-data-checked:bg-yellow-500 group-data-checked:stroke-white": box,
"group-data-checked:stroke-yellow-500": !box
}
)}
box={box}
{...props}
/>
);
}

View File

@@ -1,20 +1,84 @@
import { useRef } from "react";
import type { FileInputProps } from "$/types/Input";
import { humanReadableBytes } from "$/util/FileUtil";
import clsx from "clsx";
import { useEffect, useRef, useState } from "react";
export default function DragAndDropFileInput(){
export default function DragAndDropFileInput({
id,
className,
name,
minSize,
maxSize,
showFileName,
showSize,
onChange,
disabled,
children
}: FileInputProps){
const [ file, setFile ] = useState<File>();
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
onChange?.(file);
}, [ file ]);
return (
<div
className="relative border-2 rounded-lg w-full h-full cursor-pointer"
<label
className={clsx(
"flex flex-col items-center justify-center border-2 rounded-lg w-full h-full cursor-pointer",
className
)}
onDragOver={(e) => e.preventDefault()}
onDrop={(e) => {
e.preventDefault();
setFile(e.dataTransfer.files[0]);
if(inputRef.current){ inputRef.current.files = e.dataTransfer.files; }
}}
>
<input
ref={inputRef}
type="file"
id={id}
className="sr-only"
name={name}
onChange={(e) => setFile(e.target.files?.[0])}
disabled={disabled}
/>
Drag And Drop File Input
</div>
<div
className="flex flex-col items-center justify-between w-full h-full px-2"
>
{children}
<div
className="flex flex-row items-center justify-between gap-x-8 w-full"
>
{
showFileName &&
<div
className="text-center"
>
{file?.name}
</div>
}
{
showSize &&
<div
className={clsx(
{
"text-red-600": minSize && file?.size && file?.size < minSize,
"text-red-600 ": maxSize && file?.size && file?.size > 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)}
</div>
}
</div>
</div>
</label>
);
}

View File

@@ -23,16 +23,16 @@ export default function FileInput({
return (
<div
className="flex flex-row items-center justify-between w-full border-2 rounded-lg"
className={clsx(
"flex flex-row items-center justify-between w-full border-2 rounded-lg",
className
)}
>
<input
ref={inputRef}
id={id}
type="file"
className={clsx(
"sr-only",
className
)}
className="sr-only"
name={name}
onChange={(e) => { setFile(e.target.files?.[0]); onChange?.(e.target.files?.[0]); }}
disabled={disabled}
@@ -76,6 +76,7 @@ export default function FileInput({
className="text-nowrap rounded-r-lg"
rounding="none"
onClick={() => { inputRef.current?.click(); }}
disabled={disabled}
>
Click Me
</SecondaryButton>

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function DangerRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-red-600",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function DarkRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-black",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function InfoRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-cyan-500",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function LightRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-white",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function MoltenRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-orange-600",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function PrimaryRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-blue-500",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,44 @@
import type { RadioButtonProps } from "$/types/Input";
import { Radio } from "@headlessui/react";
import clsx from "clsx";
export default function RadioButton({
id,
className,
labelClassName,
size = "sm",
value,
children
}: RadioButtonProps){
return (
<Radio
id={id}
value={value}
className="group flex flex-row items-center justify-center gap-x-2 cursor-pointer"
>
<div
className={clsx(
"rounded-full not-group-data-checked:border",
className,
{
"": size === "none",
"size-3": size === "xs",
"size-4": size === "sm",
"size-5": size === "md",
"size-6": size === "lg",
"size-7": size === "xl"
}
)}
/>
{
children &&
<div
className={labelClassName}
>
{children}
</div>
}
</Radio>
);
}

View File

@@ -0,0 +1,35 @@
import type { RadioListProps } from "$/types/Input";
import { RadioGroup } from "@headlessui/react";
import clsx from "clsx";
export default function RadioList({
id,
className,
name,
value,
onChange,
defaultValue,
direction = "horizontal",
children
}: RadioListProps){
return (
<RadioGroup
id={id}
className={clsx(
"flex items-center justify-center",
className,
{
"flex-row gap-x-8": direction === "horizontal",
"flex-col gap-y-2": direction === "vertical"
}
)}
name={name}
value={value}
onChange={onChange}
defaultValue={defaultValue}
>
{children}
</RadioGroup>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function SecondaryRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-neutral-600",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function SuccessRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-green-600",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function TertiaryRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-purple-600",
className
)}
{...props}
/>
);
}

View File

@@ -0,0 +1,19 @@
import type { RadioButtonProps } from "$/types/Input";
import clsx from "clsx";
import RadioButton from "./RadioButton";
export default function WarningRadioButton({
className,
...props
}: RadioButtonProps){
return (
<RadioButton
className={clsx(
"group-data-checked:bg-yellow-500",
className
)}
{...props}
/>
);
}

42
lib/types/Input.d.ts vendored
View File

@@ -105,9 +105,47 @@ export interface FileInputProps {
maxSize?: number;
showFileName?: boolean;
showSize?: boolean;
defaultValue?: File;
value?: File;
onChange?: (newFile: File | undefined) => void;
disabled?: boolean;
children?: React.ReactNode;
}
export type CheckboxSize = "none" | "xs" | "sm" | "md" | "lg" | "xl";
export interface CheckboxProps {
id?: string;
className?: string;
labelClassName?: string;
name?: string;
size?: CheckboxSize;
box?: boolean;
onChange?: (newChecked: boolean) => void;
checked?: boolean;
defaultChecked?: boolean;
strokeWidth?: number;
value?: string;
children?: React.ReactNode;
}
export type RadioButtonSize = "none" | "xs" | "sm" | "md" | "lg" | "xl";
export interface RadioButtonProps {
id?: string;
className?: string;
labelClassName?: string;
size?: RadioButtonSize;
value: string;
children?: React.ReactNode;
}
export interface RadioListProps {
id?: string;
className?: string;
name?: string;
value?: string;
onChange?: (value: string) => void;
defaultValue?: string;
direction?: "vertical" | "horizontal";
children?: React.ReactNode;
}