File tree Expand file tree Collapse file tree 2 files changed +47
-27
lines changed Expand file tree Collapse file tree 2 files changed +47
-27
lines changed Original file line number Diff line number Diff line change @@ -137,11 +137,30 @@ const Demo = () => {
137
137
}
138
138
```
139
139
140
+ Set (` data-color-mode="dark" ` ) dark theme.
141
+
142
+ ``` jsx
143
+ import CodeEditor from ' @uiw/react-textarea-code-editor' ;
144
+
145
+ function App () {
146
+ return (
147
+ < CodeEditor
148
+ value= " function add(a, b) {\n return a + b;\n }"
149
+ data- color- mode= " dark"
150
+ / >
151
+ );
152
+ }
153
+ ```
154
+
140
155
## Props
141
156
142
157
``` ts
143
158
interface TextareaCodeEditorProps extends React .TextareaHTMLAttributes <HTMLTextAreaElement > {
144
159
prefixCls? : string ;
160
+ /**
161
+ * Support dark-mode/night-mode
162
+ */
163
+ [' data-color-mode' ]? : ' dark' | ' light' ;
145
164
/**
146
165
* Set what programming language the code belongs to.
147
166
*/
Original file line number Diff line number Diff line change @@ -85,39 +85,40 @@ export default React.forwardRef<HTMLTextAreaElement, TextareaCodeEditorProps>((p
85
85
[ prefixCls , language , htmlStr ] ,
86
86
) ;
87
87
88
+ const textareaProps : React . TextareaHTMLAttributes < HTMLTextAreaElement > = {
89
+ autoComplete : 'off' ,
90
+ autoCorrect : 'off' ,
91
+ spellCheck : 'false' ,
92
+ autoCapitalize : 'off' ,
93
+ ...other ,
94
+ placeholder,
95
+ onKeyDown : ( evn ) => {
96
+ if ( ! other . onKeyDown || other . onKeyDown ( evn ) !== false ) {
97
+ shortcuts ( evn ) ;
98
+ }
99
+ } ,
100
+ style : {
101
+ ...styles . editor ,
102
+ ...styles . textarea ,
103
+ ...contentStyle ,
104
+ minHeight,
105
+ ...( placeholder && ! value ? { WebkitTextFillColor : 'inherit' } : { } ) ,
106
+ } ,
107
+ onChange : ( evn ) => {
108
+ setValue ( evn . target . value ) ;
109
+ onChange && onChange ( evn ) ;
110
+ } ,
111
+ className : `${ prefixCls } -text` ,
112
+ value : value ,
113
+ } ;
114
+
88
115
return (
89
116
< div
90
117
style = { { ...styles . container , ...style } }
91
118
className = { `${ prefixCls } ${ className || '' } ` }
92
119
data-color-mode = { dataColorMode }
93
120
>
94
- < textarea
95
- autoComplete = "off"
96
- autoCorrect = "off"
97
- spellCheck = "false"
98
- autoCapitalize = "off"
99
- { ...other }
100
- placeholder = { placeholder }
101
- onKeyDown = { ( evn ) => {
102
- if ( ! other . onKeyDown || other . onKeyDown ( evn ) !== false ) {
103
- shortcuts ( evn ) ;
104
- }
105
- } }
106
- style = { {
107
- ...styles . editor ,
108
- ...styles . textarea ,
109
- ...contentStyle ,
110
- minHeight,
111
- ...( placeholder && ! value ? { WebkitTextFillColor : 'inherit' } : { } ) ,
112
- } }
113
- ref = { textRef }
114
- onChange = { ( evn ) => {
115
- setValue ( evn . target . value ) ;
116
- onChange && onChange ( evn ) ;
117
- } }
118
- className = { `${ prefixCls } -text` }
119
- value = { value }
120
- />
121
+ < textarea { ...textareaProps } ref = { textRef } />
121
122
{ preView }
122
123
</ div >
123
124
) ;
You can’t perform that action at this time.
0 commit comments