-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathinput-password.ts
More file actions
80 lines (71 loc) · 1.71 KB
/
input-password.ts
File metadata and controls
80 lines (71 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {css, html} from 'lit';
import {state} from 'lit/decorators.js';
import {LionInput} from '@lion/ui/input.js';
import {inputStyles} from '../../styles/form.styles.js';
import '../icon/icon.js';
import '../button/button.js';
export default class CraftInputPassword extends LionInput {
@state()
protected _visible = false;
static override get styles() {
return [
...super.styles,
inputStyles,
css`
.input-group__container {
position: relative;
}
.input-group__suffix {
position: absolute;
inset-inline-end: var(--c-input-spacing-inline);
inset-block-start: 50%;
transform: translateY(calc(-50%));
}
`,
];
}
constructor() {
super();
this.type = 'password';
}
reveal = () => {
this._visible = !this._visible;
this.type = this._visible ? 'text' : 'password';
};
renderSuffix = () => {
return html`
<craft-button
type="button"
icon
size="small"
variant="plain"
@click="${this.reveal}"
appearance="plain"
>
<span class="icon"
>${this._visible
? html`<craft-icon name="eye-slash"></craft-icon>`
: html`<craft-icon name="eye"></craft-icon>`}
</span>
</craft-button>
`;
};
override get slots() {
return {
...super.slots,
suffix: () => {
return {
template: this.renderSuffix(),
};
},
};
}
}
if (!customElements.get('craft-input-password')) {
customElements.define('craft-input-password', CraftInputPassword);
}
declare global {
interface HTMLElementTagNameMap {
'craft-input-password': CraftInputPassword;
}
}