@@ -7,6 +7,15 @@ import { EditorFrameProps } from "./editor-frame"
7
7
8
8
export { MiniEditor , MiniEditorProps }
9
9
10
+ type SpringConfig = Parameters < typeof useSpring > [ 1 ]
11
+
12
+ const defaultSpring = {
13
+ stiffness : 120 ,
14
+ damping : 24 ,
15
+ mass : 0.2 ,
16
+ decimals : 3 ,
17
+ }
18
+
10
19
type SingleFileEditorProps = {
11
20
code : string
12
21
lang : string
@@ -15,17 +24,20 @@ type SingleFileEditorProps = {
15
24
terminal ?: string
16
25
frameProps ?: Partial < EditorFrameProps >
17
26
codeProps ?: Partial < CodeProps >
27
+ springConfig ?: SpringConfig
18
28
}
19
29
type SinglePanelEditorProps = {
20
30
files : StepFile [ ]
21
31
active : string
22
32
terminal ?: string
23
33
frameProps ?: Partial < EditorFrameProps >
24
34
codeProps ?: Partial < CodeProps >
35
+ springConfig ?: SpringConfig
25
36
}
26
37
type TwoPanelEditorProps = EditorStep & {
27
38
frameProps ?: Partial < EditorFrameProps >
28
39
codeProps ?: Partial < CodeProps >
40
+ springConfig ?: SpringConfig
29
41
}
30
42
type MiniEditorProps =
31
43
| SingleFileEditorProps
@@ -48,8 +60,8 @@ function SingleFileEditor({
48
60
focus,
49
61
filename = "" ,
50
62
terminal,
51
- frameProps ,
52
- codeProps ,
63
+ springConfig ,
64
+ ... props
53
65
} : SingleFileEditorProps ) {
54
66
const step = React . useMemo ( ( ) => {
55
67
const step : EditorStep = {
@@ -64,24 +76,26 @@ function SingleFileEditor({
64
76
return step
65
77
} , [ code , lang , focus , filename , terminal ] )
66
78
67
- const { prev, next, t } = useStepSpring ( step )
79
+ const { prev, next, t } = useStepSpring (
80
+ step ,
81
+ springConfig
82
+ )
68
83
return (
69
84
< MiniEditorTween
70
- frameProps = { frameProps }
71
85
t = { t }
72
86
backward = { false }
73
87
prev = { prev }
74
88
next = { next }
75
- codeProps = { codeProps }
89
+ { ... props }
76
90
/>
77
91
)
78
92
}
79
93
function SinglePanelEditor ( {
80
94
files,
81
95
active,
82
96
terminal,
83
- frameProps ,
84
- codeProps ,
97
+ springConfig ,
98
+ ... props
85
99
} : SinglePanelEditorProps ) {
86
100
const step = React . useMemo ( ( ) => {
87
101
const tabs = files . map ( file => file . name )
@@ -97,25 +111,27 @@ function SinglePanelEditor({
97
111
return step
98
112
} , [ files , active , terminal ] )
99
113
100
- const { prev, next, t } = useStepSpring ( step )
114
+ const { prev, next, t } = useStepSpring (
115
+ step ,
116
+ springConfig
117
+ )
101
118
return (
102
119
< MiniEditorTween
103
- frameProps = { frameProps }
104
120
t = { t }
105
121
backward = { false }
106
122
prev = { prev }
107
123
next = { next }
108
- codeProps = { codeProps }
124
+ { ... props }
109
125
/>
110
126
)
111
127
}
112
128
function TwoPanelEditor ( {
113
- frameProps,
114
- codeProps,
115
129
northPanel,
116
130
southPanel,
117
131
files,
118
132
terminal,
133
+ springConfig,
134
+ ...props
119
135
} : TwoPanelEditorProps ) {
120
136
const step = React . useMemo ( ( ) => {
121
137
return {
@@ -126,20 +142,25 @@ function TwoPanelEditor({
126
142
}
127
143
} , [ northPanel , southPanel , files , terminal ] )
128
144
129
- const { prev, next, t } = useStepSpring ( step )
145
+ const { prev, next, t } = useStepSpring (
146
+ step ,
147
+ springConfig
148
+ )
130
149
return (
131
150
< MiniEditorTween
132
- frameProps = { frameProps }
133
151
t = { t }
134
152
backward = { false }
135
153
prev = { prev }
136
154
next = { next }
137
- codeProps = { codeProps }
155
+ { ... props }
138
156
/>
139
157
)
140
158
}
141
159
142
- function useStepSpring ( step : EditorStep ) {
160
+ function useStepSpring (
161
+ step : EditorStep ,
162
+ springConfig : SpringConfig = defaultSpring
163
+ ) {
143
164
const [ { target, prev, next } , setState ] = React . useState (
144
165
{
145
166
target : 0 ,
@@ -158,12 +179,7 @@ function useStepSpring(step: EditorStep) {
158
179
}
159
180
} , [ step ] )
160
181
161
- const [ progress ] = useSpring ( target , {
162
- stiffness : 256 ,
163
- damping : 24 ,
164
- mass : 0.2 ,
165
- decimals : 3 ,
166
- } )
182
+ const [ progress ] = useSpring ( target , springConfig )
167
183
168
184
const t = progress % 1
169
185
0 commit comments