123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import React, { useState } from "react";
- import { storiesOf } from "@storybook/react";
- import { action } from "@storybook/addon-actions";
- import { withInfo } from "@storybook/addon-info";
- import { withKnobs, number, boolean, select } from "@storybook/addon-knobs";
- import { addReadme } from "storybook-readme";
-
- import { BarftEditorPage } from "@components/Editor/BraftEditor";
- import SimpleEditor from "@/components/Editor/ImgTxtEditor/SimpleEditor";
- import { ControlsToolBar } from "@components/Editor/CommonTool/ControlsToolBar";
- import { ContentUtils } from "braft-utils";
-
- import EditorData from "./data/articleData.json";
- import { Divider, Popover, Checkbox } from "antd";
- import BraftEditor from "braft-editor";
-
- import styles from './index.less';
-
- const stories = storiesOf("Editor", module);
- stories.addDecorator(storyFn => (
- <div style={{ padding: "0px 40px" }}>{storyFn()}</div>
- ));
- stories.addDecorator(withKnobs);
- stories.addDecorator(withInfo);
- stories.addDecorator(addReadme);
-
- stories.add(
- "BraftEditor",
- () => {
- return <BarftEditorPage initValue={EditorData.text} />;
- },
- {
- info: {
- inline: true
- },
- notes: "A very simple example of addon notes"
- }
- );
-
- stories.add(
- "BraftEditorCommon",
- () => {
- const [editorState, setEditorState] = useState(
- BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")
- );
- return (
- <>
- <BarftEditorPage
- value={editorState}
- onChange={setEditorState}
- controls={["bold"]}
- FloatControls={({ editorState, setEditorState }: any) => (
- <ControlsToolBar
- editorState={editorState}
- setEditorState={setEditorState}
- toolList={[
- {
- key: 1,
- color: "#f07977",
- iconClass: "schedule schedule-icon_story",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- },
- {
- key: 2,
- color: "#3d9bfe",
- iconClass: "schedule schedule-icon_topic",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- },
- {
- key: 3,
- color: "#ffa405",
- iconClass: "schedule schedule-icon_emoticon",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- },
- {
- key: 4,
- color: "#71c135",
- iconClass: "schedule schedule-icon_img",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- }
- ]}
- />
- )}
- />
- </>
- );
- },
- {
- info: {
- inline: true
- },
- notes: "A very simple example of addon notes"
- }
- );
-
- stories.add(
- "SimpleEditor",
- () => {
- const [editorState, setEditorState] = useState(
- BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")
- );
- return (
- <>
- <SimpleEditor
- value={editorState}
- onChange={setEditorState}
- controls={[]}
- injectBraftEditorProps={{
- contentStyle: {
- height: '130px'
- },
- }}
- toolList={[
- {
- key: 1,
- color: "#f07977",
- text: "长文",
- iconClass: "schedule schedule-icon_story",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- },
- },
- {
- key: 2,
- color: "#3d9bfe",
- text: "话题",
- iconClass: "schedule schedule-icon_topic",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- },
- {
- key: 3,
- color: "#ffa405",
- text: "表情",
- iconClass: "schedule schedule-icon_emoticon",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- },
- render: (i, icon, text, style) => {
- return (
- <Popover
- trigger="click"
- content="123"
- >
- <div style={style}>
- {icon}
- {text}
- </div>
- </Popover>
- )
- },
- },
- {
- key: 4,
- color: "#71c135",
- text: "图片",
- iconClass: "schedule schedule-icon_img",
- onClick: () => {
- setEditorState(
- ContentUtils.insertText(editorState, "Hello World")
- );
- }
- }
- ]}
- injectControlsToolBar={{
- injectIconWrapStyle: {
- marginRight: "4px"
- }
- }}
- toolAlign={select("toolAlign", {
- Inner: 'inner',
- Bottom: 'bottom',
- }, "bottom")}
- toolBarContainerStyle={{
- display: 'flex',
- justifyContent: 'space-between',
- height: '55px',
- alignItems: 'center',
- }}
- appendToolBtn={(
- <div style={{ display: 'flex', alignItems: 'center', width: '400px', justifyContent: 'space-between'}}>
- <div className={styles.QAAnonymous}>
- <Popover
- trigger="hover"
- content={
- <div>
- 警告
- </div>
- }
- >
- <Checkbox>
- Anonymous
- </Checkbox>
- </Popover>
- </div>
- <div
- className={styles.QASaveBtn}
- >
- Save
- </div>
- <div
- className={styles.QASubmitBtn}
- >
- Submit
- </div>
- </div>
- )}
- />
- </>
- );
- },
- {
- info: {
- inline: true
- },
- notes: "A very simple example of addon notes"
- }
- );
-
|