-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Fix area appearing (mui#14711)
- Loading branch information
1 parent
4bce2f6
commit c36a8d5
Showing
3 changed files
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { animated, useTransition } from '@react-spring/web'; | ||
import { cleanId } from '../internals/cleanId'; | ||
import { useChartId, useDrawingArea } from '../hooks'; | ||
import { SeriesId } from '../models/seriesType/common'; | ||
|
||
interface AppearingMaskProps { | ||
id: SeriesId; | ||
skipAnimation?: boolean; | ||
children: React.ReactNode; | ||
} | ||
|
||
/** | ||
* @ignore - internal component. | ||
*/ | ||
export function AppearingMask(props: AppearingMaskProps) { | ||
const drawingArea = useDrawingArea(); | ||
const chartId = useChartId(); | ||
|
||
const transitionAppear = useTransition<typeof drawingArea, { animatedWidth: number }>( | ||
[drawingArea], | ||
{ | ||
from: (v) => ({ animatedWidth: v.left }), | ||
enter: (v) => ({ animatedWidth: v.width + v.left + v.right }), | ||
leave: (v) => ({ animatedWidth: v.width + v.left + v.right }), | ||
reset: false, | ||
immediate: props.skipAnimation, | ||
}, | ||
); | ||
|
||
const clipId = cleanId(`${chartId}-${props.id}`); | ||
return ( | ||
<React.Fragment> | ||
<clipPath id={clipId}> | ||
{transitionAppear((style) => ( | ||
<animated.rect | ||
x={0} | ||
y={0} | ||
width={style.animatedWidth} | ||
height={drawingArea.top + drawingArea.height + drawingArea.bottom} | ||
/> | ||
))} | ||
</clipPath> | ||
<g clipPath={`url(#${clipId})`}>{props.children}</g> | ||
</React.Fragment> | ||
); | ||
} |