@hari_digitus/sms-ui-library 5.0.1 → 5.0.3

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
@@ -508,3 +508,291 @@ export default function TestRadio() {
508
508
  | `onChange` | `(value: string) => void` | — | Triggered when option changes |
509
509
  | `disabled` | `boolean` | `false` | Disables radio interaction |
510
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