Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. //React.PropTypes has been deprecated, use prop-types instead. Recommended by facebook
  2. import PropTypes from 'prop-types'
  3.  
  4. const TABLE_STYLES = ['Default', 'Striped Rows', 'Bordered Table', 'Hover Rows', 'Condensed Table', 'Contextual Classes']
  5.  
  6. export class Table extends Element2 {
  7.  
  8. static get propTypes() {
  9. return {
  10. ...super.propTypes,
  11. variant : PropTypes.string,
  12. rows: PropTypes.number,
  13. header: PropTypes.array,
  14. table: PropTypes.array,
  15. }
  16. }
  17.  
  18. static get defaultProps() {
  19. return {
  20. ...super.defaultProps,
  21. variant: 'Default', //default style
  22. rows: 2,
  23. header: ['foo', 'bar', 'baz'],
  24. table: [
  25. [1, 'David', 'BloodSeeker'],
  26. [2, 'Kelvin', 'Storm Spirit']
  27. ]
  28. }
  29. }
  30.  
  31. handleClick(_style = 'Default') {
  32. this.saveState({ variant : _style })
  33. }
  34.  
  35.  
  36. get inspector() {
  37. return {
  38. ...super.inspector,
  39. content: <UI_Field_Content label="style">
  40. <UI_Field_Select options={TABLE_STYLES} bind="variant" />
  41.  
  42. </UI_Field_Content>
  43. }
  44. }
  45.  
  46. render() {
  47. return (
  48. <table>
  49. <colgroup>
  50. <col style={{ fontWeight: 'bold', color: 'red' }} />
  51. <col />
  52. </colgroup>
  53. <THeader header={this.state.header} />
  54. <TBody body={this.state.table} />
  55. </table>
  56. )
  57. }
  58. }
  59.  
  60. class THeader extends React.Component {
  61.  
  62. constructor(props) {
  63. super(props)
  64. }
  65.  
  66. render() {
  67. return <thead>
  68. <tr>
  69. {this.props.header.map(e => {
  70. return <td> {e} </td>
  71. })}
  72. </tr>
  73. </thead>
  74. }
  75. }
  76.  
  77. class TBody extends React.Component {
  78. render() {
  79. return <tbody>
  80. <tr>
  81. <th>1</th>
  82. <th>ahihi</th>
  83. <th>bloodseeker</th>
  84. </tr>
  85. </tbody>
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement