import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; import { Segment, SegmentInput, useStyles2 } from '@grafana/ui'; export type EditableParam = { name: string; value: string; optional: boolean; multiple: boolean; options: Array>; }; type FieldEditorProps = { editableParam: EditableParam; onChange: (value: string) => void; onExpandedChange: (expanded: boolean) => void; autofocus: boolean; }; /** * Render a function parameter with a segment dropdown for multiple options or simple input. */ export function FunctionParamEditor({ editableParam, onChange, onExpandedChange, autofocus }: FieldEditorProps) { const styles = useStyles2(getStyles); if (editableParam.options?.length > 0) { return ( { onChange(value.value || ''); }} onExpandedChange={onExpandedChange} inputMinWidth={150} allowCustomValue={true} allowEmptyValue={true} > ); } else { return ( { onChange(value.toString()); }} onExpandedChange={onExpandedChange} // input style style={{ height: '25px', paddingTop: '2px', marginTop: '2px', paddingLeft: '4px', minWidth: '100px' }} > ); } } const getStyles = (theme: GrafanaTheme2) => ({ segment: css({ margin: 0, padding: 0, }), input: css` margin: 0; padding: 0; input { height: 25px; }, `, });