LinkEditModal.jsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Modal, ModalHeader, ModalBody } from 'reactstrap';
  4. import PagePathAutoComplete from '../PagePathAutoComplete';
  5. export default class LinkEditModal extends React.PureComponent {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. show: false,
  10. isUseRelativePath: false,
  11. linkInputValue: '',
  12. labelInputValue: '',
  13. output: '[label](link)',
  14. };
  15. this.show = this.show.bind(this);
  16. this.hide = this.hide.bind(this);
  17. this.cancel = this.cancel.bind(this);
  18. this.inputChangeHandler = this.inputChangeHandler.bind(this);
  19. this.submitHandler = this.submitHandler.bind(this);
  20. this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
  21. this.showLog = this.showLog.bind(this);
  22. this.save = this.save.bind(this);
  23. }
  24. show(defaultLabelInputValue = '') {
  25. this.setState({ show: true, labelInputValue: defaultLabelInputValue });
  26. }
  27. cancel() {
  28. this.hide();
  29. }
  30. hide() {
  31. this.setState({
  32. show: false,
  33. });
  34. }
  35. toggleIsUseRelativePath() {
  36. this.setState({ isUseRelativePath: !this.state.isUseRelativePath });
  37. }
  38. renderPreview() {
  39. // TODO GW-2658
  40. }
  41. insertLinkIntoEditor() {
  42. // TODO GW-2659
  43. }
  44. showLog() {
  45. console.log(this.state.linkInputValue);
  46. }
  47. save() {
  48. if (this.props.onSave != null) {
  49. this.props.onSave(this.state.output);
  50. }
  51. this.hide();
  52. }
  53. inputChangeHandler(inputChangeValue) {
  54. this.setState({ linkInputValue: inputChangeValue });
  55. }
  56. submitHandler(submitValue) {
  57. this.setState({ linkInputValue: submitValue });
  58. }
  59. render() {
  60. return (
  61. <Modal isOpen={this.state.show} toggle={this.cancel} size="lg">
  62. <ModalHeader tag="h4" toggle={this.cancel} className="bg-primary text-light">
  63. Edit Links
  64. </ModalHeader>
  65. <ModalBody className="container">
  66. <div className="row">
  67. <div className="col">
  68. <div className="form-gorup my-3">
  69. <label htmlFor="linkInput">Link</label>
  70. <div className="input-group">
  71. <PagePathAutoComplete
  72. value={this.state.linkInputValue}
  73. onInputChange={this.inputChangeHandler}
  74. onSubmit={this.submitHandler}
  75. />
  76. <div className="input-group-append">
  77. <button type="button" id="button-addon" className="btn btn-secondary" onClick={this.showLog}>
  78. Preview
  79. </button>
  80. </div>
  81. </div>
  82. </div>
  83. <div className="d-block d-lg-none">
  84. {this.renderPreview}
  85. render preview
  86. </div>
  87. <div className="linkedit-tabs">
  88. <ul className="nav nav-tabs" role="tabist">
  89. <li className="nav-item">
  90. <a className="nav-link active" href="#Pukiwiki" role="tab" data-toggle="tab">
  91. Pukiwiki
  92. </a>
  93. </li>
  94. <li className="nav-item">
  95. <a className="nav-link" href="#Crowi" role="tab" data-toggle="tab">
  96. Crowi
  97. </a>
  98. </li>
  99. <li className="nav-item">
  100. <a className="nav-link" href="#MD" role="tab" data-toggle="tab">
  101. MD
  102. </a>
  103. </li>
  104. </ul>
  105. <div className="tab-content pt-3">
  106. <div id="Pukiwiki" className="tab-pane active" role="tabpanel">
  107. <form className="form-group">
  108. <div className="form-group">
  109. <label htmlFor="pukiwikiLink">Label</label>
  110. <input
  111. type="text"
  112. className="form-control"
  113. id="pukiwikiLink"
  114. value={this.state.labelInputValue}
  115. onChange={e => this.labelInputChange(e.target.value)}
  116. />
  117. </div>
  118. <span className="p-2">[[{this.state.labelInputValue} &gt; {this.state.linkInputValue}]]</span>
  119. <div className="form-inline">
  120. <div className="custom-control custom-checkbox custom-checkbox-info">
  121. <input className="custom-control-input" id="pukiwikiRelativePath" type="checkbox" checked={this.state.isUseRelativePath} />
  122. <label className="custom-control-label" htmlFor="pukiwikiRelativePath" onClick={this.toggleIsUseRelativePath}>
  123. Use relative path
  124. </label>
  125. </div>
  126. <button type="button" className="btn btn-primary ml-auto" onClick={this.save}>
  127. Done
  128. </button>
  129. </div>
  130. </form>
  131. </div>
  132. <div id="Crowi" className="tab-pane" role="tabpanel">
  133. <form className="form-group">
  134. <div className="form-group">
  135. <label htmlFor="crowiLink">Label</label>
  136. <input type="text" className="form-control" id="crowiLink"></input>
  137. </div>
  138. <div>
  139. <span>URI</span>
  140. </div>
  141. <div className="d-flex">
  142. <button type="button" className="btn btn-primary ml-auto" onClick={this.save}>
  143. Done
  144. </button>
  145. </div>
  146. </form>
  147. </div>
  148. <div id="MD" className="tab-pane" role="tabpanel">
  149. <form className="form-group">
  150. <div className="form-group">
  151. <label htmlFor="MDLink">Label</label>
  152. <input type="text" className="form-control" id="MDLink"></input>
  153. </div>
  154. <div>
  155. <span>URI</span>
  156. </div>
  157. <div className="form-inline">
  158. <div className="custom-control custom-checkbox custom-checkbox-info">
  159. <input className="custom-control-input" id="mdRelativePath" type="checkbox" checked={this.state.isUseRelativePath} />
  160. <label className="custom-control-label" htmlFor="mdRelativePath" onClick={this.toggleIsUseRelativePath}>
  161. Use relative path
  162. </label>
  163. </div>
  164. <button type="button" className="btn btn-primary ml-auto" onClick={this.save}>
  165. Done
  166. </button>
  167. </div>
  168. </form>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <div className="col d-none d-lg-block">
  174. {this.renderPreview}
  175. render preview
  176. </div>
  177. </div>
  178. </ModalBody>
  179. </Modal>
  180. );
  181. }
  182. }
  183. LinkEditModal.propTypes = {
  184. onSave: PropTypes.func,
  185. };