No Description

SimpleEditor.tsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import { BarftEditorPage, BaseEditorProps } from "@components/Editor/BraftEditor";
  3. import { ControlsToolBar, ToolListItem } from "@components/Editor/CommonTool/ControlsToolBar";
  4. import { ContentUtils } from "braft-utils";
  5. import styles from './index.less';
  6. interface SimpleEditorProps extends BaseEditorProps {
  7. toolAlign?: 'inner' | 'bottom' | 'both';
  8. toolList?: Array<ToolListItem>;
  9. injectControlsToolBar?: any;
  10. injectBraftEditorProps?: any;
  11. toolBarContainerStyle?: any;
  12. appendToolBtn?: any;
  13. appendInnderBar?: any;
  14. }
  15. const SimpleEditor = (props: SimpleEditorProps) => {
  16. const {
  17. value,
  18. onChange,
  19. toolAlign = 'inner',
  20. toolList = [],
  21. injectControlsToolBar = {},
  22. toolBarContainerStyle = {},
  23. injectBraftEditorProps = {},
  24. appendToolBtn = null,
  25. appendInnderBar = null,
  26. } = props;
  27. if (toolAlign === 'inner') {
  28. return (
  29. <BarftEditorPage
  30. value={value}
  31. onChange={onChange}
  32. controls={[]}
  33. FloatControls={({ editorState, setEditorState }: any) => (
  34. <ControlsToolBar
  35. editorState={editorState}
  36. setEditorState={setEditorState}
  37. toolList={toolList}
  38. {...injectControlsToolBar}
  39. />)
  40. }
  41. {...injectBraftEditorProps}
  42. />
  43. )
  44. }
  45. if (toolAlign === 'both') {
  46. return (
  47. <div>
  48. <BarftEditorPage
  49. value={value}
  50. onChange={onChange}
  51. controls={[]}
  52. FloatControls={() => appendInnderBar}
  53. {...injectBraftEditorProps}
  54. />
  55. <div style={toolBarContainerStyle}>
  56. <div className={styles.bottomToolBarWrapper}>
  57. <ControlsToolBar
  58. editorState={value}
  59. setEditorState={onChange}
  60. toolList={toolList}
  61. {...injectControlsToolBar}
  62. />
  63. </div>
  64. {appendToolBtn}
  65. </div>
  66. </div>
  67. )
  68. }
  69. return (
  70. <div>
  71. <BarftEditorPage
  72. value={value}
  73. onChange={onChange}
  74. controls={[]}
  75. {...injectBraftEditorProps}
  76. />
  77. <div style={toolBarContainerStyle}>
  78. <div className={styles.bottomToolBarWrapper}>
  79. <ControlsToolBar
  80. editorState={value}
  81. setEditorState={onChange}
  82. toolList={toolList}
  83. {...injectControlsToolBar}
  84. />
  85. </div>
  86. {appendToolBtn}
  87. </div>
  88. </div>
  89. );
  90. }
  91. export default SimpleEditor;