mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
- Fix scene title input bug (Chris) - scene rename restyle and behavior Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com>
78 lines
2.2 KiB
TypeScript
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";
|