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 { 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<any, State> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { placeholder, defaultStat, allowMultiple } = this.props;
|
||||
const { placeholder, allowMultiple, menuPlacement, width } = this.props;
|
||||
const { stats } = this.state;
|
||||
|
||||
return (
|
||||
<StatsPicker
|
||||
placeholder={placeholder}
|
||||
defaultStat={defaultStat}
|
||||
allowMultiple={allowMultiple}
|
||||
stats={stats}
|
||||
onChange={(stats: string[]) => {
|
||||
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<Props> = (args) => {
|
||||
return (
|
||||
<div>
|
||||
<WrapperWithState
|
||||
placeholder={placeholder}
|
||||
defaultStat={defaultStat}
|
||||
allowMultiple={allowMultiple}
|
||||
initialStats={initialStats}
|
||||
/>
|
||||
<WrapperWithState {...args} />
|
||||
</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';
|
||||
|
||||
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<Props> {
|
||||
};
|
||||
|
||||
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<Props> {
|
||||
className={className}
|
||||
isClearable={!defaultStat}
|
||||
isMulti={allowMultiple}
|
||||
width={width}
|
||||
isSearchable={true}
|
||||
options={select.options}
|
||||
placeholder={placeholder}
|
||||
|
Loading…
Reference in New Issue
Block a user