@exmg/exm-form-drawer 1.1.12 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
+ import { PropertyValues } from 'lit';
1
2
  import '@exmg/exm-drawer/exm-drawer.js';
2
3
  import '@exmg/exm-button/exm-filled-button.js';
3
4
  import '@material/web/button/text-button.js';
5
+ import { ExmFormBase } from '@exmg/exm-form';
4
6
  import { ExmgElement } from '@exmg/lit-base';
5
- declare const ExmFormDrawerBase_base: import("@exmg/exm-form").Constructor<import("@exmg/exm-form/dist/exm-form-validate-mixin.js").FormValidateMixinInterface> & typeof ExmgElement;
6
- export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
7
+ export declare class ExmFormDrawerBase extends ExmgElement {
7
8
  /**
8
9
  * Opened state of the form-drawer
9
10
  * @type {Boolean}
@@ -13,17 +14,12 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
13
14
  * The title of the 'submit' button
14
15
  * @type {String}
15
16
  */
16
- submitBtnTitle: string;
17
- /**
18
- * Whether or not to hide the submit button
19
- * @type {Boolean}
20
- */
21
- submitBtnHidden: boolean;
17
+ submitBtn: string;
22
18
  /**
23
19
  * Title of the cancel button
24
20
  * @type {String}
25
21
  */
26
- cancelBtnTitle: string;
22
+ cancelBtn: string;
27
23
  /**
28
24
  * Whether or not to keep the form drawer opened on submit success
29
25
  * @type {Boolean}
@@ -34,21 +30,12 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
34
30
  * @type {Boolean}
35
31
  */
36
32
  noCancelOnOutsideClick: boolean;
37
- /**
38
- * Disable sticky header in drawer
39
- * @type {Boolean}
40
- */
41
- disableStickyHeader: boolean;
42
33
  /**
43
34
  * Internall used to show button spinner.
44
35
  */
45
36
  submitting: boolean;
46
- /**
47
- * Scroll action of the drawer
48
- * @type {'lock' | 'refit' | 'cancel' | undefined}
49
- */
50
- scrollAction?: 'lock' | 'refit' | 'cancel' | undefined;
51
37
  errorMessage?: string | null;
38
+ exmForm?: ExmFormBase;
52
39
  /**
53
40
  * Opens and shows the drawer.
54
41
  */
@@ -67,15 +54,12 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
67
54
  * @param {CustomEvent} e
68
55
  */
69
56
  doAction?(formData: unknown): Promise<void> | void;
70
- protected handleSubmit(): Promise<void>;
71
- private handleCancelBtnClick;
72
- showError(message: string): void;
57
+ protected firstUpdated(_changedProperties: PropertyValues): void;
58
+ private handleSubmitFinished;
73
59
  /**
74
60
  * Method should be overriden to render form content
75
61
  */
76
- protected renderFormContent(): import("lit-html").TemplateResult<1>;
77
- protected renderError(): import("lit-html").TemplateResult<1>;
62
+ protected renderFormContent(): import("lit-html").TemplateResult<1> | undefined;
78
63
  protected handleDrawerOpenedChanged(e: CustomEvent): void;
79
64
  protected render(): import("lit-html").TemplateResult<1>;
80
65
  }
81
- export {};
@@ -1,13 +1,12 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, nothing } from 'lit';
3
- import { property } from 'lit/decorators.js';
4
- import { ifDefined } from 'lit/directives/if-defined.js';
2
+ import { html } from 'lit';
3
+ import { property, query } from 'lit/decorators.js';
5
4
  import '@exmg/exm-drawer/exm-drawer.js';
6
5
  import '@exmg/exm-button/exm-filled-button.js';
7
6
  import '@material/web/button/text-button.js';
8
7
  import { ExmgElement } from '@exmg/lit-base';
9
- import { serializeForm, ExmFormValidateMixin } from '@exmg/exm-form';
10
- export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
8
+ import { ifDefined } from 'lit/directives/if-defined.js';
9
+ export class ExmFormDrawerBase extends ExmgElement {
11
10
  constructor() {
12
11
  super(...arguments);
13
12
  /**
@@ -19,17 +18,12 @@ export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
19
18
  * The title of the 'submit' button
20
19
  * @type {String}
21
20
  */
22
- this.submitBtnTitle = 'Submit';
23
- /**
24
- * Whether or not to hide the submit button
25
- * @type {Boolean}
26
- */
27
- this.submitBtnHidden = false;
21
+ this.submitBtn = 'Submit';
28
22
  /**
29
23
  * Title of the cancel button
30
24
  * @type {String}
31
25
  */
32
- this.cancelBtnTitle = 'Cancel';
26
+ this.cancelBtn = 'Reset';
33
27
  /**
34
28
  * Whether or not to keep the form drawer opened on submit success
35
29
  * @type {Boolean}
@@ -40,11 +34,6 @@ export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
40
34
  * @type {Boolean}
41
35
  */
42
36
  this.noCancelOnOutsideClick = false;
43
- /**
44
- * Disable sticky header in drawer
45
- * @type {Boolean}
46
- */
47
- this.disableStickyHeader = false;
48
37
  /**
49
38
  * Internall used to show button spinner.
50
39
  */
@@ -74,62 +63,41 @@ export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
74
63
  }
75
64
  }
76
65
  reset() {
66
+ if (!this.exmForm) {
67
+ return;
68
+ }
77
69
  this.errorMessage = null;
78
- const form = this.getForm();
70
+ const form = this.exmForm.getForm();
79
71
  form.reset();
80
72
  }
81
- async handleSubmit() {
82
- const form = this.getForm();
83
- this.errorMessage = null;
84
- // Check form validity
85
- this.checkFormValidity();
86
- // Return when there are invalid fields
87
- if (!this.formValid) {
73
+ firstUpdated(_changedProperties) {
74
+ var _a;
75
+ if (!this.exmForm && !this.doAction) {
88
76
  return;
89
77
  }
90
- // Serialize form data
91
- const data = serializeForm(form);
92
- if (this.doAction) {
93
- try {
94
- this.submitting = true;
95
- await this.doAction(data);
96
- this.fire('action-success');
97
- }
98
- catch (error) {
99
- this.errorMessage = error instanceof Error ? error.message : 'Unkbnown error';
100
- this.fire('action-error', { message: this.errorMessage }, true);
101
- }
102
- finally {
103
- this.submitting = false;
104
- if (this.errorMessage === null && !this.keepOpenedOnSubmitSuccess) {
105
- this.opened = false;
106
- }
107
- }
108
- }
109
- else {
110
- this.fire('action-submit', data, true);
111
- }
112
- }
113
- handleCancelBtnClick() {
114
- this.reset();
115
- this.close();
78
+ // By default form doAction is undefined, TS does not like that
79
+ // @ts-ignore
80
+ this.exmForm.doAction = (_a = this.doAction) === null || _a === void 0 ? void 0 : _a.bind(this);
116
81
  }
117
- showError(message) {
118
- this.errorMessage = message;
82
+ handleSubmitFinished({ detail }) {
83
+ if (detail.success && !this.keepOpenedOnSubmitSuccess) {
84
+ this.opened = false;
85
+ }
119
86
  }
120
87
  /**
121
88
  * Method should be overriden to render form content
122
89
  */
123
90
  renderFormContent() {
124
- return html `<slot></slot>`;
125
- }
126
- renderError() {
127
- return html `<div class="error"><div>${this.errorMessage}</div></div>`;
91
+ var _a;
92
+ return (_a = this.exmForm) === null || _a === void 0 ? void 0 : _a.renderFormContent();
128
93
  }
129
94
  handleDrawerOpenedChanged(e) {
130
95
  this.opened = e.detail.value;
96
+ if (!this.exmForm) {
97
+ return;
98
+ }
131
99
  if (this.opened) {
132
- this.checkFormValidity();
100
+ this.exmForm.checkFormValidity();
133
101
  }
134
102
  }
135
103
  render() {
@@ -138,28 +106,29 @@ export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
138
106
  ?opened="${this.opened}"
139
107
  ?no-cancel-on-outside-click="${this.noCancelOnOutsideClick}"
140
108
  @exm-drawer-opened-changed=${this.handleDrawerOpenedChanged}
141
- scroll-action=${ifDefined(this.scrollAction)}
142
109
  maxWidth="${this.style.maxWidth || '547px'}"
143
110
  >
144
- <div class="header">
145
- <slot name="title" class="title">${this.title}</slot>
146
- <div class="header-buttons">
147
- <md-text-button slot="footer" dialogFocus @click=${() => this.handleCancelBtnClick()}
148
- >${this.cancelBtnTitle}</md-text-button
149
- >
150
- ${this.submitBtnHidden
151
- ? ''
152
- : html ` <exm-filled-button
153
- slot="footer"
154
- @click=${this.handleSubmit}
155
- ?disabled=${this.submitting || !this.formValid}
156
- ?loading=${this.submitting}
157
- >${this.submitBtnTitle}</exm-filled-button
158
- >`}
159
- </div>
160
- </div>
161
- ${this.errorMessage ? this.renderError() : nothing}
162
- <div class="form-elements">${this.renderFormContent()}</div>
111
+ <section class="drawer-content">
112
+ <header class="header">
113
+ <slot name="title" class="title">${this.title}</slot>
114
+ <div class="actions">
115
+ <md-icon-button @click=${this.close}>
116
+ <md-icon>close</md-icon>
117
+ </md-icon-button>
118
+ </div>
119
+ </header>
120
+ <exm-form
121
+ submitBtn=${this.submitBtn}
122
+ cancelBtn=${this.cancelBtn}
123
+ .errorMessage=${this.errorMessage}
124
+ class="form-elements"
125
+ @form-submit-finished=${this.handleSubmitFinished}
126
+ @form-cancel=${this.reset}
127
+ doAction=${ifDefined(this.doAction)}
128
+ >
129
+ ${this.renderFormContent()}
130
+ </exm-form>
131
+ </section>
163
132
  </exm-drawer>
164
133
  `;
165
134
  }
@@ -169,29 +138,23 @@ __decorate([
169
138
  ], ExmFormDrawerBase.prototype, "opened", void 0);
170
139
  __decorate([
171
140
  property({ type: String, attribute: 'submit-btn-title' })
172
- ], ExmFormDrawerBase.prototype, "submitBtnTitle", void 0);
173
- __decorate([
174
- property({ type: Boolean, attribute: 'submit-btn-hidden' })
175
- ], ExmFormDrawerBase.prototype, "submitBtnHidden", void 0);
141
+ ], ExmFormDrawerBase.prototype, "submitBtn", void 0);
176
142
  __decorate([
177
143
  property({ type: String, attribute: 'cancel-btn-title' })
178
- ], ExmFormDrawerBase.prototype, "cancelBtnTitle", void 0);
144
+ ], ExmFormDrawerBase.prototype, "cancelBtn", void 0);
179
145
  __decorate([
180
146
  property({ type: Boolean, attribute: 'keep-opened-on-submit-success' })
181
147
  ], ExmFormDrawerBase.prototype, "keepOpenedOnSubmitSuccess", void 0);
182
148
  __decorate([
183
149
  property({ type: Boolean, attribute: 'no-cancel-on-outside-click' })
184
150
  ], ExmFormDrawerBase.prototype, "noCancelOnOutsideClick", void 0);
185
- __decorate([
186
- property({ type: Boolean, attribute: 'disable-sticky-header' })
187
- ], ExmFormDrawerBase.prototype, "disableStickyHeader", void 0);
188
151
  __decorate([
189
152
  property({ type: Boolean })
190
153
  ], ExmFormDrawerBase.prototype, "submitting", void 0);
191
- __decorate([
192
- property({ type: String, attribute: 'scroll-action' })
193
- ], ExmFormDrawerBase.prototype, "scrollAction", void 0);
194
154
  __decorate([
195
155
  property({ type: String })
196
156
  ], ExmFormDrawerBase.prototype, "errorMessage", void 0);
157
+ __decorate([
158
+ query('exm-form')
159
+ ], ExmFormDrawerBase.prototype, "exmForm", void 0);
197
160
  //# sourceMappingURL=exm-form-drawer-base.js.map
@@ -1,7 +1,7 @@
1
1
  import { ExmFormDrawerBase } from './exm-form-drawer-base.js';
2
2
  export declare class ExmFormDrawer extends ExmFormDrawerBase {
3
3
  static styles: import("lit").CSSResult[];
4
- getForm(): HTMLFormElement | null;
4
+ protected firstUpdated(): void;
5
5
  }
6
6
  declare global {
7
7
  interface HTMLElementTagNameMap {
@@ -4,8 +4,15 @@ import { style } from './styles/exm-form-drawer-styles-css.js';
4
4
  import { ExmFormDrawerBase } from './exm-form-drawer-base.js';
5
5
  import { formStyles } from '@exmg/exm-form';
6
6
  let ExmFormDrawer = class ExmFormDrawer extends ExmFormDrawerBase {
7
- getForm() {
8
- return this.querySelector('form');
7
+ firstUpdated() {
8
+ super.firstUpdated(new Map());
9
+ if (!this.exmForm) {
10
+ return;
11
+ }
12
+ /**
13
+ * We have to overwrite the getForm method because for whatever reason the form is not properly accessible from within the exm-form component
14
+ */
15
+ this.exmForm.getForm = () => this.querySelector('form');
9
16
  }
10
17
  };
11
18
  ExmFormDrawer.styles = [style, formStyles];
@@ -1,60 +1,18 @@
1
1
  import { css } from 'lit';
2
2
  export const style = css `
3
- :host {
4
- display: flex;
5
- }
6
-
7
- :host .header {
8
- display: flex;
9
- flex-direction: row;
10
- align-items: center;
11
- margin: 0;
12
- padding: 20px;
13
- border-bottom: 1px solid
14
- var(--exm-form-drawer-header-separator-color, var(--mdc-theme-on-surface, rgba(2, 24, 43, 0.1)));
3
+ .drawer-content {
4
+ height: 100%;
5
+ display: grid;
6
+ grid-template-rows: auto 1fr;
15
7
  }
16
8
 
17
- :host .header .title {
9
+ .header {
18
10
  font-size: 1.4rem;
19
- }
20
-
21
- :host .form-elements {
22
- padding: 0 0px;
23
- }
24
-
25
- .header-buttons {
11
+ padding: 1rem;
26
12
  display: flex;
27
- flex-direction: row;
28
- flex: 1;
29
- justify-content: flex-end;
30
- }
31
-
32
- .header-buttons > * {
33
- margin-left: 20px;
34
- }
35
-
36
- :host(:not([disable-sticky-header])) .header {
37
- position: sticky;
38
- top: 0;
39
- color: var(--exm-drawer-color, var(--md-sys-color-on-surface-variant, black));
40
- background-color: var(--exm-drawer-bg-color, var(--md-sys-color-surface-variant, white));
41
- z-index: 2;
42
- }
43
-
44
- form {
45
- margin: 1rem 0 !important;
46
- padding: 0.5rem 1rem;
47
- box-sizing: border-box;
48
- }
49
-
50
- .error {
51
- background-color: var(--md-sys-color-error-container);
52
- color: var(--md-sys-color-on-error-container);
53
- padding: 0.5rem;
54
- }
55
-
56
- .error > * {
57
- margin: 1rem;
13
+ min-height: 3rem;
14
+ align-items: center;
15
+ justify-content: space-between;
58
16
  }
59
17
  `;
60
18
  //# sourceMappingURL=exm-form-drawer-styles-css.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-form-drawer",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@exmg/exm-drawer": "^1.1.12",
35
- "@exmg/exm-form": "^1.1.12"
34
+ "@exmg/exm-drawer": "^1.1.14",
35
+ "@exmg/exm-form": "^1.1.14"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "lit": "^3.2.1",
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "1478e41cdcc8b109995cf78f8ccfadd7699c22aa"
45
+ "gitHead": "b9c43c753dfb8a1f43c7a978335f066d199591d7"
46
46
  }