From 3eab56a04972efa43b1c56c95dba07cb7f6f2b27 Mon Sep 17 00:00:00 2001 From: chenjiajian <770230504@qq.com> Date: Fri, 28 Apr 2023 18:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96collapse=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/collapse/index.js | 39 +++++++++++--------- src/popconfirm/index.js | 82 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 src/popconfirm/index.js diff --git a/src/collapse/index.js b/src/collapse/index.js index 38cda0c..62cff09 100644 --- a/src/collapse/index.js +++ b/src/collapse/index.js @@ -4,7 +4,7 @@ * @date 2023/03/26 16:14:10 */ -import { css, html, Component } from '@bd/core' +import { css, html, Component, styleMap, nextTick } from '@bd/core' import '../icon/index.js' class Collapse extends Component { @@ -60,6 +60,7 @@ class Collapse extends Component { mounted() { this.$children = Array.from(this.children) this.updateView() + this.$on('updateValue', e => this.updateValue(e.name)) } } class CollapseItem extends Component { @@ -69,6 +70,7 @@ class CollapseItem extends Component { disabled: false } _show = false + contentHeight = 0 static styles = [ css` :host { @@ -117,37 +119,40 @@ class CollapseItem extends Component { if (this.disabled) { return } - this.parentNode.updateValue(this.name) + this.$emit('updateValue', { name: this.name }) } get show() { return this._show } set show(val) { - const { content, wrapper, icon } = this.$refs - if (!wrapper) { - this.onMounted = () => (this.show = val) - return - } - if (val) { - wrapper.style.height = content.offsetHeight + 'px' - icon.style.transform = 'rotate(90deg)' - } else { - wrapper.style.height = 0 - icon.style.transform = 'rotate(0deg)' - } this._show = val + this.contentHeight = this.$refs.content?.offsetHeight || 0 + this.$requestUpdate() } mounted() { - this.onMounted && this.onMounted() + nextTick(() => { + this.contentHeight = this.$refs.content.offsetHeight + this.$requestUpdate() + }) } render() { return html`