@daeryun/dr_components 0.9.61 → 0.9.62

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.
@@ -10,70 +10,86 @@ import DaeryuntalkIntro from '../../asset/images/daeryuntalk/daeryuntalk_home_bg
10
10
  import CloseSvgIcon from '../../asset/images/daeryuntalk/close.svg';
11
11
  import { useScrollShadow } from './_hooks/useScrollShadow';
12
12
  import Button3 from './_ui/buttons/Button3';
13
+ import { useHoverScrollbar } from './_hooks/useHoverScrollbar';
14
+ import { useWindowSize } from './_hooks/useWindowSize';
13
15
  const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClose, isHash }) => {
14
16
  const { containerRef, isScroll, isBottom, checkScroll, isScrolling } = useScrollShadow();
15
17
  const wrapperRef = useRef(null);
16
18
  const [contentHeight, setContentHeight] = useState(210);
17
19
  const currentHeightRef = useRef(210);
18
20
  const prevWrapperHeightRef = useRef(null);
21
+ const { style: hoverStyle } = useHoverScrollbar(containerRef);
22
+ const browserSize = useWindowSize();
19
23
  useEffect(() => {
20
24
  const updateContentHeight = () => {
21
25
  var _a;
22
26
  if (!wrapperRef.current)
23
27
  return;
24
28
  // 모바일이거나 width가 480px 미만이면 contentHeight를 210으로 되돌림
25
- if (isMobile || window.innerWidth < 480) {
29
+ if (isMobile) {
26
30
  currentHeightRef.current = 210;
27
31
  setContentHeight(210);
28
32
  return;
29
33
  }
30
- const rect = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
31
- const gap = rect.top;
32
- const wrapperHeight = wrapperRef.current.offsetHeight;
33
- const currentHeight = currentHeightRef.current;
34
- // 이전 높이와 비교하여 줄어드는 중인지 판단
35
- const prevHeight = prevWrapperHeightRef.current;
36
- const isShrinking = prevHeight !== null && wrapperHeight < prevHeight;
37
- const isExpanding = prevHeight !== null && wrapperHeight > prevHeight;
38
- prevWrapperHeightRef.current = wrapperHeight; // 현재 높이를 저장
39
- // 줄어드는 애니메이션 (2단계)
40
- if (isShrinking) {
41
- if (currentHeight > 140) {
42
- if (wrapperHeight <= 625) {
43
- // 1단계: 210 → 140
44
- const next = Math.max(140, currentHeight - 6);
45
- currentHeightRef.current = next;
46
- setContentHeight(next);
47
- }
48
- }
49
- else if (currentHeight > 80) {
50
- // 여기에 height가 526 경우에만 가능
51
- // 2단계: 140 → 80
52
- if (wrapperHeight <= 526) {
53
- const next = Math.max(80, currentHeight - 4);
54
- currentHeightRef.current = next;
55
- setContentHeight(next);
56
- }
57
- }
58
- }
59
- // 다시 늘어나는 애니메이션 (2단계)
60
- else if (isExpanding) {
61
- if (currentHeight < 140) {
62
- // 1단계: 80 → 140
63
- const next = Math.min(140, currentHeight + 4);
64
- currentHeightRef.current = next;
65
- setContentHeight(next);
66
- }
67
- else if (currentHeight < 210) {
68
- if (wrapperHeight >= 526) {
69
- // 2단계: 140 → 210
70
- const next = Math.min(210, currentHeight + 6);
71
- currentHeightRef.current = next;
72
- setContentHeight(next);
73
- }
34
+ else {
35
+ if (browserSize.width < 480) {
36
+ // 브라우저 세로 - 헤더 - 고정 200px - 푸터 - 문의 버튼 크기
37
+ const nextHeight = browserSize.height - 56 - 200 - 64 - 88 - 48;
38
+ currentHeightRef.current = nextHeight;
39
+ setContentHeight(nextHeight);
40
+ return;
74
41
  }
75
42
  else {
76
43
  setContentHeight(210);
44
+ const rect = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
45
+ const gap = rect.top;
46
+ const wrapperHeight = wrapperRef.current.offsetHeight;
47
+ const currentHeight = currentHeightRef.current;
48
+ // 이전 높이와 비교하여 줄어드는 중인지 판단
49
+ const prevHeight = prevWrapperHeightRef.current;
50
+ const isShrinking = prevHeight !== null && wrapperHeight < prevHeight;
51
+ const isExpanding = prevHeight !== null && wrapperHeight > prevHeight;
52
+ prevWrapperHeightRef.current = wrapperHeight; // 현재 높이를 저장
53
+ // 줄어드는 애니메이션 (2단계)
54
+ if (isShrinking) {
55
+ if (currentHeight > 140) {
56
+ if (wrapperHeight <= 625) {
57
+ // 1단계: 210 → 140
58
+ const next = Math.max(140, currentHeight - 6);
59
+ currentHeightRef.current = next;
60
+ setContentHeight(next);
61
+ }
62
+ }
63
+ else if (currentHeight > 80) {
64
+ // 여기에 height가 526 경우에만 가능
65
+ // 2단계: 140 → 80
66
+ if (wrapperHeight <= 526) {
67
+ const next = Math.max(80, currentHeight - 4);
68
+ currentHeightRef.current = next;
69
+ setContentHeight(next);
70
+ }
71
+ }
72
+ }
73
+ // 다시 늘어나는 애니메이션 (2단계)
74
+ else if (isExpanding) {
75
+ if (currentHeight < 140) {
76
+ // 1단계: 80 → 140
77
+ const next = Math.min(140, currentHeight + 4);
78
+ currentHeightRef.current = next;
79
+ setContentHeight(next);
80
+ }
81
+ else if (currentHeight < 210) {
82
+ if (wrapperHeight >= 526) {
83
+ // 2단계: 140 → 210
84
+ const next = Math.min(210, currentHeight + 6);
85
+ currentHeightRef.current = next;
86
+ setContentHeight(next);
87
+ }
88
+ }
89
+ else {
90
+ setContentHeight(210);
91
+ }
92
+ }
77
93
  }
78
94
  }
79
95
  };
@@ -84,7 +100,7 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
84
100
  };
85
101
  rafId = requestAnimationFrame(loop);
86
102
  return () => cancelAnimationFrame(rafId);
87
- }, [isMobile, inquiryMainData]);
103
+ }, [isMobile, inquiryMainData, browserSize.width]);
88
104
  useEffect(() => {
89
105
  checkScroll();
90
106
  }, [inquiryMainData]);
@@ -110,16 +126,17 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
110
126
 
111
127
  <div className={`absolute left-0 top-0 z-0 w-full overflow-hidden ${isMobile ? 'aspect-[16/9] max-h-[360px]' : 'h-full max-h-[360px]'}`}>
112
128
  {/*<div className={`relative`}>*/}
113
- <Image src={backgroundImage} alt="대화 배경" fill className={`will-change-transform ${isMobile ? 'object-cover object-center' : ' object-cover object-top xs:object-contain '}`} priority/>
129
+ <Image src={backgroundImage} alt="대화 배경" fill className={`will-change-transform ${isMobile ? 'object-cover object-top' : ' object-cover object-top xs:object-contain '}`} priority/>
114
130
  <div className="pointer-events-none absolute bottom-0 left-0 h-24 w-full bg-gradient-to-t from-white to-transparent"/>
115
131
  {/*</div>*/}
116
132
  </div>
133
+ {!isMobile && <div className={`block h-[200px] xs:hidden`}></div>}
117
134
 
118
- <div className={` relative z-10 px-[20px] ${isMobile ? 'flex w-full justify-center pb-[20px]' : 'flex h-full w-full flex-col justify-center pb-[34px] xs:h-fit'}`}>
119
- <section className={` flex flex-col rounded-[12px] bg-white px-[16px] py-[24px] sm:h-fit ${isMobile ? 'w-full' : ''}`} style={{ boxShadow: '0px 4px 10px 0px #00000026' }}>
135
+ <div className={` relative z-10 px-[20px] ${isMobile ? 'flex w-full justify-center pb-[20px]' : 'flex h-full w-full flex-col justify-center pb-[84px] xs:h-fit xs:pb-[34px]'}`}>
136
+ <section className={` flex h-full flex-col rounded-[12px] bg-white px-[16px] py-[24px] sm:h-fit ${isMobile ? 'w-full' : ' justify-between xs:justify-start '}`} style={{ boxShadow: '0px 4px 10px 0px #00000026' }}>
120
137
  {/* 해당 컴포넌트의 최상위 부모와 브라우저 상단과 닿았을 때 우선적으로 해당 부분의 높이가 먼저 줄어들게 하고 싶다*/}
121
138
  <div className="relative">
122
- <div ref={containerRef} className={`no-scrollbar flex max-h-[210px] min-h-[80px] flex-col overflow-auto`} style={{ maxHeight: `${contentHeight}px` }}>
139
+ <div ref={containerRef} className={`flex min-h-[80px] flex-col ${isMobile ? 'overflow-y-auto ' : ''} overlay-scrollbar`} style={Object.assign({ maxHeight: `${contentHeight}px` }, (!isMobile ? hoverStyle : {}))}>
123
140
  <div className="flex items-center gap-[10px]">
124
141
  {(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_logo_image_url) ? (<Image src={inquiryMainData.channel_logo_image_url} alt="로고" width={32} height={32}/>) : (<DaeryunLogoIcon width={24} height={24} className="mr-2"/>)}
125
142
  <h2 className="dr_talk_title_small text-drTalkBlack">
@@ -133,18 +150,20 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
133
150
  {isScroll && !isBottom && <ShadowBox />}
134
151
  </div>
135
152
 
136
- <Button3 onClick={handleStartChat} isDisabled={isLoading || !(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number)} className="mt-[40px]">
137
- <div className="flex items-center justify-center gap-[4px]">
138
- {!(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) ? (<div>{'로딩 중...'}</div>) : (<div>{isLoading ? '로딩 중...' : '문의하기'}</div>)}
139
- {!isLoading && <SendIcon width={24} height={24}/>}
140
- </div>
141
- </Button3>
153
+ <div className={`mt-[40px] `}>
154
+ <Button3 className={`w-full`} onClick={handleStartChat} isDisabled={isLoading || !(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number)}>
155
+ <div className="flex items-center justify-center gap-[4px]">
156
+ {!(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.channel_number) ? (<div>{'로딩 중...'}</div>) : (<div>{isLoading ? '로딩 중...' : '문의하기'}</div>)}
157
+ {!isLoading && <SendIcon width={24} height={24}/>}
158
+ </div>
159
+ </Button3>
142
160
 
143
- <div className="flex items-center justify-center gap-[4px] pt-[20px]">
144
- <InfoIcon width={20} height={20}/>
145
- <span className="dr_talk_body_small1 text-drTalkGrayscale2">
146
- {(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.answer_speed_message) || '빠르게 답변 받으실 수 있어요'}
147
- </span>
161
+ <div className="flex items-center justify-center gap-[4px] pt-[20px]">
162
+ <InfoIcon width={20} height={20}/>
163
+ <span className="dr_talk_body_small1 text-drTalkGrayscale2">
164
+ {(inquiryMainData === null || inquiryMainData === void 0 ? void 0 : inquiryMainData.answer_speed_message) || '빠르게 답변 받으실 수 있어요'}
165
+ </span>
166
+ </div>
148
167
  </div>
149
168
  </section>
150
169
  </div>
@@ -13,6 +13,8 @@ import DaeryuntalkHomeLogo from '../../asset/images/daeryuntalk/home_bg_logo.png
13
13
  import CloseSvgIcon from '../../asset/images/daeryuntalk/close.svg';
14
14
  import { useScrollShadow } from './_hooks/useScrollShadow';
15
15
  import Button3 from './_ui/buttons/Button3';
16
+ import { useHoverScrollbar } from './_hooks/useHoverScrollbar';
17
+ import { useWindowSize } from './_hooks/useWindowSize';
16
18
 
17
19
  interface IHomeViewProps {
18
20
  inquiryMainData: IChatInquiryMainDataResponse | null;
@@ -27,69 +29,81 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
27
29
  const { containerRef, isScroll, isBottom, checkScroll, isScrolling } = useScrollShadow<HTMLDivElement>();
28
30
 
29
31
  const wrapperRef = useRef<HTMLDivElement | null>(null);
30
- const [contentHeight, setContentHeight] = useState(210);
32
+ const [contentHeight, setContentHeight] = useState<number>(210);
31
33
  const currentHeightRef = useRef(210);
32
34
  const prevWrapperHeightRef = useRef<number | null>(null);
35
+ const { style: hoverStyle } = useHoverScrollbar(containerRef);
36
+ const browserSize = useWindowSize();
33
37
 
34
38
  useEffect(() => {
35
39
  const updateContentHeight = () => {
36
40
  if (!wrapperRef.current) return;
37
41
 
38
42
  // 모바일이거나 width가 480px 미만이면 contentHeight를 210으로 되돌림
39
- if (isMobile || window.innerWidth < 480) {
43
+ if (isMobile) {
40
44
  currentHeightRef.current = 210;
41
45
  setContentHeight(210);
42
46
  return;
43
- }
44
-
45
- const rect = wrapperRef.current?.getBoundingClientRect();
46
- const gap = rect.top;
47
- const wrapperHeight = wrapperRef.current.offsetHeight;
48
-
49
- const currentHeight = currentHeightRef.current;
50
-
51
- // 이전 높이와 비교하여 줄어드는 중인지 판단
52
- const prevHeight = prevWrapperHeightRef.current;
53
- const isShrinking = prevHeight !== null && wrapperHeight < prevHeight;
54
- const isExpanding = prevHeight !== null && wrapperHeight > prevHeight;
55
-
56
- prevWrapperHeightRef.current = wrapperHeight; // 현재 높이를 저장
47
+ } else {
48
+ if (browserSize.width < 480) {
49
+ // 브라우저 세로 - 헤더 - 고정 200px - 푸터 - 문의 버튼 크기
50
+ const nextHeight = browserSize.height - 56 - 200 - 64 - 88 - 48;
51
+ currentHeightRef.current = nextHeight;
52
+ setContentHeight(nextHeight);
53
+ return;
54
+ } else {
55
+ setContentHeight(210);
57
56
 
58
- // 줄어드는 애니메이션 (2단계)
59
- if (isShrinking) {
60
- if (currentHeight > 140) {
61
- if (wrapperHeight <= 625) {
62
- // 1단계: 210 → 140
63
- const next = Math.max(140, currentHeight - 6);
64
- currentHeightRef.current = next;
65
- setContentHeight(next);
57
+ const rect = wrapperRef.current?.getBoundingClientRect();
58
+ const gap = rect.top;
59
+ const wrapperHeight = wrapperRef.current.offsetHeight;
60
+
61
+ const currentHeight = currentHeightRef.current;
62
+
63
+ // 이전 높이와 비교하여 줄어드는 중인지 판단
64
+ const prevHeight = prevWrapperHeightRef.current;
65
+ const isShrinking = prevHeight !== null && wrapperHeight < prevHeight;
66
+ const isExpanding = prevHeight !== null && wrapperHeight > prevHeight;
67
+
68
+ prevWrapperHeightRef.current = wrapperHeight; // 현재 높이를 저장
69
+
70
+ // 줄어드는 애니메이션 (2단계)
71
+ if (isShrinking) {
72
+ if (currentHeight > 140) {
73
+ if (wrapperHeight <= 625) {
74
+ // 1단계: 210 → 140
75
+ const next = Math.max(140, currentHeight - 6);
76
+ currentHeightRef.current = next;
77
+ setContentHeight(next);
78
+ }
79
+ } else if (currentHeight > 80) {
80
+ // 여기에 height가 526 경우에만 가능
81
+ // 2단계: 140 → 80
82
+ if (wrapperHeight <= 526) {
83
+ const next = Math.max(80, currentHeight - 4);
84
+ currentHeightRef.current = next;
85
+ setContentHeight(next);
86
+ }
87
+ }
66
88
  }
67
- } else if (currentHeight > 80) {
68
- // 여기에 height가 526 경우에만 가능
69
- // 2단계: 140 → 80
70
- if (wrapperHeight <= 526) {
71
- const next = Math.max(80, currentHeight - 4);
72
- currentHeightRef.current = next;
73
- setContentHeight(next);
74
- }
75
- }
76
- }
77
- // 다시 늘어나는 애니메이션 (2단계)
78
- else if (isExpanding) {
79
- if (currentHeight < 140) {
80
- // 1단계: 80 → 140
81
- const next = Math.min(140, currentHeight + 4);
82
- currentHeightRef.current = next;
83
- setContentHeight(next);
84
- } else if (currentHeight < 210) {
85
- if (wrapperHeight >= 526) {
86
- // 2단계: 140 → 210
87
- const next = Math.min(210, currentHeight + 6);
88
- currentHeightRef.current = next;
89
- setContentHeight(next);
89
+ // 다시 늘어나는 애니메이션 (2단계)
90
+ else if (isExpanding) {
91
+ if (currentHeight < 140) {
92
+ // 1단계: 80 → 140
93
+ const next = Math.min(140, currentHeight + 4);
94
+ currentHeightRef.current = next;
95
+ setContentHeight(next);
96
+ } else if (currentHeight < 210) {
97
+ if (wrapperHeight >= 526) {
98
+ // 2단계: 140 → 210
99
+ const next = Math.min(210, currentHeight + 6);
100
+ currentHeightRef.current = next;
101
+ setContentHeight(next);
102
+ }
103
+ } else {
104
+ setContentHeight(210);
105
+ }
90
106
  }
91
- } else {
92
- setContentHeight(210);
93
107
  }
94
108
  }
95
109
  };
@@ -103,7 +117,7 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
103
117
  rafId = requestAnimationFrame(loop);
104
118
 
105
119
  return () => cancelAnimationFrame(rafId);
106
- }, [isMobile, inquiryMainData]);
120
+ }, [isMobile, inquiryMainData, browserSize.width]);
107
121
  useEffect(() => {
108
122
  checkScroll();
109
123
  }, [inquiryMainData]);
@@ -149,27 +163,31 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
149
163
  alt="대화 배경"
150
164
  fill
151
165
  className={`will-change-transform ${
152
- isMobile ? 'object-cover object-center' : ' object-cover object-top xs:object-contain '
166
+ isMobile ? 'object-cover object-top' : ' object-cover object-top xs:object-contain '
153
167
  }`}
154
168
  priority
155
169
  />
156
170
  <div className="pointer-events-none absolute bottom-0 left-0 h-24 w-full bg-gradient-to-t from-white to-transparent" />
157
171
  {/*</div>*/}
158
172
  </div>
173
+ {!isMobile && <div className={`block h-[200px] xs:hidden`}></div>}
159
174
 
160
175
  <div
161
- className={` relative z-10 px-[20px] ${isMobile ? 'flex w-full justify-center pb-[20px]' : 'flex h-full w-full flex-col justify-center pb-[34px] xs:h-fit'}`}
176
+ className={` relative z-10 px-[20px] ${isMobile ? 'flex w-full justify-center pb-[20px]' : 'flex h-full w-full flex-col justify-center pb-[84px] xs:h-fit xs:pb-[34px]'}`}
162
177
  >
163
178
  <section
164
- className={` flex flex-col rounded-[12px] bg-white px-[16px] py-[24px] sm:h-fit ${isMobile ? 'w-full' : ''}`}
179
+ className={` flex h-full flex-col rounded-[12px] bg-white px-[16px] py-[24px] sm:h-fit ${isMobile ? 'w-full' : ' justify-between xs:justify-start '}`}
165
180
  style={{ boxShadow: '0px 4px 10px 0px #00000026' }}
166
181
  >
167
182
  {/* 해당 컴포넌트의 최상위 부모와 브라우저 상단과 닿았을 때 우선적으로 해당 부분의 높이가 먼저 줄어들게 하고 싶다*/}
168
183
  <div className="relative">
169
184
  <div
170
185
  ref={containerRef}
171
- className={`no-scrollbar flex max-h-[210px] min-h-[80px] flex-col overflow-auto`}
172
- style={{ maxHeight: `${contentHeight}px` }}
186
+ className={`flex min-h-[80px] flex-col ${isMobile ? 'overflow-y-auto ' : ''} overlay-scrollbar`}
187
+ style={{
188
+ maxHeight: `${contentHeight}px`,
189
+ ...(!isMobile ? hoverStyle : {})
190
+ }}
173
191
  >
174
192
  <div className="flex items-center gap-[10px]">
175
193
  {inquiryMainData?.channel_logo_image_url ? (
@@ -193,26 +211,28 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
193
211
  {isScroll && !isBottom && <ShadowBox />}
194
212
  </div>
195
213
 
196
- <Button3
197
- onClick={handleStartChat}
198
- isDisabled={isLoading || !inquiryMainData?.channel_number}
199
- className="mt-[40px]"
200
- >
201
- <div className="flex items-center justify-center gap-[4px]">
202
- {!inquiryMainData?.channel_number ? (
203
- <div>{'로딩 중...'}</div>
204
- ) : (
205
- <div>{isLoading ? '로딩 중...' : '문의하기'}</div>
206
- )}
207
- {!isLoading && <SendIcon width={24} height={24} />}
208
- </div>
209
- </Button3>
214
+ <div className={`mt-[40px] `}>
215
+ <Button3
216
+ className={`w-full`}
217
+ onClick={handleStartChat}
218
+ isDisabled={isLoading || !inquiryMainData?.channel_number}
219
+ >
220
+ <div className="flex items-center justify-center gap-[4px]">
221
+ {!inquiryMainData?.channel_number ? (
222
+ <div>{'로딩 중...'}</div>
223
+ ) : (
224
+ <div>{isLoading ? '로딩 중...' : '문의하기'}</div>
225
+ )}
226
+ {!isLoading && <SendIcon width={24} height={24} />}
227
+ </div>
228
+ </Button3>
210
229
 
211
- <div className="flex items-center justify-center gap-[4px] pt-[20px]">
212
- <InfoIcon width={20} height={20} />
213
- <span className="dr_talk_body_small1 text-drTalkGrayscale2">
214
- {inquiryMainData?.answer_speed_message || '빠르게 답변 받으실 수 있어요'}
215
- </span>
230
+ <div className="flex items-center justify-center gap-[4px] pt-[20px]">
231
+ <InfoIcon width={20} height={20} />
232
+ <span className="dr_talk_body_small1 text-drTalkGrayscale2">
233
+ {inquiryMainData?.answer_speed_message || '빠르게 답변 받으실 수 있어요'}
234
+ </span>
235
+ </div>
216
236
  </div>
217
237
  </section>
218
238
  </div>
@@ -0,0 +1,18 @@
1
+ import { RefObject, CSSProperties } from 'react';
2
+ type MaybeRef = RefObject<HTMLElement> | undefined;
3
+ /**
4
+ * useHoverScrollbar (scrollbar-gutter 완전 해결)
5
+ * - scrollbar-gutter: stable로 항상 스크롤바 공간 확보
6
+ * - 가로 밀림 현상 완전 방지
7
+ */
8
+ export declare function useHoverScrollbar(refParam?: MaybeRef): {
9
+ ref: RefObject<HTMLDivElement>;
10
+ style: CSSProperties;
11
+ };
12
+ export {};
13
+ /**
14
+ * useHoverScrollbar
15
+ * - 외부 ref를 주입(ref 파라미터)하거나, 없으면 내부 ref 생성
16
+ * - hover 중이고 스크롤이 있으면 overflow-y: auto, 아니면 hidden
17
+ * - 레이아웃 밀림 방지용 margin/padding 트릭 적용
18
+ */
@@ -0,0 +1,110 @@
1
+ // useHoverScrollbar.ts
2
+ import { useRef, useState, useEffect } from 'react';
3
+ /**
4
+ * useHoverScrollbar (scrollbar-gutter 완전 해결)
5
+ * - scrollbar-gutter: stable로 항상 스크롤바 공간 확보
6
+ * - 가로 밀림 현상 완전 방지
7
+ */
8
+ export function useHoverScrollbar(refParam) {
9
+ const localRef = useRef(null);
10
+ const ref = refParam || localRef;
11
+ const [hovered, setHovered] = useState(false);
12
+ const [hasScroll, setHasScroll] = useState(false);
13
+ // 스크롤 여부 체크
14
+ useEffect(() => {
15
+ const el = ref.current;
16
+ if (!el)
17
+ return;
18
+ const checkScroll = () => {
19
+ setHasScroll(el.scrollHeight > el.clientHeight);
20
+ };
21
+ checkScroll();
22
+ // ResizeObserver로 더 정확한 감지
23
+ const resizeObserver = new ResizeObserver(checkScroll);
24
+ resizeObserver.observe(el);
25
+ window.addEventListener('resize', checkScroll);
26
+ return () => {
27
+ resizeObserver.disconnect();
28
+ window.removeEventListener('resize', checkScroll);
29
+ };
30
+ }, [ref]);
31
+ // 호버 상태 관리
32
+ useEffect(() => {
33
+ const el = ref.current;
34
+ if (!el)
35
+ return;
36
+ const onEnter = () => setHovered(true);
37
+ const onLeave = () => setHovered(false);
38
+ el.addEventListener('mouseenter', onEnter);
39
+ el.addEventListener('mouseleave', onLeave);
40
+ return () => {
41
+ el.removeEventListener('mouseenter', onEnter);
42
+ el.removeEventListener('mouseleave', onLeave);
43
+ };
44
+ }, [ref]);
45
+ const style = {
46
+ overflowY: hovered && hasScroll ? 'auto' : 'hidden',
47
+ // 항상 스크롤바 공간을 확보 (최신 브라우저)
48
+ scrollbarGutter: 'stable' //15px
49
+ };
50
+ return { ref, style };
51
+ }
52
+ // useHoverScrollbar.ts
53
+ // import { useRef, useState, useEffect, RefObject, CSSProperties } from 'react';
54
+ //
55
+ // type MaybeRef = RefObject<HTMLElement> | undefined;
56
+ /**
57
+ * useHoverScrollbar
58
+ * - 외부 ref를 주입(ref 파라미터)하거나, 없으면 내부 ref 생성
59
+ * - hover 중이고 스크롤이 있으면 overflow-y: auto, 아니면 hidden
60
+ * - 레이아웃 밀림 방지용 margin/padding 트릭 적용
61
+ */
62
+ // export function useHoverScrollbar(refParam?: MaybeRef): {
63
+ // ref: RefObject<HTMLDivElement>;
64
+ // style: CSSProperties;
65
+ // } {
66
+ // // 1) 내부 ref 준비
67
+ // const localRef = useRef<HTMLDivElement>(null);
68
+ // // 2) 실제 사용할 ref는 외부에서 안 들어오면 localRef
69
+ // const ref = (refParam as RefObject<HTMLDivElement>) || localRef;
70
+ //
71
+ // const [hovered, setHovered] = useState(false);
72
+ // const [hasScroll, setHasScroll] = useState(false);
73
+ // const [scrollbarWidth, setScrollbarWidth] = useState(0);
74
+ //
75
+ // // 3) 요소에 스크롤이 있는지, scrollbarWidth 계산
76
+ // useEffect(() => {
77
+ // const el = ref.current;
78
+ // if (!el) return;
79
+ // const calc = () => {
80
+ // setHasScroll(el.scrollHeight > el.clientHeight);
81
+ // setScrollbarWidth(el.offsetWidth - el.clientWidth);
82
+ // };
83
+ // calc();
84
+ // window.addEventListener('resize', calc);
85
+ // return () => window.removeEventListener('resize', calc);
86
+ // }, [ref]);
87
+ //
88
+ // // 4) hover 상태 관리
89
+ // useEffect(() => {
90
+ // const el = ref.current;
91
+ // if (!el) return;
92
+ // const onEnter = () => setHovered(true);
93
+ // const onLeave = () => setHovered(false);
94
+ // el.addEventListener('mouseenter', onEnter);
95
+ // el.addEventListener('mouseleave', onLeave);
96
+ // return () => {
97
+ // el.removeEventListener('mouseenter', onEnter);
98
+ // el.removeEventListener('mouseleave', onLeave);
99
+ // };
100
+ // }, [ref]);
101
+ //
102
+ // // 5) 최종 style
103
+ // const style: CSSProperties = {
104
+ // overflowY: hovered && hasScroll ? 'auto' : 'hidden',
105
+ // marginRight: hovered && hasScroll ? `-${scrollbarWidth}px` : undefined,
106
+ // paddingRight: hovered && hasScroll ? `${scrollbarWidth}px` : undefined
107
+ // };
108
+ //
109
+ // return { ref, style };
110
+ // }