Files
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

45 lines
1.3 KiB
TypeScript

import React, { PureComponent } from 'react';
import { NavigationKey } from '../types';
export interface Props extends Omit<React.HTMLProps<HTMLInputElement>, 'onChange' | 'value'> {
onChange: (value: string) => void;
onNavigate: (key: NavigationKey, clearOthers: boolean) => void;
value: string | null;
}
export class VariableInput extends PureComponent<Props> {
onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (NavigationKey[event.keyCode]) {
const clearOthers = event.ctrlKey || event.metaKey || event.shiftKey;
this.props.onNavigate(event.keyCode as NavigationKey, clearOthers);
event.preventDefault();
}
};
onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.onChange(event.target.value);
};
render() {
const { value, id, onNavigate, ...restProps } = this.props;
return (
<input
{...restProps}
ref={(instance) => {
if (instance) {
instance.focus();
instance.setAttribute('style', `width:${Math.max(instance.width, 150)}px`);
}
}}
type="text"
className="gf-form-input"
value={value ?? ''}
onChange={this.onChange}
onKeyDown={this.onKeyDown}
placeholder="Enter variable value"
/>
);
}
}