mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ValuePicker: refactors story from knobs to control (#33122)
* ValuePicker: refactors story from knobs to control * fixes wrong type issue
This commit is contained in:
parent
13cb34bbca
commit
f92b6518c5
@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { boolean, select, text } from '@storybook/addon-knobs';
|
import { Story } from '@storybook/react';
|
||||||
import { ButtonVariant, ValuePicker } from '@grafana/ui';
|
import { ValuePicker } from '@grafana/ui';
|
||||||
import { generateOptions } from '../Select/mockOptions';
|
import { generateOptions } from '../Select/mockOptions';
|
||||||
import { getIconKnob } from '../../utils/storybook/knobs';
|
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { ComponentSize } from '../../types/size';
|
import { getAvailableIcons } from '../../types';
|
||||||
import mdx from './ValuePicker.mdx';
|
import mdx from './ValuePicker.mdx';
|
||||||
|
import { ValuePickerProps } from './ValuePicker';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'Pickers and Editors/ValuePicker',
|
title: 'Pickers and Editors/ValuePicker',
|
||||||
@ -15,33 +15,42 @@ export default {
|
|||||||
docs: {
|
docs: {
|
||||||
page: mdx,
|
page: mdx,
|
||||||
},
|
},
|
||||||
|
knobs: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
controls: {
|
||||||
|
exclude: ['onChange', 'options'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
argTypes: {
|
||||||
|
variant: {
|
||||||
|
control: {
|
||||||
|
type: 'select',
|
||||||
|
options: ['primary', 'secondary', 'destructive', 'link'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
control: {
|
||||||
|
type: 'select',
|
||||||
|
options: getAvailableIcons(),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const VISUAL_GROUP = 'Visual options';
|
|
||||||
const variants = ['primary', 'secondary', 'destructive', 'link'];
|
|
||||||
const sizes = ['sm', 'md', 'lg'];
|
|
||||||
const options = generateOptions();
|
const options = generateOptions();
|
||||||
|
|
||||||
export const simple = () => {
|
export const Simple: Story<ValuePickerProps<string>> = (args) => {
|
||||||
const label = text('Label', 'Pick an option', VISUAL_GROUP);
|
|
||||||
const variant = select('Variant', variants, 'primary', VISUAL_GROUP);
|
|
||||||
const size = select('Size', sizes, 'md', VISUAL_GROUP);
|
|
||||||
const isFullWidth = boolean('Is full width', false, VISUAL_GROUP);
|
|
||||||
const icon = getIconKnob();
|
|
||||||
const menuPlacement = select('Menu placement', ['auto', 'bottom', 'top'], 'auto', VISUAL_GROUP);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ width: '200px' }}>
|
<div style={{ width: '200px' }}>
|
||||||
<ValuePicker
|
<ValuePicker {...args} options={options} onChange={(v) => console.log(v)} />
|
||||||
options={options}
|
|
||||||
label={label}
|
|
||||||
onChange={(v) => console.log(v)}
|
|
||||||
variant={variant as ButtonVariant}
|
|
||||||
icon={icon}
|
|
||||||
isFullWidth={isFullWidth}
|
|
||||||
size={size as ComponentSize}
|
|
||||||
menuPlacement={menuPlacement}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Simple.args = {
|
||||||
|
label: 'Pick an option',
|
||||||
|
variant: 'primary',
|
||||||
|
size: 'md',
|
||||||
|
isFullWidth: false,
|
||||||
|
icon: 'plus',
|
||||||
|
menuPlacement: 'auto',
|
||||||
|
};
|
||||||
|
@ -7,7 +7,7 @@ import { FullWidthButtonContainer } from '../Button/FullWidthButtonContainer';
|
|||||||
import { ComponentSize } from '../../types/size';
|
import { ComponentSize } from '../../types/size';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
|
|
||||||
interface ValuePickerProps<T> {
|
export interface ValuePickerProps<T> {
|
||||||
/** Label to display on the picker button */
|
/** Label to display on the picker button */
|
||||||
label: string;
|
label: string;
|
||||||
/** Icon to display on the picker button */
|
/** Icon to display on the picker button */
|
||||||
|
Loading…
Reference in New Issue
Block a user