Geen omschrijving

Editor.stories.tsx 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, { useState } from "react";
  2. import { storiesOf } from "@storybook/react";
  3. import { action } from "@storybook/addon-actions";
  4. import { withInfo } from "@storybook/addon-info";
  5. import { withKnobs, number, boolean, select } from "@storybook/addon-knobs";
  6. import { addReadme } from "storybook-readme";
  7. import { BarftEditorPage } from "@components/Editor/BraftEditor";
  8. import SimpleEditor from "@components/Editor/QAEditor/SimpleEditor";
  9. import { ControlsToolBar } from "@components/Editor/CommonTool/ControlsToolBar";
  10. import { ContentUtils } from "braft-utils";
  11. import EditorData from "./data/articleData.json";
  12. import { Divider, Popover, Checkbox } from "antd";
  13. import BraftEditor from "braft-editor";
  14. import styles from './index.less';
  15. const stories = storiesOf("Editor", module);
  16. stories.addDecorator(storyFn => (
  17. <div style={{ padding: "0px 40px" }}>{storyFn()}</div>
  18. ));
  19. stories.addDecorator(withKnobs);
  20. stories.addDecorator(withInfo);
  21. stories.addDecorator(addReadme);
  22. stories.add(
  23. "BraftEditor",
  24. () => {
  25. return <BarftEditorPage initValue={EditorData.text} />;
  26. },
  27. {
  28. info: {
  29. inline: true
  30. },
  31. notes: "A very simple example of addon notes"
  32. }
  33. );
  34. stories.add(
  35. "BraftEditorCommon",
  36. () => {
  37. const [editorState, setEditorState] = useState(
  38. BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")
  39. );
  40. return (
  41. <>
  42. <BarftEditorPage
  43. value={editorState}
  44. onChange={setEditorState}
  45. controls={["bold"]}
  46. FloatControls={({ editorState, setEditorState }: any) => (
  47. <ControlsToolBar
  48. editorState={editorState}
  49. setEditorState={setEditorState}
  50. toolList={[
  51. {
  52. key: 1,
  53. color: "#f07977",
  54. iconClass: "schedule schedule-icon_story",
  55. onClick: () => {
  56. setEditorState(
  57. ContentUtils.insertText(editorState, "Hello World")
  58. );
  59. }
  60. },
  61. {
  62. key: 2,
  63. color: "#3d9bfe",
  64. iconClass: "schedule schedule-icon_topic",
  65. onClick: () => {
  66. setEditorState(
  67. ContentUtils.insertText(editorState, "Hello World")
  68. );
  69. }
  70. },
  71. {
  72. key: 3,
  73. color: "#ffa405",
  74. iconClass: "schedule schedule-icon_emoticon",
  75. onClick: () => {
  76. setEditorState(
  77. ContentUtils.insertText(editorState, "Hello World")
  78. );
  79. }
  80. },
  81. {
  82. key: 4,
  83. color: "#71c135",
  84. iconClass: "schedule schedule-icon_img",
  85. onClick: () => {
  86. setEditorState(
  87. ContentUtils.insertText(editorState, "Hello World")
  88. );
  89. }
  90. }
  91. ]}
  92. />
  93. )}
  94. />
  95. </>
  96. );
  97. },
  98. {
  99. info: {
  100. inline: true
  101. },
  102. notes: "A very simple example of addon notes"
  103. }
  104. );
  105. stories.add(
  106. "QASimpleEditor",
  107. () => {
  108. const [editorState, setEditorState] = useState(
  109. BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")
  110. );
  111. return (
  112. <>
  113. <SimpleEditor
  114. value={editorState}
  115. onChange={setEditorState}
  116. controls={[]}
  117. toolList={[
  118. {
  119. key: 1,
  120. color: "#f07977",
  121. iconClass: "schedule schedule-icon_story",
  122. onClick: () => {
  123. setEditorState(
  124. ContentUtils.insertText(editorState, "Hello World")
  125. );
  126. }
  127. },
  128. {
  129. key: 2,
  130. color: "#3d9bfe",
  131. iconClass: "schedule schedule-icon_topic",
  132. onClick: () => {
  133. setEditorState(
  134. ContentUtils.insertText(editorState, "Hello World")
  135. );
  136. }
  137. },
  138. {
  139. key: 3,
  140. color: "#ffa405",
  141. iconClass: "schedule schedule-icon_emoticon",
  142. onClick: () => {
  143. setEditorState(
  144. ContentUtils.insertText(editorState, "Hello World")
  145. );
  146. }
  147. },
  148. {
  149. key: 4,
  150. color: "#71c135",
  151. iconClass: "schedule schedule-icon_img",
  152. onClick: () => {
  153. setEditorState(
  154. ContentUtils.insertText(editorState, "Hello World")
  155. );
  156. }
  157. }
  158. ]}
  159. toolAlign={select("toolAlign", {
  160. Inner: 'inner',
  161. Bottom: 'bottom',
  162. }, "bottom")}
  163. toolBarContainerStyle={{
  164. display: 'flex',
  165. justifyContent: 'space-between',
  166. height: '55px',
  167. alignItems: 'center',
  168. }}
  169. appendToolBtn={(
  170. <div style={{ display: 'flex', alignItems: 'center', width: '400px', justifyContent: 'space-between'}}>
  171. <div className={styles.QAAnonymous}>
  172. <Popover
  173. trigger="hover"
  174. content={
  175. <div>
  176. 警告
  177. </div>
  178. }
  179. >
  180. <Checkbox>
  181. anonymous
  182. </Checkbox>
  183. </Popover>
  184. </div>
  185. <div
  186. className={styles.QASaveBtn}
  187. >
  188. Save
  189. </div>
  190. <div
  191. className={styles.QASubmitBtn}
  192. >
  193. Submit
  194. </div>
  195. </div>
  196. )}
  197. />
  198. </>
  199. );
  200. },
  201. {
  202. info: {
  203. inline: true
  204. },
  205. notes: "A very simple example of addon notes"
  206. }
  207. );