11import { InputTypes } from "../constants/input-types" ;
22import { InputProperties } from "../interfaces/input-properties" ;
3+ import { Icons } from "../constants/icons" ;
4+ import { IconSizes } from "../constants/icon-sizes" ;
5+ import { Icon } from "../icons/icon" ;
36import React from "react" ;
7+ import "./text-input.scss" ;
48
59// -----------------------------------------------------------------------------------------
610// #region Interfaces
711// -----------------------------------------------------------------------------------------
812
913export interface TextInputProps extends InputProperties {
14+ icon ?: Icons ;
15+ iconSize ?: IconSizes ;
1016 id : string ;
1117 maxLength ?: number ;
1218 name ?: string ;
@@ -24,9 +30,13 @@ export interface TextInputProps extends InputProperties {
2430// -----------------------------------------------------------------------------------------
2531
2632const TextInput : React . FC < TextInputProps > = ( props : TextInputProps ) => {
33+ let classNames : string [ ] = [ "c-text-input" ] ;
34+
2735 const {
2836 ariaLabelledBy,
2937 disabled,
38+ icon,
39+ iconSize,
3040 id,
3141 name,
3242 onChange,
@@ -37,19 +47,29 @@ const TextInput: React.FC<TextInputProps> = (props: TextInputProps) => {
3747
3848 const maxLength = props . maxLength != null ? props . maxLength : 20 ;
3949
50+ if ( icon ) {
51+ classNames . push ( "-icon" ) ;
52+ }
53+
4054 return (
41- < input
42- aria-labelledby = { ariaLabelledBy }
43- data-testid = { testId }
44- disabled = { disabled }
45- id = { id }
46- placeholder = { placeholder }
47- maxLength = { maxLength }
48- name = { name }
49- onChange = { onChange }
50- type = { InputTypes . Text }
51- value = { value }
52- />
55+ < div className = { classNames . join ( " " ) } >
56+ { // if
57+ icon &&
58+ < Icon type = { icon } size = { iconSize ?? IconSizes . Large } />
59+ }
60+ < input
61+ aria-labelledby = { ariaLabelledBy }
62+ data-testid = { testId }
63+ disabled = { disabled }
64+ id = { id }
65+ placeholder = { placeholder }
66+ maxLength = { maxLength }
67+ name = { name }
68+ onChange = { onChange }
69+ type = { InputTypes . Text }
70+ value = { value }
71+ />
72+ </ div >
5373 ) ;
5474} ;
5575
0 commit comments