Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit 119d6ed

Browse files
committed
add null check, animate open/close
The await on animation finish is delightful! Yay web platform
1 parent 2afc3f7 commit 119d6ed

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/micro-panel-editor-entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class MicroPanelEditorEntry extends LitElement {
6363
this._modify(entry, draft => draft.properties[propname].push(''))
6464
} title="Add new value to this property" class="icon-button">${iconCode(icons.plus)}</button>
6565
</header>
66-
${entry.properties[propname].map((propval, idx) => html`
66+
${entry.properties[propname] && entry.properties[propname].map((propval, idx) => html`
6767
<div class="input-row">
6868
${this._rowEditor(entry, propname, propval, idx)}
6969
<button on-click=${_ =>

src/micro-panel-editor.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class MicroPanelEditor extends LitElement {
4343
left: 0;
4444
right: 0;
4545
background: var(--neutral);
46+
z-index: 69420;
4647
}
4748
#root-editor {
4849
flex: 1;
@@ -71,18 +72,31 @@ export default class MicroPanelEditor extends LitElement {
7172
`
7273
}
7374

74-
close () {
75+
async close () {
7576
if (this.entryIsModified && !confirm('Abandon current modified entry?')) {
7677
return
7778
}
79+
if ('animate' in this && 'finished' in Animation.prototype) {
80+
await this.animate({transform: ['none', 'translateY(100vh)']}, {duration: 300, easing: 'ease-out'}).finished
81+
}
7882
this.hidden = true
83+
document.body.style.overflow = this.oldBodyOverflow
84+
}
85+
86+
show () {
87+
this.oldBodyOverflow = document.body.style.overflow
88+
document.body.style.overflow = 'hidden'
89+
this.hidden = false
90+
if ('animate' in this) {
91+
this.animate({transform: ['translateY(100vh)', 'none']}, {duration: 300, easing: 'ease-out'})
92+
}
7993
}
8094

8195
async editEntry (url) {
8296
this.entry = await (await micropubGet(this.micropub, `q=source&url=${encodeURIComponent(url)}`)).json()
8397
this.entryIsNew = false
8498
this.entryIsModified = false
85-
this.hidden = false
99+
this.show()
86100
}
87101

88102
newEntry (properties = { name: ['New post'], content: [''] }) {
@@ -92,7 +106,7 @@ export default class MicroPanelEditor extends LitElement {
92106
}
93107
this.entryIsNew = true
94108
this.entryIsModified = false
95-
this.hidden = false
109+
this.show()
96110
}
97111

98112
createEntry () {

0 commit comments

Comments
 (0)