Skip to content

Commit 8eed1ec

Browse files
committedMar 23, 2025·
优化Markdown输入字段样式,添加禁用状态支持及发送按钮
1 parent 36ccfd6 commit 8eed1ec

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
 

‎src/MarkdownEditor/demos/markdownInputField.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@ export default () => {
77
<div
88
style={{
99
padding: '20px',
10+
margin: 'auto',
11+
maxWidth: '800px',
12+
display: 'flex',
13+
flexDirection: 'column',
14+
gap: '20px',
1015
}}
1116
>
1217
<MarkdownInputField
1318
value=""
1419
onChange={() => {}}
1520
placeholder="请输入内容"
1621
/>
22+
<MarkdownInputField
23+
value=""
24+
disabled
25+
onChange={() => {}}
26+
placeholder="请输入内容"
27+
/>
1728
</div>
1829
);
1930
};

‎src/MarkdownInputField/MarkdownInputField.tsx

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
1-
import React from 'react';
1+
import { SendOutlined } from '@ant-design/icons';
2+
import { Button } from 'antd';
3+
import React from 'react';
24
import { BaseMarkdownEditor } from '../MarkdownEditor';
35

46
export type MarkdownInputFieldProps = {
57
value: string;
68
onChange: (value: string) => void;
79
placeholder?: string;
10+
style: React.CSSProperties;
11+
className?: string;
12+
disabled?: boolean;
13+
};
14+
15+
const disableStyle: React.CSSProperties = {
16+
opacity: 0.5,
17+
backgroundColor: 'rgba(0,0,0,0.04)',
18+
cursor: 'not-allowed',
819
};
920

1021
export const MarkdownInputField: React.FC<MarkdownInputFieldProps> = (
1122
props,
1223
) => {
1324
return (
1425
<div
26+
className={props.className}
1527
style={{
1628
width: '100%',
1729
height: '100%',
1830
display: 'flex',
31+
boxShadow: `0 1px 2px 0 rgba(0, 0, 0, 0.03),0 1px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px 0 rgba(0, 0, 0, 0.02)`,
1932
flexDirection: 'column',
2033
alignItems: 'center',
2134
justifyContent: 'center',
22-
border: '2px solid #f0f0f0',
35+
outline: '1px solid #d9d9d9',
2336
borderRadius: '12px',
2437
minHeight: '32px',
38+
maxWidth: 980,
39+
position: 'relative',
40+
...(props.disabled ? disableStyle : {}),
41+
...props.style,
2542
}}
2643
>
2744
<BaseMarkdownEditor
@@ -30,6 +47,7 @@ export const MarkdownInputField: React.FC<MarkdownInputFieldProps> = (
3047
minHeight: '32px',
3148
height: '100%',
3249
}}
50+
readonly={props.disabled}
3351
contentStyle={{
3452
padding: '12px',
3553
}}
@@ -47,6 +65,17 @@ export const MarkdownInputField: React.FC<MarkdownInputFieldProps> = (
4765
enable: false,
4866
}}
4967
/>
68+
<Button
69+
style={{
70+
position: 'absolute',
71+
right: 8,
72+
bottom: 8,
73+
}}
74+
disabled={props.disabled}
75+
type="primary"
76+
shape="circle"
77+
icon={<SendOutlined />}
78+
/>
5079
</div>
5180
);
5281
};

1 commit comments

Comments
 (1)
Please sign in to comment.