All files / src/entities/project/ui/modal ModalInputs.tsx

100% Statements 4/4
100% Branches 4/4
100% Functions 4/4
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96                                                        37x                                       7x                                   3x                         1x                                
import React from 'react';
import { preventEnterSubmit } from '@/shared/lib/utils';
 
interface ModalInputsProps {
	showInput?: boolean;
	showCanvasInputs?: boolean;
	customContent?: React.ReactNode;
	name: string;
	width: number;
	height: number;
	error: string | null;
	setName: (val: string) => void;
	setWidth: (val: number) => void;
	setHeight: (val: number) => void;
}
 
export function ModalInputs({
	showInput,
	showCanvasInputs,
	customContent,
	name,
	width,
	height,
	error,
	setName,
	setWidth,
	setHeight,
}: ModalInputsProps) {
	if (!showInput) {
		return <div className="text-gray-700 text-sm">{customContent}</div>;
	}
 
	return (
		<div className="space-y-4">
			{/* Project name */}
			<div className="space-y-2">
				<label
					htmlFor="project-name"
					className="block text-sm font-medium text-gray-600"
				>
					Project name
				</label>
				<input
					id="project-name"
					type="text"
					value={name}
					data-testid="project-input"
					placeholder="Enter project name"
					onChange={(event) => setName(event.target.value)}
					className="border border-gray-300 rounded-lg px-4 py-2.5 w-full text-gray-800 bg-white/80
							   focus:ring-2 focus:ring-indigo-500 focus:shadow-[0_0_8px_rgba(99,102,241,0.25)]
							   outline-none transition"
				/>
			</div>
 
			{/* Canvas size inputs */}
			{showCanvasInputs && (
				<div className="flex gap-4">
					<div className="flex-1">
						<label className="block text-sm font-medium text-gray-600">
							Width (px)
						</label>
						<input
							type="number"
							value={width}
							onKeyDown={preventEnterSubmit}
							onChange={(event) => setWidth(Number(event.target.value))}
							data-testid="canvas-width"
							className="border border-gray-300 rounded-lg px-3 py-2 w-full text-gray-800 bg-white/80 focus:ring-2 focus:ring-indigo-500 outline-none transition"
						/>
					</div>
					<div className="flex-1">
						<label className="block text-sm font-medium text-gray-600">
							Height (px)
						</label>
						<input
							type="number"
							onKeyDown={preventEnterSubmit}
							value={height}
							onChange={(event) => setHeight(Number(event.target.value))}
							data-testid="canvas-height"
							className="border border-gray-300 rounded-lg px-3 py-2 w-full text-gray-800 bg-white/80 focus:ring-2 focus:ring-indigo-500 outline-none transition"
						/>
					</div>
				</div>
			)}
 
			{error && (
				<p role="alert" className="text-red-500 text-sm mt-1">
					{error}
				</p>
			)}
		</div>
	);
}