@hari_digitus/sms-ui-library 5.0.4 → 5.0.8
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 +0 -0
- package/dist/SideNavBar.cjs.js +1 -0
- package/dist/SideNavBar.es.js +1 -0
- package/dist/types/components/SideNavBar.d.ts +67 -0
- package/dist/types/index.d.ts +0 -13
- package/package.json +20 -24
- package/README.md +0 -798
- package/dist/form-controls.cjs.js +0 -214
- package/dist/form-controls.es.js +0 -11537
- package/dist/sms-ui-library.css +0 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +0 -19
- package/dist/types/components/DatePicker/DatePicker.d.ts +0 -30
- package/dist/types/components/DragDropUpload/DragDropUpload.d.ts +0 -26
- package/dist/types/components/InputFields/Input.d.ts +0 -14
- package/dist/types/components/MultiSelect/MultiSelect.d.ts +0 -22
- package/dist/types/components/RadioButton/RadioButton.d.ts +0 -15
- package/dist/types/components/Select/Select.d.ts +0 -41
- package/dist/types/components/SingleSelect/SingleSelect.d.ts +0 -24
- package/dist/types/components/TextArea/textarea.d.ts +0 -6
- package/dist/types/components/ToggleButton/ToggleSwitch.d.ts +0 -15
- package/dist/types/components/Tooltip/Tooltip.d.ts +0 -7
- package/dist/types/icons/icon.d.ts +0 -4
package/README.md
DELETED
|
@@ -1,798 +0,0 @@
|
|
|
1
|
-
To import CSS, use:
|
|
2
|
-
|
|
3
|
-
```js/ts
|
|
4
|
-
import "@digitus-fci-oa/form-controls/style.css";
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
# CustomDatePicker
|
|
8
|
-
|
|
9
|
-
## Single Date
|
|
10
|
-
|
|
11
|
-
```tsx
|
|
12
|
-
<CustomDatePicker
|
|
13
|
-
mode="date"
|
|
14
|
-
value={date}
|
|
15
|
-
onChangeSingle={setDate}
|
|
16
|
-
/>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Date & Time
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
<CustomDatePicker
|
|
25
|
-
mode="dateTime"
|
|
26
|
-
value={dateTime}
|
|
27
|
-
onChangeSingle={setDateTime}
|
|
28
|
-
/>
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Date Range
|
|
34
|
-
|
|
35
|
-
```tsx
|
|
36
|
-
<CustomDatePicker
|
|
37
|
-
mode="range"
|
|
38
|
-
fromDate={startDate}
|
|
39
|
-
endDate={endDate}
|
|
40
|
-
onRangeChange={(start, end) => {
|
|
41
|
-
setStartDate(start)
|
|
42
|
-
setEndDate(end)
|
|
43
|
-
}}
|
|
44
|
-
/>
|
|
45
|
-
```
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
# Checkbox
|
|
49
|
-
|
|
50
|
-
## Basic Checkbox
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
import { Checkbox } from "@digitus-fci-oa/form-controls";
|
|
54
|
-
import { useState } from "react";
|
|
55
|
-
|
|
56
|
-
export default function TestCheckbox() {
|
|
57
|
-
const [checked, setChecked] = useState(false);
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<Checkbox
|
|
61
|
-
label="Mandatory Field"
|
|
62
|
-
checked={checked}
|
|
63
|
-
onChange={setChecked}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
## Checkbox With Required
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
<Checkbox
|
|
75
|
-
label="Accept Terms & Conditions"
|
|
76
|
-
checked={checked}
|
|
77
|
-
onChange={setChecked}
|
|
78
|
-
required
|
|
79
|
-
/>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## Disabled Checkbox
|
|
85
|
-
|
|
86
|
-
```tsx
|
|
87
|
-
<Checkbox
|
|
88
|
-
label="Disabled Checkbox"
|
|
89
|
-
checked={true}
|
|
90
|
-
onChange={setChecked}
|
|
91
|
-
disabled
|
|
92
|
-
/>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## Checkbox With Test Id
|
|
98
|
-
|
|
99
|
-
```tsx
|
|
100
|
-
<Checkbox
|
|
101
|
-
label="Mandatory Field"
|
|
102
|
-
checked={checked}
|
|
103
|
-
onChange={setChecked}
|
|
104
|
-
dataTestId="mandatory-checkbox"
|
|
105
|
-
/>
|
|
106
|
-
```
|
|
107
|
-
npm install @digitus-fci-oa/form-controls
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
import { DragDropUpload } from "@digitus-fci-oa/form-controls";
|
|
111
|
-
import { Upload } from "lucide-react";
|
|
112
|
-
|
|
113
|
-
function App() {
|
|
114
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
115
|
-
|
|
116
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
117
|
-
const [isUploading, setIsUploading] = useState(false);
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<DragDropUpload
|
|
121
|
-
inputRef={inputRef}
|
|
122
|
-
isDragging={isDragging}
|
|
123
|
-
isUploading={isUploading}
|
|
124
|
-
disabled={false}
|
|
125
|
-
multiple={true}
|
|
126
|
-
accept=".pdf,.doc,.docx,.png,.jpg"
|
|
127
|
-
onFilesChange={(files) => {
|
|
128
|
-
console.log(files);
|
|
129
|
-
}}
|
|
130
|
-
onDrop={(e) => {
|
|
131
|
-
e.preventDefault();
|
|
132
|
-
setIsDragging(false);
|
|
133
|
-
}}
|
|
134
|
-
onDragOver={(e) => {
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
setIsDragging(true);
|
|
137
|
-
}}
|
|
138
|
-
onDragLeave={() => {
|
|
139
|
-
setIsDragging(false);
|
|
140
|
-
}}
|
|
141
|
-
onClick={() => inputRef.current?.click()}
|
|
142
|
-
title="Drag & Drop Files Here"
|
|
143
|
-
subtitle="or"
|
|
144
|
-
buttonText="Browse"
|
|
145
|
-
uploadingText="Uploading files..."
|
|
146
|
-
footerText="(File Size Max 10MB)"
|
|
147
|
-
icon={<Upload className="w-12 h-12" />}
|
|
148
|
-
buttonClassName="
|
|
149
|
-
!px-[25px]
|
|
150
|
-
!py-[6px]
|
|
151
|
-
!bg-[#1570EF]
|
|
152
|
-
text-white
|
|
153
|
-
hover:bg-[#0047a3]
|
|
154
|
-
"
|
|
155
|
-
/>
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
```
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## Props
|
|
163
|
-
|
|
164
|
-
| Prop | Type | Default | Description |
|
|
165
|
-
| ---------------- | ----------------------------- | ------------ | ------------------------------------ |
|
|
166
|
-
| `label` | `string` | `undefined` | Checkbox label text |
|
|
167
|
-
| `checked` | `boolean` | `false` | Controls checked state |
|
|
168
|
-
| `onChange` | `(checked: boolean) => void` | � | Triggered when checkbox changes |
|
|
169
|
-
| `disabled` | `boolean` | `false` | Disables checkbox |
|
|
170
|
-
| `id` | `string` | `undefined` | HTML id for checkbox |
|
|
171
|
-
| `className` | `string` | `""` | Custom wrapper class |
|
|
172
|
-
| `labelClassName` | `string` | `""` | Custom label class |
|
|
173
|
-
| `required` | `boolean` | `false` | Shows required asterisk |
|
|
174
|
-
| `dataTestId` | `string` | `undefined` | Test id for automation/testing |
|
|
175
|
-
| `onFilesChange` | `(files: FileList \| null) => void` | `undefined` | Callback triggered when files are
|
|
176
|
-
| `accept` | `string` | `"*"` | Allowed file types |
|
|
177
|
-
| `multiple` | `boolean` | `true` | Allows multiple file selection |
|
|
178
|
-
| `disabled` | `boolean` | `false` | Disables uploader interactions |
|
|
179
|
-
| `isUploading` | `boolean` | `false` | Shows uploading state |
|
|
180
|
-
| `title` | `string` | `"Drag & Drop Files Here"` | Main upload area itle |
|
|
181
|
-
| `subtitle` | `string` | `"or"` | Subtitle text below title |
|
|
182
|
-
| `buttonText` |`string` | `"Browse"` | Browse button text |
|
|
183
|
-
| `uploadingText` | `string` | `"Uploading files..."` | Uploading message text |
|
|
184
|
-
| `footerText` | `string` | `"(File Size Max 10MB)"` | Footer/helper text |
|
|
185
|
-
| `icon` | `React.ReactNode` | `undefined` | Custom upload icon |
|
|
186
|
-
| `containerClassName` | `string` | `""` | Custom wrapper/container class |
|
|
187
|
-
| `dropZoneClassName` | `string` | `""` | Custom dropzone class |
|
|
188
|
-
| `buttonClassName` | `string` | `""` | Custom browse button class |
|
|
189
|
-
| `inputId` | `string` | `"file-upload"` | Custom input element id |
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
# MultiSelect Component
|
|
194
|
-
|
|
195
|
-
A lightweight, accessible multi-select dropdown built with React and Tailwind CSS.
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## Usage
|
|
200
|
-
|
|
201
|
-
```tsx
|
|
202
|
-
import { MultiSelect } from "./components/MultiSelect";
|
|
203
|
-
|
|
204
|
-
const options = [
|
|
205
|
-
{ label: "Apple", value: "apple" },
|
|
206
|
-
{ label: "Banana", value: "banana" },
|
|
207
|
-
{ label: "Cherry", value: "cherry" },
|
|
208
|
-
];
|
|
209
|
-
|
|
210
|
-
function App() {
|
|
211
|
-
const [selected, setSelected] = React.useState<string[]>([]);
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
<MultiSelect
|
|
215
|
-
options={options}
|
|
216
|
-
value={selected}
|
|
217
|
-
onChange={setSelected}
|
|
218
|
-
placeholder="Select fruits..."
|
|
219
|
-
/>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
```
|
|
225
|
-
interface TooltipProps {
|
|
226
|
-
|
|
227
|
-
value: string;
|
|
228
|
-
icon?: React.ReactNode;
|
|
229
|
-
}
|
|
230
|
-
import Tooltip from "@digitus-fci-oa/form-controls";
|
|
231
|
-
|
|
232
|
-
<Tooltip
|
|
233
|
-
value="View Questionnaire"
|
|
234
|
-
icon={
|
|
235
|
-
<Eye
|
|
236
|
-
size={16}
|
|
237
|
-
className="cursor-pointer text-blue-600"
|
|
238
|
-
/>
|
|
239
|
-
}
|
|
240
|
-
/>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
---
|
|
246
|
-
|
|
247
|
-
## Props
|
|
248
|
-
|
|
249
|
-
| Prop | Type | Required | Default | Description |
|
|
250
|
-
|---------------|-------------------------------|----------|----------------|------------------------------------------|
|
|
251
|
-
| `options` | `Option[]` | ✅ | — | List of options to display |
|
|
252
|
-
| `value` | `string[]` | ✅ | — | Currently selected values |
|
|
253
|
-
| `onChange` | `(value: string[]) => void` | ✅ | — | Callback when selection changes |
|
|
254
|
-
| `placeholder` | `string` | ❌ | `"Select..."` | Text shown when nothing is selected |
|
|
255
|
-
| `error` | `string` | ❌ | — | Error message shown below the dropdown |
|
|
256
|
-
value="View Questionnaire"| `string` | | text
|
|
257
|
-
|
|
258
|
-
### Option Type
|
|
259
|
-
|
|
260
|
-
```ts
|
|
261
|
-
interface Option {
|
|
262
|
-
label: string; // Display text
|
|
263
|
-
value: string; // Underlying value
|
|
264
|
-
}
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
## Features
|
|
270
|
-
|
|
271
|
-
- Multi-selection with toggle behavior (click to select/deselect)
|
|
272
|
-
- Selected labels shown as comma-separated text in the trigger button
|
|
273
|
-
- Dropdown opens/closes on button click
|
|
274
|
-
- Red border and error message on validation failure via `error` prop
|
|
275
|
-
- Scrollable list capped at `max-h-60`
|
|
276
|
-
- Checkmark indicator on selected items
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
## Error State
|
|
281
|
-
|
|
282
|
-
Pass an `error` string to show validation feedback:
|
|
283
|
-
|
|
284
|
-
```tsx
|
|
285
|
-
<MultiSelect
|
|
286
|
-
options={options}
|
|
287
|
-
value={selected}
|
|
288
|
-
onChange={setSelected}
|
|
289
|
-
error="Please select at least one option."
|
|
290
|
-
/>
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
---
|
|
294
|
-
|
|
295
|
-
## Close on Outside Click
|
|
296
|
-
|
|
297
|
-
The dropdown does not close automatically on outside click. Add this to your component if needed:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
## Dependencies
|
|
305
|
-
|
|
306
|
-
| Package | Purpose |
|
|
307
|
-
|-----------------|--------------------------------|
|
|
308
|
-
| `lucide-react` | Icons (`ChevronDown`, `Check`) |
|
|
309
|
-
| `tailwindcss` | Utility-based styling |
|
|
310
|
-
| `clsx` / `tailwind-merge` | `cn()` utility for class merging |
|
|
311
|
-
|
|
312
|
-
---
|
|
313
|
-
|
|
314
|
-
## File Structure
|
|
315
|
-
|
|
316
|
-
```
|
|
317
|
-
src/
|
|
318
|
-
├── components/
|
|
319
|
-
│ └── MultiSelect.tsx ← Component file
|
|
320
|
-
└── lib/
|
|
321
|
-
└── utils.ts ← cn() utility
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
# Textarea Component
|
|
329
|
-
|
|
330
|
-
A resizable textarea input built with React and Tailwind CSS, with built-in error state support.
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
## Usage
|
|
335
|
-
|
|
336
|
-
```tsx
|
|
337
|
-
import { Textarea } from "./components/Textarea";
|
|
338
|
-
|
|
339
|
-
function App() {
|
|
340
|
-
const [value, setValue] = React.useState("");
|
|
341
|
-
|
|
342
|
-
return (
|
|
343
|
-
<Textarea
|
|
344
|
-
value={value}
|
|
345
|
-
onChange={(e) => setValue(e.target.value)}
|
|
346
|
-
placeholder="Enter your text here..."
|
|
347
|
-
/>
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
---
|
|
353
|
-
|
|
354
|
-
## Props
|
|
355
|
-
|
|
356
|
-
| Prop | Type | Required | Default | Description |
|
|
357
|
-
|-------------|-----------|----------|------------------------------|----------------------------------------------------------|
|
|
358
|
-
| `error` | `string` | ❌ | — | Error message displayed below the textarea |
|
|
359
|
-
| `className` | `string` | ❌ | — | Additional Tailwind classes to merge |
|
|
360
|
-
| `ref` | `Ref` | ❌ | — | Forwarded ref to the underlying `<textarea>` element |
|
|
361
|
-
| ...rest | `React.TextareaHTMLAttributes` | ❌ | — | All standard HTML textarea attributes (`onChange`, `disabled`, `rows`, etc.) |
|
|
362
|
-
|
|
363
|
-
> Extends all native `React.TextareaHTMLAttributes<HTMLTextAreaElement>` props.
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
## Features
|
|
368
|
-
|
|
369
|
-
- Forwarded ref support via `React.forwardRef`
|
|
370
|
-
- Built-in error state with red border and error message
|
|
371
|
-
- Fixed height of `4.5rem` with `resize-none` by default
|
|
372
|
-
- Custom `className` support with `cn()` merge utility
|
|
373
|
-
- Default placeholder text
|
|
374
|
-
|
|
375
|
-
---
|
|
376
|
-
|
|
377
|
-
## Error State
|
|
378
|
-
|
|
379
|
-
Pass an `error` string to highlight the field and show a message:
|
|
380
|
-
|
|
381
|
-
```tsx
|
|
382
|
-
<Textarea
|
|
383
|
-
value={value}
|
|
384
|
-
onChange={(e) => setValue(e.target.value)}
|
|
385
|
-
error="This field is required."
|
|
386
|
-
/>
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
---
|
|
390
|
-
|
|
391
|
-
## With React Hook Form
|
|
392
|
-
|
|
393
|
-
```tsx
|
|
394
|
-
import { useForm } from "react-hook-form";
|
|
395
|
-
import { Textarea } from "./components/Textarea";
|
|
396
|
-
|
|
397
|
-
function Form() {
|
|
398
|
-
const { register, formState: { errors } } = useForm();
|
|
399
|
-
|
|
400
|
-
return (
|
|
401
|
-
<Textarea
|
|
402
|
-
{...register("description", { required: "Description is required" })}
|
|
403
|
-
error={errors.description?.message}
|
|
404
|
-
/>
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
---
|
|
410
|
-
|
|
411
|
-
## Customizing Height
|
|
412
|
-
|
|
413
|
-
Override the default height using `className`:
|
|
414
|
-
|
|
415
|
-
```tsx
|
|
416
|
-
<Textarea className="h-32" /> {/* taller */}
|
|
417
|
-
<Textarea className="h-20" /> {/* shorter */}
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
---
|
|
421
|
-
|
|
422
|
-
## Dependencies
|
|
423
|
-
|
|
424
|
-
| Package | Purpose |
|
|
425
|
-
|---------------------------|----------------------------------|
|
|
426
|
-
| `react` | `forwardRef`, `TextareaHTMLAttributes` |
|
|
427
|
-
| `tailwindcss` | Utility-based styling |
|
|
428
|
-
| `clsx` / `tailwind-merge` | `cn()` utility for class merging |
|
|
429
|
-
|
|
430
|
-
---
|
|
431
|
-
|
|
432
|
-
## File Structure
|
|
433
|
-
|
|
434
|
-
```
|
|
435
|
-
src/
|
|
436
|
-
├── components/
|
|
437
|
-
│ └── Textarea.tsx ← Component file
|
|
438
|
-
└── lib/
|
|
439
|
-
└── utils.ts ← cn() utility
|
|
440
|
-
```
|
|
441
|
-
## Toggle Switch
|
|
442
|
-
|
|
443
|
-
## Usage
|
|
444
|
-
import { ToggleSwitch } from "@digitus-fci-oa/form-controls";
|
|
445
|
-
import { useState } from "react";
|
|
446
|
-
|
|
447
|
-
export default function TestToggleSwitch() {
|
|
448
|
-
const [enabled, setEnabled] = useState(false);
|
|
449
|
-
|
|
450
|
-
return (
|
|
451
|
-
<ToggleSwitch
|
|
452
|
-
checked={enabled}
|
|
453
|
-
onChange={setEnabled}
|
|
454
|
-
label={enabled ? "Yes" : "No"}
|
|
455
|
-
/>
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
## Props
|
|
460
|
-
|
|
461
|
-
| Prop | Type | Default | Description |
|
|
462
|
-
| ---------- | ---------------------------- | ----------- | ----------------------------------- |
|
|
463
|
-
| `checked` | `boolean` | `false` | Controls toggle state |
|
|
464
|
-
| `onChange` | `(checked: boolean) => void` | — | Triggered when toggle state changes |
|
|
465
|
-
| `disabled` | `boolean` | `false` | Disables toggle interaction |
|
|
466
|
-
| `label` | `string` | `undefined` | Optional label beside toggle |
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
# RadioButton
|
|
470
|
-
|
|
471
|
-
import { Radio } from "@digitus-fci-oa/form-controls";
|
|
472
|
-
import { useState } from "react";
|
|
473
|
-
|
|
474
|
-
export default function TestRadio() {
|
|
475
|
-
const [selected, setSelected] = useState("yes");
|
|
476
|
-
|
|
477
|
-
return (
|
|
478
|
-
<div className="flex gap-4">
|
|
479
|
-
|
|
480
|
-
<Radio
|
|
481
|
-
label="Yes"
|
|
482
|
-
name="approval"
|
|
483
|
-
value="yes"
|
|
484
|
-
checked={selected === "yes"}
|
|
485
|
-
onChange={setSelected}
|
|
486
|
-
/>
|
|
487
|
-
|
|
488
|
-
<Radio
|
|
489
|
-
label="No"
|
|
490
|
-
name="approval"
|
|
491
|
-
value="no"
|
|
492
|
-
checked={selected === "no"}
|
|
493
|
-
onChange={setSelected}
|
|
494
|
-
/>
|
|
495
|
-
|
|
496
|
-
</div>
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
## Props
|
|
501
|
-
|
|
502
|
-
| Prop | Type | Default | Description |
|
|
503
|
-
| ---------- | ------------------------- | ----------- | ------------------------------------- |
|
|
504
|
-
| `label` | `string` | `undefined` | Radio label text |
|
|
505
|
-
| `name` | `string` | — | Shared group name for radio selection |
|
|
506
|
-
| `value` | `string` | — | Value of radio option |
|
|
507
|
-
| `checked` | `boolean` | `false` | Controls selected state |
|
|
508
|
-
| `onChange` | `(value: string) => void` | — | Triggered when option changes |
|
|
509
|
-
| `disabled` | `boolean` | `false` | Disables radio interaction |
|
|
510
|
-
|
|
511
|
-
-----------------------------------------------Input field Latest-------------------------------
|
|
512
|
-
|
|
513
|
-
# Input Component
|
|
514
|
-
|
|
515
|
-
A flexible, fully controlled input component built with React and inline styles — no Tailwind dependency in the consuming app.
|
|
516
|
-
|
|
517
|
-
---
|
|
518
|
-
|
|
519
|
-
## Installation
|
|
520
|
-
|
|
521
|
-
```bash
|
|
522
|
-
npm i @hari_digitus/sms-ui-library
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
## Import
|
|
526
|
-
|
|
527
|
-
```tsx
|
|
528
|
-
import { Input } from "@hari_digitus/sms-ui-library";
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
---
|
|
532
|
-
|
|
533
|
-
## Props
|
|
534
|
-
|
|
535
|
-
| Prop | Type | Default | Description |
|
|
536
|
-
|---|---|---|---|
|
|
537
|
-
| `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Controls height and font size |
|
|
538
|
-
| `error` | `string` | `undefined` | Shows red border and red error message below input |
|
|
539
|
-
| `hint` | `string` | `undefined` | Shows gray hint text below input (only shown when no error) |
|
|
540
|
-
| `label` | `string` | `undefined` | Label rendered above the input |
|
|
541
|
-
| `required` | `boolean` | `false` | Appends red `*` to the label |
|
|
542
|
-
| `leadingIcon` | `React.ReactNode` | `undefined` | Icon rendered on the left side of the input |
|
|
543
|
-
| `trailingIcon` | `React.ReactNode` | `undefined` | Icon rendered on the right side of the input |
|
|
544
|
-
| `regex` | `RegExp` | `undefined` | Blocks characters that don't match the pattern while typing |
|
|
545
|
-
| `onRegexFail` | `(value: string) => void` | `undefined` | Called when the typed value fails the regex test |
|
|
546
|
-
| `placeholder` | `string` | `"Enter text.."` | Placeholder text (font-weight 400, color #6F778E) |
|
|
547
|
-
| `type` | `string` | `"text"` | HTML input type: `"text"`, `"password"`, `"email"`, `"number"`, `"tel"` etc. |
|
|
548
|
-
| `disabled` | `boolean` | `false` | Disables the input — gray background, not-allowed cursor, no caret |
|
|
549
|
-
| `readOnly` | `boolean` | `false` | Makes input read-only — gray background, not-allowed cursor, no caret |
|
|
550
|
-
| `value` | `string` | `undefined` | Controlled value |
|
|
551
|
-
| `defaultValue` | `string` | `undefined` | Uncontrolled default value |
|
|
552
|
-
| `onChange` | `(e: ChangeEvent<HTMLInputElement>) => void` | `undefined` | Change handler — called only when value passes regex (if set) |
|
|
553
|
-
| `onBlur` | `(e: FocusEvent<HTMLInputElement>) => void` | `undefined` | Blur handler |
|
|
554
|
-
| `onFocus` | `(e: FocusEvent<HTMLInputElement>) => void` | `undefined` | Focus handler |
|
|
555
|
-
| `onKeyDown` | `(e: KeyboardEvent<HTMLInputElement>) => void` | `undefined` | Key down handler |
|
|
556
|
-
| `onKeyUp` | `(e: KeyboardEvent<HTMLInputElement>) => void` | `undefined` | Key up handler |
|
|
557
|
-
| `maxLength` | `number` | `undefined` | Maximum number of characters allowed |
|
|
558
|
-
| `minLength` | `number` | `undefined` | Minimum number of characters required |
|
|
559
|
-
| `min` | `number` | `undefined` | Minimum value (for `type="number"`) |
|
|
560
|
-
| `max` | `number` | `undefined` | Maximum value (for `type="number"`) |
|
|
561
|
-
| `step` | `number` | `undefined` | Step value (for `type="number"`) |
|
|
562
|
-
| `pattern` | `string` | `undefined` | HTML pattern attribute for form validation |
|
|
563
|
-
| `autoComplete` | `string` | `undefined` | Browser autocomplete hint e.g. `"off"`, `"email"` |
|
|
564
|
-
| `autoFocus` | `boolean` | `false` | Autofocus on mount |
|
|
565
|
-
| `spellCheck` | `boolean` | `undefined` | Enable or disable spellcheck |
|
|
566
|
-
| `id` | `string` | `undefined` | Custom id — auto-generated from label if not provided |
|
|
567
|
-
| `name` | `string` | `undefined` | Input name for form submission |
|
|
568
|
-
| `tabIndex` | `number` | `undefined` | Tab order |
|
|
569
|
-
| `style` | `React.CSSProperties` | `undefined` | Override any inline style (border, height, background etc.) |
|
|
570
|
-
| `className` | `string` | `undefined` | Additional CSS class names |
|
|
571
|
-
|
|
572
|
-
---
|
|
573
|
-
|
|
574
|
-
## Size Reference
|
|
575
|
-
|
|
576
|
-
| `inputSize` | Height | Font Size |
|
|
577
|
-
|---|---|---|
|
|
578
|
-
| `sm` | 34px | 12px |
|
|
579
|
-
| `md` | 40px | 14px |
|
|
580
|
-
| `lg` | 48px | 16px |
|
|
581
|
-
|
|
582
|
-
---
|
|
583
|
-
|
|
584
|
-
## Examples
|
|
585
|
-
|
|
586
|
-
### Basic
|
|
587
|
-
|
|
588
|
-
```tsx
|
|
589
|
-
<Input placeholder="Enter text" />
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
### With Error
|
|
593
|
-
|
|
594
|
-
```tsx
|
|
595
|
-
<Input
|
|
596
|
-
placeholder="Enter department name"
|
|
597
|
-
error="This field is required"
|
|
598
|
-
/>
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
### With Hint
|
|
602
|
-
|
|
603
|
-
```tsx
|
|
604
|
-
<Input
|
|
605
|
-
placeholder="Enter email"
|
|
606
|
-
hint="We'll never share your email"
|
|
607
|
-
/>
|
|
608
|
-
```
|
|
609
|
-
|
|
610
|
-
### With Label
|
|
611
|
-
|
|
612
|
-
```tsx
|
|
613
|
-
<Input
|
|
614
|
-
label="Department Name"
|
|
615
|
-
required
|
|
616
|
-
placeholder="Enter department name"
|
|
617
|
-
/>
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
### With Label + Error
|
|
621
|
-
|
|
622
|
-
```tsx
|
|
623
|
-
<Input
|
|
624
|
-
label="Department Name"
|
|
625
|
-
required
|
|
626
|
-
placeholder="Enter department name"
|
|
627
|
-
error="This field is required"
|
|
628
|
-
/>
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
### Sizes
|
|
632
|
-
|
|
633
|
-
```tsx
|
|
634
|
-
<Input inputSize="sm" placeholder="Small input" />
|
|
635
|
-
<Input inputSize="md" placeholder="Medium input" />
|
|
636
|
-
<Input inputSize="lg" placeholder="Large input" />
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
### Disabled
|
|
640
|
-
|
|
641
|
-
```tsx
|
|
642
|
-
<Input placeholder="Disabled input" disabled />
|
|
643
|
-
```
|
|
644
|
-
|
|
645
|
-
### Read Only
|
|
646
|
-
|
|
647
|
-
```tsx
|
|
648
|
-
<Input value="Read only value" readOnly />
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
### Password
|
|
652
|
-
|
|
653
|
-
```tsx
|
|
654
|
-
<Input type="password" placeholder="Enter password" />
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
### With Leading Icon
|
|
658
|
-
|
|
659
|
-
```tsx
|
|
660
|
-
import { SearchIcon } from "lucide-react";
|
|
661
|
-
|
|
662
|
-
<Input
|
|
663
|
-
placeholder="Search..."
|
|
664
|
-
leadingIcon={<SearchIcon size={16} />}
|
|
665
|
-
/>
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
### With Trailing Icon
|
|
669
|
-
|
|
670
|
-
```tsx
|
|
671
|
-
import { EyeIcon } from "lucide-react";
|
|
672
|
-
|
|
673
|
-
<Input
|
|
674
|
-
type="password"
|
|
675
|
-
placeholder="Enter password"
|
|
676
|
-
trailingIcon={<EyeIcon size={16} />}
|
|
677
|
-
/>
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-
### Numbers Only (Regex)
|
|
681
|
-
|
|
682
|
-
```tsx
|
|
683
|
-
const [value, setValue] = useState("");
|
|
684
|
-
const [error, setError] = useState("");
|
|
685
|
-
|
|
686
|
-
<Input
|
|
687
|
-
placeholder="Enter number"
|
|
688
|
-
value={value}
|
|
689
|
-
regex={/^\d+$/}
|
|
690
|
-
onRegexFail={() => setError("Only numbers allowed")}
|
|
691
|
-
onChange={(e) => {
|
|
692
|
-
setValue(e.target.value);
|
|
693
|
-
setError("");
|
|
694
|
-
}}
|
|
695
|
-
error={error}
|
|
696
|
-
/>
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
### Letters Only (Regex)
|
|
700
|
-
|
|
701
|
-
```tsx
|
|
702
|
-
<Input
|
|
703
|
-
placeholder="Enter name"
|
|
704
|
-
regex={/^[a-zA-Z\s]+$/}
|
|
705
|
-
onRegexFail={() => setError("Only letters allowed")}
|
|
706
|
-
/>
|
|
707
|
-
```
|
|
708
|
-
|
|
709
|
-
### Email with Regex
|
|
710
|
-
|
|
711
|
-
```tsx
|
|
712
|
-
const [value, setValue] = useState("");
|
|
713
|
-
const [error, setError] = useState("");
|
|
714
|
-
|
|
715
|
-
const isValidEmail = (val: string) =>
|
|
716
|
-
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val);
|
|
717
|
-
|
|
718
|
-
<Input
|
|
719
|
-
placeholder="Enter email"
|
|
720
|
-
value={value}
|
|
721
|
-
regex={/^[a-zA-Z0-9._%+\-@]*$/}
|
|
722
|
-
onRegexFail={() => setError("Invalid characters")}
|
|
723
|
-
onChange={(e) => {
|
|
724
|
-
setValue(e.target.value);
|
|
725
|
-
setError("");
|
|
726
|
-
}}
|
|
727
|
-
onBlur={() => {
|
|
728
|
-
if (value && !isValidEmail(value)) {
|
|
729
|
-
setError("Please enter a valid email");
|
|
730
|
-
}
|
|
731
|
-
}}
|
|
732
|
-
error={error}
|
|
733
|
-
/>
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
### Phone Number (Max 10 digits)
|
|
737
|
-
|
|
738
|
-
```tsx
|
|
739
|
-
<Input
|
|
740
|
-
placeholder="Enter phone number"
|
|
741
|
-
regex={/^\d{0,10}$/}
|
|
742
|
-
onRegexFail={() => setError("Maximum 10 digits allowed")}
|
|
743
|
-
type="tel"
|
|
744
|
-
/>
|
|
745
|
-
```
|
|
746
|
-
|
|
747
|
-
### Style Override
|
|
748
|
-
|
|
749
|
-
```tsx
|
|
750
|
-
{/* Custom border color */}
|
|
751
|
-
<Input
|
|
752
|
-
placeholder="Enter text"
|
|
753
|
-
style={{ border: "1px solid #F79009" }}
|
|
754
|
-
/>
|
|
755
|
-
|
|
756
|
-
{/* Custom height */}
|
|
757
|
-
<Input
|
|
758
|
-
placeholder="Enter text"
|
|
759
|
-
style={{ height: "56px" }}
|
|
760
|
-
/>
|
|
761
|
-
|
|
762
|
-
{/* Custom background */}
|
|
763
|
-
<Input
|
|
764
|
-
placeholder="Enter text"
|
|
765
|
-
style={{ backgroundColor: "#F0F4FF" }}
|
|
766
|
-
/>
|
|
767
|
-
```
|
|
768
|
-
|
|
769
|
-
### Max Length
|
|
770
|
-
|
|
771
|
-
```tsx
|
|
772
|
-
<Input
|
|
773
|
-
placeholder="Enter text"
|
|
774
|
-
maxLength={50}
|
|
775
|
-
/>
|
|
776
|
-
```
|
|
777
|
-
|
|
778
|
-
### Controlled Input
|
|
779
|
-
|
|
780
|
-
```tsx
|
|
781
|
-
const [value, setValue] = useState("");
|
|
782
|
-
|
|
783
|
-
<Input
|
|
784
|
-
value={value}
|
|
785
|
-
onChange={(e) => setValue(e.target.value)}
|
|
786
|
-
placeholder="Controlled input"
|
|
787
|
-
/>
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
---
|
|
791
|
-
|
|
792
|
-
## Styling Notes
|
|
793
|
-
|
|
794
|
-
- All styles are applied via inline `style` — no Tailwind dependency in the consuming app
|
|
795
|
-
- `style` prop is spread last so consumer overrides always win
|
|
796
|
-
- Typed text is `font-weight: 500`, placeholder is `font-weight: 400`
|
|
797
|
-
- `readOnly` and `disabled` both apply `#F3F3F3` background, `not-allowed` cursor, and hidden caret
|
|
798
|
-
- Error border `#FDA29B` and error text `#F04438` are applied automatically when `error` prop is passed
|