1
1
import { defineComponent , ref , computed , watch , onMounted , toRefs , CSSProperties , Teleport } from 'vue' ;
2
2
import GradientIcon from './icon/gradient' ;
3
3
import { addClass , removeClass } from '../utils/dom' ;
4
- import { renderTNodeJSX , renderContent } from '../utils/render-tnode' ;
5
- import props from './props' ;
6
-
4
+ import { getPropertyValFromObj } from '@tdesign/common-js/utils/general' ;
5
+ import { useTNodeJSX , useContent } from '../hooks/tnode' ;
7
6
import { usePrefixClass , useCommonClassName } from '../hooks/useConfig' ;
8
7
import useTeleport from '../hooks/useTeleport' ;
9
-
10
- import { getPropertyValFromObj } from '@tdesign/common-js/utils/general' ;
8
+ import props from './props' ;
11
9
12
10
const useComponentClassName = ( ) => {
13
11
return {
@@ -26,13 +24,15 @@ export default defineComponent({
26
24
name : 'TLoading' ,
27
25
inheritAttrs : false ,
28
26
props,
29
- setup ( props , { slots } ) {
27
+ setup ( props , { slots, attrs } ) {
30
28
const delayShowLoading = ref ( false ) ;
31
29
32
30
const { name, centerClass, fullscreenClass, lockClass, overlayClass, relativeClass, fullClass, inheritColorClass } =
33
31
useComponentClassName ( ) ;
34
32
35
33
const classPrefix = usePrefixClass ( ) ;
34
+ const renderTNodeJSX = useTNodeJSX ( ) ;
35
+ const renderContent = useContent ( ) ;
36
36
const { SIZE } = useCommonClassName ( ) ;
37
37
38
38
const countDelay = ( ) => {
@@ -64,7 +64,6 @@ export default defineComponent({
64
64
const showText = computed ( ( ) => Boolean ( props . text || slots . text ) ) ;
65
65
const showWrapLoading = computed ( ( ) => hasContent . value && props . loading && delayCounted . value ) ;
66
66
const showFullScreenLoading = computed ( ( ) => props . fullscreen && props . loading && delayCounted . value ) ;
67
- const showNormalLoading = computed ( ( ) => props . attach && props . loading && delayCounted . value ) ;
68
67
const showAttachedLoading = computed ( ( ) => props . attach && props . loading && delayCounted . value ) ;
69
68
const classes = computed ( ( ) => {
70
69
const baseClasses = [
@@ -104,78 +103,63 @@ export default defineComponent({
104
103
props . delay && countDelay ( ) ;
105
104
} ) ;
106
105
107
- return {
108
- classPrefix,
109
- relativeClass,
110
- delayShowLoading,
111
- styles,
112
- showText,
113
- hasContent,
114
- classes,
115
- lockFullscreen,
116
- showWrapLoading,
117
- showNormalLoading,
118
- showFullScreenLoading,
119
- showAttachedLoading,
120
- teleportElement,
121
- } ;
122
- } ,
123
- render ( ) {
124
- const { fullScreenClasses, baseClasses, withContentClasses, attachClasses, normalClasses } = this . classes ;
125
-
126
- const defaultIndicator = < GradientIcon size = { this . size } /> ;
127
- const indicator = this . loading && renderTNodeJSX ( this , 'indicator' , defaultIndicator ) ;
128
- const text = this . showText && < div class = { `${ this . classPrefix } -loading__text` } > { renderTNodeJSX ( this , 'text' ) } </ div > ;
129
-
130
- // full screen loading
131
- if ( this . fullscreen ) {
132
- if ( ! this . showFullScreenLoading || ! this . loading ) return null ;
133
- return (
134
- < Teleport disabled = { ! this . attach || ! this . teleportElement } to = { this . teleportElement } >
135
- < div class = { fullScreenClasses } style = { this . styles } { ...this . $attrs } >
136
- < div class = { baseClasses } >
137
- { indicator }
138
- { text }
106
+ return ( ) => {
107
+ const { fullScreenClasses, baseClasses, withContentClasses, attachClasses, normalClasses } = classes . value ;
108
+
109
+ const defaultIndicator = < GradientIcon size = { props . size } /> ;
110
+ const indicator = loading . value && renderTNodeJSX ( 'indicator' , defaultIndicator ) ;
111
+ const text = showText . value && < div class = { `${ classPrefix . value } -loading__text` } > { renderTNodeJSX ( 'text' ) } </ div > ;
112
+
113
+ // full screen loading
114
+ if ( props . fullscreen ) {
115
+ if ( ! showFullScreenLoading . value || ! props . loading ) return null ;
116
+ return (
117
+ < Teleport disabled = { ! props . attach || ! teleportElement . value } to = { teleportElement . value } >
118
+ < div class = { fullScreenClasses } style = { styles . value } { ...attrs } >
119
+ < div class = { baseClasses } >
120
+ { indicator }
121
+ { text }
122
+ </ div >
139
123
</ div >
124
+ </ Teleport >
125
+ ) ;
126
+ }
127
+
128
+ // Loading is wrapping a HTMLElement.
129
+ if ( hasContent . value ) {
130
+ return (
131
+ < div class = { relativeClass . value } { ...attrs } >
132
+ { renderContent ( 'default' , 'content' ) }
133
+ { showWrapLoading . value && (
134
+ < div class = { withContentClasses } style = { styles . value } >
135
+ { indicator }
136
+ { text }
137
+ </ div >
138
+ ) }
140
139
</ div >
141
- </ Teleport >
142
- ) ;
143
- }
144
-
145
- // Loading is wrapping a HTMLElement.
146
- if ( this . hasContent ) {
147
- return (
148
- < div class = { this . relativeClass } { ...this . $attrs } >
149
- { renderContent ( this , 'default' , 'content' ) }
150
- { this . showWrapLoading && (
151
- < div class = { withContentClasses } style = { this . styles } >
140
+ ) ;
141
+ }
142
+
143
+ // transfer parent node
144
+ if ( props . attach ) {
145
+ if ( ! showAttachedLoading . value || ! loading . value ) return null ;
146
+ return (
147
+ < Teleport disabled = { ! props . attach || ! teleportElement . value } to = { teleportElement . value } >
148
+ < div class = { attachClasses } style = { styles . value } { ...attrs } >
152
149
{ indicator }
153
150
{ text }
154
151
</ div >
155
- ) }
152
+ </ Teleport >
153
+ ) ;
154
+ }
155
+
156
+ // Normal Loading without overlay or content
157
+ return loading . value ? (
158
+ < div class = { normalClasses } style = { styles . value } { ...attrs } >
159
+ { indicator }
160
+ { text }
156
161
</ div >
157
- ) ;
158
- }
159
-
160
- // transfer parent node
161
- if ( this . attach ) {
162
- if ( ! this . showAttachedLoading || ! this . loading ) return null ;
163
- return (
164
- < Teleport disabled = { ! this . attach || ! this . teleportElement } to = { this . teleportElement } >
165
- < div class = { attachClasses } style = { this . styles } { ...this . $attrs } >
166
- { indicator }
167
- { text }
168
- </ div >
169
- </ Teleport >
170
- ) ;
171
- }
172
-
173
- // Normal Loading without overlay or content
174
- return this . loading ? (
175
- < div class = { normalClasses } style = { this . styles } { ...this . $attrs } >
176
- { indicator }
177
- { text }
178
- </ div >
179
- ) : null ;
162
+ ) : null ;
163
+ } ;
180
164
} ,
181
165
} ) ;
0 commit comments