@devekene001/super-input 0.0.4 → 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 CHANGED
@@ -1,23 +1,105 @@
1
- # My Super Input
1
+ @devekene001/super-input
2
+ A professional, universal, and highly flexible text input component for React.
2
3
 
3
- A professional, reusable text input for React.
4
+ 🚀 Features
5
+ Universal: Built for React (Web) and React Native (Mobile).
4
6
 
5
- ## How to use it:
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
- ```javascript
10
- import SuperInput from 'my-super-input';
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] = React.useState('');
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 here..."
33
+ onChange={(val) => setName(val)}
34
+ placeholder="Type your name..."
21
35
  />
22
36
  );
23
- }
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
+ import './App.css';
45
+
46
+ function App() {
47
+ // 1. Setup an object to hold all our data
48
+ const [formData, setFormData] = useState({
49
+ firstName: '',
50
+ lastName: '',
51
+ email: ''
52
+ });
53
+
54
+ // 2. The "Universal" handler
55
+ // Our SuperInput now sends (value, name)
56
+ const handleInputChange = (value, name) => {
57
+ setFormData(prev => ({
58
+ ...prev,
59
+ [name]: value // This updates only the field that changed!
60
+ }));
61
+ };
62
+
63
+ return (
64
+ <!-- <div style={{ padding: '40px', width: "40%", fontFamily: 'Arial' }}> -->
65
+ <!-- <h1>Registration Form</h1> -->
66
+
67
+ {/* Input for First Name */}
68
+ <SuperInput
69
+ label="First Name"
70
+ name="firstName" // <--- The ID tag
71
+ value={formData.firstName}
72
+ onChange={handleInputChange}
73
+ placeholder="Enter first name"
74
+ />
75
+
76
+ {/* Input for Last Name */}
77
+ <SuperInput
78
+ label="Last Name"
79
+ name="lastName" // <--- The ID tag
80
+ value={formData.lastName}
81
+ onChange={handleInputChange}
82
+ placeholder="Enter last name"
83
+ />
84
+
85
+ {/* Input for Email with a basic error check */}
86
+ <SuperInput
87
+ label="Email Address"
88
+ name="email" // <--- The ID tag
89
+ type="email"
90
+ value={formData.email}
91
+ onChange={handleInputChange}
92
+ placeholder="example@mail.com"
93
+ error={formData.email && !formData.email.includes('@') ? "Invalid email address" : ""}
94
+ />
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>
102
+ );
103
+ }
104
+
105
+ export default App;
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
- onChange: (value: string) => void;
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
 
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
- _onChange = _ref.onChange,
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
  ,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devekene001/super-input",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A very fancy and professional text input for React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",