Няма описание

Editor.stories.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 { ContentUtils } from "braft-utils";
  9. import EditorData from "./data/articleData.json";
  10. import { Divider, Popover } from "antd";
  11. import BraftEditor from "braft-editor";
  12. const stories = storiesOf("Editor", module);
  13. stories.addDecorator(storyFn => (
  14. <div style={{ padding: "0px 40px" }}>{storyFn()}</div>
  15. ));
  16. stories.addDecorator(withKnobs);
  17. stories.addDecorator(withInfo);
  18. stories.addDecorator(addReadme);
  19. stories.add(
  20. "BraftEditor",
  21. () => {
  22. return <BarftEditorPage initValue={EditorData.text} />;
  23. },
  24. {
  25. info: {
  26. inline: true
  27. },
  28. notes: "A very simple example of addon notes"
  29. }
  30. );
  31. stories.add(
  32. "BraftEditorCommon",
  33. () => {
  34. const [editorState, setEditorState] = useState(
  35. BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")
  36. );
  37. return (
  38. <>
  39. <h3>非受控组件</h3>
  40. <BarftEditorPage controls={[]} />
  41. <Divider />
  42. <h3>受控组件</h3>
  43. <BarftEditorPage
  44. value={editorState}
  45. onChange={setEditorState}
  46. controls={["bold"]}
  47. FloatControls={({ editorState, setEditorState }: any) => {
  48. const IconWrapStyle = {
  49. cursor: "pointer",
  50. textAlign: "center" as const,
  51. width: "42px"
  52. };
  53. const IconStyle = { fontSize: "21px" };
  54. return (
  55. <>
  56. <div
  57. style={{ color: "#f07977", ...IconWrapStyle }}
  58. onClick={() => {
  59. setEditorState(
  60. ContentUtils.insertText(editorState, "Hello World")
  61. );
  62. }}
  63. >
  64. <i
  65. className="schedule schedule-icon_story"
  66. style={IconStyle}
  67. />
  68. </div>
  69. <div style={{ ...IconWrapStyle, color: "#3d9bfe" }}>
  70. <i
  71. className="schedule schedule-icon_topic"
  72. style={IconStyle}
  73. />
  74. </div>
  75. <div style={{ ...IconWrapStyle, color: "#ffa405" }}>
  76. <i
  77. className="schedule schedule-icon_emoticon"
  78. style={IconStyle}
  79. />
  80. </div>
  81. <div style={{ ...IconWrapStyle, color: "#71c135" }}>
  82. <i className="schedule schedule-icon_img" style={IconStyle} />
  83. </div>
  84. </>
  85. );
  86. }}
  87. />
  88. </>
  89. );
  90. },
  91. {
  92. info: {
  93. inline: true
  94. },
  95. notes: "A very simple example of addon notes"
  96. }
  97. );