Bottom.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, { useContext, useMemo } from 'react'
  21. import { Icon, Tooltip, Slider } from 'antd'
  22. import { ContainerContext } from './ContainerContext'
  23. interface IDisplayBottomProps {
  24. onCreateCover: () => void
  25. }
  26. const DisplayBottom: React.FC<IDisplayBottomProps> = (props) => {
  27. const { onCreateCover } = props
  28. const { sliderValue, scale, zoomIn, zoomOut, sliderChange } = useContext(
  29. ContainerContext
  30. )
  31. const percentage = useMemo(() => {
  32. if (!scale) { return '' }
  33. if (scale[0] === scale[1]) {
  34. return `${Math.floor(scale[0] * 100)}%`
  35. }
  36. return scale.map((s: number) => `${Math.floor(s * 100)}%`).join('/')
  37. }, [
  38. scale
  39. ])
  40. return (
  41. <div className="display-bottom">
  42. <div className="display-bottom-screenshot">
  43. <Tooltip title="点击生成截图封面">
  44. <Icon type="picture" onClick={onCreateCover} />
  45. </Tooltip>
  46. </div>
  47. <div className="display-bottom-slider-wrapper">
  48. <label>{percentage}</label>
  49. <Icon type="minus-circle-o" onClick={zoomIn} />
  50. <Slider
  51. className="display-bottom-slider"
  52. value={sliderValue}
  53. onChange={sliderChange}
  54. />
  55. <Icon type="plus-circle-o" onClick={zoomOut} />
  56. </div>
  57. </div>
  58. )
  59. }
  60. export default DisplayBottom