Skip to content

Commit

Permalink
new(xychart, react-spring): add tickLineProps to AnimatedTicks (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zenith00 authored May 2, 2022
1 parent 1b5897b commit 029e0b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/visx-axis/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type AxisScaleOutput = number | NumberLike | undefined;
export type AxisScale<Output extends AxisScaleOutput = AxisScaleOutput> =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
D3Scale<Output, any, any>;
type LineProps = Omit<React.SVGProps<SVGLineElement>, 'to' | 'from'>;
type LineProps = Omit<React.SVGProps<SVGLineElement>, 'to' | 'from' | 'ref'>;

type FormattedValue = string | undefined;

Expand Down
2 changes: 2 additions & 0 deletions packages/visx-react-spring/src/axis/AnimatedTicks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function AnimatedTicks<Scale extends AxisScale>({
tickStroke = '#222',
tickTransform,
ticks,
tickLineProps,
animationTrajectory,
}: TicksRendererProps<Scale> & { animationTrajectory?: AnimationTrajectory }) {
const animatedTicks = useTransition(ticks, {
Expand Down Expand Up @@ -50,6 +51,7 @@ export default function AnimatedTicks<Scale extends AxisScale>({
stroke={tickStroke}
strokeLinecap="square"
strokeOpacity={opacity}
{...tickLineProps}
/>
)}
{/** animate the group, not the Text */}
Expand Down
17 changes: 17 additions & 0 deletions packages/visx-xychart/test/components/Axis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,21 @@ describe('<BaseAxis />', () => {
expect(VisxLine).toHaveAttribute('stroke-width', `${axisStyles.axisLine.strokeWidth}`);
expect(VisxLine).toHaveAttribute('stroke', axisStyles.tickLine.stroke);
});

it('should accept props for tickline', () => {
const tickLineProps = { strokeWidth: 12345, stroke: 'banana', opacity: 0.5 };
const { container } = setup(
<BaseAxis
orientation="left"
AxisComponent={() => <AnimatedAxis orientation="top" tickLineProps={tickLineProps} />}
/>,
);

const VisxAxisTick = container.querySelector('.visx-axis-tick > line');

// specified styles in the props
expect(VisxAxisTick).toHaveAttribute('stroke-width', `${tickLineProps.strokeWidth}`);
expect(VisxAxisTick).toHaveAttribute('stroke', `${tickLineProps.stroke}`);
expect(VisxAxisTick).toHaveAttribute('opacity', `${tickLineProps.opacity}`);
});
});

0 comments on commit 029e0b2

Please sign in to comment.