dees-catalog/ts_web/elements/dees-form-submit.ts

72 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-25 17:34:15 +02:00
import {
customElement,
html,
DeesElement,
css,
cssManager,
property,
2023-08-07 20:02:18 +02:00
type CSSResult,
2023-08-07 19:13:29 +02:00
} from '@design.estate/dees-element';
2022-03-18 19:40:28 +01:00
import { DeesForm } from './dees-form.js';
2020-09-13 16:24:48 +00:00
2021-02-13 21:52:36 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-form-submit': DeesFormSubmit;
}
}
2020-09-13 16:24:48 +00:00
@customElement('dees-form-submit')
2021-05-05 20:55:49 +00:00
export class DeesFormSubmit extends DeesElement {
2021-08-25 17:34:15 +02:00
public static demo = () => html`<dees-form-submit>This is a sloted text</dees-form-submit>`;
2021-08-25 13:51:55 +02:00
@property({
2021-08-25 17:34:15 +02:00
type: Boolean,
2023-08-19 18:56:32 +02:00
reflect: true,
2021-08-25 13:51:55 +02:00
})
public disabled = false;
2021-08-25 16:09:52 +02:00
@property({
2021-08-25 17:34:15 +02:00
type: String,
2021-08-25 16:09:52 +02:00
})
public text: string;
2021-08-27 13:38:08 +02:00
@property({
2023-04-12 02:47:45 +02:00
type: String,
2021-08-27 13:38:08 +02:00
})
public status: 'normal' | 'pending' | 'success' | 'error' = 'normal';
2021-05-05 20:55:49 +00:00
constructor() {
super();
}
2020-09-13 16:24:48 +00:00
2021-05-05 20:55:49 +00:00
public static styles = [cssManager.defaultStyles, css``];
2020-09-13 16:24:48 +00:00
public render() {
2021-08-25 17:34:15 +02:00
return html`
2023-04-12 02:47:45 +02:00
<dees-button
status=${this.status}
@click=${this.submit}
.disabled=${this.disabled}
.text=${this.text ? this.text : this.textContent}
>
2021-08-25 17:34:15 +02:00
</dees-button>
`;
2020-09-13 16:24:48 +00:00
}
public async submit() {
2021-08-25 17:34:15 +02:00
if (this.disabled) {
2021-08-25 13:51:55 +02:00
return;
}
2020-09-13 16:24:48 +00:00
const parentElement: DeesForm = this.parentElement as DeesForm;
parentElement.gatherAndDispatch();
}
2023-04-12 02:47:45 +02:00
public async focus() {
const domtools = await this.domtoolsPromise;
if (!this.disabled) {
domtools.convenience.smartdelay.delayFor(0);
this.submit();
}
}
2020-09-13 16:24:48 +00:00
}