Skip to content

Commit d4e9047

Browse files
committed
Add support for events on RangeSelector buttons. Fixes #79
1 parent c42aaf3 commit d4e9047

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

packages/react-jsx-highcharts/src/utils/events.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ export const getNonEventHandlerProps = props => {
1313
return omitBy(props, _isEventKey);
1414
};
1515

16+
export const getEventsConfig = props => {
17+
const eventProps = getEventHandlerProps(props);
18+
19+
return mapKeys(eventProps, (handler, eventName) => {
20+
return lowerFirst(eventName.replace(/^on/, ''));
21+
});
22+
}
23+
1624
export const addEventHandlersManually = (Highcharts, context, props) => {
17-
const eventProps = _getEventProps(props);
25+
const eventProps = getEventsConfig(props);
1826

1927
forEach(eventProps, (handler, eventName) => {
2028
Highcharts.addEvent(context, eventName, handler);
2129
});
2230
};
2331

2432
export const addEventHandlers = (updateFn, props) => {
25-
const events = _getEventProps(props);
33+
const events = getEventsConfig(props);
2634
updateFn({ events });
2735
};
2836

2937
const _isEventKey = (value, key) => (key.indexOf('on') === 0) && isFunction(value);
3038

31-
const _getEventProps = props => {
32-
const eventProps = getEventHandlerProps(props);
33-
34-
return mapKeys(eventProps, (handler, eventName) => {
35-
return lowerFirst(eventName.replace(/^on/, ''));
36-
});
37-
}
38-
3939
export default addEventHandlers;

packages/react-jsx-highstock/src/components/RangeSelector/RangeSelectorButton.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import { Component } from 'react';
22
import PropTypes from 'prop-types';
3+
import { getEventsConfig } from 'react-jsx-highcharts/src/utils/events';
34

45
class RangeSelectorButton extends Component {
56

67
static propTypes = {
78
count: PropTypes.number,
8-
type: PropTypes.string.isRequired,
9+
type: PropTypes.oneOf(['millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'ytd', 'all']),
10+
offsetMin: PropTypes.number.isRequired,
11+
offsetMax: PropTypes.number.isRequired,
12+
dataGrouping: PropTypes.object,
913
update: PropTypes.func, // Provided by ChartProvider
1014
getChart: PropTypes.func // Provided by ChartProvider
1115
};
1216

17+
static defaultProps = {
18+
count: 1,
19+
offsetMin: 0,
20+
offsetMax: 0
21+
};
22+
1323
constructor (props) {
1424
super(props);
1525
this.getButtons = this.getButtons.bind(this);
@@ -21,13 +31,18 @@ class RangeSelectorButton extends Component {
2131
const button = this.getButtonIndex();
2232
if (button > -1) return; // Button already present
2333

24-
const { count, type, children } = this.props;
34+
const { count, type, offsetMin, offsetMax, dataGrouping, children, ...rest } = this.props;
35+
2536
const buttons = [
2637
...this.getButtons(),
2738
{
2839
count,
2940
type,
30-
text: children
41+
offsetMin,
42+
offsetMax,
43+
dataGrouping,
44+
text: children,
45+
events: getEventsConfig(rest)
3146
}
3247
];
3348
this.updateRangeSelectorButtons(buttons);

0 commit comments

Comments
 (0)