import React, { ReactNode, useState } from 'react'; import { View, ViewProps } from 'react-native'; import { Box } from '../Box'; import { Text } from '../Text'; import type { Theme } from './../../theme/theme'; import { ColorProps, BackgroundColorProps, ResponsiveValue, createBox, } from '@shopify/restyle'; type Props = ColorProps & BackgroundColorProps & { innerColor?: ResponsiveValue; borderWidth?: number; radius: number; percent: number; text?: string; children?: ReactNode; }; const ViewStyledComponent = createBox(View); export const PercentageCircle = ({ color = 'darkBlueGray', backgroundColor = 'gray25', innerColor = 'white', borderWidth = 4, radius, percent, text, children, }: Props) => { const [borderW] = useState(borderWidth < 2 ? 2 : borderWidth); const [leftTransformerDegree] = useState( percent >= 50 ? (percent - 50) * 3.6 + 'deg' : '0deg' ); const [rightTransformerDegree] = useState( percent >= 50 ? '180deg' : percent * 3.6 + 'deg' ); return ( {children ? ( children ) : ( <> {percent}% {text && {text}} )} ); };