PivotSection.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React from 'react'
  2. import { Row, Col, Select } from 'antd'
  3. const Option = Select.Option
  4. import ColorPicker from 'components/ColorPicker'
  5. import { PIVOT_CHART_FONT_FAMILIES, PIVOT_CHART_FONT_SIZES, PIVOT_CHART_LINE_STYLES } from 'app/globalConstants'
  6. const styles = require('../Workbench.less')
  7. export interface IPivotConfig {
  8. fontFamily: string
  9. fontSize: string
  10. color: string
  11. lineStyle: string
  12. lineColor: string
  13. headerBackgroundColor: string
  14. }
  15. interface IPivotSectionProps {
  16. title: string
  17. config: IPivotConfig
  18. onChange: (prop: string, value: any) => void
  19. }
  20. export class PivotSection extends React.PureComponent<IPivotSectionProps, {}> {
  21. private selectChange = (prop) => (value) => {
  22. this.props.onChange(prop, value)
  23. }
  24. private colorChange = (prop) => (color) => {
  25. this.props.onChange(prop, color)
  26. }
  27. public render () {
  28. const { title, config } = this.props
  29. const {
  30. fontFamily,
  31. fontSize,
  32. color,
  33. lineStyle,
  34. lineColor,
  35. headerBackgroundColor
  36. } = config
  37. const fontFamilies = PIVOT_CHART_FONT_FAMILIES.map((f) => (
  38. <Option key={f.value} value={f.value}>{f.name}</Option>
  39. ))
  40. const fontSizes = PIVOT_CHART_FONT_SIZES.map((f) => (
  41. <Option key={f} value={`${f}`}>{f}</Option>
  42. ))
  43. const lineStyles = PIVOT_CHART_LINE_STYLES.map((l) => (
  44. <Option key={l.value} value={l.value}>{l.name}</Option>
  45. ))
  46. return (
  47. <div className={styles.paneBlock}>
  48. <h4>{title}</h4>
  49. <div className={styles.blockBody}>
  50. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  51. <Col span={4}>文字</Col>
  52. <Col span={8}>
  53. <Select
  54. placeholder="字体"
  55. className={styles.blockElm}
  56. value={fontFamily}
  57. onChange={this.selectChange('fontFamily')}
  58. >
  59. {fontFamilies}
  60. </Select>
  61. </Col>
  62. <Col span={8}>
  63. <Select
  64. placeholder="文字大小"
  65. className={styles.blockElm}
  66. value={fontSize}
  67. onChange={this.selectChange('fontSize')}
  68. >
  69. {fontSizes}
  70. </Select>
  71. </Col>
  72. <Col span={4}>
  73. <ColorPicker
  74. value={color}
  75. onChange={this.colorChange('color')}
  76. />
  77. </Col>
  78. </Row>
  79. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  80. <Col span={4}>边框</Col>
  81. <Col span={8}>
  82. <Select
  83. placeholder="样式"
  84. className={styles.blockElm}
  85. value={lineStyle}
  86. onChange={this.selectChange('lineStyle')}
  87. >
  88. {lineStyles}
  89. </Select>
  90. </Col>
  91. <Col span={8} />
  92. <Col span={4}>
  93. <ColorPicker
  94. value={lineColor}
  95. onChange={this.colorChange('lineColor')}
  96. />
  97. </Col>
  98. </Row>
  99. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  100. <Col span={20}>表头背景颜色</Col>
  101. <Col span={4}>
  102. <ColorPicker
  103. value={headerBackgroundColor}
  104. onChange={this.colorChange('headerBackgroundColor')}
  105. />
  106. </Col>
  107. </Row>
  108. </div>
  109. </div>
  110. )
  111. }
  112. }
  113. export default PivotSection