@exmg/exm-drawer 1.1.9 → 1.1.10-alpha.26

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.
@@ -0,0 +1,34 @@
1
+ import { ExmgElement } from '@exmg/lit-base';
2
+ export declare class ExmDrawerBase extends ExmgElement {
3
+ /**
4
+ * The opened state of the drawer
5
+ */
6
+ opened: boolean;
7
+ /**
8
+ * Which side should we show the drawer
9
+ * @type {String}
10
+ */
11
+ side: 'right' | 'left';
12
+ /**
13
+ * Prevent cancel on outside click or not
14
+ */
15
+ noCancelOnOutsideClick: boolean;
16
+ /**
17
+ * Prevent cancel on use of the escape key
18
+ */
19
+ disableEsc: boolean;
20
+ dialogElement?: HTMLDialogElement;
21
+ private onBackdropPointerDown;
22
+ private onCancel;
23
+ protected firstUpdated(): void;
24
+ disconnectedCallback(): void;
25
+ private handleOpenedChange;
26
+ /**
27
+ * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
28
+ * In the dialog is a div.content element. When clicking this area, the target is not the dialog, so will not close the client
29
+ */
30
+ private handleBackdropClick;
31
+ openDialog(): void;
32
+ closeDialog(): void;
33
+ render(): import("lit-html").TemplateResult<1>;
34
+ }
@@ -0,0 +1,99 @@
1
+ import { __decorate } from "tslib";
2
+ import { html } from 'lit';
3
+ import { property, query } from 'lit/decorators.js';
4
+ import { ExmgElement, observer } from '@exmg/lit-base';
5
+ export class ExmDrawerBase extends ExmgElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ /**
9
+ * The opened state of the drawer
10
+ */
11
+ this.opened = false;
12
+ /**
13
+ * Which side should we show the drawer
14
+ * @type {String}
15
+ */
16
+ this.side = 'right';
17
+ /**
18
+ * Prevent cancel on outside click or not
19
+ */
20
+ this.noCancelOnOutsideClick = false;
21
+ /**
22
+ * Prevent cancel on use of the escape key
23
+ */
24
+ this.disableEsc = false;
25
+ this.onBackdropPointerDown = (event) => this.handleBackdropClick(event);
26
+ this.onCancel = (event) => {
27
+ if (this.disableEsc) {
28
+ event.preventDefault();
29
+ }
30
+ };
31
+ }
32
+ firstUpdated() {
33
+ if (!this.dialogElement)
34
+ return;
35
+ this.dialogElement.addEventListener('pointerdown', this.onBackdropPointerDown);
36
+ this.dialogElement.addEventListener('cancel', this.onCancel);
37
+ }
38
+ disconnectedCallback() {
39
+ var _a, _b;
40
+ (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('pointerdown', this.onBackdropPointerDown);
41
+ (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('cancel', this.onCancel);
42
+ super.disconnectedCallback();
43
+ }
44
+ async handleOpenedChange(opened) {
45
+ if (!this.dialogElement)
46
+ return;
47
+ if (opened) {
48
+ this.dialogElement.showModal();
49
+ }
50
+ else {
51
+ this.dialogElement.close();
52
+ }
53
+ this.fire('exm-drawer-opened-changed', { value: opened }, true);
54
+ }
55
+ /**
56
+ * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
57
+ * In the dialog is a div.content element. When clicking this area, the target is not the dialog, so will not close the client
58
+ */
59
+ handleBackdropClick(event) {
60
+ var _a;
61
+ if (!this.noCancelOnOutsideClick && event.target === this.dialogElement) {
62
+ (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.close();
63
+ }
64
+ }
65
+ openDialog() {
66
+ this.opened = true;
67
+ }
68
+ closeDialog() {
69
+ this.opened = false;
70
+ }
71
+ render() {
72
+ return html `
73
+ <dialog class="${this.side}" @close=${() => (this.opened = false)}>
74
+ <div class="content">
75
+ <slot></slot>
76
+ </div>
77
+ </dialog>
78
+ `;
79
+ }
80
+ }
81
+ __decorate([
82
+ property({ type: Boolean }),
83
+ observer(function (opened) {
84
+ this.handleOpenedChange(opened);
85
+ })
86
+ ], ExmDrawerBase.prototype, "opened", void 0);
87
+ __decorate([
88
+ property({ type: String })
89
+ ], ExmDrawerBase.prototype, "side", void 0);
90
+ __decorate([
91
+ property({ type: Boolean, attribute: 'no-cancel-on-outside-click' })
92
+ ], ExmDrawerBase.prototype, "noCancelOnOutsideClick", void 0);
93
+ __decorate([
94
+ property({ type: Boolean, attribute: 'no-cancel-on-escape' })
95
+ ], ExmDrawerBase.prototype, "disableEsc", void 0);
96
+ __decorate([
97
+ query('dialog')
98
+ ], ExmDrawerBase.prototype, "dialogElement", void 0);
99
+ //# sourceMappingURL=exm-drawer-base.js.map
@@ -0,0 +1,9 @@
1
+ import { ExmDrawerBase } from './exm-drawer-base.js';
2
+ export declare class ExmDrawer extends ExmDrawerBase {
3
+ static styles: import("lit").CSSResult[];
4
+ }
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ 'exm-drawer': ExmDrawer;
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { style } from './styles/exm-drawer-styles-css.js';
4
+ import { ExmDrawerBase } from './exm-drawer-base.js';
5
+ let ExmDrawer = class ExmDrawer extends ExmDrawerBase {
6
+ };
7
+ ExmDrawer.styles = [style];
8
+ ExmDrawer = __decorate([
9
+ customElement('exm-drawer')
10
+ ], ExmDrawer);
11
+ export { ExmDrawer };
12
+ //# sourceMappingURL=exm-drawer.js.map
@@ -0,0 +1,3 @@
1
+ export { ExmDrawer } from './exm-drawer.js';
2
+ export { ExmDrawerBase } from './exm-drawer-base.js';
3
+ export { style as drawerStyles } from './styles/exm-drawer-styles-css.js';
@@ -0,0 +1,4 @@
1
+ export { ExmDrawer } from './exm-drawer.js';
2
+ export { ExmDrawerBase } from './exm-drawer-base.js';
3
+ export { style as drawerStyles } from './styles/exm-drawer-styles-css.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export declare const style: import("lit").CSSResult;
@@ -0,0 +1,81 @@
1
+ import { css } from 'lit';
2
+ export const style = css `
3
+ :host {
4
+ --_exm-drawer-max-width: var(--exm-drawer-max-width, 574px);
5
+ --_exm-drawer-top-offset: var(--exm-drawer-top-offset, 0);
6
+ }
7
+
8
+ dialog {
9
+ --drawer-animation-start: var(--_exm-drawer-max-width);
10
+ --drawer-animation-end: 0;
11
+
12
+ position: fixed;
13
+ top: var(--_exm-drawer-top-offset);
14
+ right: 0;
15
+ left: auto;
16
+ width: var(--_exm-drawer-max-width);
17
+ margin: 0;
18
+ height: calc(100vh - var(--_exm-drawer-top-offset));
19
+ max-height: calc(100vh - var(--_exm-drawer-top-offset));
20
+ padding: 0;
21
+ transition:
22
+ display 0.3s allow-discrete,
23
+ overlay 0.3s allow-discrete;
24
+ animation: drawerClose 0.3s forwards;
25
+ border: 0;
26
+ background-color: var(--exm-drawer-container-color, var(--md-sys-color-surface-container, #f3edf7));
27
+ color: var(--exm-drawer-container-on-color, var(--md-sys-color-on-surface, #f3edf7));
28
+
29
+ &[open] {
30
+ animation: drawerShow 0.3s forwards;
31
+ }
32
+
33
+ &::backdrop {
34
+ background: rgba(0, 0, 0, 0.7);
35
+ backdrop-filter: blur(4px);
36
+ top: var(--_exm-drawer-top-offset);
37
+ animation: overlayShow 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
38
+ }
39
+
40
+ &.left {
41
+ --drawer-animation-start: calc(var(--_exm-drawer-max-width) * -1);
42
+
43
+ left: 0;
44
+ right: auto;
45
+ }
46
+
47
+ .content {
48
+ position: absolute;
49
+ width: 100%;
50
+ height: 100%;
51
+ }
52
+ }
53
+
54
+ @keyframes overlayShow {
55
+ from {
56
+ opacity: 0;
57
+ }
58
+ to {
59
+ opacity: 1;
60
+ }
61
+ }
62
+
63
+ @keyframes drawerShow {
64
+ from {
65
+ transform: translateX(var(--drawer-animation-start));
66
+ }
67
+ to {
68
+ transform: translateX(var(--drawer-animation-end));
69
+ }
70
+ }
71
+
72
+ @keyframes drawerClose {
73
+ from {
74
+ transform: translateX(var(--drawer-animation-end));
75
+ }
76
+ to {
77
+ transform: translateX(var(--drawer-animation-start));
78
+ }
79
+ }
80
+ `;
81
+ //# sourceMappingURL=exm-drawer-styles-css.js.map
@@ -1,4 +1,3 @@
1
- import { PropertyValues } from 'lit';
2
1
  import { ExmgElement } from '@exmg/lit-base';
3
2
  export declare class ExmDrawerBase extends ExmgElement {
4
3
  /**
@@ -19,21 +18,17 @@ export declare class ExmDrawerBase extends ExmgElement {
19
18
  */
20
19
  disableEsc: boolean;
21
20
  dialogElement?: HTMLDialogElement;
21
+ private onBackdropPointerDown;
22
+ private onCancel;
23
+ protected firstUpdated(): void;
22
24
  disconnectedCallback(): void;
23
- protected firstUpdated(_changedProperties: PropertyValues): void;
24
25
  private handleOpenedChange;
25
26
  /**
26
27
  * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
27
28
  * In the dialog is a div.content element. When clicking this area, the target is not the dialog, so will not close the client
28
29
  */
29
30
  private handleBackdropClick;
30
- private catchEscKey;
31
- private handleCloseEvent;
32
- private handleOpenedChanged;
33
31
  openDialog(): void;
34
32
  closeDialog(): void;
35
- /**
36
- * The div.content in the render is needed for making the backdrop click work
37
- */
38
33
  render(): import("lit-html").TemplateResult<1>;
39
34
  }
@@ -1,8 +1,9 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate } from 'tslib';
2
2
  import { html } from 'lit';
3
3
  import { property, query } from 'lit/decorators.js';
4
- import { ExmgElement, observer } from '@exmg/lit-base';
5
- export class ExmDrawerBase extends ExmgElement {
4
+ import { observer, ExmgElement } from '@exmg/lit-base';
5
+
6
+ class ExmDrawerBase extends ExmgElement {
6
7
  constructor() {
7
8
  super(...arguments);
8
9
  /**
@@ -22,31 +23,35 @@ export class ExmDrawerBase extends ExmgElement {
22
23
  * Prevent cancel on use of the escape key
23
24
  */
24
25
  this.disableEsc = false;
26
+ this.onBackdropPointerDown = (event) => this.handleBackdropClick(event);
27
+ this.onCancel = (event) => {
28
+ if (this.disableEsc) {
29
+ event.preventDefault();
30
+ }
31
+ };
32
+ }
33
+ firstUpdated() {
34
+ if (!this.dialogElement)
35
+ return;
36
+ this.dialogElement.addEventListener('pointerdown', this.onBackdropPointerDown);
37
+ this.dialogElement.addEventListener('cancel', this.onCancel);
25
38
  }
26
39
  disconnectedCallback() {
27
40
  var _a, _b;
28
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('close', this.handleCloseEvent.bind(this));
29
- (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('keydown', this.catchEscKey.bind(this));
41
+ (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('pointerdown', this.onBackdropPointerDown);
42
+ (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.removeEventListener('cancel', this.onCancel);
30
43
  super.disconnectedCallback();
31
44
  }
32
- firstUpdated(_changedProperties) {
33
- var _a;
34
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.addEventListener('close', this.handleCloseEvent.bind(this));
35
- }
36
- handleOpenedChange(opened) {
37
- var _a, _b, _c, _d;
45
+ async handleOpenedChange(opened) {
46
+ if (!this.dialogElement)
47
+ return;
38
48
  if (opened) {
39
- if (!this.noCancelOnOutsideClick) {
40
- (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.handleBackdropClick.bind(this));
41
- }
42
- if (this.disableEsc) {
43
- (_b = this.dialogElement) === null || _b === void 0 ? void 0 : _b.addEventListener('keydown', this.catchEscKey.bind(this));
44
- }
45
- (_c = this.dialogElement) === null || _c === void 0 ? void 0 : _c.showModal();
49
+ this.dialogElement.showModal();
46
50
  }
47
51
  else {
48
- (_d = this.dialogElement) === null || _d === void 0 ? void 0 : _d.close();
52
+ this.dialogElement.close();
49
53
  }
54
+ this.fire('exm-drawer-opened-changed', { value: opened }, true);
50
55
  }
51
56
  /**
52
57
  * Handle the backdrop click. Check if the clicked element is the dialog. If so close it.
@@ -54,34 +59,19 @@ export class ExmDrawerBase extends ExmgElement {
54
59
  */
55
60
  handleBackdropClick(event) {
56
61
  var _a;
57
- if (event.target === this.dialogElement) {
62
+ if (!this.noCancelOnOutsideClick && event.target === this.dialogElement) {
58
63
  (_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.close();
59
64
  }
60
65
  }
61
- catchEscKey(event) {
62
- if (event.code === 'Escape') {
63
- event.preventDefault();
64
- }
65
- }
66
- handleCloseEvent() {
67
- this.handleOpenedChanged({ detail: { value: false } });
68
- }
69
- handleOpenedChanged(e) {
70
- this.opened = e.detail.value;
71
- this.fire('exm-drawer-opened-changed', this.opened, true);
72
- }
73
66
  openDialog() {
74
67
  this.opened = true;
75
68
  }
76
69
  closeDialog() {
77
70
  this.opened = false;
78
71
  }
79
- /**
80
- * The div.content in the render is needed for making the backdrop click work
81
- */
82
72
  render() {
83
73
  return html `
84
- <dialog class="${this.side}" @opened-changed="${this.handleOpenedChanged}">
74
+ <dialog class="${this.side}" @close=${() => (this.opened = false)}>
85
75
  <div class="content">
86
76
  <slot></slot>
87
77
  </div>
@@ -107,4 +97,6 @@ __decorate([
107
97
  __decorate([
108
98
  query('dialog')
109
99
  ], ExmDrawerBase.prototype, "dialogElement", void 0);
110
- //# sourceMappingURL=exm-drawer-base.js.map
100
+
101
+ export { ExmDrawerBase };
102
+ //# sourceMappingURL=exm-drawer-base.js.map
@@ -1,12 +1,14 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate } from 'tslib';
2
2
  import { customElement } from 'lit/decorators.js';
3
3
  import { style } from './styles/exm-drawer-styles-css.js';
4
4
  import { ExmDrawerBase } from './exm-drawer-base.js';
5
+
5
6
  let ExmDrawer = class ExmDrawer extends ExmDrawerBase {
6
7
  };
7
8
  ExmDrawer.styles = [style];
8
9
  ExmDrawer = __decorate([
9
10
  customElement('exm-drawer')
10
11
  ], ExmDrawer);
12
+
11
13
  export { ExmDrawer };
12
- //# sourceMappingURL=exm-drawer.js.map
14
+ //# sourceMappingURL=exm-drawer.js.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ExmDrawer } from './exm-drawer.js';
2
2
  export { ExmDrawerBase } from './exm-drawer-base.js';
3
3
  export { style as drawerStyles } from './styles/exm-drawer-styles-css.js';
4
- //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,6 @@
1
1
  import { css } from 'lit';
2
- export const style = css `
2
+
3
+ const style = css `
3
4
  :host {
4
5
  --_exm-drawer-max-width: var(--exm-drawer-max-width, 574px);
5
6
  --_exm-drawer-top-offset: var(--exm-drawer-top-offset, 0);
@@ -24,7 +25,7 @@ export const style = css `
24
25
  animation: drawerClose 0.3s forwards;
25
26
  border: 0;
26
27
  background-color: var(--exm-drawer-container-color, var(--md-sys-color-surface-container, #f3edf7));
27
- color: var(--exm-drawer-container-on-color, var(--md-sys-color-on-surface-container, #f3edf7));
28
+ color: var(--exm-drawer-container-on-color, var(--md-sys-color-on-surface, #f3edf7));
28
29
 
29
30
  &[open] {
30
31
  animation: drawerShow 0.3s forwards;
@@ -78,4 +79,6 @@ export const style = css `
78
79
  }
79
80
  }
80
81
  `;
81
- //# sourceMappingURL=exm-drawer-styles-css.js.map
82
+
83
+ export { style };
84
+ //# sourceMappingURL=exm-drawer-styles-css.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-drawer",
3
- "version": "1.1.9",
3
+ "version": "1.1.10-alpha.26+dffd4ec",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,16 +29,13 @@
29
29
  "directory": "packages/exm-drawer"
30
30
  },
31
31
  "license": "MIT",
32
- "dependencies": {
33
- "lit": "^3.0.0",
32
+ "peerDependencies": {
33
+ "lit": "^3.2.1",
34
34
  "tslib": "^2.6.2"
35
35
  },
36
- "devDependencies": {
37
- "@exmg/lit-cli": "1.1.13"
38
- },
39
36
  "scripts": {},
40
37
  "publishConfig": {
41
38
  "access": "public"
42
39
  },
43
- "gitHead": "ac876ab3f3d6d83a43a3944c052c8e71de300832"
40
+ "gitHead": "dffd4ecb68fdeb061f4e8ad585af221bfb0f8e8b"
44
41
  }