From 7c7032021f21be200a0cae41f231d81a0685015c Mon Sep 17 00:00:00 2001 From: AtsushiM Date: Sat, 25 Jan 2025 07:57:32 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20useDecorators=E3=82=92generics?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=A6=E3=82=82=E5=8B=95=E4=BD=9C=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/smarthr-ui/src/components/Textarea/Textarea.tsx | 7 ++----- packages/smarthr-ui/src/libs/decorator.ts | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/smarthr-ui/src/components/Textarea/Textarea.tsx b/packages/smarthr-ui/src/components/Textarea/Textarea.tsx index 3cff713243..115a67657e 100644 --- a/packages/smarthr-ui/src/components/Textarea/Textarea.tsx +++ b/packages/smarthr-ui/src/components/Textarea/Textarea.tsx @@ -64,7 +64,7 @@ const DECORATOR_DEFAULT_TEXTS = { afterMaxLettersCountExceeded: 'オーバー', beforeScreenReaderMaxLettersDescription: '最大', afterScreenReaderMaxLettersDescription: '文字入力できます', -} +} as const const textarea = tv({ slots: { @@ -120,10 +120,7 @@ export const Textarea = forwardRef( const [count, setCount] = useState(currentValue ? getStringLength(currentValue) : 0) const [srCounterMessage, setSrCounterMessage] = useState('') - const decorated = useDecorators( - DECORATOR_DEFAULT_TEXTS, - decorators, - ) + const decorated = useDecorators(DECORATOR_DEFAULT_TEXTS, decorators) const getCounterMessage = useCallback( (counterValue: number) => { diff --git a/packages/smarthr-ui/src/libs/decorator.ts b/packages/smarthr-ui/src/libs/decorator.ts index ffc5532bee..7b485fb7fe 100644 --- a/packages/smarthr-ui/src/libs/decorator.ts +++ b/packages/smarthr-ui/src/libs/decorator.ts @@ -6,16 +6,16 @@ export type DecoratorsType = { export type DecoratorType = (text: string) => ReactNode -export const useDecorators = ( - defaultTexts: { [K in T]: string }, - decorators: DecoratorsType | undefined, +export const useDecorators = ( + defaultTexts: T, + decorators: DecoratorsType | undefined, ) => useMemo(() => { if (!decorators) { return defaultTexts } - const decorated = {} as { [K in T]: ReactNode } + const decorated = {} as { [K in keyof T]: ReactNode } for (const key in defaultTexts) { const value = defaultTexts[key]