The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/variables/editor/VariableSelectField.tsx

53 lines
1.3 KiB

import { css } from '@emotion/css';
import React, { PropsWithChildren, ReactElement } from 'react';
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
import { Field, Select, useStyles2 } from '@grafana/ui';
import { useUniqueId } from 'app/plugins/datasource/influxdb/components/useUniqueId';
interface VariableSelectFieldProps<T> {
name: string;
value: SelectableValue<T>;
options: Array<SelectableValue<T>>;
onChange: (option: SelectableValue<T>) => void;
testId?: string;
width?: number;
description?: React.ReactNode;
}
export function VariableSelectField({
name,
description,
value,
options,
onChange,
testId,
width,
}: PropsWithChildren<VariableSelectFieldProps<any>>): ReactElement {
const styles = useStyles2(getStyles);
const uniqueId = useUniqueId();
const inputId = `variable-select-input-${name}-${uniqueId}`;
return (
<Field label={name} description={description} htmlFor={inputId}>
<div data-testid={testId}>
<Select
inputId={inputId}
onChange={onChange}
value={value}
width={width ?? 30}
options={options}
className={styles.selectContainer}
/>
</div>
</Field>
);
}
function getStyles(theme: GrafanaTheme2) {
return {
selectContainer: css`
margin-right: ${theme.spacing(0.5)};
`,
};
}