@daeryun/dr_components 1.0.73 → 1.0.75

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.
@@ -7,12 +7,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useCallback, useEffect } from 'react';
10
+ import React, { useCallback, useEffect, useState } from 'react';
11
11
  import { useDaeryuntalk } from './DaeryuntalkContext';
12
12
  import useBrowser from '../hook/useBrowser';
13
13
  const ChatButton = ({ isOpen, onClick, apiVersion, isMobile = false, hashValue = null, bannerHeight = 0 }) => {
14
14
  const { initializeDaeryuntalk, centerCode } = useDaeryuntalk();
15
15
  const { width } = useBrowser(true);
16
+ const [isScrollTop, setIsScrollTop] = useState(true);
17
+ useEffect(() => {
18
+ const handleScroll = () => {
19
+ const scrollTop = window.scrollY || document.documentElement.scrollTop;
20
+ setIsScrollTop(scrollTop === 0);
21
+ };
22
+ handleScroll();
23
+ window.addEventListener('scroll', handleScroll);
24
+ return () => {
25
+ window.removeEventListener('scroll', handleScroll);
26
+ };
27
+ }, []);
16
28
  const handleClick = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
17
29
  onClick();
18
30
  if (!isOpen) {
@@ -39,14 +51,20 @@ const ChatButton = ({ isOpen, onClick, apiVersion, isMobile = false, hashValue =
39
51
  }
40
52
  }, [hashValue, apiVersion, initializeDaeryuntalk]);
41
53
  return (<button aria-label="채팅 상담 열기" onClick={handleClick} style={{
42
- bottom: width >= 1024 ? (bannerHeight > 0 ? `${bannerHeight + 20}px` : '20px') : '88px'
54
+ bottom: bannerHeight > 0 && (!isScrollTop || width >= 1024)
55
+ ? width >= 1024
56
+ ? `${bannerHeight + 20}px`
57
+ : `${bannerHeight + 78}px`
58
+ : width >= 1024
59
+ ? '20px'
60
+ : '88px'
43
61
  }} className={`
44
62
  ${isOpen ? 'hidden h-[50px] w-[50px] xs:block ' : 'h-[70px] w-[70px] 5xl:h-[100px] 5xl:w-[100px]'}
45
63
  ${hashValue ? 'pointer-events-none opacity-0' : ''}
46
64
  fixed right-[10px] rounded-[10px] border lg:right-[25px]
47
65
  ${isOpen ? 'border-gray-200 bg-white' : 'border-[#AA1D36] bg-[#AA1D36]'}
48
66
  z-[50] flex transform cursor-pointer items-center justify-center
49
- p-0 shadow-lg outline-none transition-[height,width] duration-300 ease-in-out
67
+ p-0 shadow-lg outline-none transition-all duration-300 ease-in-out
50
68
  hover:${isOpen ? 'bg-gray-100' : 'bg-[#8A1729]'}
51
69
  `}>
52
70
  {!isOpen && (<span style={{
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect } from 'react';
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
2
  import { useDaeryuntalk } from './DaeryuntalkContext';
3
3
  import useBrowser from '../hook/useBrowser';
4
4
 
@@ -21,6 +21,21 @@ const ChatButton: React.FC<ChatButtonProps> = ({
21
21
  }) => {
22
22
  const { initializeDaeryuntalk, centerCode } = useDaeryuntalk();
23
23
  const { width } = useBrowser(true);
24
+ const [isScrollTop, setIsScrollTop] = useState(true);
25
+
26
+ useEffect(() => {
27
+ const handleScroll = () => {
28
+ const scrollTop = window.scrollY || document.documentElement.scrollTop;
29
+ setIsScrollTop(scrollTop === 0);
30
+ };
31
+ handleScroll();
32
+
33
+ window.addEventListener('scroll', handleScroll);
34
+
35
+ return () => {
36
+ window.removeEventListener('scroll', handleScroll);
37
+ };
38
+ }, []);
24
39
 
25
40
  const handleClick = useCallback(async () => {
26
41
  onClick();
@@ -51,7 +66,14 @@ const ChatButton: React.FC<ChatButtonProps> = ({
51
66
  aria-label="채팅 상담 열기"
52
67
  onClick={handleClick}
53
68
  style={{
54
- bottom: width >= 1024 ? (bannerHeight > 0 ? `${bannerHeight + 20}px` : '20px') : '88px'
69
+ bottom:
70
+ bannerHeight > 0 && (!isScrollTop || width >= 1024)
71
+ ? width >= 1024
72
+ ? `${bannerHeight + 20}px`
73
+ : `${bannerHeight + 78}px`
74
+ : width >= 1024
75
+ ? '20px'
76
+ : '88px'
55
77
  }}
56
78
  className={`
57
79
  ${isOpen ? 'hidden h-[50px] w-[50px] xs:block ' : 'h-[70px] w-[70px] 5xl:h-[100px] 5xl:w-[100px]'}
@@ -59,7 +81,7 @@ const ChatButton: React.FC<ChatButtonProps> = ({
59
81
  fixed right-[10px] rounded-[10px] border lg:right-[25px]
60
82
  ${isOpen ? 'border-gray-200 bg-white' : 'border-[#AA1D36] bg-[#AA1D36]'}
61
83
  z-[50] flex transform cursor-pointer items-center justify-center
62
- p-0 shadow-lg outline-none transition-[height,width] duration-300 ease-in-out
84
+ p-0 shadow-lg outline-none transition-all duration-300 ease-in-out
63
85
  hover:${isOpen ? 'bg-gray-100' : 'bg-[#8A1729]'}
64
86
  `}
65
87
  >
@@ -1,3 +1,6 @@
1
1
  import 'swiper/css';
2
- declare const TopBanner: () => import("react").JSX.Element;
2
+ import { SetterOrUpdater } from 'recoil';
3
+ declare const TopBanner: ({ setBannerHeight }: {
4
+ setBannerHeight?: SetterOrUpdater<number>;
5
+ }) => import("react").JSX.Element;
3
6
  export default TopBanner;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  import style from './TopBanner.module.css';
12
- import { useEffect, useState } from 'react';
12
+ import { useEffect, useState, useRef } from 'react';
13
13
  import 'swiper/css';
14
14
  import { Swiper, SwiperSlide } from 'swiper/react';
15
15
  import { Autoplay } from 'swiper/modules';
@@ -83,10 +83,11 @@ import useBrowser from '../hook/useBrowser';
83
83
  // start_at: '2025-01-20T10:15:00.000Z'
84
84
  // }
85
85
  // ];
86
- const TopBanner = () => {
86
+ const TopBanner = ({ setBannerHeight }) => {
87
87
  //이미지 패스
88
88
  const ImagePath = process.env.NEXT_PUBLIC_S3_URL + '';
89
89
  const { width } = useBrowser();
90
+ const bannerRef = useRef(null);
90
91
  //팝업 리스트
91
92
  const [popup, setPopup] = useState([]);
92
93
  const addClickCnt = (idx) => {
@@ -122,6 +123,26 @@ const TopBanner = () => {
122
123
  // setPopup(POPUP_DUMMY);
123
124
  // console.log('popup : ', popup);
124
125
  // }, [popup]);
126
+ // 배너 높이
127
+ useEffect(() => {
128
+ const updateBannerHeight = () => {
129
+ if (bannerRef.current) {
130
+ const height = bannerRef.current.offsetHeight;
131
+ if (setBannerHeight)
132
+ setBannerHeight(height);
133
+ }
134
+ };
135
+ updateBannerHeight();
136
+ if (bannerRef.current && setBannerHeight) {
137
+ const resizeObserver = new ResizeObserver(() => {
138
+ updateBannerHeight();
139
+ });
140
+ resizeObserver.observe(bannerRef.current);
141
+ return () => {
142
+ resizeObserver.disconnect();
143
+ };
144
+ }
145
+ }, [setBannerHeight]);
125
146
  const findDays = (item, today) => {
126
147
  if (item.days) {
127
148
  return item.days.includes(today);
@@ -220,7 +241,7 @@ const TopBanner = () => {
220
241
  // const endHour = 8//팝업종료 시간의 '시'
221
242
  // const endMin = 50//팝업종료 시간의 '분'
222
243
  return (<>
223
- <div className={style.header_banner_wrap}>
244
+ <div ref={bannerRef} className={style.header_banner_wrap}>
224
245
  {/* pc */}
225
246
  {width > 900 && (<div className={style.header_banner}>
226
247
  {popup && popup.filter(item => item.file_type === 'file_pc').length > 0 ? (<Swiper autoplay={{ delay: 5000 }} modules={[Autoplay]} loop={popup.filter(item => item.file_type === 'file_pc').length > 1}>
@@ -2,7 +2,9 @@ import TopBanner from './TopBanner';
2
2
  import type { StoryObj } from '@storybook/react';
3
3
  import '../../styles/globals.css';
4
4
  declare const meta: {
5
- component: () => import("react").JSX.Element;
5
+ component: ({ setBannerHeight }: {
6
+ setBannerHeight?: import("recoil").SetterOrUpdater<number>;
7
+ }) => import("react").JSX.Element;
6
8
  title: string;
7
9
  };
8
10
  export default meta;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import style from './TopBanner.module.css';
4
- import { useEffect, useState, useCallback } from 'react';
4
+ import { useEffect, useState, useCallback, useRef } from 'react';
5
5
  import 'swiper/css';
6
6
  import { Swiper, SwiperSlide } from 'swiper/react';
7
7
  import { Autoplay } from 'swiper/modules';
@@ -12,6 +12,7 @@ import { DateTime } from 'luxon';
12
12
  import classNames from 'classnames';
13
13
  import Link from 'next/link';
14
14
  import useBrowser from '../hook/useBrowser';
15
+ import { SetterOrUpdater } from 'recoil';
15
16
 
16
17
  //배너타입
17
18
  interface IBannerTypes {
@@ -94,10 +95,11 @@ interface IBannerTypes {
94
95
  // }
95
96
  // ];
96
97
 
97
- const TopBanner = () => {
98
+ const TopBanner = ({ setBannerHeight }: { setBannerHeight?: SetterOrUpdater<number> }) => {
98
99
  //이미지 패스
99
100
  const ImagePath: string = process.env.NEXT_PUBLIC_S3_URL + '';
100
101
  const { width } = useBrowser();
102
+ const bannerRef = useRef<HTMLDivElement>(null);
101
103
 
102
104
  //팝업 리스트
103
105
  const [popup, setPopup] = useState<IBannerTypes[]>([]);
@@ -150,6 +152,27 @@ const TopBanner = () => {
150
152
  // console.log('popup : ', popup);
151
153
  // }, [popup]);
152
154
 
155
+ // 배너 높이
156
+ useEffect(() => {
157
+ const updateBannerHeight = () => {
158
+ if (bannerRef.current) {
159
+ const height = bannerRef.current.offsetHeight;
160
+ if (setBannerHeight) setBannerHeight(height);
161
+ }
162
+ };
163
+ updateBannerHeight();
164
+
165
+ if (bannerRef.current && setBannerHeight) {
166
+ const resizeObserver = new ResizeObserver(() => {
167
+ updateBannerHeight();
168
+ });
169
+ resizeObserver.observe(bannerRef.current);
170
+ return () => {
171
+ resizeObserver.disconnect();
172
+ };
173
+ }
174
+ }, [setBannerHeight]);
175
+
153
176
  const findDays = (item: any, today: string) => {
154
177
  if (item.days) {
155
178
  return item.days.includes(today);
@@ -253,7 +276,7 @@ const TopBanner = () => {
253
276
 
254
277
  return (
255
278
  <>
256
- <div className={style.header_banner_wrap}>
279
+ <div ref={bannerRef} className={style.header_banner_wrap}>
257
280
  {/* pc */}
258
281
  {width > 900 && (
259
282
  <div className={style.header_banner}>
@@ -8387,12 +8387,6 @@ html {
8387
8387
  transition-duration: 150ms;
8388
8388
  }
8389
8389
 
8390
- .transition-\[height\2c width\] {
8391
- transition-property: height,width;
8392
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
8393
- transition-duration: 150ms;
8394
- }
8395
-
8396
8390
  .transition-\[left\] {
8397
8391
  transition-property: left;
8398
8392
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);