Skip to content

Commit

Permalink
Merge pull request #673 from Tencent/feat/button/loading-props
Browse files Browse the repository at this point in the history
feat(button): use t-loading && support loading-props
  • Loading branch information
LeeJim authored Jul 29, 2022
2 parents 153d88f + 50be127 commit 2bf6d5c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ghost | Boolean | false | 是否为幽灵按钮(镂空按钮) | N
icon | String | - | 图标名称 | N
icon-props | Object | {} | 图标属性,透传至 icon | N
loading | Boolean | false | 是否显示为加载状态 | N
loading-props | Object | - | 加载loading属性,透传至loading。TS 类型:`LoadingProps` | N
shape | String | rectangle | 按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形。可选项:rectangle/square/round/circle | N
size | String | medium | 组件尺寸。可选项:small/medium/large。TS 类型:`SizeEnum` | N
theme | String | default | 组件风格,依次为品牌色、危险色。可选项:default/primary/danger | N
Expand Down
3 changes: 2 additions & 1 deletion src/button/button.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"component": true,
"usingComponents": {
"t-icon": "../icon/icon"
"t-icon": "../icon/icon",
"t-loading": "../loading/loading"
}
}
54 changes: 14 additions & 40 deletions src/button/button.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @import (css) '../common/index.wxss';
@import '../common/style/index.less';

@primary-color-disabled: #bbd3fb;
Expand Down Expand Up @@ -203,12 +202,7 @@
font-size: @button-icon-size-l;
}

& .@{prefix}-button--loading {
width: @button-icon-size-l;
height: @button-icon-size-l;
}

.@{prefix}-button--loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__icon + .@{prefix}-button__content:not(:empty) {
margin-left: 16rpx;
}
Expand All @@ -219,12 +213,7 @@
font-size: @button-icon-size-m;
}

& .@{prefix}-button--loading {
width: @button-icon-size-m;
height: @button-icon-size-m;
}

.@{prefix}-button--loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__icon + .@{prefix}-button__content:not(:empty) {
margin-left: 8rpx;
}
Expand All @@ -238,12 +227,7 @@
font-size: @button-icon-size-s;
}

& .@{prefix}-button--loading {
width: @button-icon-size-s;
height: @button-icon-size-s;
}

.@{prefix}-button--loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__loading + .@{prefix}-button__content:not(:empty),
.@{prefix}-button__icon + .@{prefix}-button__content:not(:empty) {
margin-left: 8rpx;
}
Expand Down Expand Up @@ -323,30 +307,20 @@
}
}

&--loading {
box-sizing: border-box;
animation: rotate 0.8s linear infinite;
.@{prefix}-button__circular {
border-radius: 50%;
width: 100%;
height: 100%;
opacity: 1;
background: conic-gradient(
from 90deg at 50% 50%,
rgba(255, 255, 255, 0) 0% 0deg,
currentColor 360deg,
rgba(255, 255, 255, 1) 100% 360deg
);
mask: radial-gradient(transparent calc(50% - 1rpx), #fff 50%);

/* stylelint-disable-next-line */
-webkit-mask: radial-gradient(transparent calc(50% - 1rpx), #fff 50%);
}
}

&.button-hover:after {
border-radius: 8rpx;
}

// loading
.position-center {
display: flex;
align-items: center;
justify-content: center;
}

.indicator-blue {
color: white;
}
}

// button group
Expand Down
3 changes: 0 additions & 3 deletions src/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export default class Button extends SuperComponent {
if (this.data.disabled) {
classList.push(`${prefix}-is-disabled`);
}
// if (this.data.loading) {
// classList.push(`${prefix}-is-loading`);
// }
classList.push(`${name}--${this.data.variant}`);
if (this.data.ghost) {
classList.push(`${name}--ghost`);
Expand Down
19 changes: 17 additions & 2 deletions src/button/button.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@
customStyle="{{iconProps.customStyle}}"
class="{{classPrefix}}__icon {{prefix}}-class-icon"
></t-icon>
<view wx:if="{{loading}}" class="{{classPrefix}}--loading {{prefix}}-class-loading">
<view class="{{classPrefix}}__circular"></view>
<view wx:if="{{loading}}" class="{{classPrefix}}__loading">
<t-loading
delay="{{loadingProps.delay || 0}}"
duration="{{loadingProps.duration || 800}}"
indicator="{{loadingProps.indicator || true}}"
inheritColor="{{loadingProps.indicator || false}}"
layout="{{loadingProps.layout || 'horizontal'}}"
pause="{{loadingProps.pause || false}}"
progress="{{loadingProps.progress}}"
reverse="{{loadingProps.reverse}}"
size="{{loadingProps.size || '40rpx'}}"
text="{{loadingProps.text }}"
theme="{{loadingProps.theme || 'circular'}}"
loading
t-class="position-center"
t-class-indicator="indicator-blue {{prefix}}-class-loading"
></t-loading>
</view>
<view class="{{classPrefix}}__content">
<slot name="content" />
Expand Down
4 changes: 4 additions & 0 deletions src/button/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const props: TdButtonProps = {
type: Boolean,
value: false,
},
/** 加载loading样式 */
loadingProps: {
type: Object,
},
/** 按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形 */
shape: {
type: String,
Expand Down
8 changes: 8 additions & 0 deletions src/button/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* */

import { SizeEnum } from '../common/common';
import { LoadingProps } from '../loading/index';

export interface TdButtonProps {
/**
Expand Down Expand Up @@ -76,6 +77,13 @@ export interface TdButtonProps {
type: BooleanConstructor;
value?: boolean;
};
/**
* 加载loading样式
*/
loadingProps?: {
type: ObjectConstructor;
value?: LoadingProps;
};
/**
* 按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形
* @default rectangle
Expand Down

0 comments on commit 2bf6d5c

Please sign in to comment.