Skip to content

Commit

Permalink
FormLabel: allow any rather than just a string for tooltip (grafana#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu authored May 1, 2019
1 parent 9d01b21 commit 2e326d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/grafana-ui/src/components/FormField/FormField.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { InputHTMLAttributes, FunctionComponent } from 'react';
import { FormLabel } from '../FormLabel/FormLabel';
import { PopperContent } from '../Tooltip/PopperController';

export interface Props extends InputHTMLAttributes<HTMLInputElement> {
label: string;
tooltip?: PopperContent<any>;
labelWidth?: number;
inputWidth?: number;
inputEl?: React.ReactNode;
Expand All @@ -17,10 +19,19 @@ const defaultProps = {
* 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.
*/
export const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, inputEl, ...inputProps }) => {
export const FormField: FunctionComponent<Props> = ({
label,
tooltip,
labelWidth,
inputWidth,
inputEl,
...inputProps
}) => {
return (
<div className="form-field">
<FormLabel width={labelWidth}>{label}</FormLabel>
<FormLabel width={labelWidth} tooltip={tooltip}>
{label}
</FormLabel>
{inputEl || <input type="text" className={`gf-form-input width-${inputWidth}`} {...inputProps} />}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/grafana-ui/src/components/FormLabel/FormLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { FunctionComponent, ReactNode } from 'react';
import classNames from 'classnames';
import { Tooltip } from '../Tooltip/Tooltip';
import { PopperContent } from '../Tooltip/PopperController';

interface Props {
children: ReactNode;
className?: string;
htmlFor?: string;
isFocused?: boolean;
isInvalid?: boolean;
tooltip?: string;
tooltip?: PopperContent<any>;
width?: number;
}

Expand Down

0 comments on commit 2e326d1

Please sign in to comment.