|
1 | 1 | <script lang="ts"> |
2 | 2 | import { page } from '$app/stores'; |
3 | | - import { TOP_NAV, SUB_NAV, isActive, type NavItem, type NavGroup } from '$lib/constants/nav'; |
| 3 | + import { TOP_NAV, SUB_NAV, isActive, type NavItem, type NavGroup, isGroupWithActiveItem, isGroupWithActiveSubDropdown } from '$lib/constants/nav'; |
4 | 4 | import Icon from '$lib/components/global/Icon.svelte'; |
5 | 5 | import { navbarDisplay } from '$lib/stores/navbarDisplay'; |
6 | 6 | import { bookmarks } from '$lib/stores/bookmarks'; |
|
133 | 133 | > |
134 | 134 | <a |
135 | 135 | href={item.href} |
136 | | - class="nav-link {isActive(currentPath, item.href) ? 'active' : ''}" |
| 136 | + class="nav-link" |
| 137 | + class:active={isActive(currentPath, item.href)} |
| 138 | + class:dropdown-open={hasSubPages(item.href) && activeDropdown === item.href} |
137 | 139 | aria-current={isActive(currentPath, item.href) ? 'page' : undefined} |
138 | 140 | aria-expanded={activeDropdown === item.href} |
139 | 141 | aria-haspopup={hasSubPages(item.href)} |
|
182 | 184 | <!-- Nav group with secondary dropdown --> |
183 | 185 | <div |
184 | 186 | class="nav-group" |
| 187 | + class:active={isGroupWithActiveItem(currentPath, subItem)} |
| 188 | + class:dropdown-open={isGroupWithActiveSubDropdown(activeSubDropdown, subItem)} |
185 | 189 | class:has-secondary={subItem.items.length > 0} |
186 | 190 | role="menuitem" |
187 | 191 | tabindex="0" |
|
222 | 226 | {#each subItem.items.filter((i) => i.label) as groupItem (groupItem.href)} |
223 | 227 | <a |
224 | 228 | href={groupItem.href} |
225 | | - class="dropdown-link {isActive(currentPath, groupItem.href) ? 'active' : ''}" |
| 229 | + class="dropdown-link" |
| 230 | + class:active={isActive(currentPath, groupItem.href)} |
226 | 231 | aria-current={isActive(currentPath, groupItem.href) ? 'page' : undefined} |
227 | 232 | > |
228 | 233 | <div class="link-content"> |
|
296 | 301 | flex-shrink: 0; |
297 | 302 | } |
298 | 303 |
|
299 | | - &:hover { |
| 304 | + &:hover, |
| 305 | + &.dropdown-open { |
300 | 306 | color: var(--text-primary); |
301 | 307 | background: var(--surface-hover); |
302 | 308 | .dropdown-icon { |
|
325 | 331 | left: 0; |
326 | 332 | z-index: 5; |
327 | 333 | overflow: visible; |
| 334 | + margin-top: var(--spacing-sm); |
328 | 335 | } |
329 | 336 |
|
330 | 337 | .primary-dropdown { |
|
429 | 436 | padding-top: var(--spacing-xs); |
430 | 437 | border-top: 1px solid var(--border-secondary); |
431 | 438 | } |
432 | | -
|
| 439 | + |
| 440 | + &:has(+ .dropdown-link) { |
| 441 | + margin-bottom: var(--spacing-xs); |
| 442 | + padding-bottom: var(--spacing-xs); |
| 443 | + border-bottom: 1px solid var(--border-secondary); |
| 444 | + } |
| 445 | + |
| 446 | + &.has-secondary, |
| 447 | + &.active { |
| 448 | + .group-title { |
| 449 | + padding: var(--spacing-sm) var(--spacing-md); |
| 450 | + border-radius: var(--radius-md); |
| 451 | + } |
| 452 | + } |
| 453 | + |
433 | 454 | &.has-secondary { |
434 | 455 | cursor: pointer; |
435 | | -
|
| 456 | + |
436 | 457 | .group-title { |
437 | | - border-radius: var(--radius-md); |
438 | 458 | transition: background-color 0.15s ease; |
439 | | -
|
| 459 | + |
440 | 460 | &:hover { |
441 | 461 | background: var(--surface-hover); |
442 | 462 | } |
443 | 463 | } |
444 | 464 | } |
| 465 | +
|
| 466 | + &.dropdown-open { |
| 467 | + .group-title { |
| 468 | + transition: background-color none; |
| 469 | + background: var(--surface-hover); |
| 470 | + } |
| 471 | + } |
| 472 | +
|
| 473 | + &.active { |
| 474 | + .group-title { |
| 475 | + color: var(--color-primary); |
| 476 | + background: color-mix(in srgb, var(--color-primary), transparent 95%); |
| 477 | + } |
| 478 | + } |
445 | 479 | } |
446 | 480 |
|
447 | 481 | .group-title { |
|
0 commit comments