Files
artcraft/app/components/Input.tsx
T
BFlatandChristopher Oliphant a47e5767b7 Fix scene title input bug + restyle/behavior (#329)
- Fix scene title input bug (Chris)
- scene rename restyle and behavior

Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com>
2024-05-07 11:10:57 -07:00

78 lines
2.2 KiB
TypeScript

import React from "react";
import { twMerge } from "tailwind-merge";
import { IconDefinition } from "@fortawesome/pro-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Label, H6 } from "./Typography";
import { kebabCase } from "~/utilities";
import {
disableHotkeyInput,
enableHotkeyInput,
DomLevels,
} from "~/pages/PageEnigma/store";
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
inputClassName?: string;
label?: string;
icon?: IconDefinition;
isError?: boolean;
errorMessage?: string;
}
export const Input = React.forwardRef(
(
{
label,
icon,
inputClassName,
className,
id,
isError,
onBlur,
onFocus,
errorMessage,
...rest
}: InputProps,
ref: React.ForwardedRef<HTMLInputElement>,
) => {
return (
<div className={twMerge("flex flex-col", className)}>
{label && <Label htmlFor={id ? id : kebabCase(label)}>{label}</Label>}
<div className="relative w-full">
{icon && (
<FontAwesomeIcon icon={icon} className="absolute h-5 pl-3 pt-2.5" />
)}
<input
ref={ref}
id={id ? id : label ? kebabCase(label) : undefined}
className={twMerge(
"h-10 w-full rounded-md bg-brand-secondary px-3 py-2.5 text-white outline-none outline-offset-0 transition-all duration-150 ease-in-out focus:outline-brand-primary",
icon && "pl-12",
isError && "outline-red focus:outline-red",
inputClassName,
)}
onFocus={(e: React.FocusEvent<HTMLInputElement>) => {
if (onFocus) {
onFocus(e);
}
disableHotkeyInput(DomLevels.INPUT);
}}
onBlur={(e: React.FocusEvent<HTMLInputElement>) => {
if (onBlur) {
onBlur(e);
}
enableHotkeyInput(DomLevels.INPUT);
}}
{...rest}
/>
{errorMessage && (
<H6 className="absolute z-10 text-red">{errorMessage}</H6>
)}
</div>
</div>
);
},
);
Input.displayName = "Input";