1
|
1 |
|
import "./styles.css"; |
2
|
|
|
|
3
|
1 |
|
import React from "react"; |
4
|
|
|
|
5
|
|
|
import { InputComponent } from "./types"; |
6
|
|
|
|
7
|
1 |
|
import { buildBoxComponent } from "../../../utils"; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A flexible text input element |
11
|
|
|
* |
12
|
|
|
* @since 1.0.0 |
13
|
|
|
* |
14
|
|
|
* @param {string} value text input value |
15
|
|
|
* @param {(newValue:string)=>void} onChange callback triggered when numeric input changes |
16
|
|
|
* @param {string} label `common modular-ui prop` - component top label |
17
|
|
|
* @param {string} className `common modular-ui prop` - custom className (to better customize it) |
18
|
|
|
* @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it) |
19
|
|
|
* @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM) |
20
|
|
|
* @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode |
21
|
|
|
* @param {boolean} hide `common modular-ui prop` - Hide/show component |
22
|
|
|
* @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it) |
23
|
|
|
* |
24
|
|
|
* @example <caption>Example Input usage</caption> |
25
|
|
|
* import { render } from "react-dom"; |
26
|
|
|
* import { Input } from '@cianciarusocataldo/modular-ui'; |
27
|
|
|
* |
28
|
|
|
* render(<Input value="example text" />, document.getElementById("root")); |
29
|
|
|
* |
30
|
|
|
* @see https://cianciarusocataldo.github.io/modular-ui/components/atoms/Input |
31
|
|
|
* |
32
|
|
|
* @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo> |
33
|
|
|
* |
34
|
|
|
* @copyright 2022 Cataldo Cianciaruso*/ |
35
|
1 |
|
const Input: InputComponent = ({ |
36
|
17 |
|
onChange = () => {}, |
37
|
17 |
|
value, |
38
|
17 |
|
placeholder, |
39
|
17 |
|
readOnly, |
40
|
17 |
|
label, |
41
|
17 |
|
...commonProps |
42
|
|
|
}) => |
43
|
17 |
|
buildBoxComponent({ |
44
|
17 |
|
callBack: (value, setValue) => ({ |
45
|
|
|
name: "modular-inputbox", |
46
|
|
|
Component: ( |
47
|
|
|
<input |
48
|
|
|
type="text" |
49
|
|
|
value={value} |
50
|
|
|
placeholder={placeholder} |
51
|
|
|
className="input-box" |
52
|
|
|
readOnly={readOnly} |
53
|
|
|
onChange={(e) => { |
54
|
6 |
|
if (!readOnly) { |
55
|
5 |
|
const newValue = e.target.value ? e.target.value : ""; |
56
|
5 |
|
onChange(newValue); |
57
|
5 |
|
setValue(newValue); |
58
|
|
|
} |
59
|
|
|
}} |
60
|
|
|
/> |
61
|
|
|
), |
62
|
|
|
commonProps, |
63
|
|
|
}), |
64
|
|
|
defaultValue: value || "", |
65
|
|
|
value, |
66
|
|
|
label, |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
export default Input; |
70
|
|
|
|