-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Next-Room/feat/hint-qa4
- Loading branch information
Showing
19 changed files
with
262 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import "./textArea.modules.sass"; | ||
import classNames from "classnames"; | ||
|
||
import useTextArea from "./useTextArea"; | ||
import { ThemeInfoTextAreaType } from "./TextAreaType"; | ||
|
||
export default function ThemeTextArea({ | ||
id, | ||
tabIndex, | ||
content, | ||
infoText, | ||
textAreaPlaceholder, | ||
checkErrorText, | ||
}: ThemeInfoTextAreaType) { | ||
const { | ||
textAreaValue, | ||
isFocus, | ||
setIsFocus, | ||
errorText, | ||
textAreaRef, | ||
handleTextAreaChange, | ||
handleTextAreaBlur, | ||
} = useTextArea({ id, content, checkErrorText }); | ||
|
||
return ( | ||
<div tabIndex={isFocus ? -1 : tabIndex} onFocus={() => setIsFocus(true)}> | ||
<textarea | ||
ref={textAreaRef} | ||
className={classNames("theme-textarea", { | ||
error: errorText, | ||
filled: textAreaValue && !(errorText || isFocus), | ||
})} | ||
value={textAreaValue} | ||
placeholder={textAreaPlaceholder} | ||
onChange={handleTextAreaChange} | ||
onBlur={handleTextAreaBlur} | ||
tabIndex={tabIndex} | ||
/> | ||
|
||
{errorText && ( | ||
<div className="theme-textfield-info error" tabIndex={-1}> | ||
{errorText} | ||
</div> | ||
)} | ||
{infoText && ( | ||
<div className="theme-textfield-info" tabIndex={-1}> | ||
{infoText} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
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,11 @@ | ||
type ValidationFunction<T> = (value: T) => string; | ||
|
||
export type ThemeInfoTextAreaType = { | ||
id: "contents" | "answer"; | ||
tabIndex?: number; | ||
title?: string; | ||
content: string; | ||
infoText?: string; | ||
textAreaPlaceholder?: string; | ||
checkErrorText?: ValidationFunction<unknown>; | ||
}; |
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,38 @@ | ||
@import '../../style/variables' | ||
@import '../../style/mixins' | ||
@import '../../style/button' | ||
|
||
.theme-textarea | ||
width: 100% | ||
min-height: 120px | ||
padding: 8px 12px | ||
display: flex | ||
border: 1px solid $color-white20 | ||
border-radius: 8px | ||
background-color: $color-white5 | ||
color: $color-white | ||
resize: none | ||
cursor: pointer | ||
|
||
&.filled | ||
background-color: $color-main | ||
&:focus | ||
outline: none | ||
border: 1px solid $color-white | ||
background-color: $color-black | ||
cursor: text | ||
&:hover | ||
background-color: $color-black | ||
&.error | ||
border: 1px solid $color-semantic100 | ||
cursor: text | ||
|
||
.theme-textfield-info | ||
margin: 4px 0 0 16px | ||
cursor: default | ||
|
||
@include body12R | ||
color: $color-white70 | ||
&.error | ||
color: $color-semantic100 | ||
|
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,76 @@ | ||
import { ChangeEvent, FocusEvent, useEffect, useRef, useState } from "react"; | ||
|
||
import { useCreateTheme } from "@/components/atoms/createTheme.atom"; | ||
import { useCreateHint } from "@/components/atoms/createHint.atom"; | ||
|
||
import { ThemeInfoTextAreaType } from "./TextAreaType"; | ||
|
||
const useTextArea = ({ | ||
id, | ||
content, | ||
checkErrorText, | ||
}: ThemeInfoTextAreaType) => { | ||
const [textAreaValue, setTextAreaValue] = useState<string>(content || ""); | ||
const [isFocus, setIsFocus] = useState<boolean>(false); | ||
const [errorText, setErrorText] = useState<string>(""); | ||
const textAreaRef = useRef<HTMLTextAreaElement>(null); | ||
const [, setCreateHint] = useCreateHint(); | ||
const [, setCreateTheme] = useCreateTheme(); | ||
|
||
useEffect(() => { | ||
if (errorText) return; | ||
setCreateTheme((prev) => ({ | ||
...prev, | ||
[id]: textAreaValue, | ||
})); | ||
setCreateHint((prev) => ({ | ||
...prev, | ||
[id]: textAreaValue, | ||
})); | ||
}, [textAreaValue, id, setCreateTheme, setCreateHint, errorText]); | ||
|
||
useEffect(() => { | ||
if (!isFocus || !textAreaRef.current) { | ||
setErrorText(""); | ||
return; | ||
} | ||
textAreaRef.current.focus(); | ||
}, [isFocus]); | ||
|
||
const handleTextAreaChange = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
const cur = e.target.value; | ||
const error = checkErrorText ? checkErrorText(cur) : ""; | ||
if (error) { | ||
setErrorText(error); | ||
setTextAreaValue(textAreaValue); | ||
return; | ||
} | ||
setErrorText(""); | ||
setTextAreaValue(cur); | ||
}; | ||
|
||
const handleTextAreaBlur = (e: FocusEvent<HTMLTextAreaElement>) => { | ||
if ( | ||
!e.relatedTarget || | ||
(e.relatedTarget.className !== "theme-info focus" && | ||
e.relatedTarget.className !== "theme-info error") | ||
) { | ||
setIsFocus(false); | ||
return; | ||
} | ||
textAreaRef.current?.focus(); | ||
setIsFocus(true); | ||
}; | ||
|
||
return { | ||
textAreaValue, | ||
isFocus, | ||
setIsFocus, | ||
errorText, | ||
textAreaRef, | ||
handleTextAreaChange, | ||
handleTextAreaBlur, | ||
}; | ||
}; | ||
|
||
export default useTextArea; |
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
Oops, something went wrong.