MetaData.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React from 'react'
  2. class MetaDataForm extends React.Component {
  3. constructor () {
  4. super()
  5. this.changeType = this.changeType.bind(this)
  6. }
  7. changeType (event) {
  8. console.log(this.sali.value)
  9. this.props.data.type = this.sali.value
  10. }
  11. render () {
  12. const { data } = this.props
  13. const metaElements = {
  14. text: (
  15. <fieldset>
  16. <input type='text' placeholder='Key Name' />
  17. <input type='text' placeholder='Value' />
  18. </fieldset>
  19. ),
  20. image: (
  21. <fieldset>
  22. <input type='text' placeholder='Image URL' />
  23. <button>Select from Gallery</button>
  24. <input type='file' placeholder='Upload file' />
  25. <input type='text' placeholder='Name' />
  26. <input type='text' placeholder='Description' />
  27. </fieldset>
  28. ),
  29. link: (
  30. <fieldset>
  31. <input type='text' placeholder='URL' />
  32. <input type='text' placeholder='Description' />
  33. </fieldset>
  34. ),
  35. file: (
  36. <fieldset>
  37. <input type='file' placeholder='URL' />
  38. <input type='text' placeholder='Description' />
  39. </fieldset>
  40. )
  41. }
  42. if (typeof data.type === 'undefined') {
  43. data.type = 'text'
  44. }
  45. return (
  46. <form>
  47. <select value={data.type} ref={(input) => { this.sali = input }} onChange={this.changeType}>
  48. <option value='text'>Text</option>
  49. <option value='image'>Image</option>
  50. <option value='link'>Link</option>
  51. <option value='file'>File</option>
  52. </select>
  53. {metaElements[data.type]}
  54. </form>
  55. )
  56. }
  57. }
  58. class MetaDataDisplay extends React.Component {
  59. constructor () {
  60. super()
  61. this.changeType = this.changeType.bind(this)
  62. }
  63. changeType (event) {
  64. console.log(event, this.sali)
  65. this.props.data.type = this.sali.value
  66. }
  67. render () {
  68. const { data } = this.props
  69. const metaElements = {
  70. text: (
  71. <p>
  72. <em>{data.key}</em>&nbsp;<span>{data.value}</span>
  73. </p>
  74. ),
  75. image: (
  76. <fieldset>
  77. <input type='text' placeholder='Image URL' />
  78. <button>Select from Gallery</button>
  79. <input type='file' placeholder='Upload file' />
  80. <input type='text' placeholder='Name' />
  81. <input type='text' placeholder='Description' />
  82. </fieldset>
  83. ),
  84. link: (
  85. <fieldset>
  86. <input type='text' placeholder='URL' />
  87. <input type='text' placeholder='Description' />
  88. </fieldset>
  89. ),
  90. file: (
  91. <fieldset>
  92. <input type='file' placeholder='URL' />
  93. <input type='text' placeholder='Description' />
  94. </fieldset>
  95. )
  96. }
  97. return (
  98. <form>
  99. <select value={data.type} ref={(input) => { this.sali = input }} onChange={this.changeType}>
  100. <option value='text'>Text</option>
  101. <option value='image'>Image</option>
  102. <option value='link'>Link</option>
  103. <option value='file'>File</option>
  104. </select>
  105. {metaElements[data.type]}
  106. </form>
  107. )
  108. }
  109. }
  110. class MetaData extends React.Component {
  111. render () {
  112. const { method, data } = this.props
  113. if (method === 'form') {
  114. return (
  115. <MetaDataForm method={method} data={data} />
  116. )
  117. }
  118. return (
  119. <MetaDataDisplay method={method} data={data} />
  120. )
  121. }
  122. }
  123. export default MetaData