Browse Source

dev: 初步实现图文编辑组件

Roxas 4 years ago
parent
commit
a9fd17774d

+ 9
- 1
src/components/Editor/CommonTool/ControlsToolBar.tsx View File

@@ -14,6 +14,7 @@ interface ControlsToolBarProps {
14 14
   toolList: Array<ToolListItem>;
15 15
   injectIconWrapStyle?: any;
16 16
   injectIconStyle?: any;
17
+  injectIconTextStyle?: any;
17 18
 }
18 19
 
19 20
 export const ControlsToolBar = (props: ControlsToolBarProps) => {
@@ -23,14 +24,18 @@ export const ControlsToolBar = (props: ControlsToolBarProps) => {
23 24
     toolList = [],
24 25
     injectIconWrapStyle = {},
25 26
     injectIconStyle = {},
27
+    injectIconTextStyle = {},
26 28
   } = props;
27 29
   const IconWrapStyle = {
30
+    display: 'flex',
31
+    alignItems: 'center',
28 32
     cursor: "pointer",
29 33
     textAlign: "center" as const,
30
-    width: "42px",
34
+    minWidth: "42px",
31 35
     ...injectIconWrapStyle,
32 36
   };
33 37
   const IconStyle = { fontSize: "21px", ...injectIconStyle };
38
+  const IconTextStyle = { margin: "0 4px", ...injectIconTextStyle };
34 39
 
35 40
   if (toolList.length < 1) {
36 41
     return null;
@@ -46,6 +51,9 @@ export const ControlsToolBar = (props: ControlsToolBarProps) => {
46 51
           onClick={i.onClick}
47 52
         >
48 53
           <i className={i.iconClass} style={IconStyle} />
54
+          {
55
+            i.text ? <span style={IconTextStyle}>{i.text}</span> : null
56
+          }
49 57
         </div>
50 58
       ))
51 59
     }

+ 3
- 0
src/components/Editor/QAEditor/SimpleEditor.tsx View File

@@ -7,6 +7,7 @@ import styles from './index.less';
7 7
 interface QASimpleEditorProps extends BaseEditorProps {
8 8
   toolAlign?: 'inner' | 'bottom';
9 9
   toolList?: Array<ToolListItem>;
10
+  injectControlsToolBar?: any;
10 11
   toolBarContainerStyle?: any;
11 12
   appendToolBtn?: any;
12 13
 }
@@ -17,6 +18,7 @@ const QASimpleEditor = (props: QASimpleEditorProps) => {
17 18
     onChange, 
18 19
     toolAlign = 'inner',
19 20
     toolList = [],
21
+    injectControlsToolBar = {},
20 22
     toolBarContainerStyle = {},
21 23
     appendToolBtn = null,
22 24
   } = props;
@@ -52,6 +54,7 @@ const QASimpleEditor = (props: QASimpleEditorProps) => {
52 54
             editorState={value}
53 55
             setEditorState={onChange}
54 56
             toolList={toolList}
57
+            {...injectControlsToolBar}
55 58
           />
56 59
         </div>
57 60
         {appendToolBtn}

+ 10
- 1
stories/Editor.stories.tsx View File

@@ -125,6 +125,7 @@ stories.add(
125 125
             {
126 126
               key: 1,
127 127
               color: "#f07977",
128
+              text: "长文",
128 129
               iconClass: "schedule schedule-icon_story",
129 130
               onClick: () => {
130 131
                 setEditorState(
@@ -135,6 +136,7 @@ stories.add(
135 136
             {
136 137
               key: 2,
137 138
               color: "#3d9bfe",
139
+              text: "话题",
138 140
               iconClass: "schedule schedule-icon_topic",
139 141
               onClick: () => {
140 142
                 setEditorState(
@@ -145,6 +147,7 @@ stories.add(
145 147
             {
146 148
               key: 3,
147 149
               color: "#ffa405",
150
+              text: "表情",
148 151
               iconClass: "schedule schedule-icon_emoticon",
149 152
               onClick: () => {
150 153
                 setEditorState(
@@ -155,6 +158,7 @@ stories.add(
155 158
             {
156 159
               key: 4,
157 160
               color: "#71c135",
161
+              text: "图片",
158 162
               iconClass: "schedule schedule-icon_img",
159 163
               onClick: () => {
160 164
                 setEditorState(
@@ -163,6 +167,11 @@ stories.add(
163 167
               }
164 168
             }
165 169
           ]}
170
+          injectControlsToolBar={{
171
+            injectIconWrapStyle: {
172
+              marginRight: "4px"
173
+            }
174
+          }}
166 175
           toolAlign={select("toolAlign", {
167 176
             Inner: 'inner',
168 177
             Bottom: 'bottom',
@@ -185,7 +194,7 @@ stories.add(
185 194
                   }
186 195
                 >
187 196
                   <Checkbox>
188
-                    anonymous
197
+                    Anonymous
189 198
                   </Checkbox>
190 199
                 </Popover>
191 200
               </div>