Skip to content

Commit

Permalink
[shape] add innerRef prop to <LinkHorizontal />
Browse files Browse the repository at this point in the history
  • Loading branch information
hshoff committed Oct 7, 2017
1 parent 931dbee commit ed1ee3b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
11 changes: 9 additions & 2 deletions packages/vx-shape/src/shapes/LinkHorizontal.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { linkHorizontal } from 'd3-shape';
import additionalProps from '../util/additionalProps';

LinkHorizontal.propTypes = {
innerRef: PropTypes.func,
};

export default function LinkHorizontal({
className,
innerRef,
data,
x = d => d.y,
y = d => d.x,
...restProps
}) {
const link = linkHorizontal()
const link = linkHorizontal();
link.x(x);
link.y(y);
return (
<path
ref={innerRef}
className={cx('vx-link-horizontal', className)}
d={link(data)}
{...additionalProps(restProps, data)}
/>
);
}
}
33 changes: 30 additions & 3 deletions packages/vx-shape/test/LinkHorizontal.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { hierarchy } from 'd3-hierarchy';
import { LinkHorizontal } from '../src';

const mockHierarchy = hierarchy({
name: 'Eve',
children: [
{ name: 'Cain' },
{
name: 'Seth',
children: [{ name: 'Enos' }, { name: 'Noam' }],
},
],
});
const link = mockHierarchy.links()[0];

describe('<LinkHorizontal />', () => {
test('it should be defined', () => {
expect(LinkHorizontal).toBeDefined()
})
})
expect(LinkHorizontal).toBeDefined();
});

test('it should expose its ref via an innerRef prop', done => {
const node = document.createElement('div');
const refCallback = n => {
expect(n.tagName).toEqual('PATH');
done();
};
ReactDOM.render(
<LinkHorizontal innerRef={refCallback} data={link} />,
node,
);
});
});

0 comments on commit ed1ee3b

Please sign in to comment.