From ce6e31c030b8b505d38346af2a617d320286d477 Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Wed, 7 Apr 2021 16:58:35 +0100 Subject: [PATCH] Input: updates story from knobs to control (#32712) * Input: updates story from knobs to control * assigned args value to a variable * exported default as meta --- .../src/components/Input/Input.story.tsx | 140 +++++++++--------- .../datasource/alertmanager/plugin.json | 2 +- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/packages/grafana-ui/src/components/Input/Input.story.tsx b/packages/grafana-ui/src/components/Input/Input.story.tsx index cf5f2a40711..9ca827ffd10 100644 --- a/packages/grafana-ui/src/components/Input/Input.story.tsx +++ b/packages/grafana-ui/src/components/Input/Input.story.tsx @@ -1,11 +1,22 @@ import React, { useState } from 'react'; -import { boolean, text, select, number } from '@storybook/addon-knobs'; +import { Story, Meta } from '@storybook/react'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import mdx from './Input.mdx'; import { getAvailableIcons, IconName } from '../../types'; import { KeyValue } from '@grafana/data'; import { Field, Icon, Button, Input } from '@grafana/ui'; +const prefixSuffixOpts = { + None: null, + Text: '$', + ...getAvailableIcons().reduce>((prev, c) => { + return { + ...prev, + [`Icon: ${c}`]: `icon-${c}`, + }; + }, {}), +}; + export default { title: 'Forms/Input', component: Input, @@ -14,47 +25,50 @@ export default { docs: { page: mdx, }, - }, -}; - -export const Simple = () => { - const prefixSuffixOpts = { - None: null, - Text: '$', - ...getAvailableIcons().reduce>((prev, c) => { - return { - ...prev, - [`Icon: ${c}`]: `icon-${c}`, - }; - }, {}), - }; - - const BEHAVIOUR_GROUP = 'Behaviour props'; - // --- - const type = select( - 'Type', - { - text: 'text', - password: 'password', - number: 'number', + knobs: { + disable: true, }, - 'text', - BEHAVIOUR_GROUP - ); - const disabled = boolean('Disabled', false, BEHAVIOUR_GROUP); - const invalid = boolean('Invalid', false, BEHAVIOUR_GROUP); - const loading = boolean('Loading', false, BEHAVIOUR_GROUP); + controls: { + exclude: ['prefix', 'suffix', 'addonBefore', 'addonAfter'], + }, + }, + args: { + type: 'text', + width: 40, + prefixVisible: '', + suffixVisible: '', + invalid: false, + loading: false, + }, + argTypes: { + prefixVisible: { + control: { + type: 'select', + options: prefixSuffixOpts, + }, + }, + suffixVisible: { + control: { + type: 'select', + options: prefixSuffixOpts, + }, + }, + type: { + control: { + type: 'select', + options: ['text', 'number', 'password'], + }, + }, + // validation: { name: 'Validation regex (will do a partial match if you do not anchor it)' }, + width: { control: { type: 'range', min: 10, max: 200, step: 10 } }, + }, +} as Meta; - const VISUAL_GROUP = 'Visual options'; - // --- - const width = number('Width', 0, undefined, VISUAL_GROUP); - const placeholder = text('Placeholder', 'Enter your name here...', VISUAL_GROUP); - const before = boolean('Addon before', false, VISUAL_GROUP); - const after = boolean('Addon after', false, VISUAL_GROUP); +export const Simple: Story = (args) => { const addonAfter = ; const addonBefore =
Input
; - const prefix = select('Prefix', prefixSuffixOpts, null, VISUAL_GROUP); - const suffix = select('Suffix', prefixSuffixOpts, null, VISUAL_GROUP); + const prefix = args.prefixVisible; + const suffix = args.suffixVisible; let prefixEl: any = prefix; if (prefix && prefix.match(/icon-/g)) { prefixEl = ; @@ -64,45 +78,35 @@ export const Simple = () => { suffixEl = ; } - const CONTAINER_GROUP = 'Container options'; - // --- - const containerWidth = number( - 'Container width', - 300, - { - range: true, - min: 100, - max: 500, - step: 10, - }, - CONTAINER_GROUP - ); - return ( -
- -
+ ); }; +Simple.args = { + disabled: false, + before: false, + after: false, + placeholder: 'Enter your name here...', +}; -export const WithFieldValidation = () => { +export const WithFieldValidation: Story = (args) => { const [value, setValue] = useState(''); return (
- setValue(e.currentTarget.value)} /> + setValue(e.currentTarget.value)} {...args} />
); diff --git a/public/app/plugins/datasource/alertmanager/plugin.json b/public/app/plugins/datasource/alertmanager/plugin.json index 665af564386..088bdd5adef 100644 --- a/public/app/plugins/datasource/alertmanager/plugin.json +++ b/public/app/plugins/datasource/alertmanager/plugin.json @@ -60,4 +60,4 @@ } ] } -} \ No newline at end of file +}