Skip to content

Commit 46ad398

Browse files
committed
chore(Badge): optimze ribbon badge
1 parent 0f3fcd9 commit 46ad398

File tree

3 files changed

+46
-60
lines changed

3 files changed

+46
-60
lines changed

packages/components/badge/__test__/__snapshots__/demo.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ exports[`Badge Badge theme demo works fine 1`] = `
256256
title="单行标题"
257257
>
258258
<t-badge
259-
count="New"
259+
count="NEW"
260260
offset="{{
261261
Array [
262262
0,
@@ -278,7 +278,7 @@ exports[`Badge Badge theme demo works fine 1`] = `
278278
title="单行标题"
279279
>
280280
<t-badge
281-
count="New"
281+
count="NEW"
282282
offset="{{
283283
Array [
284284
0,

packages/components/badge/_example/theme/index.wxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828

2929
<view class="demo-desc" style="margin-bottom: 32rpx">角标</view>
3030
<t-cell title="单行标题" t-class="t-class-cell">
31-
<t-badge count="New" offset="{{skylineRender ? ['-18rpx', '-32rpx']: [0, 0]}}" shape="ribbon" slot="note" />
31+
<t-badge count="NEW" offset="{{skylineRender ? ['-18rpx', '-32rpx']: [0, 0]}}" shape="ribbon" slot="note" />
3232
</t-cell>
3333

3434
<view class="demo-desc" style="margin-bottom: 32rpx">三角角标</view>
3535
<t-cell title="单行标题" t-class="t-class-cell">
36-
<t-badge count="New" offset="{{skylineRender ? ['-24rpx', '-32rpx']: [0, 0]}}" shape="triangle-right" slot="note" />
36+
<t-badge count="NEW" offset="{{skylineRender ? ['-24rpx', '-32rpx']: [0, 0]}}" shape="triangle-right" slot="note" />
3737
</t-cell>

packages/components/badge/badge.less

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,54 +75,18 @@
7575
}
7676
}
7777

78-
&--ribbon,
79-
&--ribbon-right,
80-
&--ribbon-left {
81-
position: relative;
82-
display: inline-block;
83-
transform-origin: center center;
84-
border-radius: 0;
85-
86-
&::before,
87-
&::after {
88-
content: '';
89-
position: absolute;
90-
width: 0;
91-
height: 0;
92-
bottom: 0;
93-
border-bottom: @badge-basic-height solid @badge-color;
94-
font-size: 0;
95-
}
96-
97-
&::before {
98-
left: calc(-1 * @badge-basic-height + 1rpx);
99-
border-left: @badge-basic-height solid transparent;
100-
}
101-
102-
&::after {
103-
right: calc(-1 * @badge-basic-height + 1rpx);
104-
border-right: @badge-basic-height solid transparent;
105-
}
106-
}
107-
108-
&--ribbon,
109-
&--ribbon-right {
110-
transform: translate(calc(50% - @badge-basic-height + 1rpx), calc(-50% + @badge-basic-height - 1rpx)) rotate(45deg);
111-
}
112-
113-
&--ribbon-left {
114-
transform: translate(calc(-50% + @badge-basic-height - 1rpx), calc(-50% + @badge-basic-height - 1rpx))
115-
rotate(-45deg);
116-
}
117-
11878
&--bubble {
11979
border-radius: @border-bubble-border-radius;
12080
}
12181

82+
&--ribbon,
83+
&--ribbon-right,
84+
&--ribbon-left,
12285
&--triangle-left,
12386
&--triangle-right {
12487
width: calc(@badge-basic-height * 2);
12588
height: calc(@badge-basic-height * 2);
89+
border-radius: 0;
12690
padding: 0;
12791
position: absolute;
12892
top: 0;
@@ -132,21 +96,39 @@
13296
overflow: hidden;
13397
}
13498

99+
&--ribbon,
100+
&--ribbon-right {
101+
background: linear-gradient(45deg, transparent 50%, @badge-color 50%, @badge-color 82%, transparent 82%);
102+
}
103+
135104
&--triangle-right {
136105
background: linear-gradient(45deg, transparent 50%, @badge-color 50%);
106+
}
107+
108+
&--ribbon,
109+
&--ribbon-right,
110+
&--triangle-right {
137111
right: 0;
138112

139113
.@{prefix}-badge__count {
140-
transform: rotate(45deg) translateY(calc(-1 * var(--td-line-height-mark-extraSmall, 32rpx) / 2));
114+
transform: rotate(45deg) translateY(calc(-1 * var(--td-line-height-mark-extraSmall, 32rpx) / 2 + 2rpx));
141115
}
142116
}
143117

118+
&--ribbon-left {
119+
background: linear-gradient(-45deg, transparent 50%, @badge-color 50%, @badge-color 82%, transparent 82%);
120+
}
121+
144122
&--triangle-left {
145123
background: linear-gradient(-45deg, transparent 50%, @badge-color 50%);
124+
}
125+
126+
&--ribbon-left,
127+
&--triangle-left {
146128
left: 0;
147129

148130
.@{prefix}-badge__count {
149-
transform: rotate(-45deg) translateY(calc(-1 * var(--td-line-height-mark-extraSmall, 32rpx) / 2));
131+
transform: rotate(-45deg) translateY(calc(-1 * var(--td-line-height-mark-extraSmall, 32rpx) / 2 + 2rpx));
150132
}
151133
}
152134

@@ -162,36 +144,40 @@
162144
border-radius: calc(@badge-large-height / 2);
163145
}
164146

147+
&--large&--ribbon,
148+
&--large&--ribbon-right,
149+
&--large&--ribbon-left,
165150
&--large&--triangle-right,
166151
&--large&--triangle-left {
167152
width: calc(@badge-large-height * 2);
168153
height: calc(@badge-large-height * 2);
169154
}
170155

171-
&__content:not(:empty) + &--ribbon.@{prefix}-has-count,
172-
&__content:not(:empty) + &--ribbon-right.@{prefix}-has-count,
173-
&__content:not(:empty) + &--ribbon-left.@{prefix}-has-count,
156+
&--large&--ribbon,
157+
&--large&--ribbon-right,
158+
&--large&--triangle-right {
159+
.@{prefix}-badge__count {
160+
transform: rotate(45deg) translateY(calc(-1 * var(--td-line-height-mark-small, 40rpx) / 2 + 2rpx));
161+
}
162+
}
163+
164+
&--large&--ribbon-left,
165+
&--large&--triangle-left {
166+
.@{prefix}-badge__count {
167+
transform: rotate(-45deg) translateY(calc(-1 * var(--td-line-height-mark-small, 40rpx) / 2 + 2rpx));
168+
}
169+
}
170+
174171
&__content:not(:empty) + &--bubble.@{prefix}-has-count,
175172
&__content:not(:empty) + &--circle.@{prefix}-has-count,
176173
&__content:not(:empty) + &--square.@{prefix}-has-count {
177174
transform-origin: center center;
178175
transform: translate(-50%, -50%);
179176
position: absolute;
180177
top: 0;
181-
}
182-
183-
&__content:not(:empty) + &--ribbon.@{prefix}-has-count,
184-
&__content:not(:empty) + &--ribbon-right.@{prefix}-has-count,
185-
&__content:not(:empty) + &--bubble.@{prefix}-has-count,
186-
&__content:not(:empty) + &--circle.@{prefix}-has-count,
187-
&__content:not(:empty) + &--square.@{prefix}-has-count {
188178
left: 100%;
189179
}
190180

191-
&__content:not(:empty) + &--ribbon-left.@{prefix}-has-count {
192-
right: 100%;
193-
}
194-
195181
&__content-text {
196182
display: block;
197183
font: @font-body-large;

0 commit comments

Comments
 (0)