File size: 1,194 Bytes
6294700
 
 
 
 
 
 
76ea2b9
6294700
 
 
 
 
 
76ea2b9
6294700
 
 
 
 
76ea2b9
 
6294700
76ea2b9
6294700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { ChangeEvent } from "react";

interface Props {
  value: string;
  onChange: (value: string) => void;
  placeholder?: string;
  label?: string;
  onlyAlphaNumeric?: boolean;
}

export const TextInput: React.FC<Props> = ({
  value,
  onChange,
  placeholder,
  onlyAlphaNumeric = true,
  label,
}) => {
  const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
    const newValue = event.target.value;
    // Only allow numbers or strings
    if (onlyAlphaNumeric && /^[0-9a-zA-Z]*$/.test(newValue)) {
      return onChange(newValue);
    }
    onChange(newValue);
  };

  return (
    <div className="w-full relative grid grid-cols-1 gap-2.5">
      <label className="text-slate-400 text-sm font-medium capitalize">
        {label}:
      </label>
      <input
        type="text"
        value={value}
        placeholder={placeholder}
        onChange={handleInputChange}
        className="transition-all duration-200 w-full h-full px-4 py-4 bg-slate-950/50 rounded-lg  outline-none text-slate-200 placeholder:text-slate-600 focus:ring-4 focus:ring-indigo-600 focus:ring-opacity-40 border border-slate-950/50 focus:border-indigo-500"
      />
    </div>
  );
};