Files
dees-catalog/ts_web/elements/dees-simple-login.ts

153 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-09-09 13:34:46 +02:00
import { demoFunc } from './dees-simple-login.demo.js';
2023-08-19 11:47:45 +02:00
import {
customElement,
html,
DeesElement,
property,
type TemplateResult,
cssManager,
css,
} from '@design.estate/dees-element';
declare global {
interface HTMLElementTagNameMap {
'dees-simple-login': DeesSimpleLogin;
}
}
@customElement('dees-simple-login')
export class DeesSimpleLogin extends DeesElement {
// STATIC
2023-09-09 13:34:46 +02:00
public static demo = demoFunc
2023-08-19 11:47:45 +02:00
// INSTANCE
@property()
public name: string = 'Application';
2023-08-19 11:47:45 +02:00
public static styles = [
cssManager.defaultStyles,
css`
:host {
color: ${cssManager.bdTheme('#333', '#ccc')};
2023-08-19 18:56:32 +02:00
user-select: none;
display: block;
width: 100%;
height: 100%;
font-family: 'Geist Sans', sans-serif;
2023-08-19 11:47:45 +02:00
}
2024-01-22 18:30:00 +01:00
.loginContainer {
2023-09-02 14:05:33 +02:00
position: absolute;
2023-08-19 11:47:45 +02:00
display: flex;
justify-content: center;
align-items: center;
2023-09-02 14:05:33 +02:00
width: 100%;
2023-08-19 11:47:45 +02:00
height: 100%;
top: 0;
left: 0;
background: ${cssManager.bdTheme('#f5f5f5', '#000')};
2023-08-19 11:47:45 +02:00
}
2024-01-22 18:30:00 +01:00
.slotContainer {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
pointer-events: none;
2024-01-22 18:30:00 +01:00
}
2023-08-19 11:47:45 +02:00
.login {
min-width: 320px;
background: ${cssManager.bdTheme('#ffffff', '#111')};
box-shadow: ${cssManager.bdTheme(
'0 4px 12px rgba(0, 0, 0, 0.15)',
'0 4px 12px rgba(0, 0, 0, 0.3)'
)};
2024-01-10 05:11:55 +01:00
border-radius: 8px;
border: 1px solid ${cssManager.bdTheme('#e0e0e0', '#202020')};
2023-08-19 11:47:45 +02:00
padding: 24px;
2023-09-02 14:05:33 +02:00
transition: opacity 0.3s, transform 0.3s;
2023-08-19 11:47:45 +02:00
}
.header {
text-align: center;
font-size: 16px;
font-weight: 600;
margin-bottom: 20px;
color: ${cssManager.bdTheme('#000', '#fff')};
2023-08-19 11:47:45 +02:00
}
.login dees-form {
display: flex;
flex-direction: column;
gap: 12px;
}
.login dees-input-text {
width: 100%;
}
.login dees-form-submit {
margin-top: 4px;
width: 100%;
2023-09-02 14:05:33 +02:00
}
2023-08-19 11:47:45 +02:00
`,
];
public render(): TemplateResult {
return html`
<div class="loginContainer">
<div class="login">
<div class="header">Login to ${this.name}</div>
2023-08-19 11:47:45 +02:00
<dees-form>
<dees-input-text key="username" label="Username" required></dees-input-text>
<dees-input-text key="password" label="Password" isPasswordBool required></dees-input-text>
<dees-form-submit>Login</dees-form-submit>
2023-08-19 11:47:45 +02:00
</dees-form>
</div>
</div>
2023-09-02 14:05:33 +02:00
<div class="slotContainer">
<slot></slot>
</div>
2023-08-19 11:47:45 +02:00
`;
}
2023-08-19 18:56:32 +02:00
public async firstUpdated(_changedProperties: Map<string | number | symbol, unknown>): Promise<void> {
2023-08-19 18:56:32 +02:00
super.firstUpdated(_changedProperties);
const form = this.shadowRoot.querySelector('dees-form') as any;
if (form) {
form.addEventListener('formData', (event: CustomEvent) => {
this.dispatchEvent(new CustomEvent('login', {
detail: event.detail,
bubbles: true,
composed: true
}));
});
}
2023-08-19 18:56:32 +02:00
}
2023-09-02 14:05:33 +02:00
/**
* allows switching to slotted content
*/
public async switchToSlottedContent() {
const domtools = await this.domtoolsPromise;
const loginDiv: HTMLDivElement = this.shadowRoot.querySelector('.login');
const loginContainerDiv: HTMLDivElement = this.shadowRoot.querySelector('.loginContainer');
const slotContainerDiv: HTMLDivElement = this.shadowRoot.querySelector('.slotContainer');
loginDiv.style.opacity = '0';
loginDiv.style.transform = 'translateY(20px)';
loginContainerDiv.style.pointerEvents = 'none';
slotContainerDiv.style.transform = 'translateY(20px)';
await domtools.convenience.smartdelay.delayFor(300);
slotContainerDiv.style.opacity = '1';
slotContainerDiv.style.transform = 'translateY(0px)';
await domtools.convenience.smartdelay.delayFor(300);
slotContainerDiv.style.pointerEvents = 'all';
}
2023-08-19 11:47:45 +02:00
}