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

255 lines
5.9 KiB
TypeScript
Raw Normal View History

2024-01-21 00:12:57 +00:00
import * as colors from './00colors.js';
2023-10-23 14:13:02 +00:00
import {
customElement,
DeesElement,
type TemplateResult,
property,
html,
cssManager,
css,
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-10-23 15:26:03 +00:00
public changeSubject = new domtools.plugins.smartrx.rxjs.Subject<DeesInputText>();
2021-08-19 22:25:14 +00:00
2021-08-26 19:30:35 +00:00
@property({
2023-10-23 14:13:02 +00:00
type: String,
2021-08-26 19:30:35 +00:00
})
2023-01-16 10:51:21 +00:00
public label: string;
2020-09-13 16:24:48 +00:00
2024-01-21 00:12:57 +00:00
@property({
type: String,
})
public description: string;
2021-08-26 19:30:35 +00:00
@property({
2023-08-28 07:49:51 +00:00
type: String,
reflect: true,
2021-08-26 19:30:35 +00:00
})
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({
2023-10-23 14:13:02 +00:00
type: Boolean,
2021-08-25 11:51:55 +00:00
})
public required: boolean = false;
2021-08-26 19:30:35 +00:00
@property({
2023-10-23 14:13:02 +00:00
type: Boolean,
2021-08-26 19:30:35 +00:00
})
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;
2023-10-23 14:13:02 +00:00
@property({
type: Boolean,
reflect: true,
})
public validationState: 'valid' | 'warn' | 'invalid';
2020-09-13 16:24:48 +00:00
2023-10-23 14:13:02 +00:00
@property({
reflect: true,
})
public validationText: string = '';
@property({})
validationFunction: (value: string) => boolean;
public static styles = [
cssManager.defaultStyles,
css`
* {
box-sizing: border-box;
}
:host {
position: relative;
display: grid;
margin: 8px 0px;
margin-bottom: 24px;
z-index: auto;
}
.maincontainer {
color: ${cssManager.bdTheme('#333', '#ccc')};
}
input {
2024-01-18 01:08:19 +00:00
margin-top: 0px;
2023-10-23 14:13:02 +00:00
background: ${cssManager.bdTheme('#fafafa', '#222')};
2024-01-18 01:08:19 +00:00
border-top: ${cssManager.bdTheme('1px solid #CCC', '1px solid #ffffff10')};
border-bottom: ${cssManager.bdTheme('1px solid #CCC', '1px solid #222')};
2023-10-23 14:13:02 +00:00
border-right: ${cssManager.bdTheme('1px solid #CCC', 'none')};
border-left: ${cssManager.bdTheme('1px solid #CCC', 'none')};
padding-left: 10px;
padding-right: 10px;
border-radius: 2px;
width: 100%;
line-height: 36px;
transition: all 0.2s;
outline: none;
font-size: 16px;
position: relative;
z-index: 2;
2023-12-26 20:21:18 +00:00
cursor: default;
2023-10-23 14:13:02 +00:00
}
input:disabled {
background: ${cssManager.bdTheme('#ffffff00', '#11111100')};
border: 1px dashed ${cssManager.bdTheme('#666666', '#666666')};
color: #9b9b9e;
cursor: default;
}
input:focus {
outline: none;
2024-01-21 00:12:57 +00:00
border-bottom: 1px solid ${cssManager.bdTheme( colors.bright.blueActive, colors.dark.blueActive)};
2023-12-26 20:21:18 +00:00
cursor: text;
}
input:hover {
filter: ${cssManager.bdTheme('brightness(0.95)', 'brightness(1.1)')};
2023-10-23 14:13:02 +00:00
}
.showPassword {
position: absolute;
bottom: 7px;
right: 10px;
border: 1px dashed #444;
border-radius: 7px;
padding: 4px 0px;
width: 40px;
2023-12-08 17:15:40 +00:00
z-index: 3;
2023-10-23 14:13:02 +00:00
}
.showPassword:hover {
background: ${cssManager.bdTheme('#00000010', '#ffffff10')};
}
.validationContainer {
text-align: center;
padding: 6px 2px 2px 2px;
margin-top: -4px;
font-size: 12px;
color: #fff;
background: #e4002b;
position: relative;
z-index: 1;
border-radius: 3px;
transition: all 0.2s;
}
`,
];
2020-09-13 16:24:48 +00:00
2023-10-23 14:13:02 +00:00
public render(): TemplateResult {
return html`
<style>
2020-09-13 16:24:48 +00:00
input {
font-family: ${this.isPasswordBool ? 'monospace' : 'Geist Sans'};
2023-10-23 14:13:02 +00:00
letter-spacing: ${this.isPasswordBool ? '1px' : 'normal'};
2021-08-26 19:30:35 +00:00
color: ${this.goBright ? '#333' : '#ccc'};
}
2023-10-23 14:13:02 +00:00
${this.validationText ? css`
.validationContainer {
height: 22px;
opacity: 1;
}
` : css`
.validationContainer {
height: 4px;
padding: 2px !important;
opacity: 0;
}
`}
2020-09-13 16:24:48 +00:00
</style>
<div class="maincontainer">
2024-01-21 00:12:57 +00:00
<dees-label .label=${this.label} .description=${this.description}></dees-label>
2023-10-23 14:13:02 +00:00
<input
type="${this.isPasswordBool && !this.showPasswordBool ? 'password' : 'text'}"
.value=${this.value}
@input="${this.updateValue}"
.disabled=${this.disabled}
/>
<div class="validationContainer">
${this.validationText}
</div>
${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>
`;
}
2023-10-23 14:13:02 +00:00
firstUpdated() {
const input = this.shadowRoot.querySelector('input');
input.addEventListener('input', (eventArg: InputEvent) => {
});
}
2020-09-13 16:24:48 +00:00
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);
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
2023-10-23 14:13:02 +00:00
public async togglePasswordView() {
2023-01-16 10:51:21 +00:00
const domtools = await this.domtoolsPromise;
this.showPasswordBool = !this.showPasswordBool;
2023-10-23 14:13:02 +00:00
console.log(`this.showPasswordBool is: ${this.showPasswordBool}`);
2023-01-16 10:51:21 +00:00
}
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
}