The Slider is used to allow users to make selections from a range of values.
NativeBase exports 4 slider-related components:
Slider: The wrapper that provides context and functionality for all children.
Slider.Track: The empty part of the slider that shows the track.
Slider.FilledTrack: The filled part of the slider.
Slider.Thumb: The handle that is used to change the slider value.
import { Slider } from 'native-base';
const Example = () => {
return <Box mx={5} width="80%">
<Slider defaultValue={70} minValue={0} maxValue={100} accessibilityLabel="hello world" step={10}>
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
</Box>;
};
const Example = () => {
return <Box mx={5} width="80%">
<Slider defaultValue={70} colorScheme="red">
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
</Box>;
};
const Example = () => {
const [onChangeValue, setOnChangeValue] = React.useState(70);
const [onChangeEndValue, setOnChangeEndValue] = React.useState(70);
return <Stack mx={5} space={4} alignItems="center" w="100%">
<Text>onChangeValue - {onChangeValue}</Text>
<Text>onChangeEndValue - {onChangeEndValue}</Text>
<Box mx={5} w="250">
<Slider defaultValue={70} colorScheme="cyan" onChange={v => {
setOnChangeValue(Math.floor(v));
}} onChangeEnd={v => {
v && setOnChangeEndValue(Math.floor(v));
}}>
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
</Box>
</Stack>;
};
const Example = () => {
return <VStack space={4} width="80%">
<Slider defaultValue={40} colorScheme="red" size="lg">
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
<Slider defaultValue={60} size="md">
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
<Slider defaultValue={80} colorScheme="green" size="sm">
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
</VStack>;
};
const Example = () => {
return <Box mx={5} width="80%">
<Slider defaultValue={70} size="lg" colorScheme="orange">
<Slider.Track bg="orange.100">
<Slider.FilledTrack bg="green.400" />
</Slider.Track>
<Slider.Thumb borderWidth={0} bg="gray.200">
<Icon as={MaterialIcons} name="park" color="green.500" />
</Slider.Thumb>
</Slider>
</Box>;
};
const Example = () => {
return <VStack space={4} mx={10} width="80%">
<FormControl isRequired isInvalid isDisabled>
<FormControl.Label>Just Slide</FormControl.Label>
<Slider defaultValue={50}>
<Slider.Track>
<Slider.FilledTrack />
</Slider.Track>
<Slider.Thumb />
</Slider>
<FormControl.HelperText>
We'll keep this between us.
</FormControl.HelperText>
<FormControl.ErrorMessage>
Don't worry, it's just an example.
</FormControl.ErrorMessage>
</FormControl>
</VStack>;
};
Slider implements
,
,
,
,
,
,
,
,
,
,
,
,
The current value of the Slider
The default value (uncontrolled).
Handler that is called when the value changes.
Type: (value: number) => void
Color scheme of the slider
Text description of slider. This will be announced by screen reader/
If true, the value will be incremented or decremented in reverse.
The orientation of the Slider.
Type: "horizontal" | "vertical"
Whether the whole Slider is disabled.
Fired when the slider stops moving, due to being let go.
Type: (value: number) => void
The slider's minimum value.
The slider's maximum value.
Slider.Track,
Slider.FilledTrack, and
Slider.Thumb composes the
component.
NativeBase ships with a default theme for each component. Check out the default theme of the Slider
.
Info:
We can easily extend the Slider component theme using extendTheme function as described in the documentation .Increments/decrements by the step value depending on orientation.
Increments/decrements by the step value depending on orientation.
Increases the value by the step amount.
Decreases the value by the step amount.