From f93166e7b27c5126df672dbaa6e7b4c3c50f86bf Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Wed, 17 Mar 2021 14:43:31 +0100 Subject: [PATCH] Legacy Input: updates story from knobs to control (#32059) --- .../Legacy/Input/Input.story.internal.tsx | 76 +++++++++++-------- .../components/Forms/Legacy/Input/Input.tsx | 2 +- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.story.internal.tsx b/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.story.internal.tsx index 569c1e77dfe..774c0431765 100644 --- a/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.story.internal.tsx +++ b/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.story.internal.tsx @@ -3,41 +3,57 @@ import { zip, fromPairs } from 'lodash'; import { withCenteredStory } from '../../../../utils/storybook/withCenteredStory'; import { Input } from './Input'; -import { text, select } from '@storybook/addon-knobs'; +import { Story } from '@storybook/react'; import { EventsWithValidation } from '../../../../utils'; - -const getKnobs = () => { - return { - validation: text('Validation regex (will do a partial match if you do not anchor it)', ''), - validationErrorMessage: text('Validation error message', 'Input not valid'), - validationEvent: select( - 'Validation event', - fromPairs(zip(Object.keys(EventsWithValidation), Object.values(EventsWithValidation))), - EventsWithValidation.onBlur - ), - }; -}; - -const Wrapper = () => { - const { validation, validationErrorMessage, validationEvent } = getKnobs(); - const [value, setValue] = useState(''); - const validations = { - [validationEvent]: [ - { - rule: (value: string) => { - return !!value.match(validation); - }, - errorMessage: validationErrorMessage, - }, - ], - }; - return setValue(e.currentTarget.value)} validationEvents={validations} />; -}; +import { NOOP_CONTROL } from '../../../../utils/storybook/noopControl'; export default { title: 'Forms/Legacy/Input', component: Input, decorators: [withCenteredStory], + parameters: { + knobs: { + disable: true, + }, + }, + argTypes: { + validationEvents: { + control: { + type: 'select', + options: fromPairs(zip(Object.keys(EventsWithValidation), Object.values(EventsWithValidation))), + }, + }, + validation: { name: 'Validation regex (will do a partial match if you do not anchor it)' }, + inputRef: NOOP_CONTROL, + }, }; -export const basic = () => ; +const Wrapper: Story = (args) => { + const [value, setValue] = useState(''); + const validations = { + [args.validationEvents]: [ + { + rule: (value: string) => { + return !!value.match(args.validation); + }, + errorMessage: args.validationErrorMessage, + }, + ], + }; + return ( + setValue(e.currentTarget.value)} + validationEvents={validations} + hideErrorMessage={args.hideErrorMessage} + /> + ); +}; + +export const Basic = Wrapper.bind({}); +Basic.args = { + validation: '', + validationErrorMessage: 'Input not valid', + validationEvents: EventsWithValidation.onBlur, + hideErrorMessage: false, +}; diff --git a/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.tsx b/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.tsx index bfc552bc00f..85e28a09442 100644 --- a/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.tsx +++ b/packages/grafana-ui/src/components/Forms/Legacy/Input/Input.tsx @@ -8,7 +8,7 @@ export enum LegacyInputStatus { Valid = 'valid', } -interface Props extends React.HTMLProps { +export interface Props extends React.HTMLProps { validationEvents?: ValidationEvents; hideErrorMessage?: boolean; inputRef?: React.LegacyRef;