({
children,
display = 'auto',
color = 'var(--Dash-Fill-Interactive-Strong)',
id,
className,
style,
parent_className,
parent_style,
overlay_style,
fullscreen,
debug,
show_initially = true,
type: spinnerType = 'default',
delay_hide = 0,
delay_show = 0,
target_components,
custom_spinner,
}: LoadingProps)
| 80 | }; |
| 81 | |
| 82 | function Loading({ |
| 83 | children, |
| 84 | display = 'auto', |
| 85 | color = 'var(--Dash-Fill-Interactive-Strong)', |
| 86 | id, |
| 87 | className, |
| 88 | style, |
| 89 | parent_className, |
| 90 | parent_style, |
| 91 | overlay_style, |
| 92 | fullscreen, |
| 93 | debug, |
| 94 | show_initially = true, |
| 95 | type: spinnerType = 'default', |
| 96 | delay_hide = 0, |
| 97 | delay_show = 0, |
| 98 | target_components, |
| 99 | custom_spinner, |
| 100 | }: LoadingProps) { |
| 101 | const ctx = window.dash_component_api.useDashContext(); |
| 102 | |
| 103 | const loading = ctx.useSelector( |
| 104 | loadingSelector(ctx.componentPath, target_components), |
| 105 | equals |
| 106 | ); |
| 107 | |
| 108 | const [showSpinner, setShowSpinner] = useState(show_initially); |
| 109 | const dismissTimer = useRef<number | void>(); |
| 110 | const showTimer = useRef<number | void>(); |
| 111 | |
| 112 | const containerStyle: React.CSSProperties = useMemo(() => { |
| 113 | if (showSpinner) { |
| 114 | return {visibility: 'hidden', ...overlay_style, ...parent_style}; |
| 115 | } |
| 116 | return parent_style ?? {}; |
| 117 | }, [showSpinner, parent_style]); |
| 118 | |
| 119 | useEffect(() => { |
| 120 | if (display === 'show' || display === 'hide') { |
| 121 | setShowSpinner(display === 'show'); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (loading) { |
| 126 | // if component is currently loading and there's a dismiss timer active |
| 127 | // we need to clear it. |
| 128 | if (dismissTimer.current) { |
| 129 | dismissTimer.current = window.clearTimeout( |
| 130 | dismissTimer.current |
| 131 | ); |
| 132 | } |
| 133 | // if component is currently loading but the spinner is not showing and |
| 134 | // there is no timer set to show, then set a timeout to show |
| 135 | if (!showSpinner && !showTimer.current) { |
| 136 | showTimer.current = window.setTimeout(() => { |
| 137 | setShowSpinner(true); |
| 138 | showTimer.current = undefined; |
| 139 | }, delay_show); |
nothing calls this directly
no test coverage detected
searching dependent graphs…