mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
StatsPicker: updates story from knobs to control (#34008)
This commit is contained in:
parent
8f91b59640
commit
765e771a2a
@ -3,16 +3,8 @@ import React, { PureComponent } from 'react';
|
|||||||
import { action } from '@storybook/addon-actions';
|
import { action } from '@storybook/addon-actions';
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { StatsPicker } from '@grafana/ui';
|
import { StatsPicker } from '@grafana/ui';
|
||||||
import { text, boolean } from '@storybook/addon-knobs';
|
import { Meta, Story } from '@storybook/react';
|
||||||
|
import { Props } from './StatsPicker';
|
||||||
const getKnobs = () => {
|
|
||||||
return {
|
|
||||||
placeholder: text('Placeholder Text', ''),
|
|
||||||
defaultStat: text('Default Stat', ''),
|
|
||||||
allowMultiple: boolean('Allow Multiple', false),
|
|
||||||
initialStats: text('Initial Stats', ''),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
stats: string[];
|
stats: string[];
|
||||||
@ -42,19 +34,20 @@ class WrapperWithState extends PureComponent<any, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { placeholder, defaultStat, allowMultiple } = this.props;
|
const { placeholder, allowMultiple, menuPlacement, width } = this.props;
|
||||||
const { stats } = this.state;
|
const { stats } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatsPicker
|
<StatsPicker
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
defaultStat={defaultStat}
|
|
||||||
allowMultiple={allowMultiple}
|
allowMultiple={allowMultiple}
|
||||||
stats={stats}
|
stats={stats}
|
||||||
onChange={(stats: string[]) => {
|
onChange={(stats: string[]) => {
|
||||||
action('Picked:')(stats);
|
action('Picked:')(stats);
|
||||||
this.setState({ stats });
|
this.setState({ stats });
|
||||||
}}
|
}}
|
||||||
|
menuPlacement={menuPlacement}
|
||||||
|
width={width}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -64,19 +57,26 @@ export default {
|
|||||||
title: 'Pickers and Editors/StatsPicker',
|
title: 'Pickers and Editors/StatsPicker',
|
||||||
component: StatsPicker,
|
component: StatsPicker,
|
||||||
decorators: [withCenteredStory],
|
decorators: [withCenteredStory],
|
||||||
};
|
parameters: {
|
||||||
|
controls: {
|
||||||
export const picker = () => {
|
exclude: ['onChange', 'stats', 'defaultStat', 'className'],
|
||||||
const { placeholder, defaultStat, allowMultiple, initialStats } = getKnobs();
|
},
|
||||||
|
knobs: {
|
||||||
|
disable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as Meta;
|
||||||
|
|
||||||
|
export const Picker: Story<Props> = (args) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<WrapperWithState
|
<WrapperWithState {...args} />
|
||||||
placeholder={placeholder}
|
|
||||||
defaultStat={defaultStat}
|
|
||||||
allowMultiple={allowMultiple}
|
|
||||||
initialStats={initialStats}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Picker.args = {
|
||||||
|
placeholder: 'placeholder',
|
||||||
|
allowMultiple: false,
|
||||||
|
menuPlacement: 'auto',
|
||||||
|
width: 10,
|
||||||
|
};
|
||||||
|
@ -6,13 +6,14 @@ import { Select } from '../Select/Select';
|
|||||||
|
|
||||||
import { fieldReducers, SelectableValue } from '@grafana/data';
|
import { fieldReducers, SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
interface Props {
|
export interface Props {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
onChange: (stats: string[]) => void;
|
onChange: (stats: string[]) => void;
|
||||||
stats: string[];
|
stats: string[];
|
||||||
allowMultiple?: boolean;
|
allowMultiple?: boolean;
|
||||||
defaultStat?: string;
|
defaultStat?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
width?: number;
|
||||||
menuPlacement?: 'auto' | 'bottom' | 'top';
|
menuPlacement?: 'auto' | 'bottom' | 'top';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ export class StatsPicker extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
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);
|
const select = fieldReducers.selectOptions(stats);
|
||||||
return (
|
return (
|
||||||
@ -71,6 +72,7 @@ export class StatsPicker extends PureComponent<Props> {
|
|||||||
className={className}
|
className={className}
|
||||||
isClearable={!defaultStat}
|
isClearable={!defaultStat}
|
||||||
isMulti={allowMultiple}
|
isMulti={allowMultiple}
|
||||||
|
width={width}
|
||||||
isSearchable={true}
|
isSearchable={true}
|
||||||
options={select.options}
|
options={select.options}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
Loading…
Reference in New Issue
Block a user