1
1
import { LitElement , html } from 'lit' ;
2
2
import { classMap } from 'lit/directives/class-map.js' ;
3
- import { customElement , property } from 'lit/decorators.js' ;
3
+ import { customElement , property , state } from 'lit/decorators.js' ;
4
4
import { styleCustom } from './index.css' ;
5
5
import { form } from '../../foundation/semantic-tokens/form.css' ;
6
6
import { InputTypes , FormSizesType } from '../../globals/types' ;
7
7
import { BlrFormLabel } from '../form-label' ;
8
8
import { BlrFormHint } from '../form-hint' ;
9
9
import { IconType } from '@boiler/icons' ;
10
+ import { iconButton } from '../../foundation/component-tokens/action.css' ;
10
11
11
12
@customElement ( 'blr-text-input' )
12
13
export class BlrTextInput extends LitElement {
13
- static styles = [ styleCustom , form ] ;
14
+ static styles = [ styleCustom , form , iconButton ] ;
14
15
15
16
@property ( ) textInputId ! : string ;
16
17
@property ( ) type : InputTypes = 'text' ;
@@ -30,17 +31,21 @@ export class BlrTextInput extends LitElement {
30
31
@property ( ) hint ?: string ;
31
32
@property ( ) hintIcon ?: IconType ;
32
33
34
+ @state ( ) protected currentType : InputTypes = this . type ;
35
+
33
36
toggleInputType ( ) {
34
- this . type = this . type === 'password' ? 'text' : 'password' ;
37
+ this . currentType = this . currentType === 'password' ? 'text' : 'password' ;
35
38
}
36
39
37
40
render ( ) {
41
+ const wasInitialPasswordField = Boolean ( this . type === 'password' ) ;
42
+
38
43
const classes = classMap ( {
39
44
[ `${ this . size } ` ] : this . size || 'md' ,
40
45
[ `disabled` ] : this . disabled || false ,
41
46
} ) ;
42
47
43
- const inputclasses = classMap ( {
48
+ const inputClasses = classMap ( {
44
49
[ `error` ] : this . hasError || false ,
45
50
[ `error-input` ] : this . hasError || false ,
46
51
[ `${ this . size } ` ] : this . size || 'md' ,
@@ -50,9 +55,9 @@ export class BlrTextInput extends LitElement {
50
55
< div class ="blr-input ${ classes } ">
51
56
${ BlrFormLabel ( { labelText : this . label } ) }
52
57
< input
53
- class ="blr-form-element ${ inputclasses } "
58
+ class ="blr-form-element ${ inputClasses } "
54
59
id =${ this . textInputId }
55
- type ="${ this . type } "
60
+ type ="${ this . currentType } "
56
61
value="${ this . value } "
57
62
placeholder="${ this . placeholder } "
58
63
?disabled="${ this . disabled } "
@@ -64,12 +69,17 @@ export class BlrTextInput extends LitElement {
64
69
pattern="${ this . pattern } "
65
70
hasError="${ this . hasError } "
66
71
/>
67
- < blr-icon
68
- class ="blr-input-icon ${ inputclasses } "
69
- @click =${ this . toggleInputType }
70
- name ="${ this . type . includes ( 'password' ) ? 'blrEyeSm' : this . hasError ? 'blrFlagSm' : this . hintIcon } "
71
- aria-hidden
72
- > </ blr-icon >
72
+
73
+ ${ wasInitialPasswordField
74
+ ? html `< blr-icon
75
+ class ="blr-input-icon "
76
+ @click =${ this . toggleInputType }
77
+ icon ="${ this . currentType . includes ( 'password' ) ? 'blrCloseSm' : 'blrEyeSm' } "
78
+ size="md"
79
+ name="${ this . currentType . includes ( 'password' ) ? 'blrEyeSm' : this . hasError ? 'blrFlagSm' : this . hintIcon } "
80
+ aria-hidden
81
+ > </ blr-icon > `
82
+ : html `` }
73
83
${ BlrFormHint ( {
74
84
message : this . hasError ? this . errorMessage : this . hint ,
75
85
variant : this . hasError ? 'error' : 'hint' ,
0 commit comments