Spaces:
Running
Running
File size: 6,048 Bytes
df62a7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | class BottomNav extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: white;
border-top: 1px solid #e5e7eb;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
z-index: 50;
}
.nav-container {
max-width: 480px;
margin: 0 auto;
display: flex;
justify-content: space-around;
padding: 8px 0;
}
.nav-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
padding: 8px 4px;
text-decoration: none;
color: #6b7280;
transition: all 0.3s ease;
cursor: pointer;
position: relative;
}
.nav-item.active {
color: #6366f1;
}
.nav-item:hover {
color: #6366f1;
}
.nav-item i {
width: 24px;
height: 24px;
margin-bottom: 4px;
}
.nav-label {
font-size: 11px;
font-weight: 500;
}
.pulse-dot {
position: absolute;
top: 8px;
right: calc(50% - 20px);
width: 8px;
height: 8px;
background: #ef4444;
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
}
}
</style>
<div class="bottom-nav">
<div class="nav-container">
<a href="#dashboard" class="nav-item active" data-page="dashboard">
<i data-feather="home"></i>
<span class="nav-label">วันนี้</span>
</a>
<a href="#sleep" class="nav-item" data-page="sleep">
<i data-feather="moon"></i>
<span class="nav-label">นอน</span>
</a>
<a href="#activity" class="nav-item" data-page="activity">
<i data-feather="activity"></i>
<span class="nav-label">กิจกรรม</span>
</a>
<a href="#nutrition" class="nav-item" data-page="nutrition">
<i data-feather="coffee"></i>
<span class="nav-label">โภชนาการ</span>
</a>
<a href="#mental" class="nav-item" data-page="mental">
<i data-feather="heart"></i>
<span class="nav-label">จิตใจ</span>
<div class="pulse-dot"></div>
</a>
</div>
</div>
`;
// Add click event listeners
this.shadowRoot.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', (e) => {
e.preventDefault();
const targetId = item.getAttribute('href').substring(1);
// Update active state
this.shadowRoot.querySelectorAll('.nav-item').forEach(navItem => {
navItem.classList.remove('active');
});
item.classList.add('active');
// Navigate to page
navigateToPage(targetId);
});
});
}
}
customElements.define('bottom-nav', BottomNav);
function navigateToPage(pageId) {
// Hide all pages
document.querySelectorAll('.page-content').forEach(page => {
page.classList.remove('active');
});
// Show target page
const targetPage = document.getElementById(pageId);
if (targetPage) {
targetPage.classList.add('active');
}
// Update URL hash
window.location.hash = pageId;
// Scroll to top
window.scrollTo(0, 0);
}
// Handle browser back/forward buttons
window.addEventListener('popstate', function() {
const hash = window.location.hash.substring(1);
if (hash) {
navigateToPage(hash);
// Update bottom nav active state
document.querySelectorAll('bottom-nav .nav-item').forEach(item => {
item.classList.remove('active');
if (item.getAttribute('href') === '#' + hash) {
item.classList.add('active');
}
});
}
});
// Set initial page based on URL hash
window.addEventListener('load', function() {
const hash = window.location.hash.substring(1) || 'dashboard';
navigateToPage(hash);
// Update bottom nav active state
document.querySelectorAll('bottom-nav .nav-item').forEach(item => {
item.classList.remove('active');
if (item.getAttribute('href') === '#' + hash) {
item.classList.add('active');
}
});
}); |