Skip to content

Commit

Permalink
(AIR-61698): bug fix for when spinner doesn't spin for mobile view (#…
Browse files Browse the repository at this point in the history
…1469)

* bug fix for when spinner doesn't spin for mobile view

* bugfix(AIR-61698): add rush change

* bugfix(AIR-61698): fix for unnecessary import

* bugfix(AIR-61698): add story for different width of gradient spinner
  • Loading branch information
Andrewleel authored Mar 7, 2024
1 parent f3e671c commit 3e78da6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "bug fix for when spinner doesn't spin on mobile devices",
"type": "patch"
}
],
"packageName": "pcln-design-system"
}
10 changes: 10 additions & 0 deletions packages/core/src/Animate/Animate.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,13 @@ export const ComposedAnimations = () => {
</Box>
)
}

export const SpinAnimation = () => {
return (
<Flex width='fit-content'>
<Animate variant='spin'>
<Button m={2}>Spin!</Button>
</Animate>
</Flex>
)
}
5 changes: 5 additions & 0 deletions packages/core/src/Animate/Animate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type MotionVariant =
| 'slideOutBottom'
| 'slideOutRight'
| 'slideInRight'
| 'spin'

/**
* @public
Expand Down Expand Up @@ -114,6 +115,10 @@ export const MotionVariants: Record<MotionVariant, HTMLMotionProps<'div'>> = {
initial: { opacity: 1, y: 0 },
animate: { opacity: 0, y: '100%' },
},
spin: {
animate: { rotate: 360, height: 'auto' },
transition: { duration: 1, repeat: Infinity, ease: 'linear' },
},
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/Spinner/Spinner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ WithGradientCustomWidth.args = {
useGradient: true,
strokeWidth: '10px',
}

export const WithGradientDifferentSize = Template.bind({})
WithGradientDifferentSize.args = {
size: 'medium',
useGradient: true,
}
59 changes: 31 additions & 28 deletions packages/core/src/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Absolute } from '../Absolute/Absolute'
import { Flex } from '../Flex/Flex'
import { PaletteFamilyName } from '../theme/theme'
import { applySizes, getPaletteColor } from '../utils/utils'
import { Animate } from './../Animate/Animate'

const sizes = {
small: css`
Expand Down Expand Up @@ -75,40 +76,42 @@ type GradientRingProps = {
function GradientRing({ strokeWidth = '6px', ...props }: GradientRingProps) {
const strokeColor = getPaletteColor(props.color, 'base')(props)
return (
<GradientRingWrapper>
<svg
width='100%'
height='100%'
viewBox='0 0 200 200'
color={strokeColor}
fill='none'
overflow='visible'
>
<defs>
<linearGradient id='spinner-secondHalf'>
<stop offset='0%' stop-opacity='0' stop-color='currentColor' />
<stop offset='100%' stop-opacity='0.5' stop-color='currentColor' />
</linearGradient>
<linearGradient id='spinner-firstHalf'>
<stop offset='0%' stop-opacity='1' stop-color='currentColor' />
<stop offset='100%' stop-opacity='0.5' stop-color='currentColor' />
</linearGradient>
</defs>

<g stroke-width={strokeWidth}>
<path stroke='url(#spinner-secondHalf)' d='M 4 100 A 96 96 0 0 1 196 100' />
<path stroke='url(#spinner-firstHalf)' d='M 196 100 A 96 96 0 0 1 4 100' />
<path stroke='currentColor' stroke-linecap='round' d='M 4 100 A 96 96 0 0 1 4 98' />
</g>
<animateTransform
<GradientRingWrapper mt='-3px'>
<Animate variant='spin'>
<svg
width='100%'
height='100%'
viewBox='0 0 200 200'
color={strokeColor}
fill='none'
overflow='visible'
>
<defs>
<linearGradient id='spinner-secondHalf'>
<stop offset='0%' stop-opacity='0' stop-color='currentColor' />
<stop offset='100%' stop-opacity='0.5' stop-color='currentColor' />
</linearGradient>
<linearGradient id='spinner-firstHalf'>
<stop offset='0%' stop-opacity='1' stop-color='currentColor' />
<stop offset='100%' stop-opacity='0.5' stop-color='currentColor' />
</linearGradient>
</defs>

<g stroke-width={strokeWidth}>
<path stroke='url(#spinner-secondHalf)' d='M 4 100 A 96 96 0 0 1 196 100' />
<path stroke='url(#spinner-firstHalf)' d='M 196 100 A 96 96 0 0 1 4 100' />
<path stroke='currentColor' stroke-linecap='round' d='M 4 100 A 96 96 0 0 1 4 98' />
</g>
{/* <animateTransform
from='0 0 0'
to='360 0 0'
attributeName='transform'
type='rotate'
repeatCount='indefinite'
dur='1000ms'
/>
</svg>
/> */}
</svg>
</Animate>
</GradientRingWrapper>
)
}
Expand Down

0 comments on commit 3e78da6

Please sign in to comment.