-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/BAR-169] 끄적이는 수정 모드 구현 (#61)
- Loading branch information
1 parent
6ff3616
commit 5f14b84
Showing
10 changed files
with
302 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { type ChangeEvent, type KeyboardEvent, useRef, useState } from 'react'; | ||
|
||
import { type UseInputReturn } from '@hooks/useInput'; | ||
|
||
import * as styles from './editInput.css'; | ||
|
||
interface EditInputProps { | ||
inputProps: UseInputReturn; | ||
} | ||
|
||
const EditInput = ({ inputProps }: EditInputProps) => { | ||
const inputRef = useRef<HTMLTextAreaElement | null>(null); | ||
const [textareaHeight, setTextareaHeight] = useState<{ | ||
row: number; | ||
lineBreak: Record<number, boolean>; | ||
}>({ | ||
row: 1, | ||
lineBreak: {}, | ||
}); | ||
|
||
const handleResize = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
const { scrollHeight, clientHeight, value } = e.target; | ||
|
||
if (value.length === 0) { | ||
setTextareaHeight((prev) => ({ | ||
row: 1, | ||
lineBreak: { ...prev.lineBreak, [e.target.value.length]: false }, | ||
})); | ||
} | ||
|
||
if (scrollHeight > clientHeight) { | ||
setTextareaHeight((prev) => ({ | ||
row: prev.row + 1, | ||
lineBreak: { ...prev.lineBreak, [value.length - 1]: true }, | ||
})); | ||
} | ||
|
||
if (textareaHeight.lineBreak[value.length]) { | ||
setTextareaHeight((prev) => ({ | ||
row: prev.row - 1, | ||
lineBreak: { ...prev.lineBreak, [value.length]: false }, | ||
})); | ||
} | ||
}; | ||
|
||
const handleKeydownEnter = (e: KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.code === 'Enter') { | ||
setTextareaHeight((prev) => ({ | ||
row: prev.row + 1, | ||
lineBreak: { ...prev.lineBreak, [inputProps.value.length]: true }, | ||
})); | ||
return; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.editContainer}> | ||
<textarea | ||
{...inputProps} | ||
ref={inputRef} | ||
className={styles.editInput} | ||
autoComplete="off" | ||
rows={textareaHeight.row} | ||
maxLength={500} | ||
onInput={handleResize} | ||
onKeyDown={handleKeydownEnter} | ||
/> | ||
<p className={styles.editInputTextCount}> | ||
<span className={styles.editTextCurrentCount}> | ||
{inputProps.value.length} | ||
</span> | ||
/ 500 | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.