Skip to content

Commit

Permalink
perf(Badge): 针对使用Transition进行优化
Browse files Browse the repository at this point in the history
  • Loading branch information
79E committed Dec 1, 2022
1 parent 3c53192 commit 3c2e933
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/components/badge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { Badge } from "aunt";
| bordered | 是否有白色边框 | `boolean` | `false` |
| color | 徽标背景颜色 | `string` | `-` |
| offset | 徽标位置偏移量 | `[number \| string, number \| string]` | `-` |
| transitionStyles | Transition 组件动画样式 | `TransitionStyles` | `-` |

## 样式变量

Expand Down
6 changes: 1 addition & 5 deletions src/components/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ const Badge: FunctionComponent<BadgeProps> = props => {

return (
<div className={ns.b()}>
<Transition
in={visible}
timeout={timeout}
type={ns.m(props.children ? 'scale-translate' : 'scale')}
>
<Transition in={visible} timeout={timeout} transitionStyles={props.transitionStyles}>
<div className={varClasses} style={varStyles}>
{!dot && <>{Number(content) && Number(content) > maxCount ? `${maxCount}+` : content}</>}
</div>
Expand Down
60 changes: 0 additions & 60 deletions src/components/badge/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,63 +58,3 @@
border-radius: 100%;
}
}

@keyframes scale-translate-on {
0% {
transform: scale(0) translate(50%, -50%);
opacity: 0;
}
100% {
transform: scale(1) translate(50%, -50%);
opacity: 1;
}
}

@keyframes scale-translate-off {
0% {
transform: scale(1) translate(50%, -50%);
opacity: 1;
}
100% {
transform: scale(0) translate(50%, -50%);
opacity: 0;
}
}

.@{class-prefix}-badge--scale-translate-enter-active {
animation: scale-translate-on 0.4s cubic-bezier(0.3, 1.3, 0.3, 1) forwards;
}

.@{class-prefix}-badge--scale-translate-exit-active {
animation: scale-translate-off 0.4s cubic-bezier(0.3, 1.3, 0.3, 1) forwards;
}

@keyframes scale-on {
0% {
transform: scale(0);
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
}

@keyframes scale-off {
0% {
transform: scale(1);
opacity: 1;
}
100% {
transform: scale(0);
opacity: 0;
}
}

.@{class-prefix}-badge--scale-enter-active {
animation: scale-on 0.4s cubic-bezier(0.3, 1.3, 0.3, 1) forwards;
}

.@{class-prefix}-badge--scale-exit-active {
animation: scale-off 0.4s cubic-bezier(0.3, 1.3, 0.3, 1) forwards;
}
5 changes: 5 additions & 0 deletions src/components/badge/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { TransitionStyles } from '../transition';
import { BaseTypeProps } from '../../utils';

// 定义接受到的参数 类型
Expand Down Expand Up @@ -48,4 +49,8 @@ export interface BadgeProps extends BaseTypeProps {
* @default ''
*/
color?: string;
/**
* @name Transition 组件动画样式设定
*/
transitionStyles?: TransitionStyles;
}

0 comments on commit 3c2e933

Please sign in to comment.