@@ -12,6 +12,8 @@ import cn from 'classnames'
1212import Lottie , { LottieRefCurrentProps } from 'lottie-react'
1313
1414import { SeoLink } from 'components/link'
15+ import { applyThemeToLottie } from 'utils/lottieTheme'
16+ import { useLottieThemeColors } from 'utils/theme/theme'
1517
1618import styles from './AnimatedButtonProvider.module.css'
1719
@@ -129,45 +131,54 @@ const AnimatedButton = ({
129131 { buttonElement }
130132 </ SeoLink >
131133 ) : (
132- < button { ...rootProps } > { buttonElement } </ button >
134+ < button { ...rootProps } { ...buttonProps } >
135+ { buttonElement }
136+ </ button >
133137 )
134138}
135139
140+ export type LottieThemeVariant = 'accent' | 'neutral'
141+
136142export type AnimatedButtonProviderProps = {
137- darkMode : boolean
143+ /** @deprecated No longer used - theme applied via useLottieThemeColors */
144+ darkMode ?: boolean
138145 isMatrix : boolean
139- iconDarkJSON : ( ) => Promise < any >
140- iconLightJSON : ( ) => Promise < any >
146+ /** Base Lottie JSON loader - theme colors applied at runtime */
147+ iconJSON : ( ) => Promise < IconJSON >
148+ /** 'accent' = active state, 'neutral' = inactive state. Defaults from isActive. */
149+ variant ?: LottieThemeVariant
141150} & BaseAnimatedButtonProps
142151
143152const AnimatedButtonProvider = ( {
144- darkMode ,
145- iconDarkJSON ,
146- iconLightJSON ,
153+ iconJSON : iconJSONLoader ,
154+ isActive ,
155+ variant : variantProp ,
147156 ...buttonProps
148157} : AnimatedButtonProviderProps ) => {
149158 const [ iconJSON , setIconJSON ] = useState < IconJSON | null > ( null )
150- const defaultAnimations = useRef < IconJSON | null > ( null )
151- const darkAnimations = useRef < IconJSON | null > ( null )
159+ const baseAnimation = useRef < IconJSON | null > ( null )
160+ const themeColors = useLottieThemeColors ( )
161+ const variant = variantProp ?? ( isActive ? 'accent' : 'neutral' )
152162
153163 useEffect ( ( ) => {
154- const loadAnimations = async ( ) => {
155- if ( darkMode ) {
156- if ( ! darkAnimations . current ) {
157- darkAnimations . current = await iconDarkJSON ( )
158- }
159- setIconJSON ( { ...darkAnimations . current } )
160- } else {
161- if ( ! defaultAnimations . current ) {
162- defaultAnimations . current = await iconLightJSON ( )
163- }
164- setIconJSON ( { ...defaultAnimations . current } )
164+ const loadAndTheme = async ( ) => {
165+ if ( ! baseAnimation . current ) {
166+ baseAnimation . current = await iconJSONLoader ( )
165167 }
168+ setIconJSON (
169+ applyThemeToLottie (
170+ baseAnimation . current ,
171+ themeColors ,
172+ variant
173+ ) as IconJSON
174+ )
166175 }
167- loadAnimations ( )
168- } , [ darkMode , setIconJSON , iconDarkJSON , iconLightJSON ] )
176+ loadAndTheme ( )
177+ } , [ iconJSONLoader , themeColors , variant ] )
169178
170- return iconJSON && < AnimatedButton iconJSON = { iconJSON } { ...buttonProps } />
179+ return iconJSON ? (
180+ < AnimatedButton iconJSON = { iconJSON } isActive = { isActive } { ...buttonProps } />
181+ ) : null
171182}
172183
173184export default memo ( AnimatedButtonProvider )
0 commit comments