Skip to content
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

new(react-spring): add tickLineProps to AnimatedTicks #1490

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding tests! 🙏

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}`);
});
});