Skip to content

Instantly share code, notes, and snippets.

@betafcc
Last active December 23, 2023 20:35
Show Gist options
  • Save betafcc/a9e0fe1b02228e0153ccd3e1cf0fd571 to your computer and use it in GitHub Desktop.
Save betafcc/a9e0fe1b02228e0153ccd3e1cf0fd571 to your computer and use it in GitHub Desktop.
Clock marks with dasharray
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