|
@@ -1,10 +1,12 @@
|
|
|
import React, { InputHTMLAttributes, FunctionComponent } from 'react';
|
|
import React, { InputHTMLAttributes, FunctionComponent } from 'react';
|
|
|
|
|
+// import React, { InputHTMLAttributes } from 'react';
|
|
|
import { FormLabel } from '../FormLabel/FormLabel';
|
|
import { FormLabel } from '../FormLabel/FormLabel';
|
|
|
|
|
|
|
|
export interface Props extends InputHTMLAttributes<HTMLInputElement> {
|
|
export interface Props extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
label: string;
|
|
label: string;
|
|
|
labelWidth?: number;
|
|
labelWidth?: number;
|
|
|
inputWidth?: number;
|
|
inputWidth?: number;
|
|
|
|
|
+ inputEl?: React.ReactNode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
const defaultProps = {
|
|
@@ -12,14 +14,24 @@ const defaultProps = {
|
|
|
inputWidth: 12,
|
|
inputWidth: 12,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, ...inputProps }) => {
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Default form field including label used in Grafana UI. Default input element is simple <input />. You can also pass
|
|
|
|
|
+ * custom inputEl if required in which case inputWidth and inputProps are ignored.
|
|
|
|
|
+ * @param label
|
|
|
|
|
+ * @param labelWidth
|
|
|
|
|
+ * @param inputWidth
|
|
|
|
|
+ * @param inputEl
|
|
|
|
|
+ * @param inputProps
|
|
|
|
|
+ * @constructor
|
|
|
|
|
+ */
|
|
|
|
|
+export const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, inputEl, ...inputProps }) => {
|
|
|
return (
|
|
return (
|
|
|
<div className="form-field">
|
|
<div className="form-field">
|
|
|
<FormLabel width={labelWidth}>{label}</FormLabel>
|
|
<FormLabel width={labelWidth}>{label}</FormLabel>
|
|
|
- <input type="text" className={`gf-form-input width-${inputWidth}`} {...inputProps} />
|
|
|
|
|
|
|
+ {inputEl || <input type="text" className={`gf-form-input width-${inputWidth}`} {...inputProps} />}
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+FormField.displayName = 'FormField';
|
|
|
FormField.defaultProps = defaultProps;
|
|
FormField.defaultProps = defaultProps;
|
|
|
-export { FormField };
|
|
|