HorizontalMenuIcon
This commit is contained in:
parent
81889b4a58
commit
11201128b6
4 changed files with 64 additions and 25 deletions
|
|
@ -10,6 +10,7 @@ import { useStoreState } from '@/store'
|
|||
import { useTranslation } from 'react-i18next'
|
||||
import HorizontalMenuDropdownItem from './HorizontalMenuDropdownItem'
|
||||
import HorizontalMenuItem from './HorizontalMenuItem'
|
||||
import HorizontalMenuIcon from './HorizontalMenuIcon'
|
||||
|
||||
type HorizontalMenuContentProps = {
|
||||
manuVariant: NavMode
|
||||
|
|
@ -37,7 +38,16 @@ const HorizontalMenuContent = ({ manuVariant }: HorizontalMenuContentProps) => {
|
|||
permissions={secondarySubNav.authority}
|
||||
>
|
||||
{secondarySubNav.subMenu.length > 0 ? (
|
||||
<Dropdown.Menu title={t(secondarySubNav.translateKey, secondarySubNav.title)}>
|
||||
<Dropdown.Menu
|
||||
title={
|
||||
<div className="flex items-center">
|
||||
<HorizontalMenuIcon icon={secondarySubNav.icon} />
|
||||
<span>
|
||||
{t(secondarySubNav.translateKey, secondarySubNav.title)}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{secondarySubNav.subMenu.map((tertiarySubNav) => (
|
||||
<PermissionCheck
|
||||
key={tertiarySubNav.key}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export type HorizontalMenuItemProps = {
|
|||
}
|
||||
|
||||
const HorizontalMenuDropdownItem = ({ nav }: HorizontalMenuItemProps) => {
|
||||
const { title, translateKey, path, key, isExternalLink } = nav
|
||||
const { title, translateKey, path, key, isExternalLink, icon } = nav
|
||||
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ const HorizontalMenuDropdownItem = ({ nav }: HorizontalMenuItemProps) => {
|
|||
eventKey={key}
|
||||
className={
|
||||
classNames(
|
||||
path && 'px-1'
|
||||
path
|
||||
)
|
||||
}
|
||||
>
|
||||
|
|
@ -35,10 +35,11 @@ const HorizontalMenuDropdownItem = ({ nav }: HorizontalMenuItemProps) => {
|
|||
path={path}
|
||||
className={
|
||||
classNames(
|
||||
path && 'px-2'
|
||||
path
|
||||
)
|
||||
}
|
||||
isExternalLink={isExternalLink}
|
||||
icon={icon}
|
||||
>
|
||||
{itemTitle}
|
||||
</HorizontalMenuNavLink>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import navigationIcon from '@/configs/navigation-icon.config'
|
||||
import type { ElementType, ComponentPropsWithRef } from 'react'
|
||||
|
||||
type HorizontalMenuIconProps = {
|
||||
icon: string
|
||||
}
|
||||
|
||||
export const Icon = <T extends ElementType>({
|
||||
component,
|
||||
...props
|
||||
}: {
|
||||
header: T
|
||||
} & ComponentPropsWithRef<T>) => {
|
||||
const Component = component
|
||||
return <Component {...props} />
|
||||
}
|
||||
|
||||
const HorizontalMenuIcon = ({ icon }: HorizontalMenuIconProps) => {
|
||||
if (typeof icon !== 'string' && !icon) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
return <span className="text-2xl ltr:mr-2 rtl:ml-2">{navigationIcon[icon]}</span>
|
||||
}
|
||||
|
||||
export default HorizontalMenuIcon
|
||||
|
|
@ -1,32 +1,34 @@
|
|||
import { Link } from 'react-router-dom'
|
||||
import classNames from 'classnames'
|
||||
import type { PropsWithChildren } from 'react'
|
||||
import HorizontalMenuIcon from './HorizontalMenuIcon'
|
||||
|
||||
export type HorizontalMenuNavLinkProps = PropsWithChildren<{
|
||||
path: string
|
||||
isExternalLink?: boolean
|
||||
className?: string
|
||||
path: string
|
||||
isExternalLink?: boolean
|
||||
className?: string
|
||||
icon?: string
|
||||
}>
|
||||
|
||||
const HorizontalMenuNavLink = ({
|
||||
path,
|
||||
children,
|
||||
isExternalLink,
|
||||
className
|
||||
path,
|
||||
children,
|
||||
isExternalLink,
|
||||
className,
|
||||
icon,
|
||||
}: HorizontalMenuNavLinkProps) => {
|
||||
return (
|
||||
<Link
|
||||
className={
|
||||
classNames(
|
||||
'h-full w-full flex items-center',
|
||||
className
|
||||
)}
|
||||
to={path}
|
||||
target={isExternalLink ? '_blank' : ''}
|
||||
>
|
||||
<span>{children}</span>
|
||||
</Link>
|
||||
)
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
<Link
|
||||
className={classNames('h-full w-full flex items-center', className)}
|
||||
to={path}
|
||||
target={isExternalLink ? '_blank' : ''}
|
||||
>
|
||||
<HorizontalMenuIcon icon={icon || ''} />
|
||||
<span>{children}</span>
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default HorizontalMenuNavLink
|
||||
|
|
|
|||
Loading…
Reference in a new issue