From 07bb6b8daee24e5ec7cfbab5a71447ede46f080b Mon Sep 17 00:00:00 2001 From: Oscar Kilhed Date: Tue, 26 Jan 2021 09:53:39 +0100 Subject: [PATCH] Grafana/UI: Add disable prop to Segment (#30539) * Grafana/UI: Add disable prop to Segment SegmentSync, SegmentAsync and SegmentInput had the disable prop inherited from HTMLProp but it did not disable the component. The disable prop should now disable the component. * Use InlineLabel instead of span and remove some sass-classes in Segments * Change MetricsQueryEditor test to reflect new layout of AsyncSegment * Use useStyles hook to get themed styles for segment inputs Co-authored-by: Alex Khomenko --- .../src/components/Segment/Segment.tsx | 20 +++++++++++++-- .../src/components/Segment/SegmentAsync.tsx | 20 +++++++++++++-- .../src/components/Segment/SegmentInput.tsx | 19 ++++++++++++-- .../src/components/Segment/styles.ts | 21 ++++++++++++++++ .../src/components/Segment/types.ts | 1 + .../components/Segment/useExpandableLabel.tsx | 25 +++++++++++-------- .../components/MetricsQueryEditor.test.tsx | 6 ++--- 7 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 packages/grafana-ui/src/components/Segment/styles.ts diff --git a/packages/grafana-ui/src/components/Segment/Segment.tsx b/packages/grafana-ui/src/components/Segment/Segment.tsx index 750fdf47e7b..53cdfb834cf 100644 --- a/packages/grafana-ui/src/components/Segment/Segment.tsx +++ b/packages/grafana-ui/src/components/Segment/Segment.tsx @@ -3,6 +3,9 @@ import { cx } from 'emotion'; import _ from 'lodash'; import { SelectableValue } from '@grafana/data'; import { SegmentSelect, useExpandableLabel, SegmentProps } from './'; +import { getSegmentStyles } from './styles'; +import { InlineLabel } from '../Forms/InlineLabel'; +import { useStyles } from '../../themes'; export interface SegmentSyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { value?: T | SelectableValue; @@ -18,19 +21,32 @@ export function Segment({ className, allowCustomValue, placeholder, + disabled, ...rest }: React.PropsWithChildren>) { const [Label, width, expanded, setExpanded] = useExpandableLabel(false); + const styles = useStyles(getSegmentStyles); if (!expanded) { const label = _.isObject(value) ? value.label : value; + return (