From 2d9cc30ad4ebfe0182d1ad68a23d306d7b999a2e Mon Sep 17 00:00:00 2001 From: aube-dev Date: Fri, 27 Sep 2024 19:12:49 +0900 Subject: [PATCH] feat: add `FormItem` --- .../FormInput/FormImageInput.stories.tsx | 23 ++- app/components/common/FormInput/FormInput.tsx | 13 +- app/components/common/FormInput/index.ts | 4 +- .../common/FormItem/FormImageItem.stories.tsx | 40 +++++ .../common/FormItem/FormItem.css.ts | 48 ++++++ app/components/common/FormItem/FormItem.tsx | 88 +++++++++++ .../common/FormItem/FormTextItem.stories.tsx | 41 ++++++ app/components/common/FormItem/index.ts | 1 + app/constants/style.ts | 135 +++++++++++++++++ app/styles/text.css.ts | 137 +----------------- 10 files changed, 383 insertions(+), 147 deletions(-) create mode 100644 app/components/common/FormItem/FormImageItem.stories.tsx create mode 100644 app/components/common/FormItem/FormItem.css.ts create mode 100644 app/components/common/FormItem/FormItem.tsx create mode 100644 app/components/common/FormItem/FormTextItem.stories.tsx create mode 100644 app/components/common/FormItem/index.ts 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 (