@daeryun/dr_components 0.1.9 → 0.1.11
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.
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/MapFix/AreaImage.d.ts +10 -0
- package/dist/components/MapFix/AreaImage.jsx +39 -0
- package/dist/components/MapFix/AreaImage.tsx +94 -0
- package/dist/components/MapFix/MapFix.d.ts +11 -0
- package/dist/components/MapFix/MapFix.jsx +108 -0
- package/dist/components/MapFix/MapFix.tsx +173 -0
- package/dist/components/banner/TopBanner.d.ts +4 -0
- package/dist/components/banner/TopBanner.jsx +239 -0
- package/dist/components/banner/TopBanner.module.css +111 -0
- package/dist/components/banner/TopBanner.tsx +341 -0
- package/dist/components/common/index.d.ts +1 -13
- package/dist/components/common/index.js +144 -191
- package/dist/components/common/index.ts +148 -210
- package/dist/components/index.js +1 -4
- package/dist/components/index.ts +1 -4
- package/dist/lib/utils.d.ts +7 -17
- package/dist/lib/utils.js +195 -126
- package/dist/lib/utils.ts +185 -119
- package/dist/styles/globals.css +277 -13
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/dist/components/Cat/index.d.ts +0 -3
- package/dist/components/Cat/index.jsx +0 -9
- package/dist/components/Cat/index.tsx +0 -19
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import style from './TopBanner.module.css';
|
|
2
|
+
import { useEffect, useState, useCallback } from 'react';
|
|
3
|
+
import 'swiper/css';
|
|
4
|
+
import { Swiper, SwiperSlide } from 'swiper/react';
|
|
5
|
+
import { Autoplay } from 'swiper/modules';
|
|
6
|
+
import Image from 'next/image';
|
|
7
|
+
import { useQuery } from 'react-query';
|
|
8
|
+
import { isCurrentTimeWithinPopupRange, paramFetch } from '../../lib';
|
|
9
|
+
import { DateTime } from 'luxon';
|
|
10
|
+
import classNames from 'classnames';
|
|
11
|
+
|
|
12
|
+
//배너타입
|
|
13
|
+
interface IBannerTypes {
|
|
14
|
+
color_code: string;
|
|
15
|
+
days: number[];
|
|
16
|
+
end_at: string;
|
|
17
|
+
file_alt: string;
|
|
18
|
+
file_path: string;
|
|
19
|
+
file_type: string;
|
|
20
|
+
idx: number;
|
|
21
|
+
is_show: boolean;
|
|
22
|
+
link_type: string;
|
|
23
|
+
p_link: string;
|
|
24
|
+
p_sort: number;
|
|
25
|
+
save_file_name: string;
|
|
26
|
+
start_at: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const TopBanner = () => {
|
|
30
|
+
//이미지 패스
|
|
31
|
+
const ImagePath: string = process.env.NEXT_PUBLIC_S3_URL + '';
|
|
32
|
+
|
|
33
|
+
//팝업 리스트
|
|
34
|
+
const [popup, setPopup] = useState<IBannerTypes[]>([]);
|
|
35
|
+
const [isTop, setIsTop] = useState(true);
|
|
36
|
+
|
|
37
|
+
const addClickCnt = (idx: number) => {
|
|
38
|
+
paramFetch('https://mng.daeryunlaw.com/api/popup/top/click', { idx: idx }, null);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleScroll = useCallback(() => {
|
|
42
|
+
const scrollElm: Element | null = document.scrollingElement;
|
|
43
|
+
if (scrollElm !== null) {
|
|
44
|
+
const scrollTop: number = Math.max(scrollElm.scrollTop, document.body.scrollTop);
|
|
45
|
+
if (scrollTop > 0) {
|
|
46
|
+
setIsTop(false);
|
|
47
|
+
} else {
|
|
48
|
+
setIsTop(true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const handleScroll = () => {
|
|
55
|
+
setIsTop(window.scrollY <= 0);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Add scroll event listener
|
|
59
|
+
window.addEventListener('scroll', handleScroll);
|
|
60
|
+
|
|
61
|
+
// Remove scroll event listener on component unmount
|
|
62
|
+
return () => {
|
|
63
|
+
window.removeEventListener('scroll', handleScroll);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setIsTop(true);
|
|
69
|
+
document.addEventListener('scroll', handleScroll);
|
|
70
|
+
return () => {
|
|
71
|
+
document.removeEventListener('scroll', handleScroll); //clean up
|
|
72
|
+
};
|
|
73
|
+
}, [handleScroll]);
|
|
74
|
+
|
|
75
|
+
//userQuery
|
|
76
|
+
useQuery({
|
|
77
|
+
queryKey: ['popUpImg'],
|
|
78
|
+
queryFn: () => getPopUpData(),
|
|
79
|
+
//브라우저 화면을 focus할 때 새로 api를 호출할 건지 설정하는 옵션
|
|
80
|
+
refetchOnWindowFocus: false,
|
|
81
|
+
//기본설정 cacheTime:5분, staleTime:0초, 값을 Infinity로 설정할 경우 api return 값이 바뀌지 않는 이상 서버에 새로 요청하지 않고 캐싱된 데이터를 영구적으로 사용하여 api 호출 최적화
|
|
82
|
+
cacheTime: Infinity,
|
|
83
|
+
staleTime: Infinity,
|
|
84
|
+
onSuccess: (res: { list: any[] }) => {
|
|
85
|
+
const kstDateTime = DateTime.now().setZone('Asia/Seoul');
|
|
86
|
+
const nowDate = Number(
|
|
87
|
+
kstDateTime.year + '' + zeroMaker(kstDateTime.month) + '' + zeroMaker(kstDateTime.day)
|
|
88
|
+
);
|
|
89
|
+
const nowTime = Number(zeroMaker(kstDateTime.hour) + zeroMaker(kstDateTime.minute));
|
|
90
|
+
const weekday = kstDateTime.weekdayShort + '';
|
|
91
|
+
const dateData = res.list.filter(
|
|
92
|
+
(item: any) =>
|
|
93
|
+
findDate(item, 'start') <= nowDate &&
|
|
94
|
+
findDate(item, 'end') >= nowDate &&
|
|
95
|
+
findDays(item, weekday) &&
|
|
96
|
+
findTime(item, nowTime)
|
|
97
|
+
);
|
|
98
|
+
setPopup(
|
|
99
|
+
dateData.filter(
|
|
100
|
+
(item: IBannerTypes) =>
|
|
101
|
+
!(
|
|
102
|
+
localStorage.getItem(item.idx + '_CloseTopPop') &&
|
|
103
|
+
Number(localStorage.getItem(item.idx + '_CloseTopPop')) > new Date().getTime()
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const findDays = (item: any, today: string) => {
|
|
111
|
+
if (item.days) {
|
|
112
|
+
return item.days.includes(today);
|
|
113
|
+
} else {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const findDate = (item: any, key: string) => {
|
|
119
|
+
if (key === 'start') {
|
|
120
|
+
const start = new Date(item.start_at).toISOString().split('T');
|
|
121
|
+
return Number(start[0].split('-')[0] + start[0].split('-')[1] + start[0].split('-')[2]);
|
|
122
|
+
} else {
|
|
123
|
+
const end = new Date(item.end_at).toISOString().split('T');
|
|
124
|
+
return Number(end[0].split('-')[0] + end[0].split('-')[1] + end[0].split('-')[2]);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const findTime = (item: any, nowTime: number) => {
|
|
129
|
+
if (item.start_hour === null || item.start_min === null || item.end_hour === null || item.end_min === null) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const start = Number(zeroMaker(item.start_hour) + zeroMaker(item.start_min));
|
|
134
|
+
const end = Number(zeroMaker(item.end_hour) + zeroMaker(item.end_min));
|
|
135
|
+
if (start < end) {
|
|
136
|
+
if (start <= nowTime && end >= nowTime) {
|
|
137
|
+
return true;
|
|
138
|
+
} else {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
if (nowTime >= start) {
|
|
143
|
+
return true;
|
|
144
|
+
} else if (nowTime <= end) {
|
|
145
|
+
return true;
|
|
146
|
+
} else {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const zeroMaker = (x: number) => {
|
|
153
|
+
if (x.toString().length == 1) {
|
|
154
|
+
return '0' + x.toString();
|
|
155
|
+
} else {
|
|
156
|
+
return x.toString();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//데이터 패칭 함수
|
|
161
|
+
const getPopUpData = async () => {
|
|
162
|
+
const response = await fetch('/api/popup/top/list');
|
|
163
|
+
return await response.json();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
//data.list에서 해당 idx를 삭제하는 함수
|
|
167
|
+
const filterClose = (idx: number) => {
|
|
168
|
+
const filterData = popup.filter((item: IBannerTypes) => item.idx !== idx);
|
|
169
|
+
setPopup(filterData);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//스토리지 저장
|
|
173
|
+
const addCookie = (idx: number) => {
|
|
174
|
+
//내일 현재시간까지
|
|
175
|
+
const nowDate = new Date();
|
|
176
|
+
const expires = nowDate.setHours(nowDate.getHours() + 24);
|
|
177
|
+
localStorage.setItem(idx + '_CloseTopPop', String(expires));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// //query보다 먼저 실행
|
|
181
|
+
// useEffect(() => {
|
|
182
|
+
// if (typeof localStorage != 'undefined') {
|
|
183
|
+
// // 저장된 값은 제외
|
|
184
|
+
// const newInit = initData.filter((item) => !localStorage.getItem(item.idx + '_CloseTopPop'))
|
|
185
|
+
// setPopup(newInit)
|
|
186
|
+
// }
|
|
187
|
+
// }, [])
|
|
188
|
+
|
|
189
|
+
// console.log(currentHours, currentMinutes)
|
|
190
|
+
// 팝업이 뜨는 시간 조정
|
|
191
|
+
// const startHour =7 //팝업시작 시간의 '시'
|
|
192
|
+
// const startMin = 2//팝업시작 시간의 '분'
|
|
193
|
+
// const endHour = 8//팝업종료 시간의 '시'
|
|
194
|
+
// const endMin = 50//팝업종료 시간의 '분'
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<>
|
|
198
|
+
<div className={style.header_banner_wrap}>
|
|
199
|
+
{/*pc*/}
|
|
200
|
+
<div className={style.header_banner}>
|
|
201
|
+
<Swiper
|
|
202
|
+
autoplay={{ delay: 5000 }}
|
|
203
|
+
modules={[Autoplay]}
|
|
204
|
+
loop={popup.filter(item => item.file_type === 'file_pc').length > 1}
|
|
205
|
+
>
|
|
206
|
+
{popup.length > 0 ? (
|
|
207
|
+
popup
|
|
208
|
+
.filter(
|
|
209
|
+
(item: any) =>
|
|
210
|
+
item.file_type === 'file_pc' &&
|
|
211
|
+
isCurrentTimeWithinPopupRange(
|
|
212
|
+
item.days,
|
|
213
|
+
item.startHour,
|
|
214
|
+
item.startMin,
|
|
215
|
+
item.endHour,
|
|
216
|
+
item.endMin
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
.map((item: IBannerTypes, index: number) => {
|
|
220
|
+
// {popup.length > 0 ? popup.filter((item: IBannerTypes) => item.file_type === 'file_pc').map((item: IBannerTypes, index: number) => {
|
|
221
|
+
return (
|
|
222
|
+
<SwiperSlide key={index}>
|
|
223
|
+
<div className={style.header_banner_btn}>
|
|
224
|
+
<button
|
|
225
|
+
onClick={() => {
|
|
226
|
+
filterClose(item.idx);
|
|
227
|
+
addCookie(item.idx);
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
하루동안 보지않기
|
|
231
|
+
</button>
|
|
232
|
+
<button
|
|
233
|
+
onClick={() => {
|
|
234
|
+
filterClose(item.idx);
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
<Image
|
|
238
|
+
src="/images/banner_btn.webp"
|
|
239
|
+
alt="대륜 배너 이미지"
|
|
240
|
+
width={42}
|
|
241
|
+
height={42}
|
|
242
|
+
/>
|
|
243
|
+
</button>
|
|
244
|
+
</div>
|
|
245
|
+
<div
|
|
246
|
+
className={style.banner_block}
|
|
247
|
+
style={{ background: `#${item.color_code}` }}
|
|
248
|
+
>
|
|
249
|
+
<a
|
|
250
|
+
href={item.p_link}
|
|
251
|
+
target={item.link_type}
|
|
252
|
+
onClick={() => {
|
|
253
|
+
addClickCnt(item.idx);
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<Image
|
|
257
|
+
src={ImagePath + item.file_path + '/' + item.save_file_name}
|
|
258
|
+
alt={item.file_alt}
|
|
259
|
+
width={2000}
|
|
260
|
+
height={60}
|
|
261
|
+
priority={true}
|
|
262
|
+
quality={100}
|
|
263
|
+
loading={'eager'}
|
|
264
|
+
/>
|
|
265
|
+
{/*<Image src={"/images/대표메인_팝업_PC.jpg"} alt={item.file_alt} width={1920} height={50} priority={true} />*/}
|
|
266
|
+
</a>
|
|
267
|
+
</div>
|
|
268
|
+
</SwiperSlide>
|
|
269
|
+
);
|
|
270
|
+
})
|
|
271
|
+
) : (
|
|
272
|
+
<></>
|
|
273
|
+
)}
|
|
274
|
+
</Swiper>
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
{/*mobile*/}
|
|
278
|
+
<div
|
|
279
|
+
className={classNames({
|
|
280
|
+
[style.header_banner_m]: true,
|
|
281
|
+
[style.header_banner_fix]: isTop === true ? true : false
|
|
282
|
+
})}
|
|
283
|
+
>
|
|
284
|
+
<Swiper
|
|
285
|
+
autoplay={{ delay: 5000 }}
|
|
286
|
+
modules={[Autoplay]}
|
|
287
|
+
loop={popup.filter((item: IBannerTypes) => item.file_type === 'file_mobile').length > 1}
|
|
288
|
+
>
|
|
289
|
+
{popup.length > 0 ? (
|
|
290
|
+
popup
|
|
291
|
+
.filter((item: IBannerTypes) => item.file_type === 'file_mobile')
|
|
292
|
+
.map((item: IBannerTypes, index: number) => {
|
|
293
|
+
return (
|
|
294
|
+
<SwiperSlide key={index}>
|
|
295
|
+
<div className={style.header_banner_m_btn}>
|
|
296
|
+
<button
|
|
297
|
+
onClick={() => {
|
|
298
|
+
filterClose(item.idx);
|
|
299
|
+
addCookie(item.idx);
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
하루동안 보지않기
|
|
303
|
+
</button>
|
|
304
|
+
<button
|
|
305
|
+
onClick={() => {
|
|
306
|
+
filterClose(item.idx);
|
|
307
|
+
}}
|
|
308
|
+
>
|
|
309
|
+
닫기
|
|
310
|
+
</button>
|
|
311
|
+
</div>
|
|
312
|
+
<div className={style.banner_block_m}>
|
|
313
|
+
<a href={item.p_link} target={item.link_type}>
|
|
314
|
+
<Image
|
|
315
|
+
src={ImagePath + item.file_path + '/' + item.save_file_name}
|
|
316
|
+
alt={item.file_alt}
|
|
317
|
+
width={900}
|
|
318
|
+
height={150}
|
|
319
|
+
priority={true}
|
|
320
|
+
onClick={() => {
|
|
321
|
+
addClickCnt(item.idx);
|
|
322
|
+
}}
|
|
323
|
+
quality={100}
|
|
324
|
+
/>
|
|
325
|
+
{/*<Image src={"/images/대표메인_팝업_900.jpg"} alt={item.file_alt} width={900} height={70} priority={true} />*/}
|
|
326
|
+
</a>
|
|
327
|
+
</div>
|
|
328
|
+
</SwiperSlide>
|
|
329
|
+
);
|
|
330
|
+
})
|
|
331
|
+
) : (
|
|
332
|
+
<></>
|
|
333
|
+
)}
|
|
334
|
+
</Swiper>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
</>
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export default TopBanner;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export interface IMapArea {
|
|
3
2
|
[region: string]: Array<{
|
|
4
3
|
name: string;
|
|
@@ -7,18 +6,7 @@ export interface IMapArea {
|
|
|
7
6
|
src: string;
|
|
8
7
|
}>;
|
|
9
8
|
}
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const mobileMapArea: IMapArea;
|
|
12
|
-
export declare const MapPoints: {
|
|
13
|
-
name: string;
|
|
14
|
-
province: string;
|
|
15
|
-
position: React.CSSProperties;
|
|
16
|
-
}[];
|
|
17
|
-
export declare const MobileMapPoints: {
|
|
18
|
-
name: string;
|
|
19
|
-
province: string;
|
|
20
|
-
position: React.CSSProperties;
|
|
21
|
-
}[];
|
|
9
|
+
export declare const newNapAreaMobile: IMapArea;
|
|
22
10
|
export declare const centerListExample: ({
|
|
23
11
|
code: string;
|
|
24
12
|
code_name: string;
|