-
Notifications
You must be signed in to change notification settings - Fork 25
/
progress.tsx
61 lines (53 loc) · 1.57 KB
/
progress.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Weak } from '../../../../helpers'
import { Translator } from '../../../../translator'
import { ReactFactoryContext } from '../../factory'
import { PropsUIPromptProgress } from '../../../../types/prompts'
import { ProgressBar } from '../elements/progress_bar'
type Props = Weak<PropsUIPromptProgress> & ReactFactoryContext
export const Progress = (props: Props): JSX.Element => {
const { resolve, percentage } = props
const { description, message } = prepareCopy(props)
function progressBar (): JSX.Element {
if (percentage !== undefined) {
return (
<>
<div className='mt-2' />
<ProgressBar percentage={percentage} />
</>
)
} else {
return <></>
}
}
function autoResolve (): void {
resolve?.({ __type__: 'PayloadTrue', value: true })
}
// No user action possible, resolve directly to give control back to script
autoResolve()
return (
<>
<div id='select-panel'>
<div className='flex-wrap text-bodylarge font-body text-grey1 text-left'>
{description}
</div>
<div className='mt-8' />
<div className='p-6 border-grey4 border-2 rounded'>
<div className='flex-wrap text-bodylarge font-body text-grey2 text-left'>
{message}
</div>
{progressBar()}
</div>
</div>
</>
)
}
interface Copy {
description: string
message: string
}
function prepareCopy ({ description, message, locale }: Props): Copy {
return {
description: Translator.translate(description, locale),
message: message
}
}