-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deps: upgrade react-spring to v9 #1218
Changes from 1 commit
c40b639
d111e07
9388a40
2752910
9d16b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
import { animated, useTransition, interpolate } from 'react-spring'; | ||
import { animated, useTransition, to, SpringValue } from 'react-spring'; | ||
import cx from 'classnames'; | ||
import Orientation from '@visx/axis/lib/constants/orientation'; | ||
import { TicksRendererProps, AxisScale } from '@visx/axis/lib/types'; | ||
|
@@ -20,63 +20,56 @@ export default function AnimatedTicks<Scale extends AxisScale>({ | |
ticks, | ||
animationTrajectory, | ||
}: TicksRendererProps<Scale> & { animationTrajectory?: AnimationTrajectory }) { | ||
const animatedTicks = useTransition( | ||
ticks, | ||
tick => `${tick.value}`, | ||
useLineTransitionConfig({ scale, animateXOrY: horizontal ? 'x' : 'y', animationTrajectory }), | ||
); | ||
const animatedTicks = useTransition(ticks, { | ||
...useLineTransitionConfig({ | ||
scale, | ||
animateXOrY: horizontal ? 'x' : 'y', | ||
animationTrajectory, | ||
}), | ||
keys: (tick: { value: any }) => `${tick.value}`, | ||
}); | ||
|
||
return ( | ||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
<> | ||
{animatedTicks.map( | ||
( | ||
{ | ||
item, | ||
key, | ||
// @ts-ignore react-spring types only include CSSProperties | ||
props: { fromX, toX, fromY, toY, opacity }, | ||
}, | ||
index, | ||
) => { | ||
const tickLabelProps = allTickLabelProps[index] ?? allTickLabelProps[0] ?? {}; | ||
return item == null || key == null ? null : ( | ||
{animatedTicks(({ fromX, toX, fromY, toY, opacity }, item, { key }, index) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: im getting a ts warning ->
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be caused by the type inference issue of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this is still broken in |
||
const tickLabelProps = allTickLabelProps[index] ?? allTickLabelProps[0] ?? {}; | ||
return item == null || key == null ? null : ( | ||
<animated.g | ||
key={key} | ||
className={cx('visx-axis-tick', tickClassName)} | ||
transform={tickTransform} | ||
> | ||
{!hideTicks && ( | ||
<animated.line | ||
x1={fromX} | ||
x2={toX} | ||
y1={fromY} | ||
y2={toY} | ||
stroke={tickStroke} | ||
strokeLinecap="square" | ||
strokeOpacity={opacity} | ||
/> | ||
)} | ||
{/** animate the group, not the Text */} | ||
<animated.g | ||
key={key} | ||
className={cx('visx-axis-tick', tickClassName)} | ||
transform={tickTransform} | ||
> | ||
{!hideTicks && ( | ||
<animated.line | ||
x1={fromX} | ||
x2={toX} | ||
y1={fromY} | ||
y2={toY} | ||
stroke={tickStroke} | ||
strokeLinecap="square" | ||
strokeOpacity={opacity} | ||
/> | ||
key={index} | ||
transform={to( | ||
[toX as SpringValue<number>, toY as SpringValue<number>], | ||
(interpolatedX, interpolatedY) => | ||
`translate(${interpolatedX},${interpolatedY + | ||
(orientation === Orientation.bottom && | ||
typeof tickLabelProps.fontSize === 'number' | ||
? tickLabelProps.fontSize ?? 10 | ||
: 0)})`, | ||
)} | ||
{/** animate the group, not the Text */} | ||
<animated.g | ||
key={index} | ||
transform={interpolate( | ||
[toX, toY], | ||
(interpolatedX, interpolatedY) => | ||
`translate(${interpolatedX},${interpolatedY + | ||
(orientation === Orientation.bottom && | ||
typeof tickLabelProps.fontSize === 'number' | ||
? tickLabelProps.fontSize ?? 10 | ||
: 0)})`, | ||
)} | ||
opacity={opacity} | ||
> | ||
<Text {...tickLabelProps}>{item?.formattedValue}</Text> | ||
</animated.g> | ||
opacity={opacity} | ||
> | ||
<Text {...tickLabelProps}>{item?.formattedValue}</Text> | ||
</animated.g> | ||
); | ||
}, | ||
)} | ||
</animated.g> | ||
); | ||
})} | ||
</> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if we could do something like this instead of using
any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! I'll change it.