From 765e771a2ab85a11515d076f39a289f310c2b98e Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Thu, 13 May 2021 08:02:44 +0100 Subject: [PATCH] StatsPicker: updates story from knobs to control (#34008) --- .../StatsPicker/StatsPicker.story.tsx | 44 +++++++++---------- .../components/StatsPicker/StatsPicker.tsx | 6 ++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx index cfc27bcd1d2..b3eedd92915 100644 --- a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx +++ b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx @@ -3,16 +3,8 @@ import React, { PureComponent } from 'react'; import { action } from '@storybook/addon-actions'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { StatsPicker } from '@grafana/ui'; -import { text, boolean } from '@storybook/addon-knobs'; - -const getKnobs = () => { - return { - placeholder: text('Placeholder Text', ''), - defaultStat: text('Default Stat', ''), - allowMultiple: boolean('Allow Multiple', false), - initialStats: text('Initial Stats', ''), - }; -}; +import { Meta, Story } from '@storybook/react'; +import { Props } from './StatsPicker'; interface State { stats: string[]; @@ -42,19 +34,20 @@ class WrapperWithState extends PureComponent { } render() { - const { placeholder, defaultStat, allowMultiple } = this.props; + const { placeholder, allowMultiple, menuPlacement, width } = this.props; const { stats } = this.state; return ( { action('Picked:')(stats); this.setState({ stats }); }} + menuPlacement={menuPlacement} + width={width} /> ); } @@ -64,19 +57,26 @@ export default { title: 'Pickers and Editors/StatsPicker', component: StatsPicker, decorators: [withCenteredStory], -}; - -export const picker = () => { - const { placeholder, defaultStat, allowMultiple, initialStats } = getKnobs(); + parameters: { + controls: { + exclude: ['onChange', 'stats', 'defaultStat', 'className'], + }, + knobs: { + disable: true, + }, + }, +} as Meta; +export const Picker: Story = (args) => { return (
- +
); }; +Picker.args = { + placeholder: 'placeholder', + allowMultiple: false, + menuPlacement: 'auto', + width: 10, +}; diff --git a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx index cc7741f2a79..899c1a6fa7c 100644 --- a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx +++ b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx @@ -6,13 +6,14 @@ import { Select } from '../Select/Select'; import { fieldReducers, SelectableValue } from '@grafana/data'; -interface Props { +export interface Props { placeholder?: string; onChange: (stats: string[]) => void; stats: string[]; allowMultiple?: boolean; defaultStat?: string; className?: string; + width?: number; menuPlacement?: 'auto' | 'bottom' | 'top'; } @@ -62,7 +63,7 @@ export class StatsPicker extends PureComponent { }; render() { - const { stats, allowMultiple, defaultStat, placeholder, className, menuPlacement } = this.props; + const { stats, allowMultiple, defaultStat, placeholder, className, menuPlacement, width } = this.props; const select = fieldReducers.selectOptions(stats); return ( @@ -71,6 +72,7 @@ export class StatsPicker extends PureComponent { className={className} isClearable={!defaultStat} isMulti={allowMultiple} + width={width} isSearchable={true} options={select.options} placeholder={placeholder}