1+ import React , { useState } from "react" ;
2+ import DaumPostcode , { Address } from "react-daum-postcode" ;
3+
14interface DeliveryAddressFormProps {
25 zipcode : string ;
36 setZipcode : ( v : string ) => void ;
7+ setAddress : ( v : string ) => void ;
48 detailAddress : string ;
59 setDetailAddress : ( v : string ) => void ;
610}
711
812const DeliveryAddressForm : React . FC < DeliveryAddressFormProps > = ( {
913 zipcode,
1014 setZipcode,
15+ setAddress,
1116 detailAddress,
1217 setDetailAddress,
1318} ) => {
19+ // 임베디드 검색창 열림/닫힘
20+ const [ isPostcodeOpen , setIsPostcodeOpen ] = useState ( false ) ;
21+ // 기준 주소(도로명/지번 등 최종 선택 주소)
22+ const [ baseAddress , setBaseAddress ] = useState ( "" ) ;
23+
24+ const handleComplete = ( data : Address ) => {
25+ // 선택된 값 반영
26+ setZipcode ( data . zonecode ) ;
27+ setBaseAddress ( data . address ) ; // 도로명/지번 자동 선택 규칙에 따른 최종 주소
28+ setIsPostcodeOpen ( false ) ; // 선택 후 검색창 닫기 (원하면 유지해도 OK)
29+ setAddress ( data . address ) ;
30+ } ;
31+
1432 return (
1533 < div className = "flex flex-col gap-3 w-full max-w-md" >
1634 < h2 className = "text-lg font-semibold" > 받는 분 정보</ h2 >
35+
36+ { /* 주소 + 우편번호 */ }
1737 < div className = "flex flex-col gap-3" >
1838 < div
1939 className = { `flex flex-col gap-1 border-b py-2 ${
@@ -22,29 +42,47 @@ const DeliveryAddressForm: React.FC<DeliveryAddressFormProps> = ({
2242 >
2343 < label className = "block text-gray-600 text-sm" > 주소</ label >
2444 < div >
25- < div className = "flex justify-between w-full gap-0.25 " >
45+ < div className = "flex justify-between w-full gap-0.5 " >
2646 < input
2747 type = "text"
2848 value = { zipcode }
2949 onChange = { e => setZipcode ( e . target . value ) }
30- placeholder = "우편번호를 입력해주세요"
31- className = "flex-1 text-sm placeholder:text-gray-400 placeholder:text-body2 focus:outline-none"
50+ placeholder = "우편번호를 찾아 선택해주세요"
51+ className = "flex-1 text-body2 placeholder:text-gray-400 placeholder:text-body2 focus:outline-none"
52+ readOnly
3253 />
3354 < button
3455 type = "button"
3556 className = "whitespace-nowrap bg-gray-200 text-gray-600 px-3 py-1 text-body-sb rounded-lg"
57+ onClick = { ( ) => setIsPostcodeOpen ( v => ! v ) }
3658 >
37- 우편번호 찾기
59+ { isPostcodeOpen ? "닫기" : "주소 검색" }
3860 </ button >
3961 </ div >
4062 </ div >
4163 </ div >
42- < textarea
43- className = "w-full border rounded-[8px] text-body2 resize-none border-gray-400 bg-gray-200"
44- rows = { 2 }
64+
65+ { /* 임베디드 우편번호 검색창 */ }
66+ { isPostcodeOpen && (
67+ < div className = "w-full rounded-lg overflow-hidden border border-gray-200" >
68+ < DaumPostcode
69+ onComplete = { handleComplete }
70+ style = { { width : "100%" , height : "380px" } }
71+ autoClose = { false } // 임베디드에선 수동으로 닫는 게 자연스럽습니다
72+ />
73+ </ div >
74+ ) }
75+
76+ { /* 선택된 기준 주소 표시 */ }
77+ < input
78+ className = "flex items-center justify-center w-full resize-none border rounded-[8px] border-gray-400 bg-gray-50 p-2 py-3 text-body2 focus:outline-none placeholder:text-gray-400 placeholder:text-body2"
79+ placeholder = "주소가 자동으로 입력 됩니다."
80+ value = { baseAddress }
81+ readOnly
4582 />
4683 </ div >
4784
85+ { /* 상세 주소 */ }
4886 < div
4987 className = { `flex flex-col border-b py-2 gap-1 ${
5088 detailAddress ? "border-primary" : "border-gray-400"
0 commit comments