@sonhoseong/mfa-lib 1.2.3 → 1.2.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StickyNav.d.ts","sourceRoot":"","sources":["../../../src/components/navigation/StickyNav.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB;IACjB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"StickyNav.d.ts","sourceRoot":"","sources":["../../../src/components/navigation/StickyNav.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB;IACjB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwM9C,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect, useCallback } from 'react';
|
|
3
|
-
export const StickyNav = ({ sections, triggerPoint = 0.2, scrollOffset = 80, topPosition = 20, onLogoClick, showLogo = true, className = '' }) => {
|
|
3
|
+
export const StickyNav = ({ sections, triggerPoint = 0.2, scrollOffset = 80, topPosition = 20, onLogoClick, showLogo = true, className = '', updateHash = true }) => {
|
|
4
4
|
const [activeSection, setActiveSection] = useState('');
|
|
5
5
|
const [hoveredSection, setHoveredSection] = useState(null);
|
|
6
|
-
//
|
|
6
|
+
// 초기 로드 시 hash가 있으면 해당 섹션으로 스크롤 + hashchange 이벤트 처리
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const scrollToHash = () => {
|
|
9
|
+
if (window.location.hash) {
|
|
10
|
+
const id = window.location.hash.slice(1);
|
|
11
|
+
const element = document.getElementById(id);
|
|
12
|
+
if (element) {
|
|
13
|
+
const elementPosition = element.getBoundingClientRect().top;
|
|
14
|
+
const offsetPosition = elementPosition + window.pageYOffset - scrollOffset;
|
|
15
|
+
window.scrollTo({ top: offsetPosition, behavior: 'smooth' });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
// 초기 로드
|
|
20
|
+
if (updateHash && window.location.hash) {
|
|
21
|
+
setTimeout(scrollToHash, 100);
|
|
22
|
+
}
|
|
23
|
+
// 브라우저 뒤로/앞으로 버튼 처리
|
|
24
|
+
if (updateHash) {
|
|
25
|
+
window.addEventListener('hashchange', scrollToHash);
|
|
26
|
+
return () => window.removeEventListener('hashchange', scrollToHash);
|
|
27
|
+
}
|
|
28
|
+
}, [updateHash, scrollOffset]);
|
|
29
|
+
// Scroll spy - 스크롤 시 active section 업데이트 + hash 업데이트
|
|
7
30
|
useEffect(() => {
|
|
8
31
|
const handleScroll = () => {
|
|
9
32
|
const viewportHeight = window.innerHeight;
|
|
@@ -13,7 +36,13 @@ export const StickyNav = ({ sections, triggerPoint = 0.2, scrollOffset = 80, top
|
|
|
13
36
|
if (element) {
|
|
14
37
|
const rect = element.getBoundingClientRect();
|
|
15
38
|
if (rect.top <= trigger && rect.bottom > trigger) {
|
|
16
|
-
|
|
39
|
+
if (activeSection !== section.id) {
|
|
40
|
+
setActiveSection(section.id);
|
|
41
|
+
// 스크롤 시에도 hash 업데이트 (pushState로 히스토리 쌓지 않음)
|
|
42
|
+
if (updateHash) {
|
|
43
|
+
window.history.replaceState(null, '', `#${section.id}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
17
46
|
break;
|
|
18
47
|
}
|
|
19
48
|
}
|
|
@@ -22,15 +51,19 @@ export const StickyNav = ({ sections, triggerPoint = 0.2, scrollOffset = 80, top
|
|
|
22
51
|
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
23
52
|
handleScroll();
|
|
24
53
|
return () => window.removeEventListener('scroll', handleScroll);
|
|
25
|
-
}, [sections, triggerPoint]);
|
|
54
|
+
}, [sections, triggerPoint, activeSection, updateHash]);
|
|
26
55
|
const scrollToSection = useCallback((id) => {
|
|
27
56
|
const element = document.getElementById(id);
|
|
28
57
|
if (element) {
|
|
58
|
+
// URL hash 업데이트 (pushState로 히스토리에 추가)
|
|
59
|
+
if (updateHash) {
|
|
60
|
+
window.history.pushState(null, '', `#${id}`);
|
|
61
|
+
}
|
|
29
62
|
const elementPosition = element.getBoundingClientRect().top;
|
|
30
63
|
const offsetPosition = elementPosition + window.pageYOffset - scrollOffset;
|
|
31
64
|
window.scrollTo({ top: offsetPosition, behavior: 'smooth' });
|
|
32
65
|
}
|
|
33
|
-
}, [scrollOffset]);
|
|
66
|
+
}, [scrollOffset, updateHash]);
|
|
34
67
|
const handleLogoClick = useCallback(() => {
|
|
35
68
|
if (onLogoClick) {
|
|
36
69
|
onLogoClick();
|
|
@@ -54,7 +87,7 @@ export const StickyNav = ({ sections, triggerPoint = 0.2, scrollOffset = 80, top
|
|
|
54
87
|
alignItems: 'center',
|
|
55
88
|
gap: '4px',
|
|
56
89
|
padding: '6px',
|
|
57
|
-
background: 'rgba(255, 255, 255, 0.
|
|
90
|
+
background: 'rgba(255, 255, 255, 0.88)',
|
|
58
91
|
backdropFilter: 'blur(12px)',
|
|
59
92
|
WebkitBackdropFilter: 'blur(12px)',
|
|
60
93
|
borderRadius: '50px',
|