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 all commits
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
5 changes: 2 additions & 3 deletions packages/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { VantComponent } from '../common/component';
import { button } from '../mixins/button';
import { GRAY, RED } from '../common/color';
import { toPromise } from '../common/utils';
import type { Action } from './dialog';

Expand Down Expand Up @@ -50,11 +49,11 @@ VantComponent({
},
confirmButtonColor: {
type: String,
value: RED,
value: '',
},
cancelButtonColor: {
type: String,
value: GRAY,
value: '',
},
showConfirmButton: {
type: Boolean,
Expand Down
9 changes: 5 additions & 4 deletions packages/dialog/index.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />

<van-popup
show="{{ show }}"
Expand Down Expand Up @@ -35,7 +36,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="{{computed.buttonColor({theme, cancelButtonColor, buttonName: 'cancelButton'})}}"
bind:click="onCancel"
>
{{ cancelButtonText }}
Expand All @@ -46,7 +47,7 @@
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
custom-style="{{computed.buttonColor({theme, confirmButtonColor, buttonName: 'confirmButton'})}}"
button-id="{{ confirmButtonId }}"
open-type="{{ confirmButtonOpenType }}"
lang="{{ lang }}"
Expand Down Expand Up @@ -81,7 +82,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="{{computed.buttonColor({theme, cancelButtonColor, buttonName: 'cancelButton'})}}"
bind:click="onCancel"
>
{{ cancelButtonText }}
Expand All @@ -97,7 +98,7 @@
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
custom-style="{{computed.buttonColor({theme, confirmButtonColor, buttonName: 'confirmButton'})}}"
button-id="{{ confirmButtonId }}"
open-type="{{ confirmButtonOpenType }}"
lang="{{ lang }}"
Expand Down
26 changes: 26 additions & 0 deletions packages/dialog/index.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var RED = '#ee0a24';
var WHITE = '#fff';
var GRAY = '#323233';
function buttonColor(data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有两个改造思路,一个是 RED 这些JS变量是不是可以用全局的 CSS 变量,这里本身是 style,理论上是可以用的,避免在维护一套JS的样式变量

另外一个是这个函数是不是可以统一改造根据不同的条件回生效不同的样式,目前的实现可复用度比较低

var type = data.buttonName;
var theme = data.theme;
var color = '';
switch (type) {
case 'confirmButton':
color = data.confirmButtonColor || (theme === 'default' ? RED : WHITE);
break;
case 'cancelButton':
color = data.cancelButtonColor || (theme === 'default' ? GRAY : WHITE);
break;
}

return style({
color: color,
});
}

module.exports = {
buttonColor: buttonColor,
};
Loading