No Description

Editor.stories.tsx 6.9KB

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