1
- import React , { useBinding , useCallback , useEffect , useMemo , useRef , useState } from "@rbxts/react" ;
1
+ import {
2
+ Instant ,
3
+ Spring ,
4
+ useMotor ,
5
+ useUpdateEffect
6
+ } from "@rbxts/pretty-react-hooks" ;
7
+ import React , {
8
+ useBinding ,
9
+ useCallback ,
10
+ useEffect ,
11
+ useMemo ,
12
+ useRef ,
13
+ useState
14
+ } from "@rbxts/react" ;
15
+ import { RunService } from "@rbxts/services" ;
2
16
import { AdvancedTypes } from "@rbxts/ui-labs/src/ControlTypings/Advanced" ;
3
17
import { useTheme } from "Hooks/Reflex/Use/Theme" ;
18
+ import { useTween } from "Hooks/Utils/Tween" ;
4
19
import FrameFill from "UI/Holders/FrameFill" ;
5
20
import Corner from "UI/Styles/Corner" ;
6
21
import { Div } from "UI/Styles/Div" ;
7
22
import LeftList from "UI/Styles/List/LeftList" ;
8
23
import Padding from "UI/Styles/Padding" ;
24
+ import Rounder from "UI/Styles/Rounder" ;
9
25
import Text from "UI/Styles/Text" ;
10
26
import SlideDrag from "UI/Utils/Draggers/SlideDrag" ;
11
27
import InputEntry from "UI/Utils/InputEntry" ;
12
28
import { Decoders } from "UI/Utils/InputEntry/Decoders" ;
13
29
import { Filters } from "UI/Utils/InputEntry/Filters" ;
14
- import Mark from "./Mark" ;
15
- import Rounder from "UI/Styles/Rounder" ;
16
- import { Instant , Spring , useMotor , useUpdateEffect } from "@rbxts/pretty-react-hooks" ;
17
- import { useTween } from "Hooks/Utils/Tween" ;
18
- import { RunService } from "@rbxts/services" ;
19
30
import { Parsers } from "UI/Utils/InputEntry/Parsers" ;
31
+ import Mark from "./Mark" ;
20
32
21
33
const MIN_MARK_SEPARATION = 15 ;
22
34
@@ -32,7 +44,11 @@ function GetPercent(control: AdvancedTypes.Slider, current: number) {
32
44
return ( current - control . Min ) / gap ;
33
45
}
34
46
35
- const ACTIVE_INFO = new TweenInfo ( 0.08 , Enum . EasingStyle . Linear , Enum . EasingDirection . Out ) ;
47
+ const ACTIVE_INFO = new TweenInfo (
48
+ 0.08 ,
49
+ Enum . EasingStyle . Linear ,
50
+ Enum . EasingDirection . Out
51
+ ) ;
36
52
37
53
function SliderControl ( props : ControlElementProps < AdvancedTypes . Slider > ) {
38
54
const theme = useTheme ( ) ;
@@ -42,7 +58,10 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
42
58
const [ percent , setPercent ] = useMotor ( GetPercent ( control , props . Current ) ) ;
43
59
const [ amount , setAmount ] = useState ( props . Current ) ;
44
60
const [ markVisible , setMarkVisible ] = useState ( false ) ;
45
- const [ sliderState , setSliderState ] = useState ( { Hovering : false , Dragging : false } ) ;
61
+ const [ sliderState , setSliderState ] = useState ( {
62
+ Hovering : false ,
63
+ Dragging : false
64
+ } ) ;
46
65
const [ handleSize , tweenHandleSize ] = useTween ( ACTIVE_INFO , 0 ) ;
47
66
const sliderRef = useRef < Frame > ( ) ;
48
67
@@ -60,7 +79,9 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
60
79
61
80
const markAmount = CalculateMarks ( control ) ;
62
81
for ( let i = 0 ; i < markAmount - 1 ; i ++ ) {
63
- const newMark = < Mark Amount = { markAmount } Position = { i + 1 } Percent = { percent } /> ;
82
+ const newMark = (
83
+ < Mark Amount = { markAmount } Position = { i + 1 } Percent = { percent } />
84
+ ) ;
64
85
allMarks . push ( newMark ) ;
65
86
}
66
87
return allMarks ;
@@ -117,35 +138,45 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
117
138
props . Apply ( finalAmount ) ;
118
139
}
119
140
} ,
120
- [ control . Min , control . Max , control . Step , props . Apply , amount ] ,
141
+ [ control . Min , control . Max , control . Step , props . Apply , amount ]
121
142
) ;
122
143
const SetPercent = useCallback (
123
144
( percent : number ) => {
124
145
const amount = percent * ( control . Max - control . Min ) + control . Min ;
125
146
ApplyAmount ( amount ) ;
126
147
} ,
127
- [ ApplyAmount ] ,
148
+ [ ApplyAmount ]
149
+ ) ;
150
+ const OnStateUpdated = useCallback (
151
+ ( state : { hovering : boolean ; dragging : boolean } ) => {
152
+ setSliderState ( { Hovering : state . hovering , Dragging : state . dragging } ) ;
153
+ } ,
154
+ [ ]
128
155
) ;
129
- const OnStateUpdated = useCallback ( ( state : { hovering : boolean ; dragging : boolean } ) => {
130
- setSliderState ( { Hovering : state . hovering , Dragging : state . dragging } ) ;
131
- } , [ ] ) ;
132
156
const OnInputAbsoluteSizeChanged = useCallback (
133
157
( entry : Frame ) => {
134
158
if ( sliderState . Dragging ) return ;
135
159
setInputSize ( entry . AbsoluteSize . X ) ;
136
160
} ,
137
- [ sliderState . Dragging ] ,
161
+ [ sliderState . Dragging ]
138
162
) ;
139
163
140
164
return (
141
165
< Div >
142
166
< Padding PaddingY = { 4 } />
143
- < LeftList VerticalAlignment = { Enum . VerticalAlignment . Center } Padding = { new UDim ( 0 , 7 ) } />
167
+ < LeftList
168
+ VerticalAlignment = { Enum . VerticalAlignment . Center }
169
+ Padding = { new UDim ( 0 , 7 ) }
170
+ />
144
171
< Div
145
172
AutomaticSize = { sliderState . Dragging ? undefined : Enum . AutomaticSize . X }
146
- Size = { sliderState . Dragging ? inputSize . map ( ( offset ) => new UDim2 ( 0 , offset , 1 , 0 ) ) : UDim2 . fromScale ( 0 , 1 ) }
173
+ Size = {
174
+ sliderState . Dragging
175
+ ? inputSize . map ( ( offset ) => new UDim2 ( 0 , offset , 1 , 0 ) )
176
+ : UDim2 . fromScale ( 0 , 1 )
177
+ }
147
178
Change = { {
148
- AbsoluteSize : OnInputAbsoluteSizeChanged ,
179
+ AbsoluteSize : OnInputAbsoluteSizeChanged
149
180
} }
150
181
>
151
182
< InputEntry
@@ -156,17 +187,28 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
156
187
Filters = { [ Filters . NumberOnly ] }
157
188
TextboxProps = { {
158
189
TextSize : 12 ,
159
- Size : sliderState . Dragging ? UDim2 . fromScale ( 1 , 1 ) : UDim2 . fromScale ( 0 , 1 ) ,
160
- AutomaticSize : sliderState . Dragging ? undefined : Enum . AutomaticSize . X ,
161
- TextXAlignment : Enum . TextXAlignment . Center ,
190
+ Size : sliderState . Dragging
191
+ ? UDim2 . fromScale ( 1 , 1 )
192
+ : UDim2 . fromScale ( 0 , 1 ) ,
193
+ AutomaticSize : sliderState . Dragging
194
+ ? undefined
195
+ : Enum . AutomaticSize . X ,
196
+ TextXAlignment : Enum . TextXAlignment . Center
162
197
} }
163
198
HolderProps = { {
164
199
LayoutOrder : 1 ,
165
- Size : sliderState . Dragging ? UDim2 . fromScale ( 1 , 1 ) : UDim2 . fromScale ( 0 , 1 ) ,
166
- AutomaticSize : sliderState . Dragging ? undefined : Enum . AutomaticSize . X ,
200
+ Size : sliderState . Dragging
201
+ ? UDim2 . fromScale ( 1 , 1 )
202
+ : UDim2 . fromScale ( 0 , 1 ) ,
203
+ AutomaticSize : sliderState . Dragging
204
+ ? undefined
205
+ : Enum . AutomaticSize . X
167
206
} }
168
207
>
169
- < uisizeconstraint MaxSize = { new Vector2 ( 120 , math . huge ) } MinSize = { new Vector2 ( 35 , 0 ) } />
208
+ < uisizeconstraint
209
+ MaxSize = { new Vector2 ( 120 , math . huge ) }
210
+ MinSize = { new Vector2 ( 35 , 0 ) }
211
+ />
170
212
</ InputEntry >
171
213
</ Div >
172
214
< FrameFill FillDir = "X" FrameProps = { { LayoutOrder : 2 } } >
@@ -179,7 +221,11 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
179
221
TextXAlignment = { Enum . TextXAlignment . Right }
180
222
Position = { UDim2 . fromScale ( 0 , 0.5 ) }
181
223
/>
182
- < Div AnchorPoint = { new Vector2 ( 0.5 , 0.5 ) } Position = { UDim2 . fromScale ( 0.5 , 0.5 ) } Size = { new UDim2 ( 1 , - 75 , 1 , 0 ) } >
224
+ < Div
225
+ AnchorPoint = { new Vector2 ( 0.5 , 0.5 ) }
226
+ Position = { UDim2 . fromScale ( 0.5 , 0.5 ) }
227
+ Size = { new UDim2 ( 1 , - 75 , 1 , 0 ) }
228
+ >
183
229
< frame
184
230
key = "Slide"
185
231
AnchorPoint = { new Vector2 ( 0.5 , 0.5 ) }
@@ -197,7 +243,7 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
197
243
BackgroundTransparency : 1 ,
198
244
Position : UDim2 . fromScale ( 0.5 , 0.5 ) ,
199
245
Size : new UDim2 ( 1 , 0 , 0 , 15 ) ,
200
- ZIndex : 3 ,
246
+ ZIndex : 3
201
247
} }
202
248
SlideDir = "X"
203
249
PercentApply = { SetPercent }
@@ -216,7 +262,9 @@ function SliderControl(props: ControlElementProps<AdvancedTypes.Slider>) {
216
262
BackgroundColor3 = { theme . StorySelected . Color }
217
263
BorderSizePixel = { 0 }
218
264
Position = { new UDim2 ( 1 , 0 , 0.5 , 0 ) }
219
- Size = { handleSize . map ( ( a ) => UDim2 . fromOffset ( 10 + a * 3 , 10 + a * 3 ) ) }
265
+ Size = { handleSize . map ( ( a ) =>
266
+ UDim2 . fromOffset ( 10 + a * 3 , 10 + a * 3 )
267
+ ) }
220
268
>
221
269
< Rounder />
222
270
</ frame >
0 commit comments