import React, { FC } from 'react'; import { cx, css } from 'emotion'; import { GrafanaTheme } from '@grafana/data'; import { useTheme } from '../../themes'; import { InlineLabel } from './InlineLabel'; import { PopoverContent } from '../Tooltip/Tooltip'; import { FieldProps } from './Field'; import { getChildId } from '../../utils/children'; export interface Props extends Omit { /** Content for the label's tooltip */ tooltip?: PopoverContent; /** Custom width for the label */ labelWidth?: number | 'auto'; /** Make the field's child to fill the width of the row. Equivalent to setting `flex-grow:1` on the field */ grow?: boolean; /** Make field's background transparent */ transparent?: boolean; } export const InlineField: FC = ({ children, label, tooltip, labelWidth = 'auto', invalid, loading, disabled, className, grow, transparent, ...htmlProps }) => { const theme = useTheme(); const styles = getStyles(theme, grow); const inputId = getChildId(children); const labelElement = typeof label === 'string' ? ( {label} ) : ( label ); return (
{labelElement} {React.cloneElement(children, { invalid, disabled, loading })}
); }; InlineField.displayName = 'InlineField'; const getStyles = (theme: GrafanaTheme, grow?: boolean) => { return { container: css` display: flex; flex-direction: row; align-items: flex-start; text-align: left; position: relative; flex: ${grow ? 1 : 0} 0 auto; margin: 0 ${theme.spacing.xs} ${theme.spacing.xs} 0; `, }; };