Skip to content

Commit 5c295d5

Browse files
committed
fix: 만다라트 텍스트필드 30자 제한 및 만다라트 23자 말줄임표 처리
1 parent ca38a14 commit 5c295d5

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/common/component/TextField/mandalart/MandalartTextField.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { useState } from 'react';
22

33
import IcTextdelete from '@/assets/svg/IcTextdelete';
44

5-
import { type MandalartVariant, BIG_GOAL_MAX_LENGTH, DEFAULT_PLACEHOLDER } from './constants';
5+
import { type MandalartVariant, MANDALART_TEXT_MAX_LENGTH, DEFAULT_PLACEHOLDER } from './constants';
66
import * as s from './MandalartTextField.css';
77

88
import BaseTextField from '../BaseTextField';
99

1010
type FieldState = 'default' | 'clicked' | 'typing' | 'filled' | 'hover';
1111

12-
const pickMaxLength = (variant: MandalartVariant, maxLength?: number) =>
13-
variant === 'bigGoal' ? (maxLength ?? BIG_GOAL_MAX_LENGTH) : (maxLength ?? undefined);
12+
const pickMaxLength = (maxLength?: number) => {
13+
return maxLength ?? MANDALART_TEXT_MAX_LENGTH;
14+
};
1415

1516
const pickPlaceholder = (variant: MandalartVariant, placeholder?: string) =>
1617
placeholder ?? DEFAULT_PLACEHOLDER[variant];
@@ -51,7 +52,7 @@ const MandalartTextField = ({
5152
}: MandalartTextFieldProps) => {
5253
const [isHovered, setIsHovered] = useState(false);
5354

54-
const effectiveMaxLength = pickMaxLength(variant, maxLength);
55+
const effectiveMaxLength = pickMaxLength(maxLength);
5556
const effectivePlaceholder = pickPlaceholder(variant, placeholder);
5657

5758
const wrapperVariants =

src/common/component/TextField/mandalart/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export const DEFAULT_PLACEHOLDER = {
66
todo: '할 일을 입력해주세요',
77
} as const;
88

9-
export const BIG_GOAL_MAX_LENGTH = 30;
9+
export const MANDALART_TEXT_MAX_LENGTH = 30;

src/common/util/format.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ export function getTomorrow(date: Date): Date {
2020
tomorrow.setDate(tomorrow.getDate() + 1);
2121
return tomorrow;
2222
}
23+
24+
export function truncateText(text: string, maxLength: number): string {
25+
if (text.length <= maxLength) {
26+
return text;
27+
}
28+
return text.slice(0, maxLength) + '…';
29+
}

src/page/todo/lowerTodo/LowerTodo.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LowerTodoHeader, MandalCompleteButton, TodoFields } from './component';
66
import { useLowerTodoState, useLowerTodoAI } from './hook';
77
import { toMainSubGoals } from './utils/goal';
88
import { DEFAULT_TEXT, ALERT } from '@/common/constants/todo';
9+
import { truncateText } from '@/common/util/format';
910

1011
import GradientBackground from '@/common/component/Background/GradientBackground';
1112
import { PATH } from '@/route';
@@ -88,8 +89,11 @@ const LowerTodo = () => {
8889
<div className={styles.lowerTodoBox}>
8990
<Mandalart
9091
type="TODO_MAIN"
91-
mainGoal={mainGoal}
92-
subGoals={toMainSubGoals(coreGoalsData?.coreGoals || [])}
92+
mainGoal={truncateText(mainGoal, 23)}
93+
subGoals={toMainSubGoals(coreGoalsData?.coreGoals || []).map((goal) => ({
94+
...goal,
95+
title: truncateText(goal.title, 23),
96+
}))}
9397
onGoalClick={handleSubGoalClick}
9498
selectedGoalIndex={selectedGoalIndex}
9599
/>

src/page/todo/lowerTodo/component/TodoFields.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DEFAULT_PLACEHOLDER } from '@/common/component/TextField/mandalart/cons
55
import { MandalartTextField } from '@/common/component/TextField/mandalart';
66
import CycleDropDown from '@/common/component/CycleDropDown/CycleDropDown';
77
import { Square } from '@/common/component/Mandalart/Square/Square';
8+
import { truncateText } from '@/common/util/format';
89

910
interface TodoItem {
1011
title: string;
@@ -51,7 +52,7 @@ const TodoFields = ({ values, onChange, onEnter, selectedCoreGoalTitle }: TodoFi
5152
return (
5253
<Square.Main
5354
key={index}
54-
content={selectedCoreGoalTitle || '상위목표'}
55+
content={truncateText(selectedCoreGoalTitle || '상위목표', 23)}
5556
type="TODO_SUB"
5657
/>
5758
);
@@ -60,7 +61,7 @@ const TodoFields = ({ values, onChange, onEnter, selectedCoreGoalTitle }: TodoFi
6061
return (
6162
<Square.Sub
6263
key={index}
63-
content={values[valueIndex]?.title || ''}
64+
content={truncateText(values[valueIndex]?.title || '', 23)}
6465
type="TODO_SUB"
6566
isCompleted={!!values[valueIndex]?.title}
6667
onClick={() => {}}
@@ -85,7 +86,6 @@ const TodoFields = ({ values, onChange, onEnter, selectedCoreGoalTitle }: TodoFi
8586
onChange={(val) => handleTitleChange(index, val)}
8687
onCommit={getHandleFieldCommit(index)}
8788
placeholder={`${ORDER_LABELS[index]} ${DEFAULT_PLACEHOLDER.todo}`}
88-
maxLength={30}
8989
/>
9090
</div>
9191
))}

0 commit comments

Comments
 (0)