Skip to content

Commit fc716ab

Browse files
authored
feat: Recruit 페이지 api 기능 추가
1 parent 87bf50f commit fc716ab

File tree

2 files changed

+184
-97
lines changed

2 files changed

+184
-97
lines changed

src/components/UI/Recruit_InputField.tsx

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
// import React, { useRef } from 'react'
21
import React from 'react'
32

43
interface InputFieldProps {
5-
label: string;
6-
subLabel?: string;
7-
type?: 'text' | 'email' | 'textarea' | 'select' | 'checkbox' | 'test';
8-
placeholder?: string;
9-
required?: boolean;
10-
options?: { value: string; label: string }[];
11-
checkboxLabel?: string;
12-
phoneNumber?: boolean;
4+
label: string
5+
name: string
6+
subLabel?: string
7+
type?: 'text' | 'email' | 'textarea' | 'select' | 'checkbox'
8+
placeholder?: string
9+
required?: boolean
10+
options?: { value: string; label: string }[]
11+
checkboxLabel?: string
12+
phoneNumber?: boolean
13+
value: string | boolean
14+
checked?: boolean
15+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void
16+
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void
1317
}
1418

19+
1520
export const InputField: React.FC<InputFieldProps> = ({
1621
label,
22+
name,
1723
subLabel,
1824
type = 'text',
1925
placeholder,
2026
required = false,
2127
options = [],
2228
checkboxLabel = '확인했습니다.',
2329
phoneNumber = false,
24-
}) => {
30+
value,
31+
checked,
32+
onChange,
33+
onKeyDown
2534

26-
// const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null)
35+
}) => {
2736

28-
// const handleKeyDown = (e: React.KeyboardEvent) => {
29-
// if (e.key === 'Enter' && type !== 'textarea') {
30-
// e.preventDefault() // 기본 엔터 동작(폼 제출) 방지
31-
32-
// const inputElement = e.currentTarget as HTMLInputElement // 🔹 타입 단언 추가
33-
// const form = inputElement.form // 🔹 이제 form 속성 사용 가능
34-
35-
// if (!form) return
36-
37-
// const index = Array.from(form.elements).indexOf(inputElement)
38-
// const nextElement = form.elements[index + 1] as HTMLElement
39-
40-
// if (nextElement) {
41-
// nextElement.focus() // 다음 input으로 포커스 이동
42-
// }
43-
// }
44-
// }
37+
// 📌 textarea 동적 높이 변화
38+
const handleTextAreaChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
39+
e.target.style.height = 'auto'
40+
e.target.style.height = `${e.target.scrollHeight}px`
41+
onChange(e)
42+
}
4543

4644

47-
4845
// 📌 공통 스타일 변수
49-
const containerStyles = 'mb-4 p-3 shadow-[0px_2px_3px_rgba(255,255,255,0.2)] text-white'
50-
const baseInputStyles = 'w-full bg-mainBlack border-b border-white p-2 focus:outline-none text-[10px]'
51-
const inputStyles = 'w-4 h-4 bg-mainBlack border border-white focus:ring-white border-2 appearance-none checked:bg-white checked:border-white" '
46+
const containerStyles = 'mb-4 p-3 shadow-[0px_2px_3px_rgba(255,255,255,0.2)] text-white text-[12px]'
47+
const baseInputStyles = 'w-full bg-mainBlack border-b border-white p-2 focus:outline-none text-[10px]'
48+
const inputStyles = 'w-4 h-4 bg-mainBlack border border-white focus:ring-white border-2 rounded-[3px] appearance-none checked:bg-white checked:border-white'
5249

5350
return (
5451
<div className={containerStyles}>
55-
<label className="block text-white text-[10px] font-bold mb-1">
56-
{label.split(/(| 4)/).map((part, index) => (
57-
<span key={index} className={part === '대면으로' ? 'text-red-500' : part === '전화번호 마지막 4자리' ? 'text-[#00B493]' : ''}>
52+
<label className="block text-white mb-1">
53+
{label.split(/( 4)/).map((part, index) => (
54+
<span key={index} className={part === '전화번호 마지막 4자리' ? 'text-[#00B493]' : ''}>
5855
{part}
56+
5957
</span>
6058
))}
61-
{type !== 'checkbox' && type !== 'test' && required && <span className="text-red-500 pl-1">*</span>}
59+
{required && <span className="text-[#C11100] pl-1">*</span>}
6260
</label>
6361

6462
{subLabel && (
65-
<p className="font-bold text-[10px]">
66-
{subLabel.split(/(ex\)|\d{4})/).map((part, index, array) => (
63+
<p className="pb-[10px] font-pretendardRegular">
64+
{subLabel.split(/(|ex|0542)/).map((part, index) => (
6765
<span
6866
key={index}
6967
className={
70-
part === 'ex)'
71-
? 'text-[#A5A5A5]'
72-
: index === array.length - 2 && /\d{4}/.test(part)
73-
? 'text-[#00B493]'
74-
: ''
68+
part === '대면으로'
69+
? 'text-red-500'
70+
: part === 'ex'
71+
? 'text-[#A5A5A5]'
72+
: part === '0542'
73+
? 'text-[#00B493]'
74+
: ''
7575
}
7676
>
7777
{part}
@@ -81,25 +81,50 @@ export const InputField: React.FC<InputFieldProps> = ({
8181
)}
8282

8383
{type === 'select' ? (
84-
<select className={baseInputStyles}>
84+
<select name={name} value={value as string} onChange={onChange} required={required} className={baseInputStyles}>
8585
{options.map((option) => (
8686
<option key={option.value} value={option.value}>
8787
{option.label}
8888
</option>
8989
))}
9090
</select>
91+
9192
) : type === 'textarea' ? (
92-
<textarea placeholder={placeholder} className={baseInputStyles} required={required} />
93+
<textarea
94+
name={name}
95+
value={value as string}
96+
onChange={handleTextAreaChange}
97+
onKeyDown={onKeyDown}
98+
required={required}
99+
placeholder={placeholder}
100+
className={baseInputStyles}
101+
rows={4}
102+
/>
93103

94104
) : type === 'checkbox' ? (
95105
<div className="flex items-center space-x-2">
96-
<input type="checkbox" className={inputStyles} required={required} />
97-
98-
<span className="text-white text-[10px]">{checkboxLabel}</span>
106+
<input
107+
type="checkbox"
108+
name={name}
109+
checked={checked ?? (value as boolean)}
110+
onChange={onChange}
111+
required={required}
112+
className={inputStyles}
113+
/>
114+
<span className="text-white">{checkboxLabel}</span>
99115
</div>
100116

101117
) : (
102-
<input type={type} placeholder={placeholder} className={baseInputStyles} required={required} />
118+
<input
119+
type={type}
120+
name={name}
121+
value={value as string}
122+
onChange={onChange}
123+
onKeyDown={onKeyDown}
124+
required={required}
125+
placeholder={placeholder}
126+
className={baseInputStyles}
127+
/>
103128
)}
104129
</div>
105130
)

0 commit comments

Comments
 (0)