Skip to content

Commit

Permalink
fix circle iteration delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandawg93 committed Jun 6, 2024
1 parent aea9ac4 commit 1b433a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/components/animation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
.noAnimation {
animation: none;
}

.noPseudoAnimation {
&::before {
animation: none !important;
display: none;
}
}
7 changes: 6 additions & 1 deletion src/components/animation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Props extends BaseProps {
onAnimationIteration?: () => void
className?: string
style?: React.CSSProperties
hasPseudo?: boolean
}

const Animation = (props: Props) => {
Expand All @@ -29,6 +30,10 @@ const Animation = (props: Props) => {
'--direction': `${props.reverse ? 'reverse' : 'normal'}`,
} as React.CSSProperties

const noAnimationClassName = props.hasPseudo ? css.noPseudoAnimation : css.noAnimation
const animationClassName = animate && !props.disabled ? css.baseAnimation : noAnimationClassName
const className = `${animationClassName} ${!props.disabled && props.className}`

const handleIteration = () => {
setAnimate(false)
if (!props.iterations || (props.iterations && iteration + 1 < props.iterations)) {
Expand All @@ -45,7 +50,7 @@ const Animation = (props: Props) => {
onAnimationStart={props.onAnimationStart}
onAnimationEnd={props.onAnimationEnd}
onAnimationIteration={handleIteration}
className={`${animate && !props.disabled ? css.baseAnimation : css.noAnimation} ${!props.disabled && props.className}`}
className={className}
style={style}
>
{props.children}
Expand Down
10 changes: 5 additions & 5 deletions src/components/circle/circle.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.outer {
position: relative;
border-radius: inherit;
}

.animation {
--start-percent: 40%;
--end-percent: 60%;
Expand Down Expand Up @@ -37,11 +42,6 @@
}
}

.outer {
position: relative;
border-radius: inherit;
}

@keyframes rotate {
0% {
transform: translate(-50%, -50%) scale(1.4) rotate(0turn);
Expand Down
2 changes: 1 addition & 1 deletion src/components/circle/circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Circle = (props: Props) => {

return (
<div className={css.outer}>
<Animation {...props} children={undefined} className={css.animation} style={style}></Animation>
<Animation {...props} children={undefined} className={css.animation} style={style} hasPseudo></Animation>
{props.children}
</div>
)
Expand Down

0 comments on commit 1b433a6

Please sign in to comment.