2021-08-25 15:34:15 +00:00
|
|
|
import {
|
|
|
|
customElement,
|
|
|
|
html,
|
|
|
|
DeesElement,
|
|
|
|
css,
|
|
|
|
cssManager,
|
|
|
|
property,
|
2023-08-07 18:02:18 +00:00
|
|
|
type CSSResult,
|
2023-08-07 17:13:29 +00:00
|
|
|
} from '@design.estate/dees-element';
|
2022-03-18 18:40:28 +00: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 15:34:15 +00:00
|
|
|
public static demo = () => html`<dees-form-submit>This is a sloted text</dees-form-submit>`;
|
2021-08-25 11:51:55 +00:00
|
|
|
|
|
|
|
@property({
|
2021-08-25 15:34:15 +00:00
|
|
|
type: Boolean,
|
2023-08-19 16:56:32 +00:00
|
|
|
reflect: true,
|
2021-08-25 11:51:55 +00:00
|
|
|
})
|
|
|
|
public disabled = false;
|
|
|
|
|
2021-08-25 14:09:52 +00:00
|
|
|
@property({
|
2021-08-25 15:34:15 +00:00
|
|
|
type: String,
|
2021-08-25 14:09:52 +00:00
|
|
|
})
|
|
|
|
public text: string;
|
|
|
|
|
2021-08-27 11:38:08 +00:00
|
|
|
@property({
|
2023-04-12 00:47:45 +00:00
|
|
|
type: String,
|
2021-08-27 11:38:08 +00: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 15:34:15 +00:00
|
|
|
return html`
|
2023-04-12 00:47:45 +00:00
|
|
|
<dees-button
|
|
|
|
status=${this.status}
|
|
|
|
@click=${this.submit}
|
|
|
|
.disabled=${this.disabled}
|
|
|
|
.text=${this.text ? this.text : this.textContent}
|
|
|
|
>
|
2021-08-25 15:34:15 +00:00
|
|
|
</dees-button>
|
|
|
|
`;
|
2020-09-13 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async submit() {
|
2021-08-25 15:34:15 +00:00
|
|
|
if (this.disabled) {
|
2021-08-25 11:51:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-09-13 16:24:48 +00:00
|
|
|
const parentElement: DeesForm = this.parentElement as DeesForm;
|
|
|
|
parentElement.gatherAndDispatch();
|
|
|
|
}
|
2023-04-12 00:47:45 +00: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
|
|
|
}
|