From 8f8213faeb2692bcbd5d3736323c457628af759c Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Sat, 2 Jul 2022 18:18:56 +0200 Subject: [PATCH] add an example usage --- .../{args.stories.js => args.stories.tsx} | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) rename examples/official-storybook/stories/core/{args.stories.js => args.stories.tsx} (78%) diff --git a/examples/official-storybook/stories/core/args.stories.js b/examples/official-storybook/stories/core/args.stories.tsx similarity index 78% rename from examples/official-storybook/stories/core/args.stories.js rename to examples/official-storybook/stories/core/args.stories.tsx index 4ee37b44f996..2242a1d1f023 100644 --- a/examples/official-storybook/stories/core/args.stories.js +++ b/examples/official-storybook/stories/core/args.stories.tsx @@ -1,8 +1,20 @@ -import React, { useState } from 'react'; +import React, { FC, useState } from 'react'; import { useArgs } from '@storybook/client-api'; -// eslint-disable-next-line react/prop-types -const ArgUpdater = ({ args, updateArgs, resetArgs }) => { +interface CustomArgs { + first?: string; + last?: string; + foo?: string; +} + +type UpdateArgs = ReturnType[1]; +type ResetArgs = ReturnType[2]; + +const ArgUpdater: FC<{ args: CustomArgs; updateArgs: UpdateArgs; resetArgs: ResetArgs }> = ({ + args, + updateArgs, + resetArgs, +}) => { const [argsInput, updateArgsInput] = useState(JSON.stringify(args)); return ( @@ -30,7 +42,7 @@ export default { title: 'Core/Args', decorators: [ (story) => { - const [args, updateArgs, resetArgs] = useArgs(); + const [args, updateArgs, resetArgs] = useArgs(); return ( <> @@ -63,14 +75,14 @@ export const DifferentSet = Template.bind({}); DifferentSet.args = { foo: 'bar', bar: 2, -}; +} as CustomArgs; export const TestUndefinedArgs = Template.bind({}); TestUndefinedArgs.args = { first: 'Bob', last: 'Miller', foo: 'bar', -}; +} as CustomArgs; TestUndefinedArgs.argTypes = { first: { control: { type: 'select' },