fix(core): update
This commit is contained in:
parent
0adb319616
commit
486b8cb6a6
@ -22,18 +22,18 @@ export class DeesButton extends DeesElement {
|
||||
public static demo = () => html`<dees-button></dees-button>`;
|
||||
|
||||
@property()
|
||||
text: string;
|
||||
public text: string;
|
||||
|
||||
@property()
|
||||
eventDetailData: string;
|
||||
public eventDetailData: string;
|
||||
|
||||
@property({
|
||||
type: Boolean
|
||||
})
|
||||
disabled = false;
|
||||
public disabled = false;
|
||||
|
||||
@property()
|
||||
isHidden = false;
|
||||
public isHidden = false;
|
||||
|
||||
@property()
|
||||
public type: 'normal' | 'highlighted' | 'discreet' | 'big' = 'normal';
|
||||
@ -59,6 +59,7 @@ export class DeesButton extends DeesElement {
|
||||
display: block;
|
||||
text-align: center;
|
||||
background: ${cssManager.bdTheme('#eee', '#333')};
|
||||
box-shadow: ${cssManager.bdTheme('0px 0px 5px rgba(0,0,0,0.1)', 'none')};
|
||||
border-top: ${cssManager.bdTheme('1px solid #eee', '1px solid #444')};
|
||||
border-radius: 2px;
|
||||
line-height: 40px;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { customElement, html, DeesElement, css, cssManager } from '@designestate/dees-element';
|
||||
import { customElement, html, DeesElement, css, cssManager, property } from '@designestate/dees-element';
|
||||
import { DeesForm } from './dees-form';
|
||||
|
||||
declare global {
|
||||
@ -9,6 +9,13 @@ declare global {
|
||||
|
||||
@customElement('dees-form-submit')
|
||||
export class DeesFormSubmit extends DeesElement {
|
||||
public static demo = () => html`<dees-form-submit></dees-form-submit>`;
|
||||
|
||||
@property({
|
||||
type: Boolean
|
||||
})
|
||||
public disabled = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
@ -16,10 +23,13 @@ export class DeesFormSubmit extends DeesElement {
|
||||
public static styles = [cssManager.defaultStyles, css``];
|
||||
|
||||
public render() {
|
||||
return html` <dees-button @click="${this.submit}">${this.textContent}</dees-button> `;
|
||||
return html`<dees-button @click="${this.submit}" .disabled="${this.disabled}">${this.textContent}</dees-button> `;
|
||||
}
|
||||
|
||||
public async submit() {
|
||||
if(this.disabled) {
|
||||
return;
|
||||
}
|
||||
const parentElement: DeesForm = this.parentElement as DeesForm;
|
||||
parentElement.gatherAndDispatch();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { DeesInputText } from './dees-input-text';
|
||||
import { DeesInputQuantitySelector } from './dees-input-quantityselector';
|
||||
import { DeesInputRadio } from './dees-input-radio';
|
||||
import * as domtools from '@designestate/dees-domtools';
|
||||
import { DeesFormSubmit } from './dees-form-submit';
|
||||
|
||||
export type TFormElement = Array<DeesInputCheckbox | DeesInputText | DeesInputQuantitySelector | DeesInputRadio>;
|
||||
|
||||
@ -18,9 +19,9 @@ declare global {
|
||||
export class DeesForm extends DeesElement {
|
||||
public static demo = () => html`
|
||||
<dees-form style="display: block; margin:auto; max-width: 500px; padding: 20px">
|
||||
<dees-input-text key="hello1" label="a text"></dees-input-text>
|
||||
<dees-input-text key="hello2" label="also a text"></dees-input-text>
|
||||
<dees-input-checkbox key="hello3" label="another text"></dees-input-checkbox>
|
||||
<dees-input-text .required="${true}" key="hello1" label="a text"></dees-input-text>
|
||||
<dees-input-text .required="${true}" key="hello2" label="also a text"></dees-input-text>
|
||||
<dees-input-checkbox .required="${true}" key="hello3" label="another text"></dees-input-checkbox>
|
||||
<dees-form-submit>Submit</dees-form-submit>
|
||||
</dees-form>
|
||||
`;
|
||||
@ -41,12 +42,14 @@ export class DeesForm extends DeesElement {
|
||||
|
||||
public firstUpdated() {
|
||||
const formChildren = this.getFormChildren();
|
||||
this.checkRequiredStatus();
|
||||
for (const child of formChildren) {
|
||||
child.changeSubject.subscribe(async (elementArg: TFormElement) => {
|
||||
const valueObject = await this.gatherData();
|
||||
this.changeSubject.next(valueObject);
|
||||
console.log(valueObject);
|
||||
})
|
||||
this.checkRequiredStatus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +65,26 @@ export class DeesForm extends DeesElement {
|
||||
return formChildren;
|
||||
}
|
||||
|
||||
public async checkRequiredStatus() {
|
||||
console.log('checking the required status.')
|
||||
const children: Array<DeesElement> = this.children as any;
|
||||
let submitButton: DeesFormSubmit;
|
||||
for (const childArg of children) {
|
||||
if(childArg instanceof DeesFormSubmit) {
|
||||
submitButton = childArg;
|
||||
}
|
||||
}
|
||||
|
||||
let requiredOK = true;
|
||||
for (const childArg of this.getFormChildren()) {
|
||||
if (childArg.required && !childArg.value) {
|
||||
requiredOK = false;
|
||||
}
|
||||
}
|
||||
submitButton.disabled = !requiredOK;
|
||||
console.log(submitButton);
|
||||
}
|
||||
|
||||
public async gatherData() {
|
||||
const children = this.getFormChildren();
|
||||
const valueObject: { [key: string]: string | number | boolean} = {};
|
||||
@ -80,5 +103,7 @@ export class DeesForm extends DeesElement {
|
||||
bubbles: true
|
||||
});
|
||||
this.dispatchEvent(formDataEvent);
|
||||
console.log('dispatched data:')
|
||||
console.log(valueObject);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,10 @@
|
||||
import { customElement, DeesElement, TemplateResult, property, html } from '@designestate/dees-element';
|
||||
import {
|
||||
customElement,
|
||||
DeesElement,
|
||||
TemplateResult,
|
||||
property,
|
||||
html,
|
||||
} from '@designestate/dees-element';
|
||||
import * as domtools from '@designestate/dees-domtools';
|
||||
|
||||
declare global {
|
||||
@ -11,19 +17,29 @@ declare global {
|
||||
export class DeesInputCheckbox extends DeesElement {
|
||||
// STATIC
|
||||
public static demo = () => html`<dees-input-checkbox></dees-input-checkbox>`;
|
||||
|
||||
|
||||
// INSTANCE
|
||||
public changeSubject = new domtools.rxjs.Subject();
|
||||
|
||||
@property()
|
||||
@property({
|
||||
type: String,
|
||||
})
|
||||
public key: string;
|
||||
|
||||
@property()
|
||||
@property({
|
||||
type: String,
|
||||
})
|
||||
public label: string = 'Label';
|
||||
|
||||
@property()
|
||||
@property({
|
||||
type: Boolean,
|
||||
})
|
||||
public value: boolean = false;
|
||||
|
||||
@property({
|
||||
type: Boolean,
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
|
@ -30,6 +30,11 @@ export class DeesInputDropdown extends LitElement {
|
||||
payload: null
|
||||
};
|
||||
|
||||
@property({
|
||||
type: Boolean
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
${domtools.elementBasic.styles}
|
||||
|
@ -42,6 +42,15 @@ export class DeesInputFileupload extends DeesElement {
|
||||
@property()
|
||||
public state: 'idle' | 'dragOver' | 'dropped' | 'uploading' | 'completed' = 'idle';
|
||||
|
||||
@property({
|
||||
type: Boolean,
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static styles = [
|
||||
cssManager.defaultStyles,
|
||||
css`
|
||||
|
@ -22,6 +22,15 @@ export class DeesInputQuantitySelector extends DeesElement {
|
||||
})
|
||||
public value: number = 1;
|
||||
|
||||
@property({
|
||||
type: Boolean,
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
${domtools.elementBasic.styles}
|
||||
|
@ -23,6 +23,15 @@ export class DeesInputRadio extends LitElement {
|
||||
@property()
|
||||
public value: boolean = false;
|
||||
|
||||
@property({
|
||||
type: Boolean,
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html `
|
||||
<style>
|
||||
|
@ -23,6 +23,11 @@ export class DeesInputText extends DeesElement {
|
||||
@property()
|
||||
public value: string;
|
||||
|
||||
@property({
|
||||
type: Boolean
|
||||
})
|
||||
public required: boolean = false;
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html `
|
||||
<style>
|
||||
|
Loading…
Reference in New Issue
Block a user