Browse Source

Updated comments

Andrej Ocenas 6 years ago
parent
commit
aa14d7528c

+ 0 - 6
packages/grafana-ui/src/components/FormField/FormField.tsx

@@ -17,12 +17,6 @@ const defaultProps = {
 /**
 /**
  * Default form field including label used in Grafana UI. Default input element is simple <input />. You can also pass
  * 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.
  * 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 }) => {
 export const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, inputEl, ...inputProps }) => {
   return (
   return (

+ 20 - 5
packages/grafana-ui/src/components/SecretFormFied/SecretFormField.tsx

@@ -3,25 +3,42 @@ import React, { InputHTMLAttributes, FunctionComponent } from 'react';
 import { FormField } from '..';
 import { FormField } from '..';
 
 
 interface Props extends InputHTMLAttributes<HTMLInputElement> {
 interface Props extends InputHTMLAttributes<HTMLInputElement> {
+  // Function to use when reset is clicked. Means you have to reset the input value yourself as this is  uncontrolled
+  // component (or do something else if required).
   onReset: () => void;
   onReset: () => void;
   isConfigured: boolean;
   isConfigured: boolean;
 
 
   label?: string;
   label?: string;
   labelWidth?: number;
   labelWidth?: number;
   inputWidth?: number;
   inputWidth?: number;
+  // Placeholder of the input field when in non configured state.
+  placeholder?: string;
 }
 }
 
 
+const defaultProps = {
+  inputWidth: 12,
+  placeholder: 'Password',
+  label: 'Password',
+};
+
+/**
+ * Form field that has 2 states configured and not configured. If configured it will not show its contents and adds
+ * a reset button that will clear the input and makes it accessible. In non configured state it behaves like normal
+ * form field. This is used for passwords or anything that is encrypted on the server and is later returned encrypted
+ * to the user (like datasource passwords).
+ */
 export const SecretFormField: FunctionComponent<Props> = ({
 export const SecretFormField: FunctionComponent<Props> = ({
   label,
   label,
   labelWidth,
   labelWidth,
   inputWidth,
   inputWidth,
   onReset,
   onReset,
   isConfigured,
   isConfigured,
+  placeholder,
   ...inputProps
   ...inputProps
 }: Props) => {
 }: Props) => {
   return (
   return (
     <FormField
     <FormField
-      label={label || 'Password'}
+      label={label!}
       labelWidth={labelWidth}
       labelWidth={labelWidth}
       inputEl={
       inputEl={
         isConfigured ? (
         isConfigured ? (
@@ -41,7 +58,7 @@ export const SecretFormField: FunctionComponent<Props> = ({
           <input
           <input
             type="password"
             type="password"
             className={`gf-form-input width-${inputWidth}`}
             className={`gf-form-input width-${inputWidth}`}
-            placeholder={'password'}
+            placeholder={placeholder}
             {...inputProps}
             {...inputProps}
           />
           />
         )
         )
@@ -50,7 +67,5 @@ export const SecretFormField: FunctionComponent<Props> = ({
   );
   );
 };
 };
 
 
-SecretFormField.defaultProps = {
-  inputWidth: 12,
-};
+SecretFormField.defaultProps = defaultProps;
 SecretFormField.displayName = 'SecretFormField';
 SecretFormField.displayName = 'SecretFormField';