Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dialog): fix button color with different theme #5723

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ interface DialogOptions {
showCancelButton?: boolean;
closeOnClickOverlay?: boolean;
confirmButtonOpenType?: string;
confirmButtonColor?: string;
cancelButtonColor?: string;
}

const defaultOptions: DialogOptions = {
Expand Down
19 changes: 16 additions & 3 deletions packages/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VantComponent } from '../common/component';
import { button } from '../mixins/button';
import { GRAY, RED } from '../common/color';
import { GRAY, RED, WHITE } from '../common/color';
import { toPromise } from '../common/utils';
import type { Action } from './dialog';

Expand All @@ -13,6 +13,7 @@ VantComponent({
type: Boolean,
observer(show: boolean) {
!show && this.stopLoading();
this.handleButtonColor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是不是可以通过 wxs 来实现,性能会好一点

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已调整使用wxs

},
},
title: String,
Expand Down Expand Up @@ -50,11 +51,11 @@ VantComponent({
},
confirmButtonColor: {
type: String,
value: RED,
value: '',
},
cancelButtonColor: {
type: String,
value: GRAY,
value: '',
},
showConfirmButton: {
type: Boolean,
Expand All @@ -79,6 +80,8 @@ VantComponent({
confirm: false,
cancel: false,
},
innerConfirmButtonColor: '',
innerCancelButtonColor: '',
callback: (() => {}) as unknown as (
action: string,
context: WechatMiniprogram.Component.TrivialInstance
Expand Down Expand Up @@ -143,5 +146,15 @@ VantComponent({
});
}
},

handleButtonColor() {
const { confirmButtonColor, cancelButtonColor, theme } = this.data;
this.setData({
innerConfirmButtonColor:
confirmButtonColor || (theme === 'default' ? RED : WHITE),
innerCancelButtonColor:
cancelButtonColor || (theme === 'default' ? GRAY : WHITE),
});
},
},
});
8 changes: 4 additions & 4 deletions packages/dialog/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
custom-style="color: {{ innerCancelButtonColor }}"
bind:click="onCancel"
>
{{ cancelButtonText }}
Expand All @@ -46,7 +46,7 @@
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
custom-style="color: {{ innerConfirmButtonColor }}"
button-id="{{ confirmButtonId }}"
open-type="{{ confirmButtonOpenType }}"
lang="{{ lang }}"
Expand Down Expand Up @@ -81,7 +81,7 @@
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
custom-style="color: {{ innerCancelButtonColor }}"
bind:click="onCancel"
>
{{ cancelButtonText }}
Expand All @@ -97,7 +97,7 @@
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
custom-style="color: {{ innerConfirmButtonColor }}"
button-id="{{ confirmButtonId }}"
open-type="{{ confirmButtonOpenType }}"
lang="{{ lang }}"
Expand Down
Loading