From eef3a9c6e08fdffe6241e6c60714efa35928808d Mon Sep 17 00:00:00 2001 From: Alexander Lobyntsev Date: Fri, 27 Oct 2023 18:26:53 +0700 Subject: [PATCH] chore(plasma-b2c): migrate to CSF 3 [TextField] --- .../TextField/TextField.stories.tsx | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/packages/plasma-b2c/src/components/TextField/TextField.stories.tsx b/packages/plasma-b2c/src/components/TextField/TextField.stories.tsx index b22b6a9dcb..dd94a2885a 100644 --- a/packages/plasma-b2c/src/components/TextField/TextField.stories.tsx +++ b/packages/plasma-b2c/src/components/TextField/TextField.stories.tsx @@ -1,9 +1,10 @@ -import React from 'react'; -import { Story, Meta } from '@storybook/react'; +import React, { useState, useEffect } from 'react'; +import type { StoryObj, Meta } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { IconPlaceholder, InSpacingDecorator, disableProps } from '@salutejs/plasma-sb-utils'; -import { TextField, TextFieldView, TextFieldProps } from '.'; +import { TextField, TextFieldView } from '.'; +import type { TextFieldProps } from '.'; const onChange = action('onChange'); const onFocus = action('onFocus'); @@ -28,7 +29,7 @@ const propsToDisable = [ 'required', ]; -export default { +const meta: Meta = { title: 'Controls/TextField', component: TextField, decorators: [InSpacingDecorator], @@ -52,15 +53,19 @@ export default { }, ...disableProps(propsToDisable), }, -} as Meta; +}; + +export default meta; -interface DefaultStoryProps extends TextFieldProps { +type StoryPropsDefault = TextFieldProps & { enableContentLeft: boolean; enableContentRight: boolean; -} +}; -export const Default: Story = ({ enableContentLeft, enableContentRight, status, ...rest }) => { - const [value, setValue] = React.useState('Значение поля'); +type StoryPropsDeferredValue = { readOnly: boolean }; + +const StoryDefault = ({ enableContentLeft, enableContentRight, status, ...rest }: StoryPropsDefault) => { + const [value, setValue] = useState('Значение поля'); return ( = ({ enableContentLeft, enableCon ); }; -Default.args = { - id: 'example-text-field', - type: 'text', - placeholder: 'Заполните поле имя', - caption: 'Имя', - helperText: 'Допустимы только символы кириллицы', - enableContentLeft: true, - enableContentRight: true, - status: '' as 'success', - disabled: false, - readOnly: false, - size: 'm', +export const Default: StoryObj = { + args: { + id: 'example-text-field', + type: 'text', + placeholder: 'Заполните поле имя', + caption: 'Имя', + helperText: 'Допустимы только символы кириллицы', + enableContentLeft: true, + enableContentRight: true, + status: '' as 'success', + disabled: false, + readOnly: false, + size: 'm', + }, + render: (args) => , }; -export const DeferredValue: Story<{ readOnly: boolean }> = ({ readOnly }) => { - const [asyncValue, setAsyncValue] = React.useState(''); +const StoryDeferredValue = ({ readOnly }: StoryPropsDeferredValue) => { + const [asyncValue, setAsyncValue] = useState(''); - React.useEffect(() => { + useEffect(() => { setTimeout(() => { setAsyncValue("Sorry i'm late :)"); }, 3000); @@ -106,12 +114,12 @@ export const DeferredValue: Story<{ readOnly: boolean }> = ({ readOnly }) => { return ; }; -DeferredValue.args = { - readOnly: true, -}; - -const defValuePropsToDisable = [...propsToDisable, 'status', 'helperText', 'placeholder', 'disabled']; - -DeferredValue.argTypes = { - ...disableProps(defValuePropsToDisable), +export const DeferredValue: StoryObj = { + argTypes: { + ...disableProps([...propsToDisable, 'status', 'helperText', 'placeholder', 'disabled']), + }, + args: { + readOnly: true, + }, + render: (args) => , };