Slider
A component for selecting a numeric value from a range of values with an optional increment. These are seen in some number-valued properties in the built-in Properties widget, as well as in various built-in plugins such as the Terrain Editor.
Dark | Light |
---|---|
As with other components in this library, this is a controlled component. You should pass a
value to the Value
prop representing the current value, as well as a callback to the OnChanged
prop which will be run when the user changes the value via dragging or clicking on the slider.
In addition to these, you must also provide a Min
and a Max
prop, which together define the
range of the slider. Optionally, a Step
prop can be provided, which defines the increment of
the slider. This defaults to 0, which allows any value in the range. For a complete example:
local function MyComponent()
local value, setValue = React.useState(1)
return React.createElement(StudioComponents.Slider, {
Value = value,
OnChanged = setValue,
Min = 0,
Max = 10,
Step = 1,
})
end
Optionally, an OnCompleted
callback prop can be provided. This will be called with the latest
value of the Slider when sliding is finished. It is also called if, while sliding is in progress,
the component becomes Disabled via props or is unmounted.
Two further props can optionally be provided:
-
Border
determines whether a border is drawn around the component. This is useful for giving visual feedback when the slider is hovered or selected. -
Background
determines whether the component has a visible background. If this is value is missing or set tofalse
, any border will also be hidden.
Both of these props default to true
.
By default, the height of sliders is equal to the value found in Constants.DefaultSliderHeight. While this can be overriden by props, in order to keep inputs accessible it is not recommended to make the component any smaller than this.
Types
Props
Component Propsinterface
Props {
...:
CommonProps
Value:
number
OnChanged:
(
(
newValue:
number
)
→
(
)
)
?
OnCompleted:
(
(
newValue:
number
)
→
(
)
)
?
Min:
number
Max:
number
Step:
number?
Border:
boolean?
Background:
boolean?
}