From 55553322c8b7688b54eb47fc4ceeb80503b88390 Mon Sep 17 00:00:00 2001 From: Mofeng <52260316+DiamondMofeng@users.noreply.github.com> Date: Thu, 6 Apr 2023 21:32:39 +0800 Subject: [PATCH] Design System: Remove unused type parameter in `SegmentProps` and `SegmentInput` (#64919) * fix: Remove unused type parameter in `SegmentProps` and `SegmentInput` * lint: prettier auto fix * fix( SegmentInput.story.tsx ): adapt to changes --- packages/grafana-ui/src/components/Segment/Segment.tsx | 2 +- .../grafana-ui/src/components/Segment/SegmentAsync.tsx | 2 +- .../src/components/Segment/SegmentInput.story.tsx | 8 +++----- .../grafana-ui/src/components/Segment/SegmentInput.tsx | 8 ++++---- packages/grafana-ui/src/components/Segment/types.ts | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/grafana-ui/src/components/Segment/Segment.tsx b/packages/grafana-ui/src/components/Segment/Segment.tsx index 5c7d2e1e881..fd8401c6c82 100644 --- a/packages/grafana-ui/src/components/Segment/Segment.tsx +++ b/packages/grafana-ui/src/components/Segment/Segment.tsx @@ -11,7 +11,7 @@ import { getSegmentStyles } from './styles'; import { SegmentSelect, useExpandableLabel, SegmentProps } from './'; -export interface SegmentSyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { +export interface SegmentSyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { value?: T | SelectableValue; onChange: (item: SelectableValue) => void; options: Array>; diff --git a/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx b/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx index 99e485027a3..5d9e90c8fbc 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx @@ -15,7 +15,7 @@ import { getSegmentStyles } from './styles'; import { useExpandableLabel, SegmentProps } from '.'; -export interface SegmentAsyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { +export interface SegmentAsyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { value?: T | SelectableValue; loadOptions: (query?: string) => Promise>>; /** diff --git a/packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx b/packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx index 68958c0e6cd..5f5516c86ad 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx @@ -100,12 +100,10 @@ export const InputWithAutoFocus = () => { ); }; -export const Basic: ComponentStory>> = ( - args: SegmentInputProps -) => { +export const Basic: ComponentStory> = (args: SegmentInputProps) => { const [value, setValue] = useState(args.value); - const props: SegmentInputProps = { + const props: SegmentInputProps = { ...args, value, onChange: (value) => { @@ -117,7 +115,7 @@ export const Basic: ComponentStory - {...props} /> + ); }; diff --git a/packages/grafana-ui/src/components/Segment/SegmentInput.tsx b/packages/grafana-ui/src/components/Segment/SegmentInput.tsx index acfaef89d9d..d4d3d581b00 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentInput.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentInput.tsx @@ -10,8 +10,8 @@ import { getSegmentStyles } from './styles'; import { useExpandableLabel, SegmentProps } from '.'; -export interface SegmentInputProps - extends Omit, 'allowCustomValue' | 'allowEmptyValue'>, +export interface SegmentInputProps + extends Omit, Omit, 'value' | 'onChange'> { value: string | number; onChange: (text: string | number) => void; @@ -19,7 +19,7 @@ export interface SegmentInputProps const FONT_SIZE = 14; -export function SegmentInput({ +export function SegmentInput({ value: initialValue, onChange, Component, @@ -30,7 +30,7 @@ export function SegmentInput({ autofocus = false, onExpandedChange, ...rest -}: React.PropsWithChildren>) { +}: React.PropsWithChildren) { const ref = useRef(null); const [value, setValue] = useState(initialValue); const [inputWidth, setInputWidth] = useState(measureText((initialValue || '').toString(), FONT_SIZE).width); diff --git a/packages/grafana-ui/src/components/Segment/types.ts b/packages/grafana-ui/src/components/Segment/types.ts index 06cb23bef32..ec2d8756e82 100644 --- a/packages/grafana-ui/src/components/Segment/types.ts +++ b/packages/grafana-ui/src/components/Segment/types.ts @@ -1,6 +1,6 @@ import { ReactElement } from 'react'; -export interface SegmentProps { +export interface SegmentProps { Component?: ReactElement; className?: string; allowCustomValue?: boolean;