CommandList.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, { useCallback } from 'react'
  21. import classnames from 'classnames'
  22. import { Button, Tooltip } from 'antd'
  23. const ButtonGroup = Button.Group
  24. import IconFont from 'components/IconFont'
  25. import { LayerOperations, LayerCommands } from '../../constants'
  26. interface ILayerCommandProps {
  27. operation: LayerOperations
  28. icon: string
  29. title: string
  30. onClick: (operation: LayerOperations) => void
  31. }
  32. const LayerCommand: React.FC<ILayerCommandProps> = (props) => {
  33. const { operation, icon, title, onClick } = props
  34. const click = useCallback(() => {
  35. onClick(operation)
  36. }, [operation, onClick])
  37. return (
  38. <Tooltip placement="bottom" title={title}>
  39. <Button type="ghost" onClick={click}>
  40. <IconFont type={icon} />
  41. </Button>
  42. </Tooltip>
  43. )
  44. }
  45. interface ILayerCommandListProps {
  46. className?: string
  47. onCommand: (operation: LayerOperations) => void
  48. }
  49. const LayerCommandList: React.FC<ILayerCommandListProps> = (props) => {
  50. const { onCommand, className } = props
  51. const cls = classnames({ [className]: !!className })
  52. return (
  53. <ButtonGroup className={cls} size="small">
  54. {LayerCommands.map((cmd) => (
  55. <LayerCommand key={cmd.operation} {...cmd} onClick={onCommand} />
  56. ))}
  57. </ButtonGroup>
  58. )
  59. }
  60. export default React.memo(LayerCommandList)