File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export interface Props {
2+ /** Unique id for input */
3+ id : string ;
4+ /** Label text */
5+ label : string ;
6+ /** Name attribute */
7+ name : string ;
8+ /** Input value */
9+ value ?: string ;
10+ /** Input type (text, email, password, etc.) */
11+ type ?: string ;
12+ /** Placeholder text */
13+ placeholder ?: string ;
14+ /** Help text below input */
15+ helpText ?: string ;
16+ /** Error text */
17+ errorText ?: string ;
18+ /** Required field */
19+ required ?: boolean ;
20+ /** Disabled state */
21+ disabled ?: boolean ;
22+ /** Optional class */
23+ className ?: string ;
24+ }
25+
26+ const {
27+ id ,
28+ label ,
29+ name ,
30+ value = " " ,
31+ type = " text" ,
32+ placeholder ,
33+ helpText ,
34+ errorText ,
35+ required ,
36+ disabled ,
37+ className ,
38+ } = Astro.props;
39+
40+ const helpId = helpText ? `${ id } -help` : undefined;
41+ const errorId = errorText ? `${ id } -error` : undefined;
42+ const describedBy = [errorId, helpId].filter(Boolean).join(" ") || undefined;
43+ ---
44+
45+ <div class ={ className } >
46+ <label for ={ id } >
47+ { label }
48+ { required && <span aria-hidden = " true" > *</span >}
49+ </label >
50+
51+ { errorText && (
52+ <p id = { errorId } role = " alert" >
53+ { errorText }
54+ </p >
55+ )}
56+
57+ { helpText && <p id = { helpId } >{ helpText } </p >}
58+
59+ <input
60+ id ={ id }
61+ name ={ name }
62+ type ={ type }
63+ value ={ value }
64+ placeholder ={ placeholder }
65+ required ={ required }
66+ disabled ={ disabled }
67+ aria-describedby ={ describedBy }
68+ />
69+ </div >
You can’t perform that action at this time.
0 commit comments