Files
Hugo Häggmark 2b8c74de2e i18n: removes useTranslate hook (#106556)
* i18n: removes useTranslate hook

* chore: fix duplicate imports

* chore: fix import sorting and hook dependencies
2025-06-12 11:03:52 +02:00

41 lines
1.1 KiB
TypeScript

import { css } from '@emotion/css';
import { StandardEditorProps, GrafanaTheme2, UnitFieldConfigSettings } from '@grafana/data';
import { t } from '@grafana/i18n';
import { IconButton, UnitPicker, useStyles2 } from '@grafana/ui';
type Props = StandardEditorProps<string, UnitFieldConfigSettings>;
export function UnitValueEditor({ value, onChange, item }: Props) {
const styles = useStyles2(getStyles);
if (item?.settings?.isClearable && value != null) {
return (
<div className={styles.wrapper}>
<span className={styles.first}>
<UnitPicker value={value} onChange={onChange} />
</span>
<IconButton
name="times"
onClick={() => onChange(undefined)}
tooltip={t('options-ui.units.clear-tooltip', 'Clear unit selection')}
/>
</div>
);
}
return <UnitPicker value={value} onChange={onChange} />;
}
const getStyles = (theme: GrafanaTheme2) => ({
wrapper: css({
width: '100%',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}),
first: css({
marginRight: theme.spacing(1),
flexGrow: 2,
}),
});