Skip to content

Commit 7ae0502

Browse files
committed
feat: refactor AnimatedTimer component to use constants for dimensions and update size prop type
1 parent 8092842 commit 7ae0502

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

src/Shared/Components/AnimatedTimer/AnimatedTimer.component.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react'
22
import { motion, useMotionValue, useTransform, animate } from 'framer-motion'
33
import { AnimatedTimerProps } from './types'
4-
import { END_ANGLE, START_ANGLE } from './constants'
4+
import { CX, CY, END_ANGLE, RADIUS, START_ANGLE } from './constants'
55

66
const polarToCartesian = (cx: number, cy: number, r: number, angleInDegrees: number) => {
77
const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0
@@ -26,10 +26,6 @@ const describeArcPath = (cx: number, cy: number, r: number, endAngle: number) =>
2626
}
2727

2828
const AnimatedTimer = ({ duration, onComplete, size = 24 }: AnimatedTimerProps) => {
29-
const CX = size / 2
30-
const CY = size / 2
31-
const RADIUS = size / 4
32-
3329
const angle = useMotionValue<number>(START_ANGLE)
3430
const d = useTransform(angle, (currentAngle) => describeArcPath(CX, CY, RADIUS, currentAngle))
3531
useEffect(() => {
@@ -48,6 +44,7 @@ const AnimatedTimer = ({ duration, onComplete, size = 24 }: AnimatedTimerProps)
4844
viewBox={`0 0 ${CX * 2} ${CY * 2}`}
4945
fill="none"
5046
xmlns="http://www.w3.org/2000/svg"
47+
className={`icon-dim-${size}`}
5148
>
5249
<path
5350
fillRule="evenodd"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
export const CX = 12
2+
export const CY = 12
3+
export const RADIUS = 6
14
export const START_ANGLE = 0
25
export const END_ANGLE = 360

src/Shared/Components/AnimatedTimer/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IconBaseSizeType } from '@Shared/index'
12
import { animate } from 'framer-motion'
23

34
export interface AnimatedTimerProps extends Pick<Parameters<typeof animate>[2], 'onComplete'> {
@@ -9,5 +10,5 @@ export interface AnimatedTimerProps extends Pick<Parameters<typeof animate>[2],
910
/**
1011
* @default 24
1112
*/
12-
size?: number
13+
size?: IconBaseSizeType
1314
}

src/Shared/Components/Icon/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { FC, SVGProps } from 'react'
1818

1919
import { TooltipProps } from '@Common/Tooltip/types'
20+
import { IconBaseColorType, IconBaseSizeType } from '@Shared/index'
2021

2122
type IconMap = Record<string, FC<SVGProps<SVGSVGElement>>>
2223

@@ -29,17 +30,13 @@ export interface IconBaseProps {
2930
* The size of the icon in pixels.
3031
* @default 16
3132
*/
32-
size?: 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 28 | 30 | 32 | 34 | 36 | 40 | 42 | 44 | 48 | 72 | 80
33+
size?: IconBaseSizeType
3334
/** Props to configure the tooltip when hovering over the icon. */
3435
tooltipProps?: TooltipProps
3536
/**
3637
* The color of the icon (color tokens). \
3738
* If `null`, the default color present in icon is used.
3839
* @example `'B500'`, `'N200'`, `'G50'`, `'R700'`
3940
*/
40-
color:
41-
| `${'B' | 'N' | 'G' | 'Y' | 'R' | 'V' | 'O'}${`${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}00` | '50' | '0'}`
42-
| 'white'
43-
| 'black'
44-
| null
41+
color: IconBaseColorType
4542
}

src/Shared/types.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,32 @@ export type CountryISO2Type = ParsedCountry['iso2']
11051105
export enum ResponseHeaders {
11061106
LICENSE_STATUS = 'X-License-Status',
11071107
}
1108+
1109+
export type IconBaseSizeType =
1110+
| 6
1111+
| 8
1112+
| 10
1113+
| 12
1114+
| 14
1115+
| 16
1116+
| 18
1117+
| 20
1118+
| 22
1119+
| 24
1120+
| 28
1121+
| 30
1122+
| 32
1123+
| 34
1124+
| 36
1125+
| 40
1126+
| 42
1127+
| 44
1128+
| 48
1129+
| 72
1130+
| 80
1131+
1132+
export type IconBaseColorType =
1133+
| `${'B' | 'N' | 'G' | 'Y' | 'R' | 'V' | 'O'}${`${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}00` | '50' | '0'}`
1134+
| 'white'
1135+
| 'black'
1136+
| null

0 commit comments

Comments
 (0)