MCPcopy Create free account
hub / github.com/adobe/react-spectrum / CrossFade

Function CrossFade

packages/@react-spectrum/ai/src/ResponseStatus.tsx:361–389  ·  view source on GitHub ↗

* Cross-fades between `children` whenever `depKey` changes.

(props: {depKey: string; children: ReactNode; styles?: StyleString})

Source from the content-addressed store, hash-verified

359 * Cross-fades between `children` whenever `depKey` changes.
360 */
361function CrossFade(props: {depKey: string; children: ReactNode; styles?: StyleString}) {
362 let [state, setState] = useState(props);
363 let [prev, setPrev] = useState<typeof props | null>(null);
364 if (state.depKey !== props.depKey) {
365 setPrev(state);
366 setState(props);
367 }
368
369 return (
370 <span className={mergeStyles(crossFadeContainerStyles, props.styles)}>
371 {prev && (
372 <span
373 key={prev.depKey}
374 inert
375 className={crossFadeExitStyles}
376 onAnimationEnd={e => {
377 if (e.animationName === fadeOut) {
378 setPrev(null);
379 }
380 }}>
381 {prev.children}
382 </span>
383 )}
384 <span key={props.depKey} className={crossFadeLayerStyles({isInitial: prev == null})}>
385 {props.children}
386 </span>
387 </span>
388 );
389}
390
391export interface ResponseStatusPanelProps
392 extends

Callers

nothing calls this directly

Calls 1

mergeStylesFunction · 0.50

Tested by

no test coverage detected