hooks.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, { useMemo } from 'react'
  21. import { ILayerParams } from '../../../types'
  22. export const useLabelStyle = (params: ILayerParams) => {
  23. const labelStyle = useMemo(() => {
  24. const {
  25. fontWeight,
  26. fontFamily,
  27. fontColor,
  28. fontSize,
  29. textAlign,
  30. textStyle,
  31. lineHeight,
  32. textIndent,
  33. paddingTop,
  34. paddingBottom,
  35. paddingLeft,
  36. paddingRight
  37. } = params
  38. const style: React.CSSProperties = {
  39. wordBreak: 'break-all',
  40. overflow: 'hidden',
  41. fontWeight,
  42. fontFamily,
  43. color: `rgba(${fontColor.join()})`,
  44. fontSize: `${fontSize}px`,
  45. textAlign: textAlign as React.CSSProperties['textAlign'],
  46. lineHeight: `${lineHeight}px`,
  47. textIndent: `${textIndent}px`,
  48. paddingTop: `${paddingTop}px`,
  49. paddingRight: `${paddingRight}px`,
  50. paddingBottom: `${paddingBottom}px`,
  51. paddingLeft: `${paddingLeft}px`
  52. }
  53. if (textStyle) {
  54. style.fontStyle = textStyle.indexOf('italic') > -1 ? 'italic' : 'normal'
  55. style.textDecoration =
  56. textStyle.indexOf('underline') > -1 ? 'underline' : 'none'
  57. }
  58. return style
  59. }, [params])
  60. return labelStyle
  61. }