@hep-code-runner/react 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -0
- package/dist/index.js +73 -73
- package/dist/index.mjs +335 -335
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,3 +107,93 @@ function App() {
|
|
|
107
107
|
- react: ^16.8.0 || ^17.0.0 || ^18.0.0
|
|
108
108
|
- react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
|
|
109
109
|
- prismjs: ^1.30.0
|
|
110
|
+
|
|
111
|
+
## CodeRunnerDialog 弹窗组件
|
|
112
|
+
|
|
113
|
+
提供弹窗模式的代码执行器,支持受控和非受控模式。
|
|
114
|
+
|
|
115
|
+
### 引入
|
|
116
|
+
|
|
117
|
+
```jsx
|
|
118
|
+
import { CodeRunnerDialog } from "@hep-code-runner/react";
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 受控模式
|
|
122
|
+
|
|
123
|
+
```jsx
|
|
124
|
+
import { useState } from "react";
|
|
125
|
+
import { CodeRunnerDialog } from "@hep-code-runner/react";
|
|
126
|
+
|
|
127
|
+
function App() {
|
|
128
|
+
const [visible, setVisible] = useState(false);
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<>
|
|
132
|
+
<button onClick={() => setVisible(true)}>打开弹窗</button>
|
|
133
|
+
|
|
134
|
+
<CodeRunnerDialog
|
|
135
|
+
open={visible}
|
|
136
|
+
onClose={() => setVisible(false)}
|
|
137
|
+
title="代码执行器"
|
|
138
|
+
width={800}
|
|
139
|
+
footer={
|
|
140
|
+
<>
|
|
141
|
+
<button onClick={() => setVisible(false)}>取消</button>
|
|
142
|
+
<button onClick={handleSave}>保存</button>
|
|
143
|
+
<button onClick={handleInsert}>插入代码</button>
|
|
144
|
+
</>
|
|
145
|
+
}
|
|
146
|
+
/>
|
|
147
|
+
</>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 非受控模式
|
|
153
|
+
|
|
154
|
+
```jsx
|
|
155
|
+
import { useRef } from "react";
|
|
156
|
+
import { CodeRunnerDialog } from "@hep-code-runner/react";
|
|
157
|
+
|
|
158
|
+
function App() {
|
|
159
|
+
const dialogRef = useRef(null);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<>
|
|
163
|
+
<button onClick={() => dialogRef.current?.open()}>打开弹窗</button>
|
|
164
|
+
|
|
165
|
+
<CodeRunnerDialog
|
|
166
|
+
ref={dialogRef}
|
|
167
|
+
title="代码执行器"
|
|
168
|
+
footer={
|
|
169
|
+
<>
|
|
170
|
+
<button onClick={() => dialogRef.current?.close()}>取消</button>
|
|
171
|
+
<button onClick={handleInsert}>插入代码</button>
|
|
172
|
+
</>
|
|
173
|
+
}
|
|
174
|
+
/>
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Props 属性
|
|
181
|
+
|
|
182
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
183
|
+
|------|------|--------|------|
|
|
184
|
+
| open | boolean | - | 控制显示隐藏(受控模式) |
|
|
185
|
+
| defaultOpen | boolean | false | 初始显示状态(非受控模式) |
|
|
186
|
+
| title | string | '代码执行器' | 弹窗标题 |
|
|
187
|
+
| width | string \| number | 800 | 弹窗宽度 |
|
|
188
|
+
| onClose | () => void | - | 关闭回调 |
|
|
189
|
+
| footer | ReactNode | - | 底部自定义内容 |
|
|
190
|
+
| theme | 'light' \| 'dark' | 'light' | 主题 |
|
|
191
|
+
|
|
192
|
+
其他 Props 会透传给内部 CodeRunner 组件。
|
|
193
|
+
|
|
194
|
+
### Ref 方法
|
|
195
|
+
|
|
196
|
+
| 方法 | 说明 |
|
|
197
|
+
|------|------|
|
|
198
|
+
| open() | 打开弹窗 |
|
|
199
|
+
| close() | 关闭弹窗 |
|