Skip to content

Commit ce8d04f

Browse files
authored
feat(Toast): add type classNames (youzan#4785)
1 parent c0bc240 commit ce8d04f

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/toast/Toast.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,24 @@ export default createComponent({
8181

8282
onAfterLeave() {
8383
this.$emit('closed');
84-
}
85-
},
86-
87-
render() {
88-
const { type, icon, message, iconPrefix, loadingType } = this;
84+
},
8985

90-
const hasIcon = icon || (type === 'success' || type === 'fail');
86+
genIcon() {
87+
const { icon, type, iconPrefix, loadingType } = this;
88+
const hasIcon = icon || (type === 'success' || type === 'fail');
9189

92-
function ToastIcon() {
9390
if (hasIcon) {
9491
return <Icon class={bem('icon')} classPrefix={iconPrefix} name={icon || type} />;
9592
}
9693

9794
if (type === 'loading') {
9895
return <Loading class={bem('loading')} type={loadingType} />;
9996
}
100-
}
97+
},
98+
99+
genMessage() {
100+
const { type, message } = this;
101101

102-
function Message() {
103102
if (!isDef(message) || message === '') {
104103
return;
105104
}
@@ -110,7 +109,9 @@ export default createComponent({
110109

111110
return <div class={bem('text')}>{message}</div>;
112111
}
112+
},
113113

114+
render() {
114115
return (
115116
<transition
116117
name={this.transition}
@@ -119,14 +120,11 @@ export default createComponent({
119120
>
120121
<div
121122
vShow={this.value}
122-
class={[
123-
bem([this.position, { text: !hasIcon && type !== 'loading' }]),
124-
this.className
125-
]}
123+
class={[bem([this.position, { [this.type]: !this.icon }]), this.className]}
126124
onClick={this.onClick}
127125
>
128-
{ToastIcon()}
129-
{Message()}
126+
{this.genIcon()}
127+
{this.genMessage()}
130128
</div>
131129
</transition>
132130
);

src/toast/index.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
}
3636
}
3737

38-
&--text {
38+
&--text,
39+
&--html {
3940
width: fit-content;
4041
min-width: @toast-text-min-width;
4142
min-height: unset;

src/toast/test/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`create a forbidClick toast 1`] = `
4-
<div class="van-toast van-toast--middle" style="z-index: 2001;" name="van-fade"><i class="van-icon van-icon-success van-toast__icon">
4+
<div class="van-toast van-toast--middle van-toast--success" style="z-index: 2001;" name="van-fade"><i class="van-icon van-icon-success van-toast__icon">
55
<!----></i></div>
66
`;
77

@@ -20,15 +20,15 @@ exports[`icon-prefix prop 1`] = `
2020
`;
2121

2222
exports[`show html toast 1`] = `
23-
<div class="van-toast van-toast--middle van-toast--text" style="z-index: 2004;" name="van-fade">
23+
<div class="van-toast van-toast--middle van-toast--html" style="z-index: 2004;" name="van-fade">
2424
<div class="van-toast__text">
2525
<div>Message</div>
2626
</div>
2727
</div>
2828
`;
2929

3030
exports[`show loading toast 1`] = `
31-
<div class="van-toast van-toast--middle" style="z-index: 2003;" name="van-fade">
31+
<div class="van-toast van-toast--middle van-toast--loading" style="z-index: 2003;" name="van-fade">
3232
<div class="van-loading van-loading--circular van-toast__loading"><span class="van-loading__spinner van-loading__spinner--circular"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span></div>
3333
<div class="van-toast__text">Message</div>
3434
</div>

0 commit comments

Comments
 (0)