diff --git a/src/layer/index.js b/src/layer/index.js index 26b824e..53b3273 100644 --- a/src/layer/index.js +++ b/src/layer/index.js @@ -34,6 +34,10 @@ class Layer extends Component { this.#wrapped = !BUILDIN_TYPES.includes(v) } }, + left: { type: String, attribute: false }, + right: { type: String, attribute: false }, + top: { type: String, attribute: false }, + bottom: { type: String, attribute: false }, fixed: false, mask: false, 'mask-close': false, @@ -58,6 +62,14 @@ class Layer extends Component { :host([type]) { display: flex; } + :host([type='toast']), + :host([type='notify']), + :host([type='common']) { + .layer { + position: absolute; + } + } + .noselect { -webkit-touch-callout: none; user-select: none; @@ -70,7 +82,6 @@ class Layer extends Component { css` .layer { - overflow: hidden; flex: 0 auto; position: relative; z-index: 65535; @@ -82,11 +93,6 @@ class Layer extends Component { transition: opacity 0.2s ease-in-out, left 0.2s ease-in-out, right 0.2s ease-in-out, top 0.2s ease-in-out, bottom 0.2s ease-in-out; - &.scale { - transform: scale(1.01); - transition: transform 0.1s linear; - } - &:active { z-index: 65536; } @@ -129,9 +135,13 @@ class Layer extends Component { } ::slotted(&__toast) { + flex-shrink: 0; + flex: 1; display: flex; align-items: center; width: 300px; + min-height: 40px; + margin-bottom: 15px !important; padding: 0 10px !important; border-radius: 3px; font-weight: normal; @@ -139,6 +149,9 @@ class Layer extends Component { --size: 16px; color: var(--color-dark-1); } + ::slotted(&__toast + &__toast) { + margin-top: 30px; + } ::slotted(&__toast.style-info) { border: 1px solid #ebeef5; @@ -226,8 +239,7 @@ class Layer extends Component { css` :host([mask]) { height: 100%; - background: rgba(255, 255, 255, 0.15); - backdrop-filter: blur(5px); + background: rgba(0, 0, 0, 0.2); } :host([type='alert']), @@ -258,6 +270,7 @@ class Layer extends Component { box-shadow: none; &__content { + flex-direction: column; min-height: 40px; } } @@ -322,6 +335,40 @@ class Layer extends Component { } } + #play() { + switch (this.type) { + case 'toast': + let elem = this.lastElementChild + elem._anim = elem.animate( + [ + { marginTop: '-30px', opacity: 0 }, + { marginTop: '0', opacity: 1 } + ], + { + duration: 200, + fill: 'forwards' + } + ) + setTimeout(() => { + elem._anim.reverse() + elem._anim.onfinish = _ => { + elem.remove() + } + if (this.children.length === 0) { + this.close() + toastInstance = null + } + }, 3000) + break + case 'notify': + break + + default: + this.$refs.box.$animate() + break + } + } + mounted() { if (this.type === 'prompt') { this.$refs.input = this.firstElementChild @@ -337,15 +384,14 @@ class Layer extends Component { if (path[0] === ev.currentTarget) { if (UNIQUE_TYPES.includes(this.type)) { - this.$refs.box.classList.toggle('scale', true) - setTimeout(_ => { - this.$refs.box.classList.remove('scale') - }, 100) - } else if (this['mask-close']) { + return + } + + if (this['mask-close']) { if (this.#wrapped === false) { this.#reject() } - this.close() + this.$refs.box.$animate(true).then(_ => this.close()) } } }) @@ -357,11 +403,19 @@ class Layer extends Component { this.#toggleDrag() - this.$refs.box.$animate() + this.#play() } updated() { - this.$refs.box.$animate() + this.#play() + } + + moveTo(obj = {}) { + var css = '' + for (var k in obj) { + css += `${k}:${obj[k]};` + } + this.$refs.box.style.cssText += css } show() { @@ -442,8 +496,22 @@ class Layer extends Component { } render() { + let { type, mask, left, right, top, bottom } = this + let styles = '' + + if (type === 'common' && mask === false) { + top = top || 0 + } + + styles = styleMap({ left, right, top, bottom }) + return html` -
+
- + ${txt}
`, type: 'toast'