Skip to content

Commit 2aea0b4

Browse files
* migrated to ts
* touch problem inside the scrollview fixed
1 parent 54eb224 commit 2aea0b4

9 files changed

Lines changed: 670 additions & 400 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class LabelContainer extends PureComponent {
66
state = {
77
value: Number.NaN,
88
};
9-
9+
1010
setValue = value => {
1111
this.setState({ value });
1212
}

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ const handleValueChange = useCallback((low, high) => {
6666

6767
### Properties
6868

69-
| Name | Description | Type | Default Value |
70-
| --- | --- | --- | :-------------: |
71-
| `min` | Minimum value of slider | number | _**required**_ |
72-
| `max` | Maximum value of slider | number | _**required**_ |
73-
| `minRange` | Minimum range of thumbs allowed to be selected **by the user**.<br/>**Note:** it is still possible to set values closer to each other than `minRange` programmatically.<br/>If `disableRange` is set to true, maximum value allowed for user will be `max` - `minRange`. | number | `0` |
74-
| `step` | Step of slider | number | `1` |
75-
| `low` | Low value of slider | number | Initially `min` value will be set if not provided |
76-
| `high` | High value of slider | number | Initially `max` value will be set if not provided |
77-
| `floatingLabel` | If set to `true`, labels will not take space in component tree. Instead they will be rendered over the content above the slider (like a small popup). | boolean | `false` |
78-
| `disableRange` | Slider works as an ordinary slider with 1 control if `true` | boolean | `false` |
79-
| `disabled` | Any user interactions will be ignored if `true` | boolean | `false` |
69+
| Name | Description | Type | Default Value |
70+
|----------------------| --- | --- | :-------------: |
71+
| `min` | Minimum value of slider | number | _**required**_ |
72+
| `max` | Maximum value of slider | number | _**required**_ |
73+
| `minRange` | Minimum range of thumbs allowed to be selected **by the user**.<br/>**Note:** it is still possible to set values closer to each other than `minRange` programmatically.<br/>If `disableRange` is set to true, maximum value allowed for user will be `max` - `minRange`. | number | `0` |
74+
| `step` | Step of slider | number | `1` |
75+
| `low` | Low value of slider | number | Initially `min` value will be set if not provided |
76+
| `high` | High value of slider | number | Initially `max` value will be set if not provided |
77+
| `floatingLabel` | If set to `true`, labels will not take space in component tree. Instead they will be rendered over the content above the slider (like a small popup). | boolean | `false` |
78+
| `disableRange` | Slider works as an ordinary slider with 1 control if `true` | boolean | `false` |
79+
| `disabled` | Any user interactions will be ignored if `true` | boolean | `false` |
8080
| `allowLabelOverflow` | If set to `true`, labels are allowed to be drawn outside of slider component's bounds.<br/>Otherwise label's edges will never get out of component's edges. | boolean | `false` |
81-
| `renderThumb` | Should render the thumb. | `() => Node` | _**required**_ |
82-
| `renderRail` | Should render the "rail" for thumbs.<br/>Rendered component **should** have `flex: 1` style so it won't fill up the whole space. | `() => Node` | _**required**_ |
81+
| `renderThumb` | Should render the thumb. | `() => Node` | _**required**_ |
82+
| `renderRail` | Should render the "rail" for thumbs.<br/>Rendered component **should** have `flex: 1` style so it won't fill up the whole space. | `() => Node` | _**required**_ |
8383
| `renderRailSelected` | Should render the selected part of "rail" for thumbs.<br/>Rendered component **should not** have `flex: 1` style so it fills up the whole space. | `() => Node` | _**required**_ |
84-
| `renderLabel` | Should render label above thumbs.<br/>If no function is passed, no label will be drawn. | `(value: number) => Node` | `undefined` |
85-
| `renderNotch` | Should render the notch below the label (above the thumbs).<br/>Classic notch is a small triangle below the label.<br/>If `allowLabelOverflow` is not set to true, the notch will continue moving with thumb even if the label has already reached the edge of the component and can't move further.| `() => Node` | `undefined` |
86-
| `onValueChanged` | Will be called when a value was changed.<br/>If `disableRange` is set to true, the second argument should be ignored.<br/>`fromUser` will be true if the value was changed by user's interaction. | `(low: number, high: number, fromUser: boolean) => void` | `undefined` |
87-
| `onTouchStart` | Will be called when user starts interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
88-
| `onTouchEnd` | Will be called when user ends interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
84+
| `renderLabel` | Should render label above thumbs.<br/>If no function is passed, no label will be drawn. | `(value: number) => Node` | `undefined` |
85+
| `renderNotch` | Should render the notch below the label (above the thumbs).<br/>Classic notch is a small triangle below the label.<br/>If `allowLabelOverflow` is not set to true, the notch will continue moving with thumb even if the label has already reached the edge of the component and can't move further.| `() => Node` | `undefined` |
86+
| `onValueChanged` | Will be called when a value was changed.<br/>If `disableRange` is set to true, the second argument should be ignored.<br/>`fromUser` will be true if the value was changed by user's interaction. | `(low: number, high: number, fromUser: boolean) => void` | `undefined` |
87+
| `onSliderTouchStart` | Will be called when user starts interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
88+
| `onSliderTouchEnd` | Will be called when user ends interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
8989

9090
All the other props (e.g. style) will be passed to root container component.
9191

helpers.js renamed to helpers.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export const isLowCloser = (downX, lowPosition, highPosition) => {
1+
export const isLowCloser = (
2+
downX: number,
3+
lowPosition: number,
4+
highPosition: number,
5+
): boolean => {
26
if (lowPosition === highPosition) {
37
return downX < lowPosition;
48
}
@@ -7,11 +11,18 @@ export const isLowCloser = (downX, lowPosition, highPosition) => {
711
return distanceFromLow < distanceFromHigh;
812
};
913

10-
export const clamp = (value, min, max) => {
14+
export const clamp = (value: number, min: number, max: number): number => {
1115
return Math.min(Math.max(value, min), max);
1216
};
1317

14-
export const getValueForPosition = (positionInView, containerWidth, thumbWidth, min, max, step) => {
18+
export const getValueForPosition = (
19+
positionInView: number,
20+
containerWidth: number,
21+
thumbWidth: number,
22+
min: number,
23+
max: number,
24+
step: number,
25+
): number => {
1526
const availableSpace = containerWidth - thumbWidth;
1627
const relStepUnit = step / (max - min);
1728
let relPosition = (positionInView - thumbWidth / 2) / availableSpace;

hooks.js

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)