about summary refs log tree commit diff
path: root/src/view/com/composer/char-progress/CharProgress.tsx
blob: eaaaea5e5b6399a25afe30cf514cacd51d955e87 (plain) (blame)
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 React from 'react'
import {View} from 'react-native'
import {Text} from '../../util/text/Text'
// @ts-ignore no type definition -prf
import ProgressCircle from 'react-native-progress/Circle'
// @ts-ignore no type definition -prf
import ProgressPie from 'react-native-progress/Pie'
import {s} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette'

const MAX_LENGTH = 300
const DANGER_LENGTH = MAX_LENGTH

export function CharProgress({count}: {count: number}) {
  const pal = usePalette('default')
  const textColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.text
  const circleColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.link
  return (
    <>
      <Text style={[s.mr10, {color: textColor}]}>{MAX_LENGTH - count}</Text>
      <View>
        {count > DANGER_LENGTH ? (
          <ProgressPie
            size={30}
            borderWidth={4}
            borderColor={circleColor}
            color={circleColor}
            progress={Math.min((count - MAX_LENGTH) / MAX_LENGTH, 1)}
          />
        ) : (
          <ProgressCircle
            size={30}
            borderWidth={1}
            borderColor={pal.colors.border}
            color={circleColor}
            progress={count / MAX_LENGTH}
          />
        )}
      </View>
    </>
  )
}