mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Docs: Add docs for valuepicker (#28327)
This commit is contained in:
parent
0c09dd3526
commit
fb516ecf64
@ -0,0 +1,37 @@
|
||||
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
|
||||
import { ValuePicker } from './ValuePicker';
|
||||
|
||||
<Meta title="MDX|Button" component={ValuePicker} />
|
||||
|
||||
# ValuePicker
|
||||
A component that looks like a button but transforms into a select when clicked.
|
||||
|
||||
### Example usage
|
||||
This component is currently used when adding [FieldOverrides](https://grafana.com/docs/grafana/latest/panels/field-options/) in the panel edit mode.
|
||||
|
||||
|
||||
```tsx
|
||||
<ValuePicker
|
||||
label='Choose an option'
|
||||
options={[
|
||||
{
|
||||
value: 'option1',
|
||||
label: 'Option 1'
|
||||
},
|
||||
{
|
||||
value: 'option2',
|
||||
label: 'Option 2'
|
||||
},
|
||||
{
|
||||
value: 'option3',
|
||||
label: 'Option 3'
|
||||
}
|
||||
]}
|
||||
onChange={(value) => doThings}
|
||||
variant='primary'
|
||||
size='md'
|
||||
/>
|
||||
```
|
||||
|
||||
|
||||
<Props of={ValuePicker} />
|
@ -1,22 +1,47 @@
|
||||
import { text } from '@storybook/addon-knobs';
|
||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
import { ValuePicker } from '@grafana/ui';
|
||||
import React from 'react';
|
||||
import { boolean, select, text } from '@storybook/addon-knobs';
|
||||
import { ButtonVariant, ValuePicker } from '@grafana/ui';
|
||||
import { generateOptions } from '../Select/mockOptions';
|
||||
import { getIconKnob } from '../../utils/storybook/knobs';
|
||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
import { ComponentSize } from '../../types/size';
|
||||
import mdx from './ValuePicker.mdx';
|
||||
|
||||
export default {
|
||||
title: 'Pickers and Editors/ValuePicker',
|
||||
component: ValuePicker,
|
||||
decorators: [withCenteredStory],
|
||||
parameters: {
|
||||
docs: {
|
||||
page: mdx,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const VISUAL_GROUP = 'Visual options';
|
||||
const variants = ['primary', 'secondary', 'destructive', 'link'];
|
||||
const sizes = ['sm', 'md', 'lg'];
|
||||
const options = generateOptions();
|
||||
|
||||
export const simple = () => {
|
||||
const label = text('Label', 'Pick an option');
|
||||
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 (
|
||||
<div style={{ width: '200px' }}>
|
||||
<ValuePicker options={options} label={label} onChange={v => console.log(v)} />
|
||||
<ValuePicker
|
||||
options={options}
|
||||
label={label}
|
||||
onChange={v => console.log(v)}
|
||||
variant={variant as ButtonVariant}
|
||||
icon={icon}
|
||||
isFullWidth={isFullWidth}
|
||||
size={size as ComponentSize}
|
||||
menuPlacement={menuPlacement}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -14,10 +14,15 @@ interface ValuePickerProps<T> {
|
||||
icon?: IconName;
|
||||
/** ValuePicker options */
|
||||
options: Array<SelectableValue<T>>;
|
||||
/** Callback to handle selected option */
|
||||
onChange: (value: SelectableValue<T>) => void;
|
||||
/** Which ButtonVariant to render */
|
||||
variant?: ButtonVariant;
|
||||
/** Size of button */
|
||||
size?: ComponentSize;
|
||||
/** Should the picker cover the full width of its parent */
|
||||
isFullWidth?: boolean;
|
||||
/** Control where the menu is rendered */
|
||||
menuPlacement?: 'auto' | 'bottom' | 'top';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user