Skip to content

Commit 93f9952

Browse files
committed
feat: update README and RangeSlider component for thumb terminology
1 parent f58102c commit 93f9952

File tree

4 files changed

+203
-2415
lines changed

4 files changed

+203
-2415
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# React Native Range Slider
22

3-
A high-performance React Native range slider component built with react-native-reanimated and react-native-gesture-handler for smooth animations and precise touch control.
3+
A high-performance React Native range slider component built with [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated) and [react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler) for smooth animations and precise touch control.
44

55
## Features
66

@@ -83,22 +83,22 @@ const YourComponent = () => {
8383
| max | number | Yes | - | Maximum allowed value |
8484
| step | number | No | 1 | Step size for value changes |
8585
| sliderWidth | number | No | 270 | Width of the slider track |
86-
| markerSize | number | No | 32 | Size of marker handles |
86+
| thumbSize | number | No | 32 | Size of thumb handles |
8787
| trackHeight | number | No | 2.5 | Height of slider track |
88-
| minimumDistance | number | No | 16 | Minimum distance between markers |
88+
| minimumDistance | number | No | 16 | Minimum distance between thumbs |
8989
| enabled | boolean | No | true | Enable/disable slider |
90-
| allowOverlap | boolean | No | false | Allow markers to overlap |
91-
| showMarkerLines | boolean | No | true | Show marker lines inside handles |
90+
| allowOverlap | boolean | No | false | Allow thumbs to overlap |
91+
| showThumbLines | boolean | No | true | Show lines inside thumb handles |
9292
| selectedTrackStyle | object | No | - | Style object for selected track portion |
9393
| unselectedTrackStyle | object | No | - | Style object for unselected track portion |
94-
| markerStyle | object | No | - | Style object for both markers |
95-
| pressedMarkerStyle | object | No | - | Style applied when marker is pressed |
94+
| thumbStyle | object | No | - | Style object for both thumbs |
95+
| pressedThumbStyle | object | No | - | Style applied when thumb is pressed |
9696
| containerStyle | object | No | - | Style for the container view |
9797
| onValuesChange | function | No | () => {} | Called while dragging |
9898
| onValuesChangeStart | function | No | () => {} | Called when drag starts |
9999
| onValuesChangeFinish | function | No | () => {} | Called when drag ends |
100-
| leftMarkerAccessibilityLabel | string | No | "Left handle" | Accessibility label for left marker |
101-
| rightMarkerAccessibilityLabel | string | No | "Right handle" | Accessibility label for right marker |
100+
| leftThumbAccessibilityLabel | string | No | "Left handle" | Accessibility label for left thumb |
101+
| rightThumbAccessibilityLabel | string | No | "Right handle" | Accessibility label for right thumb |
102102

103103
## Styling
104104

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"registry": "https://registry.npmjs.org/"
6868
},
6969
"dependencies": {
70+
"prop-types": "^15.8.1",
7071
"react-native-gesture-handler": "^2.15.0",
71-
"react-native-reanimated": "^3.8.0",
72-
"prop-types": "^15.8.1"
72+
"react-native-reanimated": "^3.8.0"
7373
},
7474
"peerDependencies": {
7575
"react": "*",

src/RangeSlider.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import PropTypes from 'prop-types';
1616
// Layout constants
1717
const HORIZONTAL_PADDING = 15;
1818
const TOUCH_HITSLOP = { top: 20, bottom: 20, left: 20, right: 20 };
19-
const MIN_MARKER_SPACING = 16;
19+
const MIN_THUMB_SPACING = 16;
2020

2121
// Default values constants
2222
const DEFAULT_VALUES = {
2323
SLIDER_WIDTH: 270,
24-
MARKER_SIZE: 32,
24+
THUMB_SIZE: 32,
2525
TRACK_HEIGHT: 2.5,
2626
STEP: 1,
27-
LEFT_MARKER_LABEL: 'Left handle',
28-
RIGHT_MARKER_LABEL: 'Right handle',
29-
MINIMUM_DISTANCE: MIN_MARKER_SPACING,
30-
SHOW_MARKER_LINES: true,
27+
LEFT_THUMB_LABEL: 'Left handle',
28+
RIGHT_THUMB_LABEL: 'Right handle',
29+
MINIMUM_DISTANCE: MIN_THUMB_SPACING,
30+
SHOW_THUMB_LINES: true,
3131
};
3232

3333
const createDynamicStyles = (props) => ({
@@ -45,10 +45,10 @@ const createDynamicStyles = (props) => ({
4545
position: 'absolute',
4646
height: props.trackHeight,
4747
},
48-
marker: {
49-
height: props.markerSize,
50-
width: props.markerSize,
51-
borderRadius: props.markerSize / 2,
48+
thumb: {
49+
height: props.thumbSize,
50+
width: props.thumbSize,
51+
borderRadius: props.thumbSize / 2,
5252
backgroundColor: 'white', // Move default color here
5353
position: 'absolute',
5454
shadowColor: '#000',
@@ -58,7 +58,7 @@ const createDynamicStyles = (props) => ({
5858
elevation: 5,
5959
left: 0,
6060
top: '50%',
61-
marginTop: -(props.markerSize / 2),
61+
marginTop: -(props.thumbSize / 2),
6262
borderWidth: 0.5,
6363
borderColor: '#CECECE',
6464
justifyContent: 'center',
@@ -80,13 +80,13 @@ const RangeSlider = forwardRef(
8080
// Style props
8181
selectedTrackStyle,
8282
unselectedTrackStyle,
83-
markerStyle,
84-
pressedMarkerStyle,
83+
thumbStyle,
84+
pressedThumbStyle,
8585
containerStyle,
8686

8787
// Customization props
8888
sliderWidth = DEFAULT_VALUES.SLIDER_WIDTH,
89-
markerSize = DEFAULT_VALUES.MARKER_SIZE,
89+
thumbSize = DEFAULT_VALUES.THUMB_SIZE,
9090
trackHeight = DEFAULT_VALUES.TRACK_HEIGHT,
9191
minimumDistance = DEFAULT_VALUES.MINIMUM_DISTANCE,
9292

@@ -100,11 +100,11 @@ const RangeSlider = forwardRef(
100100
onValuesChangeStart = () => {},
101101

102102
// Accessibility props
103-
leftMarkerAccessibilityLabel = DEFAULT_VALUES.LEFT_MARKER_LABEL,
104-
rightMarkerAccessibilityLabel = DEFAULT_VALUES.RIGHT_MARKER_LABEL,
103+
leftThumbAccessibilityLabel = DEFAULT_VALUES.LEFT_THUMB_LABEL,
104+
rightThumbAccessibilityLabel = DEFAULT_VALUES.RIGHT_THUMB_LABEL,
105105

106-
// Marker lines prop
107-
showMarkerLines = DEFAULT_VALUES.SHOW_MARKER_LINES,
106+
// Visual props
107+
showThumbLines = DEFAULT_VALUES.SHOW_THUMB_LINES,
108108
},
109109
ref
110110
) => {
@@ -152,11 +152,11 @@ const RangeSlider = forwardRef(
152152
};
153153
});
154154

155-
const leftMarkerStyle = useAnimatedStyle(() => ({
155+
const leftThumbStyle = useAnimatedStyle(() => ({
156156
transform: leftTransform.value,
157157
}));
158158

159-
const rightMarkerStyle = useAnimatedStyle(() => ({
159+
const rightThumbStyle = useAnimatedStyle(() => ({
160160
transform: rightTransform.value,
161161
}));
162162

@@ -284,7 +284,7 @@ const RangeSlider = forwardRef(
284284

285285
const dynamicStyles = createDynamicStyles({
286286
sliderWidth,
287-
markerSize,
287+
thumbSize,
288288
trackHeight,
289289
enabled,
290290
});
@@ -321,17 +321,17 @@ const RangeSlider = forwardRef(
321321
>
322322
<Animated.View
323323
accessible={true}
324-
accessibilityLabel={leftMarkerAccessibilityLabel}
324+
accessibilityLabel={leftThumbAccessibilityLabel}
325325
accessibilityRole="adjustable"
326326
style={[
327-
dynamicStyles.marker,
327+
dynamicStyles.thumb,
328328
styles.markerContainer,
329-
markerStyle,
330-
pressed.left && pressedMarkerStyle,
331-
leftMarkerStyle,
329+
thumbStyle,
330+
pressed.left && pressedThumbStyle,
331+
leftThumbStyle,
332332
]}
333333
>
334-
{showMarkerLines && (
334+
{showThumbLines && (
335335
<>
336336
<View style={staticStyles.markerLine} />
337337
<View style={staticStyles.markerLine} />
@@ -349,17 +349,17 @@ const RangeSlider = forwardRef(
349349
>
350350
<Animated.View
351351
accessible={true}
352-
accessibilityLabel={rightMarkerAccessibilityLabel}
352+
accessibilityLabel={rightThumbAccessibilityLabel}
353353
accessibilityRole="adjustable"
354354
style={[
355-
dynamicStyles.marker,
355+
dynamicStyles.thumb,
356356
styles.markerContainer,
357-
markerStyle,
358-
pressed.right && pressedMarkerStyle,
359-
rightMarkerStyle,
357+
thumbStyle,
358+
pressed.right && pressedThumbStyle,
359+
rightThumbStyle,
360360
]}
361361
>
362-
{showMarkerLines && (
362+
{showThumbLines && (
363363
<>
364364
<View style={staticStyles.markerLine} />
365365
<View style={staticStyles.markerLine} />
@@ -411,13 +411,13 @@ RangeSlider.propTypes = {
411411
// Style props
412412
selectedTrackStyle: PropTypes.object,
413413
unselectedTrackStyle: PropTypes.object,
414-
markerStyle: PropTypes.object,
415-
pressedMarkerStyle: PropTypes.object,
414+
thumbStyle: PropTypes.object,
415+
pressedThumbStyle: PropTypes.object,
416416
containerStyle: PropTypes.object,
417417

418418
// Customization props
419419
sliderWidth: PropTypes.number,
420-
markerSize: PropTypes.number,
420+
thumbSize: PropTypes.number,
421421
trackHeight: PropTypes.number,
422422
minimumDistance: PropTypes.number,
423423

@@ -431,26 +431,26 @@ RangeSlider.propTypes = {
431431
onValuesChangeStart: PropTypes.func,
432432

433433
// Accessibility props
434-
leftMarkerAccessibilityLabel: PropTypes.string,
435-
rightMarkerAccessibilityLabel: PropTypes.string,
434+
leftThumbAccessibilityLabel: PropTypes.string,
435+
rightThumbAccessibilityLabel: PropTypes.string,
436436

437-
// Marker lines prop
438-
showMarkerLines: PropTypes.bool,
437+
// Visual props
438+
showThumbLines: PropTypes.bool,
439439
};
440440

441441
RangeSlider.defaultProps = {
442442
step: DEFAULT_VALUES.STEP,
443443
sliderWidth: DEFAULT_VALUES.SLIDER_WIDTH,
444-
markerSize: DEFAULT_VALUES.MARKER_SIZE,
444+
thumbSize: DEFAULT_VALUES.THUMB_SIZE,
445445
trackHeight: DEFAULT_VALUES.TRACK_HEIGHT,
446446
enabled: true,
447447
allowOverlap: false,
448448
onValuesChange: () => {},
449449
onValuesChangeFinish: () => {},
450450
onValuesChangeStart: () => {},
451-
leftMarkerAccessibilityLabel: DEFAULT_VALUES.LEFT_MARKER_LABEL,
452-
rightMarkerAccessibilityLabel: DEFAULT_VALUES.RIGHT_MARKER_LABEL,
453-
showMarkerLines: DEFAULT_VALUES.SHOW_MARKER_LINES,
451+
leftThumbAccessibilityLabel: DEFAULT_VALUES.LEFT_THUMB_LABEL,
452+
rightThumbAccessibilityLabel: DEFAULT_VALUES.RIGHT_THUMB_LABEL,
453+
showThumbLines: DEFAULT_VALUES.SHOW_THUMB_LINES,
454454
};
455455

456456
export default RangeSlider;

0 commit comments

Comments
 (0)