-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nav Redesign: Move search and notifications to footer (#90429)
- Loading branch information
Showing
11 changed files
with
174 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,97 @@ | ||
import classNames from 'classnames'; | ||
import React, { useRef, forwardRef, Fragment } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useCurrentRoute } from 'calypso/components/route'; | ||
import { getShouldShowGlobalSiteSidebar } from 'calypso/state/global-sidebar/selectors'; | ||
import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | ||
import type { ReactNode, LegacyRef } from 'react'; | ||
|
||
interface Props { | ||
url?: string; | ||
tipTarget?: string; | ||
onClick: () => void; | ||
tooltip: string; | ||
tooltipPlacement: 'bottom' | 'top' | 'right'; | ||
icon?: ReactNode; | ||
className: string; | ||
isActive?: boolean; | ||
preloadSection?: () => void; | ||
hasUnseen?: boolean; | ||
alwaysShowContent?: boolean; | ||
disabled?: boolean; | ||
} | ||
|
||
const SidebarMenuItem = forwardRef< HTMLButtonElement | HTMLAnchorElement, Props >( | ||
( | ||
{ | ||
url, | ||
tipTarget, | ||
onClick, | ||
tooltip, | ||
tooltipPlacement = 'bottom', | ||
icon, | ||
className, | ||
isActive, | ||
preloadSection, | ||
hasUnseen, | ||
alwaysShowContent, | ||
disabled, | ||
}, | ||
ref | ||
) => { | ||
const preloadedRef = useRef( false ); | ||
|
||
const selectedSiteId = useSelector( getSelectedSiteId ); | ||
const { currentSection } = useCurrentRoute() as { | ||
currentSection: false | { group?: string; name?: string }; | ||
}; | ||
const isSidebarCollapsed = useSelector( ( state ) => { | ||
return getShouldShowGlobalSiteSidebar( | ||
state, | ||
selectedSiteId, | ||
currentSection !== false ? currentSection?.group ?? '' : '', | ||
currentSection !== false ? currentSection?.name ?? '' : '' | ||
); | ||
} ); | ||
|
||
const preload = () => { | ||
if ( ! preloadedRef.current && preloadSection ) { | ||
preloadedRef.current = true; | ||
preloadSection(); | ||
} | ||
}; | ||
|
||
const renderChildren = () => { | ||
return <Fragment>{ icon && <>{ icon }</> }</Fragment>; | ||
}; | ||
|
||
const itemClasses = classNames( 'sidebar__item', className, { | ||
'is-active': isActive, | ||
'has-unseen': hasUnseen, | ||
'sidebar__item--always-show-content': alwaysShowContent, | ||
[ `tooltip tooltip-${ isSidebarCollapsed ? 'right' : tooltipPlacement }` ]: tooltip, | ||
} ); | ||
|
||
const attributes = { | ||
'data-tooltip': tooltip, | ||
'data-tip-target': tipTarget, | ||
onClick: onClick, | ||
className: itemClasses, | ||
onTouchStart: preload, | ||
onMouseEnter: preload, | ||
disabled: disabled, | ||
}; | ||
|
||
return url ? ( | ||
<a { ...attributes } href={ url } ref={ ref as LegacyRef< HTMLAnchorElement > }> | ||
{ renderChildren() } | ||
</a> | ||
) : ( | ||
<button { ...attributes } ref={ ref as LegacyRef< HTMLButtonElement > }> | ||
{ renderChildren() } | ||
</button> | ||
); | ||
} | ||
); | ||
|
||
export default SidebarMenuItem; |
This file contains 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.