@daeryun/dr_components 0.9.12 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,300 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+
4
+ import Image from 'next/image';
5
+
6
+ const Box = ({
7
+ code,
8
+ code_name,
9
+ selected,
10
+ selectedList,
11
+ setSelectedList,
12
+ activeTooltipId,
13
+ setActiveTooltipId,
14
+ tooltipTimeoutRef
15
+ }: {
16
+ code: string;
17
+ code_name: string;
18
+ selected: boolean;
19
+ selectedList: string[];
20
+ setSelectedList: React.Dispatch<React.SetStateAction<string[]>>;
21
+ activeTooltipId: string | null;
22
+ setActiveTooltipId: (id: string | null) => void;
23
+ tooltipTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>;
24
+ }) => {
25
+ const [tooltipStyle, setTooltipStyle] = useState<React.CSSProperties>({});
26
+ const buttonRef = useRef<HTMLButtonElement>(null);
27
+ const tooltipRef = useRef<HTMLDivElement>(null);
28
+
29
+ const [tooltipArrowLeft, setTooltipArrowLeft] = useState('50%');
30
+
31
+ // 외부 클릭 시 툴팁 닫기
32
+ useEffect(() => {
33
+ if (activeTooltipId !== code) return;
34
+
35
+ const handleClickOutside = (e: MouseEvent) => {
36
+ if (
37
+ tooltipRef.current &&
38
+ !tooltipRef.current.contains(e.target as Node) &&
39
+ buttonRef.current &&
40
+ !buttonRef.current.contains(e.target as Node)
41
+ ) {
42
+ setActiveTooltipId(null);
43
+ if (tooltipTimeoutRef.current) {
44
+ clearTimeout(tooltipTimeoutRef.current);
45
+ tooltipTimeoutRef.current = null;
46
+ }
47
+ }
48
+ };
49
+ const handleResize = () => {
50
+ setActiveTooltipId(null);
51
+ if (tooltipTimeoutRef.current) {
52
+ clearTimeout(tooltipTimeoutRef.current);
53
+ tooltipTimeoutRef.current = null;
54
+ }
55
+ };
56
+
57
+ window.addEventListener('resize', handleResize);
58
+ document.addEventListener('mousedown', handleClickOutside);
59
+ return () => {
60
+ document.removeEventListener('mousedown', handleClickOutside);
61
+ window.removeEventListener('resize', handleResize);
62
+ };
63
+ }, [activeTooltipId, code]);
64
+
65
+ const handleClick = () => {
66
+ const clearTooltipTimer = () => {
67
+ if (tooltipTimeoutRef.current) {
68
+ clearTimeout(tooltipTimeoutRef.current);
69
+ tooltipTimeoutRef.current = null;
70
+ }
71
+ };
72
+
73
+ if (selected) {
74
+ setSelectedList(prev => prev.filter(item => item !== code));
75
+ setActiveTooltipId(null);
76
+ clearTooltipTimer();
77
+ } else {
78
+ if (selectedList.length >= 2) {
79
+ const button = buttonRef.current;
80
+ if (button) {
81
+ const rect = button.getBoundingClientRect();
82
+ const viewportWidth = window.innerWidth;
83
+
84
+ const TOOLTIP_WIDTH = window.innerWidth >= 1024 ? 271 : window.innerWidth >= 640 ? 240 : 177;
85
+ const SCREEN_PADDING = 8;
86
+ const NUDGE_X = 20;
87
+ const TOOLTIP_OFFSET_Y = window.innerWidth >= 1024 ? 68 : window.innerWidth >= 640 ? 58 : 44;
88
+
89
+ const centerLeft = rect.width / 2 - TOOLTIP_WIDTH / 2;
90
+ let left = centerLeft;
91
+
92
+ const absoluteLeft = rect.left + centerLeft;
93
+ const absoluteRight = rect.left + centerLeft + TOOLTIP_WIDTH;
94
+
95
+ if (absoluteLeft < SCREEN_PADDING) {
96
+ left += SCREEN_PADDING - absoluteLeft + NUDGE_X;
97
+ } else if (absoluteRight > viewportWidth - SCREEN_PADDING) {
98
+ left -= absoluteRight - (viewportWidth - SCREEN_PADDING) + NUDGE_X;
99
+ }
100
+
101
+ const tooltipArrowX = rect.left + rect.width / 2 - (rect.left + left);
102
+ setTooltipArrowLeft(`${tooltipArrowX}px`);
103
+
104
+ setTooltipStyle({
105
+ position: 'absolute',
106
+ top: -TOOLTIP_OFFSET_Y,
107
+ left,
108
+ width: TOOLTIP_WIDTH
109
+ });
110
+ }
111
+
112
+ clearTooltipTimer();
113
+ setActiveTooltipId(code);
114
+
115
+ tooltipTimeoutRef.current = setTimeout(() => {
116
+ setActiveTooltipId(null);
117
+ tooltipTimeoutRef.current = null;
118
+ }, 3000000);
119
+
120
+ return;
121
+ }
122
+
123
+ setSelectedList(prev => [...prev, code]);
124
+ setActiveTooltipId(null);
125
+ clearTooltipTimer();
126
+ }
127
+ };
128
+
129
+ return (
130
+ <div className="relative inline-block">
131
+ {activeTooltipId === code && (
132
+ <div ref={tooltipRef} style={tooltipStyle} className="z-10">
133
+ <div className="relative w-full rounded-[4px] bg-[#7B2238] p-[6px] text-white shadow-md sm:rounded-[8px] sm:px-[14px] sm:py-[10px] lg:px-[16px] lg:py-[12px]">
134
+ <div className="flex items-center justify-center gap-[4px] sm:gap-[6px] lg:gap-[8px]">
135
+ <Image
136
+ src="https://d1tgonli21s4df.cloudfront.net/common-login/mark2.webp"
137
+ alt="warning"
138
+ width={24}
139
+ height={24}
140
+ className="h-[13.82px] w-[16px] sm:h-[17.27px] sm:w-[20px] lg:h-[20.73px] lg:w-[24px]"
141
+ />
142
+ <p className="label_large2_mo sm:label_large2_tb lg:label_large2">
143
+ 선택은 2개까지만 가능해요.
144
+ </p>
145
+ </div>
146
+ {/* 꼬리 */}
147
+ <div
148
+ style={{
149
+ position: 'absolute',
150
+ top: '100%',
151
+ left: tooltipArrowLeft,
152
+ transform: 'translateX(-50%)',
153
+ width: 0,
154
+ height: 0,
155
+ borderLeft: '4.8px solid transparent',
156
+ borderRight: '4.8px solid transparent',
157
+ borderTop: '8px solid #7B2238'
158
+ }}
159
+ />
160
+ </div>
161
+ </div>
162
+ )}
163
+
164
+ <button
165
+ ref={buttonRef}
166
+ onClick={handleClick}
167
+ className={`flex flex-row items-center gap-[4px] rounded-[26px] border border-solid ${
168
+ selected ? 'border-transparent bg-grayScale1' : 'border-grayScale5'
169
+ } px-[10px] py-[4px] sm:gap-[8px] sm:px-[16px] sm:py-[6px] lg:gap-[12px] lg:px-[20px] lg:py-[8px]`}
170
+ >
171
+ <div
172
+ className={`flex h-[16px] w-[16px] items-center justify-center border border-solid sm:h-[20px] sm:w-[20px] lg:h-[28px] lg:w-[28px] ${
173
+ selected ? 'border-transparent bg-white' : 'border-grayScale5 bg-white'
174
+ }`}
175
+ >
176
+ {selected && (
177
+ <img
178
+ src="https://d1tgonli21s4df.cloudfront.net/common-login/check box_4.webp"
179
+ alt="check"
180
+ width={28}
181
+ height={28}
182
+ className="h-[16px] w-[16px] sm:h-[20px] sm:w-[20px] lg:h-[28px] lg:w-[28px]"
183
+ />
184
+ )}
185
+ </div>
186
+ <p
187
+ className={`body_medium2_mo sm:body_large2_tb lg:body_large2 leading-[20px] sm:leading-[30px] lg:leading-[35px] ${selected ? 'text-grayScale8' : 'text-grayScale2'}`}
188
+ >
189
+ {code_name}
190
+ </p>
191
+ </button>
192
+ </div>
193
+ );
194
+ };
195
+
196
+ const StepOne = () => {
197
+ const [selectedList, setSelectedList] = useState<string[]>([]);
198
+ const [activeTooltipId, setActiveTooltipId] = useState<string | null>(null);
199
+ const tooltipTimeoutRef = useRef<NodeJS.Timeout | null>(null);
200
+ const categories = [
201
+ { code: 'CT0004', code_name: '기업법무' },
202
+ { code: 'CT0014', code_name: '지식재산권' },
203
+ { code: 'CT0026', code_name: '공정거래' },
204
+ { code: 'CT0021', code_name: '관세·국제통상·이민' },
205
+ { code: 'CT0007', code_name: '건설·부동산' },
206
+ { code: 'CT0005', code_name: '이혼' },
207
+ { code: 'CT0006', code_name: '상속·가사' },
208
+ { code: 'CT0012', code_name: '조세' },
209
+ { code: 'CT0024', code_name: '회계감리' },
210
+ { code: 'CT0001', code_name: '형사' },
211
+ { code: 'CT0019', code_name: '음주교통사고' },
212
+ { code: 'CT0017', code_name: '국방군사' },
213
+ { code: 'CT0002', code_name: '성범죄' },
214
+ { code: 'CT0013', code_name: '마약' },
215
+ { code: 'CT0008', code_name: '민사·중재' },
216
+ { code: 'CT0003', code_name: '학교폭력' },
217
+ { code: 'CT0009', code_name: '헌법행정' },
218
+ { code: 'CT0011', code_name: '금융·보험' },
219
+ { code: 'CT0018', code_name: '의료제약' },
220
+ { code: 'CT0027', code_name: '산업안전·중대재해' },
221
+ { code: 'CT0016', code_name: '노동·산재' },
222
+ { code: 'CT0025', code_name: '엔터테인먼트·스포츠' },
223
+ { code: 'CT0015', code_name: '증거조사' },
224
+ { code: 'CT0029', code_name: '디지털포렌식' },
225
+ { code: 'CT0030', code_name: '경호' }
226
+ ];
227
+ return (
228
+ <>
229
+ <div className="relative mx-[200px] mt-[150px] max-[1498px]:mx-[120px] max-lg:mx-[60px] max-sm:mx-[20px] sm:mt-[240px] lg:mt-[200px] ">
230
+ <div className="">
231
+ <p className="title_large_mo sm:title_large_tb lg:title_large">STEP 1</p>
232
+ <div className="xxl:flex xxl:flex-row xxl:items-center xxl:justify-between">
233
+ <div className="mt-[8px] flex flex-col gap-[4px] sm:mt-[12px] md:flex-row md:items-center md:gap-[8px] lg:mt-[12px] lg:flex-col lg:items-start 5xl:flex-row 5xl:items-center 5xl:gap-[8px]">
234
+ <p className="title_small_mo sm:title_small_tb lg:title_small">
235
+ 어떤 법률도움이 필요하신가요?
236
+ </p>
237
+ <p className="body_small2_mo sm:body_medium2_tb lg:body_medium2">
238
+ (최대 2개까지 선택할 수 있어요.)
239
+ </p>
240
+ </div>
241
+ <div className="mt-[12px] flex flex-row gap-[8px] rounded-[8px] bg-grayScale7 p-[8px] sm:mt-[40px] sm:w-[513px] sm:gap-[12px] sm:px-[20px] sm:py-[12px] lg:w-[590px] lg:rounded-[12px] lg:px-[28px] lg:py-[16px] xxl:mt-0">
242
+ <Image
243
+ src="https://d1tgonli21s4df.cloudfront.net/common-login/mark.webp"
244
+ alt="물음표"
245
+ width={28}
246
+ height={28}
247
+ className="mt-[1px] h-[16px] w-[16px] sm:mt-[2px] sm:h-[20px] sm:w-[20px] lg:mt-0 lg:h-[28px] lg:w-[28px]"
248
+ />
249
+ <p className="body_small2_mo sm:body_small2_tb lg:body_small2">
250
+ 관심 분야 및 유형은 모바일 앱에서 맞춤 콘텐츠 제공에 사용됩니다. 설정해두시면 앱에서
251
+ 더욱 편리하게 이용하실 수 있어요.
252
+ </p>
253
+ </div>
254
+ </div>
255
+ </div>
256
+
257
+ <div className="mt-[28px] flex flex-row flex-wrap gap-x-[8px] gap-y-[12px] sm:mt-[60px] sm:gap-[28px] lg:mt-[66px] lg:gap-x-[32px] lg:gap-y-[40px]">
258
+ {categories.map(item => (
259
+ <Box
260
+ key={item.code}
261
+ code={item.code}
262
+ code_name={item.code_name}
263
+ selected={selectedList.includes(item.code)}
264
+ selectedList={selectedList}
265
+ setSelectedList={setSelectedList}
266
+ activeTooltipId={activeTooltipId}
267
+ setActiveTooltipId={setActiveTooltipId}
268
+ tooltipTimeoutRef={tooltipTimeoutRef}
269
+ />
270
+ ))}
271
+ </div>
272
+ <div className="mb-[56px] mt-[40px] flex flex-col items-center justify-center sm:mt-[60px] lg:mt-[218px]">
273
+ <button
274
+ type={'button'}
275
+ onClick={async () => {}}
276
+ className={
277
+ ` ${selectedList.length > 0 ? ' bg-[#AE0E36] text-white ' : ' bg-[#EDEDED] text-grayScale3 '} ` +
278
+ ' title_small h-[72px] w-[740px] rounded-[36px] ' +
279
+ ' max-lg:body_medium2 max-lg:h-[60px] max-lg:w-[620px] ' +
280
+ ' max-sm:body_large2_mo max-sm:h-[48px] max-sm:w-full '
281
+ }
282
+ >
283
+ 다음
284
+ </button>
285
+ <button
286
+ type={'button'}
287
+ onClick={async () => {
288
+ //추가해야함
289
+ }}
290
+ className="body_small2_mo sm:body_small2_tb lg:body_small2 mt-[12px] text-grayScale2 underline sm:mt-[20px] lg:mt-[40px]"
291
+ >
292
+ 건너뛰기
293
+ </button>
294
+ </div>
295
+ </div>
296
+ </>
297
+ );
298
+ };
299
+
300
+ export default StepOne;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const StepTwo: () => React.JSX.Element;
3
+ export default StepTwo;