dees-catalog/ts_web/elements/dees-input-text.ts

172 lines
4.4 KiB
TypeScript
Raw Normal View History

2023-08-07 18:02:18 +00:00
import {customElement, DeesElement, type TemplateResult, property, html, cssManager, type CSSResult,} from '@design.estate/dees-element';
2023-08-07 17:13:29 +00:00
import * as domtools from '@design.estate/dees-domtools';
2020-09-13 16:24:48 +00:00
2021-03-06 15:48:02 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-input-text': DeesInputText;
}
}
2020-09-13 16:24:48 +00:00
@customElement('dees-input-text')
2020-12-09 23:05:13 +00:00
export class DeesInputText extends DeesElement {
2023-01-16 10:51:21 +00:00
public static demo = () => html`
2023-04-06 15:41:46 +00:00
<dees-input-text .label=${'this is a label'} .value=${'test'}></dees-input-text>
2023-01-16 10:51:21 +00:00
<dees-input-text .isPasswordBool=${true}></dees-input-text>
`;
2020-09-13 16:24:48 +00:00
2021-08-19 22:25:14 +00:00
// INSTANCE
2023-03-27 21:21:27 +00:00
public changeSubject = new domtools.rxjs.Subject<DeesInputText>();
public valueChangeSubject = new domtools.rxjs.Subject<string>();
2021-08-19 22:25:14 +00:00
2021-08-26 19:30:35 +00:00
@property({
type: String
})
2023-01-16 10:51:21 +00:00
public label: string;
2020-09-13 16:24:48 +00:00
2021-08-26 19:30:35 +00:00
@property({
type: String
})
2020-09-13 16:24:48 +00:00
public key: string;
2021-08-26 19:30:35 +00:00
@property({
2023-04-06 15:32:49 +00:00
type: String,
reflect: true,
2021-08-26 19:30:35 +00:00
})
2021-09-01 19:48:22 +00:00
public value: string = '';
2020-09-13 16:24:48 +00:00
2021-08-25 11:51:55 +00:00
@property({
type: Boolean
})
public required: boolean = false;
2021-08-26 19:30:35 +00:00
@property({
type: Boolean
})
public disabled: boolean = false;
2023-01-16 10:51:21 +00:00
@property({
type: Boolean,
reflect: true,
})
public isPasswordBool = false;
@property({
type: Boolean,
reflect: true,
})
public showPasswordBool = false;
2020-09-13 16:24:48 +00:00
public render(): TemplateResult {
return html `
<style>
* {
box-sizing: border-box;
}
:host {
position: relative;
display: grid;
margin: 10px 0px;
margin-bottom: 24px;
}
.maincontainer {
2020-12-09 23:05:13 +00:00
color: ${this.goBright ? '#333' : '#ccc'};
2020-09-13 16:24:48 +00:00
}
.label {
font-size: 14px;
margin-bottom: 5px;
}
input {
margin-top: 5px;
2020-12-09 23:05:13 +00:00
background: ${this.goBright ? '#fafafa' : '#222'};
border-top: ${this.goBright ? '1px solid #CCC' : '1px solid #444'};
border-bottom: ${this.goBright ? '1px solid #CCC' : '1px solid #333'};
border-right: ${this.goBright ? '1px solid #CCC' : 'none'};
border-left: ${this.goBright ? '1px solid #CCC' : 'none'};
2020-09-13 16:24:48 +00:00
padding-left:10px;
padding-right: 10px;
border-radius: 2px;
width: 100%;
line-height: 48px;
transition: all 0.2s;
outline: none;
font-size: 16px;
2023-01-16 10:57:24 +00:00
font-family: ${this.isPasswordBool ? 'monospace': 'Inter'};
letter-spacing: ${this.isPasswordBool ? '1px': 'normal'};
2021-08-26 19:30:35 +00:00
color: ${this.goBright ? '#333' : '#ccc'};
}
input:disabled {
background: ${cssManager.bdTheme('#ffffff00', '#11111100')};
border: 1px dashed ${cssManager.bdTheme('#666666', '#666666')};
color: #9b9b9e;
cursor: default;
2020-09-13 16:24:48 +00:00
}
input:focus {
outline: none;
border-bottom: 1px solid #e4002b;
}
2023-01-16 10:51:21 +00:00
.showPassword {
position: absolute;
bottom: 8px;
right: 10px;
border: 1px dashed #444;
border-radius: 7px;
padding: 8px 0px;
width: 40px;
}
.showPassword:hover {
cursor: pointer;
background: #333;
}
2020-09-13 16:24:48 +00:00
</style>
<div class="maincontainer">
2023-01-16 10:51:21 +00:00
${this.label ? html`<div class="label">${this.label}</div>` : html``}
<input type="${this.isPasswordBool && !this.showPasswordBool ? 'password' : 'text'}" value=${this.value} @input="${this.updateValue}" .disabled=${this.disabled} />
${this.isPasswordBool ? html`
<div class="showPassword" @click=${this.togglePasswordView}>
<dees-icon .iconFA=${this.showPasswordBool ? 'eye' : 'eyeSlash'}></dees-icon>
</div>
` : html``}
2020-09-13 16:24:48 +00:00
</div>
`;
}
public async updateValue(eventArg: Event) {
const target: any = eventArg.target;
this.value = target.value;
2021-08-19 22:25:14 +00:00
this.changeSubject.next(this);
2023-03-27 21:21:27 +00:00
this.valueChangeSubject.next(this.value);
2020-09-13 16:24:48 +00:00
}
2021-08-26 19:30:35 +00:00
public async freeze() {
this.disabled = true;
}
public async unfreeze() {
this.disabled = false;
}
2023-01-16 10:51:21 +00:00
public async togglePasswordView () {
const domtools = await this.domtoolsPromise;
this.showPasswordBool = !this.showPasswordBool;
console.log(`this.showPasswordBool is: ${this.showPasswordBool}`)
}
2023-03-26 23:22:15 +00:00
public async focus() {
const textInput = this.shadowRoot.querySelector('input');
textInput.focus();
}
2023-04-12 00:47:45 +00:00
public async blur() {
const textInput = this.shadowRoot.querySelector('input');
textInput.blur();
}
2020-09-13 16:24:48 +00:00
}