ShowTitleMenu.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React, { useState } from 'react'
  2. import '@/pages/Role/System/components/RoleMenu/index.less'
  3. interface ShowTitleMenuProps {
  4. itemTitle: string
  5. onSelect?: (vaule: string) => void
  6. selectDefaultValue?: string
  7. }
  8. const showTitleMenu: React.FC<ShowTitleMenuProps> = ({
  9. itemTitle,
  10. onSelect,
  11. selectDefaultValue = ''
  12. }) => {
  13. const [activeId, setActiveId] = useState(selectDefaultValue)
  14. const handleItemClick = (id: string) => {
  15. setActiveId(id)
  16. if (onSelect) {
  17. onSelect(id)
  18. }
  19. }
  20. return (
  21. <div className="h-full w-max-234px rounded-4px shadow-card">
  22. <div className="p-4 border-b-1 border-solid border-black border-opacity-10 bg-[#f7f9fa] justify-around text-left">
  23. <span>栏目/功能</span>
  24. </div>
  25. <div className="p-4 bg-white" style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
  26. <ul className="p-0 m-0 list-none text-primary flex flex-col flex-1">
  27. {itemTitle.map(item => (
  28. <li
  29. key={item.value}
  30. className={[
  31. 'flex justify-between items-center py-2 px-5 cursor-pointer',
  32. item.value === activeId ? 'scale-up-center' : ''
  33. ].join(' ')}
  34. onClick={() => handleItemClick(item.value)}>
  35. {item.label}
  36. </li>
  37. ))}
  38. </ul>
  39. </div>
  40. </div>
  41. )
  42. }
  43. export default showTitleMenu