Skip to content

Commit

Permalink
chore: useDecoratorsをgenericsなくても動作するように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Jan 24, 2025
1 parent 139d213 commit 7c70320
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions packages/smarthr-ui/src/components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const DECORATOR_DEFAULT_TEXTS = {
afterMaxLettersCountExceeded: 'オーバー',
beforeScreenReaderMaxLettersDescription: '最大',
afterScreenReaderMaxLettersDescription: '文字入力できます',
}
} as const

const textarea = tv({
slots: {
Expand Down Expand Up @@ -120,10 +120,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, Props & ElementProps>(
const [count, setCount] = useState(currentValue ? getStringLength(currentValue) : 0)
const [srCounterMessage, setSrCounterMessage] = useState<ReactNode>('')

const decorated = useDecorators<keyof typeof DECORATOR_DEFAULT_TEXTS>(
DECORATOR_DEFAULT_TEXTS,
decorators,
)
const decorated = useDecorators<DECORATOR_DEFAULT_TEXTS>(DECORATOR_DEFAULT_TEXTS, decorators)

const getCounterMessage = useCallback(
(counterValue: number) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/smarthr-ui/src/libs/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export type DecoratorsType<T extends string> = {

export type DecoratorType = (text: string) => ReactNode

export const useDecorators = <T extends string>(
defaultTexts: { [K in T]: string },
decorators: DecoratorsType<T> | undefined,
export const useDecorators = <T extends { [key: string]: string }>(
defaultTexts: T,
decorators: DecoratorsType<keyof T> | 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]
Expand Down

0 comments on commit 7c70320

Please sign in to comment.