forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoading.tsx
42 lines (37 loc) · 1 KB
/
Loading.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Spinner } from '@primer/react'
import { useTranslation } from 'components/hooks/useTranslation'
import { useEffect, useState } from 'react'
export function Loading() {
const [showLoading, setShowLoading] = useState(false)
useEffect(() => {
let mounted = true
setTimeout(() => {
if (mounted) {
setShowLoading(true)
}
}, 1000)
return () => {
mounted = false
}
}, [])
return showLoading ? <ShowSpinner /> : <ShowNothing />
}
function ShowSpinner() {
const { t } = useTranslation(['search'])
return (
<div className="my-12">
<Spinner size="large" />
<h2>{t('loading')}</h2>
</div>
)
}
function ShowNothing() {
return (
// The min heigh is based on inspecting what the height became when it
// does render. Making this match makes the footer to not flicker
// up or down when it goes from showing nothing to something.
<div className="my-12" style={{ minHeight: 105 }}>
{/* Deliberately empty */}
</div>
)
}