mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Clean up hoc and extend component props automatically
This commit is contained in:
parent
645812f643
commit
07ce88f685
@ -1,19 +1,17 @@
|
|||||||
import React from 'react';
|
import React, { KeyboardEvent, ComponentType, Component } from 'react';
|
||||||
import { Props as DataSourceProps } from './DataSourcePicker';
|
|
||||||
import { Props as VizTypeProps } from './VizTypePicker';
|
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
selected: number;
|
selected: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KeyboardNavigationProps {
|
export interface KeyboardNavigationProps {
|
||||||
selected?: number;
|
onKeyDown: (evt: KeyboardEvent<EventTarget>, maxSelectedIndex: number, onEnterAction: () => void) => void;
|
||||||
onKeyDown?: (evt: React.KeyboardEvent<EventTarget>, maxSelectedIndex: number, onEnterAction: () => void) => void;
|
onMouseEnter: (select: number) => void;
|
||||||
onMouseEnter?: (select: number) => void;
|
selected: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const withKeyboardNavigation = WrappedComponent => {
|
const withKeyboardNavigation = <P extends object>(WrappedComponent: ComponentType<P & KeyboardNavigationProps>) => {
|
||||||
return class extends React.Component<DataSourceProps | VizTypeProps, State> {
|
return class WithKeyboardNavigation extends Component<P, State> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@ -58,12 +56,7 @@ const withKeyboardNavigation = WrappedComponent => {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<WrappedComponent
|
<WrappedComponent {...this.state} {...this.props} onKeyDown={this.onKeyDown} onMouseEnter={this.onMouseEnter} />
|
||||||
selected={this.state.selected}
|
|
||||||
onKeyDown={this.onKeyDown}
|
|
||||||
onMouseEnter={this.onMouseEnter}
|
|
||||||
{...this.props}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user