@exmg/exm-form-drawer 1.1.11 → 1.1.13

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,9 @@
1
1
  import '@exmg/exm-drawer/exm-drawer.js';
2
2
  import '@exmg/exm-button/exm-filled-button.js';
3
3
  import '@material/web/button/text-button.js';
4
+ import { ExmFormBase } from '@exmg/exm-form';
4
5
  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 {
6
+ export declare class ExmFormDrawerBase extends ExmgElement {
7
7
  /**
8
8
  * Opened state of the form-drawer
9
9
  * @type {Boolean}
@@ -13,17 +13,12 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
13
13
  * The title of the 'submit' button
14
14
  * @type {String}
15
15
  */
16
- submitBtnTitle: string;
17
- /**
18
- * Whether or not to hide the submit button
19
- * @type {Boolean}
20
- */
21
- submitBtnHidden: boolean;
16
+ submitBtn: string;
22
17
  /**
23
18
  * Title of the cancel button
24
19
  * @type {String}
25
20
  */
26
- cancelBtnTitle: string;
21
+ cancelBtn: string;
27
22
  /**
28
23
  * Whether or not to keep the form drawer opened on submit success
29
24
  * @type {Boolean}
@@ -34,21 +29,12 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
34
29
  * @type {Boolean}
35
30
  */
36
31
  noCancelOnOutsideClick: boolean;
37
- /**
38
- * Disable sticky header in drawer
39
- * @type {Boolean}
40
- */
41
- disableStickyHeader: boolean;
42
32
  /**
43
33
  * Internall used to show button spinner.
44
34
  */
45
35
  submitting: boolean;
46
- /**
47
- * Scroll action of the drawer
48
- * @type {'lock' | 'refit' | 'cancel' | undefined}
49
- */
50
- scrollAction?: 'lock' | 'refit' | 'cancel' | undefined;
51
36
  errorMessage?: string | null;
37
+ exmForm?: ExmFormBase;
52
38
  /**
53
39
  * Opens and shows the drawer.
54
40
  */
@@ -67,15 +53,11 @@ export declare class ExmFormDrawerBase extends ExmFormDrawerBase_base {
67
53
  * @param {CustomEvent} e
68
54
  */
69
55
  doAction?(formData: unknown): Promise<void> | void;
70
- protected handleSubmit(): Promise<void>;
71
- private handleCancelBtnClick;
72
- showError(message: string): void;
56
+ private handleSubmitFinished;
73
57
  /**
74
58
  * Method should be overriden to render form content
75
59
  */
76
- protected renderFormContent(): import("lit-html").TemplateResult<1>;
77
- protected renderError(): import("lit-html").TemplateResult<1>;
60
+ protected renderFormContent(): import("lit-html").TemplateResult<1> | undefined;
78
61
  protected handleDrawerOpenedChanged(e: CustomEvent): void;
79
62
  protected render(): import("lit-html").TemplateResult<1>;
80
63
  }
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,32 @@ 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) {
88
- return;
89
- }
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);
73
+ handleSubmitFinished({ detail }) {
74
+ if (detail.success && !this.keepOpenedOnSubmitSuccess) {
75
+ this.opened = false;
111
76
  }
112
77
  }
113
- handleCancelBtnClick() {
114
- this.reset();
115
- this.close();
116
- }
117
- showError(message) {
118
- this.errorMessage = message;
119
- }
120
78
  /**
121
79
  * Method should be overriden to render form content
122
80
  */
123
81
  renderFormContent() {
124
- return html `<slot></slot>`;
125
- }
126
- renderError() {
127
- return html `<div class="error"><div>${this.errorMessage}</div></div>`;
82
+ var _a;
83
+ return (_a = this.exmForm) === null || _a === void 0 ? void 0 : _a.renderFormContent();
128
84
  }
129
85
  handleDrawerOpenedChanged(e) {
130
86
  this.opened = e.detail.value;
87
+ if (!this.exmForm) {
88
+ return;
89
+ }
131
90
  if (this.opened) {
132
- this.checkFormValidity();
91
+ this.exmForm.checkFormValidity();
133
92
  }
134
93
  }
135
94
  render() {
@@ -138,28 +97,29 @@ export class ExmFormDrawerBase extends ExmFormValidateMixin(ExmgElement) {
138
97
  ?opened="${this.opened}"
139
98
  ?no-cancel-on-outside-click="${this.noCancelOnOutsideClick}"
140
99
  @exm-drawer-opened-changed=${this.handleDrawerOpenedChanged}
141
- scroll-action=${ifDefined(this.scrollAction)}
142
100
  maxWidth="${this.style.maxWidth || '547px'}"
143
101
  >
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>
102
+ <section class="drawer-content">
103
+ <header class="header">
104
+ <slot name="title" class="title">${this.title}</slot>
105
+ <div class="actions">
106
+ <md-icon-button @click=${this.close}>
107
+ <md-icon>close</md-icon>
108
+ </md-icon-button>
109
+ </div>
110
+ </header>
111
+ <exm-form
112
+ submitBtn=${this.submitBtn}
113
+ cancelBtn=${this.cancelBtn}
114
+ .errorMessage=${this.errorMessage}
115
+ class="form-elements"
116
+ @form-submit-finished=${this.handleSubmitFinished}
117
+ @form-cancel=${this.reset}
118
+ doAction=${ifDefined(this.doAction)}
119
+ >
120
+ ${this.renderFormContent()}
121
+ </exm-form>
122
+ </section>
163
123
  </exm-drawer>
164
124
  `;
165
125
  }
@@ -169,29 +129,23 @@ __decorate([
169
129
  ], ExmFormDrawerBase.prototype, "opened", void 0);
170
130
  __decorate([
171
131
  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);
132
+ ], ExmFormDrawerBase.prototype, "submitBtn", void 0);
176
133
  __decorate([
177
134
  property({ type: String, attribute: 'cancel-btn-title' })
178
- ], ExmFormDrawerBase.prototype, "cancelBtnTitle", void 0);
135
+ ], ExmFormDrawerBase.prototype, "cancelBtn", void 0);
179
136
  __decorate([
180
137
  property({ type: Boolean, attribute: 'keep-opened-on-submit-success' })
181
138
  ], ExmFormDrawerBase.prototype, "keepOpenedOnSubmitSuccess", void 0);
182
139
  __decorate([
183
140
  property({ type: Boolean, attribute: 'no-cancel-on-outside-click' })
184
141
  ], ExmFormDrawerBase.prototype, "noCancelOnOutsideClick", void 0);
185
- __decorate([
186
- property({ type: Boolean, attribute: 'disable-sticky-header' })
187
- ], ExmFormDrawerBase.prototype, "disableStickyHeader", void 0);
188
142
  __decorate([
189
143
  property({ type: Boolean })
190
144
  ], ExmFormDrawerBase.prototype, "submitting", void 0);
191
- __decorate([
192
- property({ type: String, attribute: 'scroll-action' })
193
- ], ExmFormDrawerBase.prototype, "scrollAction", void 0);
194
145
  __decorate([
195
146
  property({ type: String })
196
147
  ], ExmFormDrawerBase.prototype, "errorMessage", void 0);
148
+ __decorate([
149
+ query('exm-form')
150
+ ], ExmFormDrawerBase.prototype, "exmForm", void 0);
197
151
  //# 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,14 @@ 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
+ if (!this.exmForm) {
9
+ return;
10
+ }
11
+ /**
12
+ * We have to overwrite the getForm method because for whatever reason the form is not properly accessible from within the exm-form component
13
+ */
14
+ this.exmForm.getForm = () => this.querySelector('form');
9
15
  }
10
16
  };
11
17
  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.11",
3
+ "version": "1.1.13",
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.11",
35
- "@exmg/exm-form": "^1.1.11"
34
+ "@exmg/exm-drawer": "^1.1.13",
35
+ "@exmg/exm-form": "^1.1.13"
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": "5a615cfa5fb07dd11e3dff848b429b9c3a0a4313"
45
+ "gitHead": "f482775e785f3e1fe8dde56cf7614428ff9a7e80"
46
46
  }