ERP-node/frontend/components/screen/widgets/InputWidget.tsx

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-09-01 11:48:12 +09:00
"use client";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { cn } from "@/lib/utils";
import { WidgetComponent } from "@/types/screen";
interface InputWidgetProps {
widget: WidgetComponent;
value?: string;
onChange?: (value: string) => void;
className?: string;
}
export default function InputWidget({ widget, value, onChange, className }: InputWidgetProps) {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange?.(e.target.value);
};
return (
2025-10-17 16:21:08 +09:00
<div className={cn("space-y-1.5", className)}>
2025-09-01 11:48:12 +09:00
{widget.label && (
2025-10-17 16:21:08 +09:00
<Label htmlFor={widget.id} className="text-xs font-medium">
2025-09-01 11:48:12 +09:00
{widget.label}
2025-10-17 16:21:08 +09:00
{widget.required && <span className="text-destructive ml-0.5">*</span>}
2025-09-01 11:48:12 +09:00
</Label>
)}
<Input
id={widget.id}
type={widget.widgetType === "number" ? "number" : "text"}
placeholder={widget.placeholder}
value={value || ""}
onChange={handleChange}
required={widget.required}
readOnly={widget.readonly}
2025-10-28 17:33:03 +09:00
className={cn("h-6 w-full text-xs", widget.readonly && "bg-muted/50 cursor-not-allowed")}
style={{ fontSize: "12px" }}
2025-09-01 11:48:12 +09:00
/>
</div>
);
}