|
|
@@ -1,29 +1,26 @@
|
|
|
-import React, { FC, useState } from "react";
|
|
|
+import React, { FC } from "react";
|
|
|
|
|
|
-interface selecteProps {
|
|
|
+interface selectProps {
|
|
|
list: string[] | number[];
|
|
|
+ onChange: Function;
|
|
|
placeholder: string;
|
|
|
- className?: string;
|
|
|
- id?: string;
|
|
|
- name?: string;
|
|
|
+ name: string;
|
|
|
+ [index: string]: any;
|
|
|
}
|
|
|
|
|
|
-const Select: FC<selecteProps> = ({ list, id, name, className, placeholder }) => {
|
|
|
- const [selected, setSelected] = useState<string | number>(placeholder);
|
|
|
+// En las props hago un "rest", que me da el resto del objeto que estoy desestructurando
|
|
|
+const Select: FC<selectProps> = ({ list, className, ...props }) => {
|
|
|
+ return (
|
|
|
+ <select {...(props as any)} className={`form-select ${className}`}>
|
|
|
+ {props.placeholder ? <option value="">{props.placeholder}</option> : null}
|
|
|
|
|
|
- const onChangeSelect = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
|
- setSelected(event.target.value);
|
|
|
- };
|
|
|
-
|
|
|
- return <select className={className?? ""} id={id?? ""} name={name?? ""} onChange={onChangeSelect} value={selected}>
|
|
|
- <option value=''>{placeholder}</option>
|
|
|
-
|
|
|
- {list.map(item => (
|
|
|
- <option value={item} key={item}>
|
|
|
- {item}
|
|
|
- </option>
|
|
|
- ))}
|
|
|
- </select>;
|
|
|
+ {list.map((item) => (
|
|
|
+ <option value={item} key={item}>
|
|
|
+ {item}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
export default Select;
|