Menu.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { memo, useRef, useMemo, useCallback } from 'react'
  21. import classnames from 'classnames'
  22. import { Menu } from 'antd'
  23. import styles from './FullScreenPanel.less'
  24. interface IMenuTitle {
  25. id: number
  26. name: string
  27. }
  28. interface IFullScreenMenuProps {
  29. itemId: number
  30. visible: boolean
  31. titles: IMenuTitle[]
  32. onChange: (itemId: number) => any
  33. }
  34. const FullScreenMenu: React.FC<IFullScreenMenuProps> = memo(
  35. ({ itemId, visible, titles, onChange }) => {
  36. const sideMenuClass = classnames({
  37. [styles.sideMenu]: true,
  38. [styles.hide]: !visible,
  39. [styles.show]: visible
  40. })
  41. const onMenuClick = useCallback(
  42. (e) => {
  43. onChange(Number(e.key))
  44. },
  45. [onChange]
  46. )
  47. const menus = useMemo(() => {
  48. return (
  49. <Menu
  50. theme="light"
  51. onClick={onMenuClick}
  52. selectedKeys={[itemId.toString()]}
  53. >
  54. {titles.map((t) => (
  55. <Menu.Item key={t.id}>
  56. <i style={{ marginRight: '8px' }} />
  57. {t.name}
  58. </Menu.Item>
  59. ))}
  60. </Menu>
  61. )
  62. }, [itemId, titles])
  63. return <div className={sideMenuClass}>{menus}</div>
  64. }
  65. )
  66. export default FullScreenMenu