mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Variables: Adds description field * Refactor: Adds new Form components * Refactor: Fixes aria labels * Refactor: removes skipped tests * Refactor: Breaks out smaller select components * Refactor: removes gf-form div * Refactor: Breaks up several more selects into smaller components * Chore: Fixes typings
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import React, { PropsWithChildren, ReactElement } from 'react';
|
|
import { InlineFormLabel, Select, useStyles } from '@grafana/ui';
|
|
import { GrafanaTheme, SelectableValue } from '@grafana/data';
|
|
import { css } from 'emotion';
|
|
|
|
interface VariableSelectFieldProps<T> {
|
|
name: string;
|
|
value: SelectableValue<T>;
|
|
options: Array<SelectableValue<T>>;
|
|
onChange: (option: SelectableValue<T>) => void;
|
|
tooltip?: string;
|
|
ariaLabel?: string;
|
|
width?: number;
|
|
labelWidth?: number;
|
|
}
|
|
|
|
export function VariableSelectField({
|
|
name,
|
|
value,
|
|
options,
|
|
tooltip,
|
|
onChange,
|
|
ariaLabel,
|
|
width,
|
|
labelWidth,
|
|
}: PropsWithChildren<VariableSelectFieldProps<any>>): ReactElement {
|
|
const styles = useStyles(getStyles);
|
|
|
|
return (
|
|
<>
|
|
<InlineFormLabel width={labelWidth ?? 6} tooltip={tooltip}>
|
|
{name}
|
|
</InlineFormLabel>
|
|
<div aria-label={ariaLabel}>
|
|
<Select
|
|
onChange={onChange}
|
|
value={value}
|
|
width={width ?? 25}
|
|
options={options}
|
|
className={styles.selectContainer}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function getStyles(theme: GrafanaTheme) {
|
|
return {
|
|
selectContainer: css`
|
|
margin-right: ${theme.spacing.xs};
|
|
`,
|
|
};
|
|
}
|