-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation Component: Add isText prop to NavigationItem (#27003)
- Loading branch information
1 parent
5040f3d
commit ec3da35
Showing
6 changed files
with
126 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useRTL } from '../../utils'; | ||
import { ItemBadgeUI, ItemTitleUI } from '../styles/navigation-styles'; | ||
|
||
export default function NavigationItemBaseContent( props ) { | ||
const { badge, title } = props; | ||
const isRTL = useRTL(); | ||
|
||
return ( | ||
<> | ||
{ title && ( | ||
<ItemTitleUI | ||
className="components-navigation__item-title" | ||
variant="body.small" | ||
isRTL={ isRTL } | ||
as="span" | ||
> | ||
{ title } | ||
</ItemTitleUI> | ||
) } | ||
|
||
{ badge && ( | ||
<ItemBadgeUI | ||
className="components-navigation__item-badge" | ||
isRTL={ isRTL } | ||
> | ||
{ badge } | ||
</ItemBadgeUI> | ||
) } | ||
</> | ||
); | ||
} |
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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { uniqueId } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useNavigationContext } from '../context'; | ||
import { useNavigationTreeItem } from './use-navigation-tree-item'; | ||
import { ItemBaseUI } from '../styles/navigation-styles'; | ||
|
||
export default function NavigationItemBase( props ) { | ||
const { children, className, ...restProps } = props; | ||
|
||
const [ itemId ] = useState( uniqueId( 'item-' ) ); | ||
|
||
useNavigationTreeItem( itemId, props ); | ||
const { navigationTree } = useNavigationContext(); | ||
|
||
if ( ! navigationTree.getItem( itemId )?._isVisible ) { | ||
return null; | ||
} | ||
|
||
const classes = classnames( 'components-navigation__item', className ); | ||
|
||
return ( | ||
<ItemBaseUI className={ classes } { ...restProps }> | ||
{ children } | ||
</ItemBaseUI> | ||
); | ||
} |
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