2019-11-14 03:59:41 -06:00
|
|
|
import { debounce } from 'lodash';
|
2022-04-22 08:33:13 -05:00
|
|
|
import React, { FunctionComponent, useState } from 'react';
|
|
|
|
|
2021-11-30 03:53:31 -06:00
|
|
|
import { Input } from '@grafana/ui';
|
2019-11-14 03:59:41 -06:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
onChange: (alias: any) => void;
|
|
|
|
value: string;
|
2022-05-04 00:36:18 -05:00
|
|
|
id?: string;
|
2019-11-14 03:59:41 -06:00
|
|
|
}
|
|
|
|
|
2022-05-04 00:36:18 -05:00
|
|
|
export const Alias: FunctionComponent<Props> = ({ value = '', onChange, id }) => {
|
2019-11-14 03:59:41 -06:00
|
|
|
const [alias, setAlias] = useState(value);
|
|
|
|
|
|
|
|
const propagateOnChange = debounce(onChange, 1500);
|
|
|
|
|
|
|
|
onChange = (e: any) => {
|
|
|
|
setAlias(e.target.value);
|
|
|
|
propagateOnChange(e.target.value);
|
|
|
|
};
|
|
|
|
|
2022-05-04 00:36:18 -05:00
|
|
|
return <Input id={id} type="text" value={alias} onChange={onChange} aria-label="Optional alias" />;
|
2019-11-14 03:59:41 -06:00
|
|
|
};
|