No Description

Editor.stories.tsx 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. text: "长文",
  122. iconClass: "schedule schedule-icon_story",
  123. onClick: () => {
  124. setEditorState(
  125. ContentUtils.insertText(editorState, "Hello World")
  126. );
  127. }
  128. },
  129. {
  130. key: 2,
  131. color: "#3d9bfe",
  132. text: "话题",
  133. iconClass: "schedule schedule-icon_topic",
  134. onClick: () => {
  135. setEditorState(
  136. ContentUtils.insertText(editorState, "Hello World")
  137. );
  138. }
  139. },
  140. {
  141. key: 3,
  142. color: "#ffa405",
  143. text: "表情",
  144. iconClass: "schedule schedule-icon_emoticon",
  145. onClick: () => {
  146. setEditorState(
  147. ContentUtils.insertText(editorState, "Hello World")
  148. );
  149. }
  150. },
  151. {
  152. key: 4,
  153. color: "#71c135",
  154. text: "图片",
  155. iconClass: "schedule schedule-icon_img",
  156. onClick: () => {
  157. setEditorState(
  158. ContentUtils.insertText(editorState, "Hello World")
  159. );
  160. }
  161. }
  162. ]}
  163. injectControlsToolBar={{
  164. injectIconWrapStyle: {
  165. marginRight: "4px"
  166. }
  167. }}
  168. toolAlign={select("toolAlign", {
  169. Inner: 'inner',
  170. Bottom: 'bottom',
  171. }, "bottom")}
  172. toolBarContainerStyle={{
  173. display: 'flex',
  174. justifyContent: 'space-between',
  175. height: '55px',
  176. alignItems: 'center',
  177. }}
  178. appendToolBtn={(
  179. <div style={{ display: 'flex', alignItems: 'center', width: '400px', justifyContent: 'space-between'}}>
  180. <div className={styles.QAAnonymous}>
  181. <Popover
  182. trigger="hover"
  183. content={
  184. <div>
  185. 警告
  186. </div>
  187. }
  188. >
  189. <Checkbox>
  190. Anonymous
  191. </Checkbox>
  192. </Popover>
  193. </div>
  194. <div
  195. className={styles.QASaveBtn}
  196. >
  197. Save
  198. </div>
  199. <div
  200. className={styles.QASubmitBtn}
  201. >
  202. Submit
  203. </div>
  204. </div>
  205. )}
  206. />
  207. </>
  208. );
  209. },
  210. {
  211. info: {
  212. inline: true
  213. },
  214. notes: "A very simple example of addon notes"
  215. }
  216. );