feat(SwipeCell): add open event (#5324)

This commit is contained in:
neverland
2019-12-20 10:20:18 +08:00
committed by GitHub
parent ac00d78a46
commit c0b1460c80
4 changed files with 55 additions and 21 deletions
+25 -18
View File
@@ -63,29 +63,28 @@ export default createComponent({
const offset =
position === 'left' ? this.computedLeftWidth : -this.computedRightWidth;
this.swipeMove(offset);
this.opened = true;
this.offset = offset;
this.$emit('open', {
position,
name: this.name,
// @deprecated
// should be removed in next major version
detail: this.name
});
},
// @exposed-api
close() {
close(position) {
this.offset = 0;
},
swipeMove(offset = 0) {
this.offset = range(
offset,
-this.computedRightWidth,
this.computedLeftWidth
);
if (!this.offset) {
if (this.opened) {
this.opened = false;
this.$emit('close', {
position,
name: this.name
});
}
},
@@ -115,7 +114,11 @@ export default createComponent({
preventDefault(event, this.stopPropagation);
}
this.swipeMove(this.deltaX + this.startOffset);
this.offset = range(
this.deltaX + this.startOffset,
-this.computedRightWidth,
this.computedLeftWidth
);
}
},
@@ -153,7 +156,7 @@ export default createComponent({
) {
this.open('left');
} else {
this.swipeMove(0);
this.close();
}
},
@@ -170,7 +173,7 @@ export default createComponent({
} else if (this.onClose) {
this.onClose(position, this, { name: this.name });
} else {
this.swipeMove(0);
this.close(position);
}
}
},
@@ -185,28 +188,32 @@ export default createComponent({
},
genLeftPart() {
if (this.slots('left')) {
const content = this.slots('left');
if (content) {
return (
<div
ref="left"
class={bem('left')}
onClick={this.getClickHandler('left', true)}
>
{this.slots('left')}
{content}
</div>
);
}
},
genRightPart() {
if (this.slots('right')) {
const content = this.slots('right');
if (content) {
return (
<div
ref="right"
class={bem('right')}
onClick={this.getClickHandler('right', true)}
>
{this.slots('right')}
{content}
</div>
);
}