@vx/legend
Advanced tools
Comparing version 0.0.153 to 0.0.154
@@ -113,7 +113,8 @@ 'use strict'; | ||
_LegendItem2.default, | ||
{ | ||
_extends({ | ||
key: 'legend-' + label + '-' + i, | ||
margin: itemMargin, | ||
flexDirection: itemDirection | ||
}, | ||
flexDirection: itemDirection, | ||
label: label | ||
}, restProps), | ||
_react2.default.createElement(_LegendShape2.default, { | ||
@@ -120,0 +121,0 @@ shape: shape, |
@@ -6,2 +6,5 @@ 'use strict'; | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.default = LegendItem; | ||
@@ -17,12 +20,26 @@ | ||
var _additionalProps = require('../util/additionalProps'); | ||
var _additionalProps2 = _interopRequireDefault(_additionalProps); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
LegendItem.propTypes = { | ||
flexDirection: _propTypes2.default.string, | ||
margin: _propTypes2.default.string, | ||
label: _propTypes2.default.object.isRequired | ||
}; | ||
function LegendItem(_ref) { | ||
var children = _ref.children, | ||
flexDirection = _ref.flexDirection, | ||
margin = _ref.margin; | ||
margin = _ref.margin, | ||
label = _ref.label, | ||
restProps = _objectWithoutProperties(_ref, ['children', 'flexDirection', 'margin', 'label']); | ||
return _react2.default.createElement( | ||
'div', | ||
{ | ||
_extends({ | ||
className: 'vx-legend-item', | ||
@@ -35,5 +52,5 @@ style: { | ||
} | ||
}, | ||
}, (0, _additionalProps2.default)(restProps, label)), | ||
children | ||
); | ||
} |
{ | ||
"name": "@vx/legend", | ||
"version": "0.0.153", | ||
"version": "0.0.154", | ||
"description": "vx legend", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -75,2 +75,4 @@ import React from 'react'; | ||
flexDirection={itemDirection} | ||
label={label} | ||
{...restProps} | ||
> | ||
@@ -77,0 +79,0 @@ <LegendShape |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import additonalProps from '../util/additionalProps'; | ||
LegendItem.propTypes = { | ||
flexDirection: PropTypes.string, | ||
margin: PropTypes.string, | ||
label: PropTypes.object.isRequired, | ||
}; | ||
export default function LegendItem({ | ||
@@ -8,6 +15,8 @@ children, | ||
margin, | ||
label, | ||
...restProps | ||
}) { | ||
return ( | ||
<div | ||
className='vx-legend-item' | ||
className="vx-legend-item" | ||
style={{ | ||
@@ -19,2 +28,3 @@ display: 'flex', | ||
}} | ||
{...additonalProps(restProps, label)} | ||
> | ||
@@ -24,2 +34,2 @@ {children} | ||
); | ||
} | ||
} |
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { Legend } from '../src'; | ||
@@ -45,2 +45,25 @@ import { scaleLinear } from '../../vx-scale'; | ||
}); | ||
test('it should pass onClick prop to <LegendItem />', () => { | ||
const event = jest.fn(event => jest.fn()); | ||
const onClick = jest.fn(data => event); | ||
const wrapper = mount( | ||
<Legend {...defaultProps} onClick={onClick} />, | ||
); | ||
wrapper | ||
.find('LegendItem') | ||
.last() | ||
.simulate('click'); | ||
// called twice, once to bind data, once when click event | ||
expect(onClick.mock.calls.length).toEqual(2); | ||
expect(event.mock.calls.length).toEqual(1); | ||
// called with click event | ||
expect(event.mock.calls[0][0].type).toEqual('click'); | ||
expect(onClick.mock.calls[1][0]).toEqual({ | ||
datum: 10, | ||
index: 1, | ||
text: '10', | ||
value: 0, | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56086
51
1528