Repository navigation
fix(navbar): 统一导航配色,优化下拉交互与定位 #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
36cd3fd
fix(navbar): unify styling and improve dropdown interactions
dethan3 58e8f31
fix(navbar): follow upstream markup and connect drawer controls
dethan3 0d95919
fix(navbar): upgrade Idea React and simplify dropdown customizations
codex d128995
fix(navbar): allow submenu expansion within the drawer and adjust men…
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| .link { | ||
| color: var(--bs-nav-link-color); | ||
| } | ||
|
|
||
| .link:hover, | ||
| .link:focus-visible, | ||
| .link[aria-expanded='true'] { | ||
| color: var(--bs-nav-link-hover-color); | ||
| } | ||
|
|
||
| .link[aria-current] { | ||
| color: var(--bs-nav-link-active-color); | ||
| font-weight: var(--bs-font-weight-bold); | ||
| } | ||
|
|
||
| .link:focus-visible, | ||
| .menuItem:focus-visible { | ||
| outline: 2px solid currentColor; | ||
| outline-offset: -2px; | ||
| } | ||
|
|
||
| .menu, | ||
| .inlineMenu { | ||
| --bs-menu-item-active-bg: var(--bs-bg-2); | ||
| --bs-menu-item-active-color: var(--bs-fg-body); | ||
| } | ||
|
|
||
| .menu { | ||
| transform-origin: top center; | ||
| } | ||
|
|
||
| .menu[data-bs-placement^='top'] { | ||
| transform-origin: bottom center; | ||
| } | ||
|
|
||
| /* Keep the four-pixel visual gap within the menu's pointer hit area. */ | ||
| .menu::before { | ||
| position: absolute; | ||
| inset-inline: 0; | ||
| top: -5px; | ||
| height: 5px; | ||
| content: ''; | ||
| } | ||
|
|
||
| .menu[data-bs-placement^='top']::before { | ||
| top: auto; | ||
| bottom: -5px; | ||
| } | ||
|
|
||
| /* Allow the submenu to expand within the drawer. */ | ||
| .inlineMenu { | ||
| max-height: none !important; | ||
| } | ||
|
|
||
| .menuItem { | ||
| color: var(--bs-menu-item-color); | ||
| } | ||
|
|
||
| .menuItem:hover, | ||
| .menuItem:focus-visible { | ||
| color: var(--bs-menu-item-hover-color); | ||
| } | ||
|
|
||
| .menuItem[aria-current] { | ||
| color: var(--bs-menu-item-active-color); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { Menu, MenuItem } from 'idea-react'; | ||
| import { action, observable } from 'mobx'; | ||
| import { observer } from 'mobx-react'; | ||
| import { Component, createRef, PointerEvent } from 'react'; | ||
|
|
||
| import type { NavigatorMenuItem } from './MainNavigator'; | ||
| import styles from './MainNavigator.module.css'; | ||
|
|
||
| interface MainNavigatorMenuProps { | ||
| id: string; | ||
| title: NavigatorMenuItem['title']; | ||
| desktop: boolean; | ||
| items: NavigatorMenuItem[]; | ||
| pathname: string; | ||
| onSelect: () => void; | ||
| } | ||
|
|
||
| @observer | ||
| export class MainNavigatorMenu extends Component<MainNavigatorMenuProps> { | ||
| @observable accessor horizontalOffset = 0; | ||
|
|
||
| menu = createRef<Menu>(); | ||
| closeTimer?: ReturnType<typeof setTimeout>; | ||
| resize?: ResizeObserver; | ||
|
|
||
| componentDidMount() { | ||
| const { trigger, panel } = this.menu.current ?? {}; | ||
| if (!this.props.desktop || !trigger?.current || !panel?.current) return; | ||
|
|
||
| this.resize = new ResizeObserver(this.centerMenu); | ||
| this.resize.observe(trigger.current); | ||
| this.resize.observe(panel.current); | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| this.cancelClose(); | ||
| this.resize?.disconnect(); | ||
| } | ||
|
|
||
| @action | ||
| centerMenu = () => { | ||
| const { trigger, panel } = this.menu.current ?? {}; | ||
| if (!trigger?.current || !panel?.current || panel.current.hidden) return; | ||
|
|
||
| // Shift start alignment to the center; Menu still clamps it to the viewport. | ||
| this.horizontalOffset = (trigger.current.offsetWidth - panel.current.offsetWidth) / 2; | ||
| }; | ||
|
|
||
| cancelClose = () => { | ||
| clearTimeout(this.closeTimer); | ||
| this.closeTimer = undefined; | ||
| }; | ||
|
|
||
| handlePointerEnter = (event: PointerEvent<HTMLElement>) => { | ||
| if (event.pointerType !== 'mouse') return; | ||
|
|
||
| this.cancelClose(); | ||
| this.menu.current?.setOpen(true); | ||
| }; | ||
|
|
||
| handlePointerLeave = (event: PointerEvent<HTMLElement>) => { | ||
| if (event.pointerType !== 'mouse') return; | ||
|
|
||
| this.cancelClose(); | ||
| // Allow diagonal movement into a menu shifted away from the viewport edge. | ||
| this.closeTimer = setTimeout(() => { | ||
| const menu = this.menu.current; | ||
| if (!menu?.panel.current?.contains(document.activeElement)) menu?.setOpen(false); | ||
|
TechQuery marked this conversation as resolved.
Resolved
|
||
| }, 200); | ||
| }; | ||
|
|
||
| render() { | ||
| const { id, title, desktop, items, pathname, onSelect } = this.props; | ||
| const active = items.some(({ href }) => href === pathname); | ||
|
|
||
| return ( | ||
| <Menu | ||
| ref={this.menu} | ||
| id={id} | ||
| label={title} | ||
| nav | ||
| theme="dark" | ||
| className={desktop ? undefined : 'w-100'} | ||
| offset={desktop ? [this.horizontalOffset, 4] : undefined} | ||
| menuClassName={ | ||
| desktop ? styles.menu : `${styles.inlineMenu} position-static min-w-0 max-w-100` | ||
| } | ||
| toggleProps={{ | ||
| className: styles.link, | ||
| 'aria-current': active ? 'true' : undefined, | ||
| }} | ||
| onPointerEnter={desktop ? this.handlePointerEnter : undefined} | ||
| onPointerLeave={desktop ? this.handlePointerLeave : undefined} | ||
| onOpenChange={this.cancelClose} | ||
| > | ||
| {items.map( | ||
| ({ href, title }) => | ||
| href && ( | ||
| <MenuItem | ||
| key={href} | ||
| href={href} | ||
| active={pathname === href} | ||
| className={styles.menuItem} | ||
| onClick={onSelect} | ||
| > | ||
| {title} | ||
| </MenuItem> | ||
| ), | ||
| )} | ||
| </Menu> | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.