@devekene001/super-input 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -24
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,46 +39,67 @@ Option 2: Handling Objects (The Pro Way)
|
|
|
39
39
|
Manage multiple inputs with a single state object. This uses the name prop to identify which field is changing.
|
|
40
40
|
|
|
41
41
|
JavaScript
|
|
42
|
-
import React, { useState } from
|
|
43
|
-
import SuperInput from
|
|
42
|
+
import React, { useState } from "react";
|
|
43
|
+
import SuperInput from "@devekene001/super-input";
|
|
44
|
+
import './App.css';
|
|
44
45
|
|
|
45
|
-
function
|
|
46
|
-
|
|
46
|
+
function App() {
|
|
47
|
+
// 1. Setup an object to hold all our data
|
|
48
|
+
const [formData, setFormData] = useState({
|
|
47
49
|
firstName: '',
|
|
48
50
|
lastName: '',
|
|
49
51
|
email: ''
|
|
50
52
|
});
|
|
51
53
|
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
// 2. The "Universal" handler
|
|
55
|
+
// Our SuperInput now sends (value, name)
|
|
56
|
+
const handleInputChange = (value, name) => {
|
|
57
|
+
setFormData(prev => ({
|
|
55
58
|
...prev,
|
|
56
|
-
[name]: value
|
|
59
|
+
[name]: value // This updates only the field that changed!
|
|
57
60
|
}));
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
return (
|
|
61
|
-
<
|
|
62
|
-
<
|
|
64
|
+
<!-- <div style={{ padding: '40px', width: "40%", fontFamily: 'Arial' }}> -->
|
|
65
|
+
<!-- <h1>Registration Form</h1> -->
|
|
66
|
+
|
|
67
|
+
{/* Input for First Name */}
|
|
68
|
+
<SuperInput
|
|
63
69
|
label="First Name"
|
|
64
|
-
name="firstName"
|
|
65
|
-
value={
|
|
66
|
-
onChange={
|
|
70
|
+
name="firstName" // <--- The ID tag
|
|
71
|
+
value={formData.firstName}
|
|
72
|
+
onChange={handleInputChange}
|
|
73
|
+
placeholder="Enter first name"
|
|
67
74
|
/>
|
|
68
|
-
|
|
75
|
+
|
|
76
|
+
{/* Input for Last Name */}
|
|
77
|
+
<SuperInput
|
|
69
78
|
label="Last Name"
|
|
70
|
-
name="lastName"
|
|
71
|
-
value={
|
|
72
|
-
onChange={
|
|
79
|
+
name="lastName" // <--- The ID tag
|
|
80
|
+
value={formData.lastName}
|
|
81
|
+
onChange={handleInputChange}
|
|
82
|
+
placeholder="Enter last name"
|
|
73
83
|
/>
|
|
74
|
-
|
|
84
|
+
|
|
85
|
+
{/* Input for Email with a basic error check */}
|
|
86
|
+
<SuperInput
|
|
75
87
|
label="Email Address"
|
|
76
|
-
name="email"
|
|
88
|
+
name="email" // <--- The ID tag
|
|
77
89
|
type="email"
|
|
78
|
-
value={
|
|
79
|
-
onChange={
|
|
80
|
-
|
|
90
|
+
value={formData.email}
|
|
91
|
+
onChange={handleInputChange}
|
|
92
|
+
placeholder="example@mail.com"
|
|
93
|
+
error={formData.email && !formData.email.includes('@') ? "Invalid email address" : ""}
|
|
81
94
|
/>
|
|
82
|
-
|
|
95
|
+
|
|
96
|
+
{/* Preview the Object in real-time */}
|
|
97
|
+
<div style={{ marginTop: '20px', padding: '10px', background: '#f4f4f4', borderRadius: '8px' }}>
|
|
98
|
+
<strong>Current State:</strong>
|
|
99
|
+
<pre>{JSON.stringify(formData, null, 2)}</pre>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
83
102
|
);
|
|
84
|
-
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default App;
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
18
18
|
var SuperInput = function SuperInput(_ref) {
|
|
19
19
|
var label = _ref.label,
|
|
20
20
|
value = _ref.value,
|
|
21
|
-
|
|
21
|
+
onChange = _ref.onChange,
|
|
22
22
|
placeholder = _ref.placeholder,
|
|
23
23
|
error = _ref.error,
|
|
24
24
|
style = _ref.style,
|
|
@@ -52,7 +52,7 @@ var SuperInput = function SuperInput(_ref) {
|
|
|
52
52
|
disabled: disabled,
|
|
53
53
|
placeholder: placeholder,
|
|
54
54
|
onChange: function onChange(e) {
|
|
55
|
-
return _onChange(e.target.value);
|
|
55
|
+
return _onChange(e.target.value, name);
|
|
56
56
|
}
|
|
57
57
|
// We use a CSS class or inline style with focus logic
|
|
58
58
|
,
|