diff --git a/app/components/common/FormInput/FormImageInput.stories.tsx b/app/components/common/FormInput/FormImageInput.stories.tsx index 2c0ae34..f0cac66 100644 --- a/app/components/common/FormInput/FormImageInput.stories.tsx +++ b/app/components/common/FormInput/FormImageInput.stories.tsx @@ -1,10 +1,29 @@ +import { action } from '@storybook/addon-actions'; import type { Meta, StoryObj } from '@storybook/react'; -import { fn } from '@storybook/test'; +import { useState } from 'react'; import FormInput from './FormInput'; const meta: Meta = { component: FormInput.Image, + decorators: [ + function Decorator(Story, ctx) { + const [previewImageUrl, setPreviewImageUrl] = useState(''); + + return ( + { + action('onImageChange')(imageUrl); + setPreviewImageUrl(imageUrl); + }, + }} + /> + ); + }, + ], }; export default meta; @@ -14,7 +33,5 @@ type Story = StoryObj; export const Main: Story = { args: { isError: false, - multiple: false, - onImageChange: fn(), }, }; diff --git a/app/components/common/FormInput/FormInput.tsx b/app/components/common/FormInput/FormInput.tsx index eb9591c..400b8f4 100644 --- a/app/components/common/FormInput/FormInput.tsx +++ b/app/components/common/FormInput/FormInput.tsx @@ -1,6 +1,5 @@ import { useRef, - useState, type DetailedHTMLProps, type InputHTMLAttributes, } from 'react'; @@ -16,7 +15,7 @@ interface FormInputPropsBase isError?: boolean; } -interface FormTextInputProps extends FormInputPropsBase { +export interface FormTextInputProps extends FormInputPropsBase { Icon?: (props: { className?: string }) => JSX.Element; onTextChange?: (newText: string) => void; } @@ -47,19 +46,20 @@ const FormTextInput = ({ ); -interface FormImageInputProps extends FormInputPropsBase { +export interface FormImageInputProps extends FormInputPropsBase { multiple?: false; + previewImageUrl?: string; onImageChange?: (imageUrl: string) => void; } const FormImageInput = ({ isError, multiple = false, + previewImageUrl, onImageChange, ...inputProps }: FormImageInputProps) => { const inputElement = useRef(null); - const [previewImageUrl, setPreviewImageUrl] = useState(''); return (