@devekene001/super-input 0.0.4 → 0.0.5
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 +71 -10
- package/dist/index.d.ts +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,84 @@
|
|
|
1
|
-
|
|
1
|
+
@devekene001/super-input
|
|
2
|
+
A professional, universal, and highly flexible text input component for React.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
🚀 Features
|
|
5
|
+
Universal: Built for React (Web) and React Native (Mobile).
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
1. Install it: `npm install my-super-input`
|
|
7
|
-
2. Use it in your code:
|
|
7
|
+
Object Support: Handle complex state objects with ease using the name prop.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Accessible: Built-in accessibility with automatic id and htmlFor linking.
|
|
10
|
+
|
|
11
|
+
Validation Ready: Visual error states and descriptive error messages.
|
|
12
|
+
|
|
13
|
+
TypeScript: Full type definitions included.
|
|
14
|
+
|
|
15
|
+
📦 Installation
|
|
16
|
+
Bash
|
|
17
|
+
npm install @devekene001/super-input
|
|
18
|
+
🛠 Usage
|
|
19
|
+
Option 1: Simple String (The Basic Way)
|
|
20
|
+
Best for single inputs like a search bar or a single name field.
|
|
21
|
+
|
|
22
|
+
JavaScript
|
|
23
|
+
import React, { useState } from 'react';
|
|
24
|
+
import SuperInput from '@devekene001/super-input';
|
|
11
25
|
|
|
12
26
|
function App() {
|
|
13
|
-
const [name, setName] =
|
|
27
|
+
const [name, setName] = useState('');
|
|
14
28
|
|
|
15
29
|
return (
|
|
16
30
|
<SuperInput
|
|
17
31
|
label="Your Name"
|
|
18
32
|
value={name}
|
|
19
|
-
onChange={setName}
|
|
20
|
-
placeholder="Type
|
|
33
|
+
onChange={(val) => setName(val)}
|
|
34
|
+
placeholder="Type your name..."
|
|
21
35
|
/>
|
|
22
36
|
);
|
|
37
|
+
}
|
|
38
|
+
Option 2: Handling Objects (The Pro Way)
|
|
39
|
+
Manage multiple inputs with a single state object. This uses the name prop to identify which field is changing.
|
|
40
|
+
|
|
41
|
+
JavaScript
|
|
42
|
+
import React, { useState } from 'react';
|
|
43
|
+
import SuperInput from '@devekene001/super-input';
|
|
44
|
+
|
|
45
|
+
function ProfileForm() {
|
|
46
|
+
const [user, setUser] = useState({
|
|
47
|
+
firstName: '',
|
|
48
|
+
lastName: '',
|
|
49
|
+
email: ''
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// One function to handle all inputs!
|
|
53
|
+
const handleChange = (value, name) => {
|
|
54
|
+
setUser(prev => ({
|
|
55
|
+
...prev,
|
|
56
|
+
[name]: value
|
|
57
|
+
}));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<form>
|
|
62
|
+
<SuperInput
|
|
63
|
+
label="First Name"
|
|
64
|
+
name="firstName"
|
|
65
|
+
value={user.firstName}
|
|
66
|
+
onChange={handleChange}
|
|
67
|
+
/>
|
|
68
|
+
<SuperInput
|
|
69
|
+
label="Last Name"
|
|
70
|
+
name="lastName"
|
|
71
|
+
value={user.lastName}
|
|
72
|
+
onChange={handleChange}
|
|
73
|
+
/>
|
|
74
|
+
<SuperInput
|
|
75
|
+
label="Email Address"
|
|
76
|
+
name="email"
|
|
77
|
+
type="email"
|
|
78
|
+
value={user.email}
|
|
79
|
+
onChange={handleChange}
|
|
80
|
+
error={!user.email.includes('@') ? "Please enter a valid email" : ""}
|
|
81
|
+
/>
|
|
82
|
+
</form>
|
|
83
|
+
);
|
|
23
84
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
export interface SuperInputProps {
|
|
4
|
+
/** The title of the input box */
|
|
4
5
|
label?: string;
|
|
6
|
+
/** The actual text inside the box */
|
|
5
7
|
value: string;
|
|
6
|
-
|
|
8
|
+
/** * The magic function!
|
|
9
|
+
* Now it sends back the VALUE and the NAME of the field
|
|
10
|
+
*/
|
|
11
|
+
onChange: (value: string, name?: string) => void;
|
|
12
|
+
/** Grey ghost text shown when empty */
|
|
7
13
|
placeholder?: string;
|
|
14
|
+
/** Red error message to show below the box */
|
|
8
15
|
error?: string;
|
|
16
|
+
/** What kind of keyboard/input to show */
|
|
9
17
|
type?: 'text' | 'password' | 'email' | 'number';
|
|
18
|
+
/** Is the box locked? */
|
|
10
19
|
disabled?: boolean;
|
|
20
|
+
/** Custom "paint" for the box */
|
|
11
21
|
style?: React.CSSProperties;
|
|
22
|
+
/** The 'Key' used to identify this input in an object (e.g., 'username') */
|
|
12
23
|
name?: string;
|
|
13
24
|
}
|
|
14
25
|
|