From 59d6f26708705beb9ca41de022c94dd0e815660e Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Tue, 23 Mar 2021 10:44:39 +0100 Subject: [PATCH] Legacy Select: updates story from Knobs to Controls (#32225) * Legacy Story: updates story from Knobs to Controls * removed type in story * adds type back to the story --- .../Legacy/Select/Select.story.internal.tsx | 96 ++++++++++--------- .../components/Forms/Legacy/Select/Select.tsx | 2 +- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.story.internal.tsx b/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.story.internal.tsx index d801ae0e7fc..0c5c03a5064 100644 --- a/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.story.internal.tsx +++ b/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.story.internal.tsx @@ -1,41 +1,64 @@ import React, { useState, useCallback } from 'react'; import { action } from '@storybook/addon-actions'; -import { withKnobs, object } from '@storybook/addon-knobs'; +import { Story } from '@storybook/react'; import { withCenteredStory } from '../../../../utils/storybook/withCenteredStory'; import { UseState } from '../../../../utils/storybook/UseState'; import { SelectableValue } from '@grafana/data'; import { Select, AsyncSelect as AsyncSelectComponent } from './Select'; +import { NOOP_CONTROL } from '../../../../utils/storybook/noopControl'; export default { title: 'Forms/Legacy/Select', component: Select, - decorators: [withCenteredStory, withKnobs], + decorators: [withCenteredStory], + parameters: { + knobs: { + disable: true, + }, + }, + argTypes: { + width: { control: { type: 'range', min: 5, max: 30 } }, + className: NOOP_CONTROL, + menuPlacement: NOOP_CONTROL, + menuPosition: NOOP_CONTROL, + maxMenuHeight: NOOP_CONTROL, + minMenuHeight: NOOP_CONTROL, + maxVisibleValues: NOOP_CONTROL, + prefix: NOOP_CONTROL, + renderControl: NOOP_CONTROL, + value: NOOP_CONTROL, + options: NOOP_CONTROL, + tooltipContent: NOOP_CONTROL, + components: NOOP_CONTROL, + inputValue: NOOP_CONTROL, + id: NOOP_CONTROL, + inputId: NOOP_CONTROL, + defaultValue: NOOP_CONTROL, + loading: NOOP_CONTROL, + 'aria-label': NOOP_CONTROL, + }, }; -const initialState: SelectableValue = { label: 'A label', value: 'A value' }; +const initialValue: SelectableValue = { label: 'A label', value: 'A value' }; -const options = object>>('Options:', [ - initialState, +const options = [ + initialValue, { label: 'Another label', value: 'Another value 1' }, { label: 'Another label', value: 'Another value 2' }, { label: 'Another label', value: 'Another value 3' }, { label: 'Another label', value: 'Another value 4' }, { label: 'Another label', value: 'Another value 5' }, { label: 'Another label', value: 'Another value ' }, -]); - -export const basic = () => { - const value = object>('Selected Value:', initialState); +]; +export const Basic: Story = (args) => { return ( - + {(value, updateValue) => { return ( { - action('onChanged fired')(value); - updateValue(value); - }} - /> - ); - }} - - ); +Basic.args = { + placeholder: 'Choose...', + options: options, + width: 20, }; -export const AsyncSelect = () => { - const [isLoading, setIsLoading] = useState(true); - const [value, setValue] = useState>(); +export const AsyncSelect: Story = (args) => { + const [isLoading, setIsLoading] = useState(args.loading); + const [asyncValue, setAsyncValue] = useState>(); const loadAsyncOptions = useCallback((inputValue) => { return new Promise>>((resolve) => { setTimeout(() => { @@ -83,15 +87,19 @@ export const AsyncSelect = () => { }, []); return ( { action('onChange')(value); - setValue(value); + setAsyncValue(value); }} /> ); }; +AsyncSelect.args = { + loading: true, + defaultOptions: true, + width: 20, +}; diff --git a/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.tsx b/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.tsx index 186188a897a..dfdf035ecdc 100644 --- a/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.tsx +++ b/packages/grafana-ui/src/components/Forms/Legacy/Select/Select.tsx @@ -39,7 +39,7 @@ interface AsyncProps extends LegacyCommonProps, Omit, value?: SelectableValue; } -interface LegacySelectProps extends LegacyCommonProps { +export interface LegacySelectProps extends LegacyCommonProps { tooltipContent?: PopoverContent; noOptionsMessage?: () => string; isDisabled?: boolean;