Last active
December 23, 2023 20:35
-
-
Save betafcc/a9e0fe1b02228e0153ccd3e1cf0fd571 to your computer and use it in GitHub Desktop.
Clock marks with dasharray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ComponentProps, FC } from 'react' | |
export const Ticks: FC< | |
Omit< | |
ComponentProps<'circle'>, | |
'strokeWidth' | 'pathLength' | 'strokeDasharray' | 'strokeDashoffset' | 'r' | |
> & { | |
r: number | |
count: number | |
length: number | |
width: number | |
align: 'in' | 'out' | 'center' | |
} | |
> = ({ r, count, length, width, align, ...props }) => { | |
const C = 2 * Math.PI * r | |
return ( | |
<circle | |
{...props} | |
r={align === 'in' ? r - length / 2 : align === 'out' ? r + length / 2 : r} | |
strokeWidth={length} | |
pathLength={C} | |
strokeDasharray={`${width} ${C / count - width}`} | |
strokeDashoffset={`${width / 2}`} | |
/> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment