From 97a08423a1ac48f654e9c48af3131c4de457e98e Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Sat, 19 Mar 2022 15:21:32 +0800
Subject: [PATCH] fix: button loading animate not work, close #5360
---
components/button/LoadingIcon.tsx | 68 +++++++++++++++++++
.../__tests__/__snapshots__/demo.test.js.snap | 10 +--
.../__snapshots__/index.test.js.snap | 4 +-
components/button/button.tsx | 20 ++++--
.../__tests__/__snapshots__/demo.test.js.snap | 4 +-
.../__tests__/__snapshots__/demo.test.js.snap | 2 +-
.../__tests__/__snapshots__/demo.test.js.snap | 32 +++++++++
7 files changed, 124 insertions(+), 16 deletions(-)
create mode 100644 components/button/LoadingIcon.tsx
diff --git a/components/button/LoadingIcon.tsx b/components/button/LoadingIcon.tsx
new file mode 100644
index 000000000..938969688
--- /dev/null
+++ b/components/button/LoadingIcon.tsx
@@ -0,0 +1,68 @@
+import { defineComponent, nextTick } from 'vue';
+import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
+import Transition from '../_util/transition';
+const getCollapsedWidth = (node: HTMLSpanElement) => {
+ if (node) {
+ node.style.width = '0px';
+ node.style.opacity = '0';
+ node.style.transform = 'scale(0)';
+ }
+};
+const getRealWidth = (node: HTMLSpanElement) => {
+ nextTick(() => {
+ if (node) {
+ node.style.width = `${node.scrollWidth}px`;
+ node.style.opacity = '1';
+ node.style.transform = 'scale(1)';
+ }
+ });
+};
+const resetStyle = (node: HTMLSpanElement) => {
+ if (node && node.style) {
+ node.style.width = null;
+ node.style.opacity = null;
+ node.style.transform = null;
+ }
+};
+export default defineComponent({
+ name: 'LoadingIcon',
+ props: {
+ prefixCls: String,
+ loading: [Boolean, Object],
+ existIcon: Boolean,
+ },
+ setup(props) {
+ return () => {
+ const { existIcon, prefixCls, loading } = props;
+ if (existIcon) {
+ return (
+
+
+
+ );
+ }
+ const visible = !!loading;
+ return (
+ {
+ setTimeout(() => {
+ getCollapsedWidth(node);
+ });
+ }}
+ onAfterLeave={resetStyle}
+ >
+ {visible ? (
+
+
+
+ ) : null}
+
+ );
+ };
+ },
+});
diff --git a/components/button/__tests__/__snapshots__/demo.test.js.snap b/components/button/__tests__/__snapshots__/demo.test.js.snap
index 1753b8ede..7f48f7c3a 100644
--- a/components/button/__tests__/__snapshots__/demo.test.js.snap
+++ b/components/button/__tests__/__snapshots__/demo.test.js.snap
@@ -143,9 +143,9 @@ exports[`renders ./components/button/demo/icon.vue correctly 1`] = `
exports[`renders ./components/button/demo/loading.vue correctly 1`] = `
@@ -157,11 +157,11 @@ exports[`renders ./components/button/demo/loading.vue correctly 1`] = `
`;
diff --git a/components/button/__tests__/__snapshots__/index.test.js.snap b/components/button/__tests__/__snapshots__/index.test.js.snap
index 59584b43b..00b3398d8 100644
--- a/components/button/__tests__/__snapshots__/index.test.js.snap
+++ b/components/button/__tests__/__snapshots__/index.test.js.snap
@@ -36,9 +36,9 @@ exports[`Button renders Chinese characters correctly 3`] = `
`;
-exports[`Button renders Chinese characters correctly 4`] = ``;
+exports[`Button renders Chinese characters correctly 4`] = ``;
-exports[`Button renders Chinese characters correctly 5`] = ``;
+exports[`Button renders Chinese characters correctly 5`] = ``;
exports[`Button renders Chinese characters correctly 6`] = `