index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { useEffect, useState } from 'react'
  2. import NavLink from './navLink'
  3. import type { NavIcon } from './navLink'
  4. import AppBasic from './basic'
  5. import AppInfo from './app-info'
  6. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  7. import {
  8. AlignLeft01,
  9. AlignRight01,
  10. } from '@/app/components/base/icons/src/vender/line/layout'
  11. import { useStore as useAppStore } from '@/app/components/app/store'
  12. export type IAppDetailNavProps = {
  13. iconType?: 'app' | 'dataset' | 'notion'
  14. title: string
  15. desc: string
  16. icon: string
  17. icon_background: string
  18. navigation: Array<{
  19. name: string
  20. href: string
  21. icon: NavIcon
  22. selectedIcon: NavIcon
  23. }>
  24. extraInfo?: (modeState: string) => React.ReactNode
  25. }
  26. const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => {
  27. const { appSidebarExpand, setAppSiderbarExpand } = useAppStore()
  28. const media = useBreakpoints()
  29. const isMobile = media === MediaType.mobile
  30. const [modeState, setModeState] = useState(appSidebarExpand)
  31. const expand = modeState === 'expand'
  32. const handleToggle = (state: string) => {
  33. setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand')
  34. }
  35. useEffect(() => {
  36. if (appSidebarExpand) {
  37. localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand)
  38. setModeState(appSidebarExpand)
  39. }
  40. }, [appSidebarExpand])
  41. return (
  42. <div
  43. className={`
  44. shrink-0 flex flex-col bg-white border-r border-gray-200 transition-all
  45. ${expand ? 'w-[216px]' : 'w-14'}
  46. `}
  47. >
  48. <div
  49. className={`
  50. shrink-0
  51. ${expand ? 'p-3' : 'p-2'}
  52. `}
  53. >
  54. {iconType === 'app' && (
  55. <AppInfo expand={expand}/>
  56. )}
  57. {iconType !== 'app' && (
  58. <AppBasic
  59. mode={modeState}
  60. iconType={iconType}
  61. icon={icon}
  62. icon_background={icon_background}
  63. name={title}
  64. type={desc}
  65. />
  66. )}
  67. </div>
  68. {!expand && (
  69. <div className='mt-1 mx-auto w-6 h-[1px] bg-gray-100'/>
  70. )}
  71. <nav
  72. className={`
  73. grow space-y-1 bg-white
  74. ${expand ? 'p-4' : 'px-2.5 py-4'}
  75. `}
  76. >
  77. {navigation.map((item, index) => {
  78. return (
  79. <NavLink key={index} mode={modeState} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} />
  80. )
  81. })}
  82. {extraInfo && extraInfo(modeState)}
  83. </nav>
  84. {
  85. !isMobile && (
  86. <div
  87. className={`
  88. shrink-0 py-3
  89. ${expand ? 'px-6' : 'px-4'}
  90. `}
  91. >
  92. <div
  93. className='flex items-center justify-center w-6 h-6 text-gray-500 cursor-pointer'
  94. onClick={() => handleToggle(modeState)}
  95. >
  96. {
  97. expand
  98. ? <AlignLeft01 className='w-[14px] h-[14px]' />
  99. : <AlignRight01 className='w-[14px] h-[14px]' />
  100. }
  101. </div>
  102. </div>
  103. )
  104. }
  105. </div>
  106. )
  107. }
  108. export default React.memo(AppDetailNav)