@@ -33,7 +33,7 @@ interface Props {
3333 * Type of animation to apply on hover (when isButton is true)
3434 * @default " boop"
3535 */
36- animationType? : ' rotate' | ' boop' | ' bounce ' | ' none'
36+ animationType? : ' rotate' | ' boop' | ' bouncing ' | ' none'
3737 /**
3838 * Animation intensity (1-10)
3939 * @default 5
@@ -81,15 +81,18 @@ const {
8181 ... rest
8282} = Astro .props
8383
84+ // Clamp animation intensity between 1-10
85+ const clampedIntensity = Math .max (1 , Math .min (10 , animationIntensity ))
86+
8487// Calculate animation values based on intensity
85- const scaleAmount = 1 + animationIntensity * 0.02 // 1.02 to 1.2
86- const rotateAmount = animationIntensity * 2 // 2deg to 20deg
88+ const scaleAmount = 1 + clampedIntensity * 0.02 // 1.02 to 1.2
89+ const rotateAmount = clampedIntensity * 2 // 2deg to 20deg
8790
88- // Only apply animation class if it's a button
89- const shouldAnimate = isButton && animateOnHover
91+ // Only apply animation class if it's a button and not 'none' type
92+ const shouldAnimate = isButton && animateOnHover && animationType !== ' none '
9093
9194// Determine animation class based on type
92- const animationClass = shouldAnimate ? ` animate-${animationType } ` : ' '
95+ const animationClass = shouldAnimate ? ` animate-${animationType }-svg ` : ' '
9396
9497// Determine if we should apply the circular class
9598const circularClass = isCircular ? ' circular' : ' '
@@ -98,7 +101,7 @@ const circularClass = isCircular ? 'circular' : ''
98101const pillClass = isPill ? ' pill' : ' '
99102
100103// Determine if we should apply the pulse class
101- const pulseClass = pulse ? ' pulse' : ' '
104+ const pulseClass = pulse ? ' animation- pulse' : ' '
102105
103106// Map logical size values to CSS class names
104107const sizeClass = ` size-${size } `
@@ -117,6 +120,7 @@ const sizeClass = `size-${size}`
117120 pulseClass ,
118121 className ,
119122 ]}
123+ style = { ` --scaleAmount: ${scaleAmount }; --rotateAmount: ${rotateAmount }deg; ` }
120124 { ... rest }
121125 >
122126 { label && <span class = " sr-only" >{ label } </span >}
@@ -141,12 +145,7 @@ const sizeClass = `size-${size}`
141145 )
142146}
143147
144- <style
145- define:vars ={ {
146- scaleAmount ,
147- rotateAmount: ` ${rotateAmount }deg ` ,
148- }}
149- >
148+ <style >
150149 :where(.badge) {
151150 --transition-duration: 0.3s;
152151 --transition-easing: cubic-bezier(0.165, 0.84, 0.44, 1);
@@ -269,56 +268,23 @@ const sizeClass = `size-${size}`
269268 }
270269
271270 /* Set pulse colors based on badge type */
272- :where(.pulse.type-default) {
271+ :where(.animation- pulse.type-default) {
273272 --pulse-color: var(--color-pulse-default);
274273 }
275274
276- :where(.pulse.type-info) {
275+ :where(.animation- pulse.type-info) {
277276 --pulse-color: var(--color-pulse-info);
278277 }
279278
280- :where(.pulse.type-success) {
279+ :where(.animation- pulse.type-success) {
281280 --pulse-color: var(--color-pulse-success);
282281 }
283282
284- :where(.pulse.type-warning) {
283+ :where(.animation- pulse.type-warning) {
285284 --pulse-color: var(--color-pulse-warning);
286285 }
287286
288- :where(.pulse.type-error) {
287+ :where(.animation- pulse.type-error) {
289288 --pulse-color: var(--color-pulse-error);
290289 }
291-
292- /* Apply pulse animation */
293- :where(.pulse) {
294- animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) 3;
295- }
296-
297- /* Animation classes - apply only to SVG icons */
298- button.animate-boop:where(:hover, :focus-visible) :global(svg) {
299- animation: boop 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
300- }
301-
302- button.animate-bounce:where(:hover, :focus-visible) :global(svg) {
303- animation: bounce 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
304- }
305-
306- button.animate-rotate:where(:hover, :focus-visible) :global(svg) {
307- animation: rotate 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
308- }
309-
310- /* Respect user preferences */
311- @media (prefers-reduced-motion: reduce) {
312- button.animate-boop:where(:hover, :focus-visible) :global(svg),
313- button.animate-bounce:where(:hover, :focus-visible) :global(svg),
314- button.animate-rotate:where(:hover, :focus-visible) :global(svg) {
315- transform: none;
316- animation: none;
317- }
318-
319- :where(.pulse) {
320- animation: none;
321- box-shadow: 0 0 0 2px rgba(var(--pulse-color, 0, 0, 0), 0.3);
322- }
323- }
324290</style >
0 commit comments