From 0f5ad343be935b703a1925120c28569f41ff49af Mon Sep 17 00:00:00 2001 From: HyeongKyeom Kim <97586683+Brokyeom@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:44:58 +0900 Subject: [PATCH] =?UTF-8?q?fix(ui):=20TextField=20value=20optional?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95,=20generic=20parameter=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C,=20forwardRef=20=EC=A0=84=EB=8B=AC.=20(#210)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: TextField value optional로 수정 * cs * forwardRef 추가 * change cs * fix: remove generic parameter. * remove * fix: remove generic type in stories * remove number type --- .changeset/fluffy-countries-flash.md | 5 ++ apps/docs/src/App.tsx | 2 +- apps/docs/src/stories/Fonts.stories.tsx | 69 +++++++++++++-------- apps/docs/src/stories/TextField.stories.tsx | 2 +- packages/ui/Input/TextField.tsx | 17 ++--- 5 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 .changeset/fluffy-countries-flash.md diff --git a/.changeset/fluffy-countries-flash.md b/.changeset/fluffy-countries-flash.md new file mode 100644 index 00000000..8b8f5bcc --- /dev/null +++ b/.changeset/fluffy-countries-flash.md @@ -0,0 +1,5 @@ +--- +'@sopt-makers/ui': patch +--- + +TextField value prop optinal 로 변경, forwardRef 추가. diff --git a/apps/docs/src/App.tsx b/apps/docs/src/App.tsx index bdafc9d1..5fe76400 100644 --- a/apps/docs/src/App.tsx +++ b/apps/docs/src/App.tsx @@ -54,7 +54,7 @@ function App() { return ( <> - + { const handleInputChange = (e: ChangeEvent) => { setInput(e.target.value); - } + }; return [input, handleInputChange] as const; -} +}; export const Default = () => { const [text, handleTextChange] = useInput('SOPT에 없던 새로운 가치를 프로덕트를 통해 만들어 갑니다.'); @@ -32,26 +32,41 @@ export const Default = () => { case 'LABEL': return '#346FFA'; } - } - - return
-

* 공통 스타일 - fontFamily : SUIT / fontStyle : normal *

- value={text} onChange={handleTextChange} placeholder="예시 문장을 입력해주세요" /> - - {Object.keys(fontsObject).map((fontName) => { - const fontObject = fontsObject[fontName as FontName]; - - return
-

{fontName}

-
-

fontWeight : {fontObject.fontWeight}

-

fontSize : {fontObject.fontSize}

-

lineHeight : {fontObject.lineHeight}

-

letterSpacing : {fontObject.letterSpacing}

-
-

{text}

-
- } - )} -
-} \ No newline at end of file + }; + + return ( +
+

* 공통 스타일 - fontFamily : SUIT / fontStyle : normal *

+ + + {Object.keys(fontsObject).map((fontName) => { + const fontObject = fontsObject[fontName as FontName]; + + return ( +
+

{fontName}

+
+

+ fontWeight : + {fontObject.fontWeight} +

+

+ fontSize : + {fontObject.fontSize} +

+

+ lineHeight : + {fontObject.lineHeight} +

+

+ letterSpacing : + {fontObject.letterSpacing} +

+
+

{text}

+
+ ); + })} +
+ ); +}; diff --git a/apps/docs/src/stories/TextField.stories.tsx b/apps/docs/src/stories/TextField.stories.tsx index 491fd47a..1b315fb9 100644 --- a/apps/docs/src/stories/TextField.stories.tsx +++ b/apps/docs/src/stories/TextField.stories.tsx @@ -17,7 +17,7 @@ const useTextField = (props: TextFieldProps) => { setText(e.target.value); }; - return {...props} value={text} onChange={handleTextChange} />; + return ; }; export default { diff --git a/packages/ui/Input/TextField.tsx b/packages/ui/Input/TextField.tsx index 959a8081..49d2e5e7 100644 --- a/packages/ui/Input/TextField.tsx +++ b/packages/ui/Input/TextField.tsx @@ -1,8 +1,8 @@ -import type { ReactNode, InputHTMLAttributes } from 'react'; +import { type ReactNode, type InputHTMLAttributes, forwardRef } from 'react'; import { FieldBox } from 'FieldBox'; import * as S from './style.css'; -interface TextFieldProps extends Omit, 'value'> { +interface TextFieldProps extends Omit, 'value'> { className?: string; topAddon?: ReactNode; bottomAddon?: ReactNode; @@ -10,13 +10,13 @@ interface TextFieldProps extends Omit, descriptionText?: string; required?: boolean; errorMessage?: string; - value: T; + value?: string; // isError -> validationFn 순서로 적용 isError?: boolean; - validationFn?: (input: T) => boolean; + validationFn?: (input: string) => boolean; } -function TextField(props: TextFieldProps) { +const TextField = forwardRef((props, ref) => { const { className, topAddon, @@ -34,7 +34,7 @@ function TextField(props: TextFieldProps) { const hasError = () => { if (inputProps.disabled || inputProps.readOnly) return false; if (isError !== undefined) return isError; - if (validationFn && !validationFn(value)) return true; + if (validationFn && value && !validationFn(value)) return true; return false; }; @@ -47,6 +47,7 @@ function TextField(props: TextFieldProps) { /> } className={className} + ref={ref} topAddon={ labelText || descriptionText ? ( @@ -58,6 +59,8 @@ function TextField(props: TextFieldProps) { ); -} +}); + +TextField.displayName = 'TextField'; export default TextField;