From fb516ecf6490d1793e548b1387c679defa77c10a Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Sat, 17 Oct 2020 08:47:06 +0200 Subject: [PATCH] Docs: Add docs for valuepicker (#28327) --- .../components/ValuePicker/ValuePicker.mdx | 37 +++++++++++++++++++ .../ValuePicker/ValuePicker.story.tsx | 37 ++++++++++++++++--- .../components/ValuePicker/ValuePicker.tsx | 5 +++ 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 packages/grafana-ui/src/components/ValuePicker/ValuePicker.mdx diff --git a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.mdx b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.mdx new file mode 100644 index 00000000000..fd3daea3459 --- /dev/null +++ b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.mdx @@ -0,0 +1,37 @@ +import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks'; +import { ValuePicker } from './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 + doThings} + variant='primary' + size='md' + /> +``` + + + diff --git a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.story.tsx b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.story.tsx index a2b4362558d..4ef9d815ab2 100644 --- a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.story.tsx +++ b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.story.tsx @@ -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 (
- console.log(v)} /> + console.log(v)} + variant={variant as ButtonVariant} + icon={icon} + isFullWidth={isFullWidth} + size={size as ComponentSize} + menuPlacement={menuPlacement} + />
); }; diff --git a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx index cae6b5d608e..530612ef060 100644 --- a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx +++ b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx @@ -14,10 +14,15 @@ interface ValuePickerProps { icon?: IconName; /** ValuePicker options */ options: Array>; + /** Callback to handle selected option */ onChange: (value: SelectableValue) => 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'; }