@tamagui/slider 1.0.1-beta.95 → 1.0.1-beta.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Slider.js +29 -29
- package/dist/cjs/Slider.js.map +2 -2
- package/dist/cjs/SliderImpl.js +2 -4
- package/dist/cjs/SliderImpl.js.map +2 -2
- package/dist/cjs/constants.js +0 -0
- package/dist/cjs/constants.js.map +0 -0
- package/dist/cjs/helpers.js +0 -0
- package/dist/cjs/helpers.js.map +2 -2
- package/dist/cjs/index.js +0 -0
- package/dist/cjs/index.js.map +0 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/Slider.js +30 -30
- package/dist/esm/Slider.js.map +2 -2
- package/dist/esm/SliderImpl.js +2 -4
- package/dist/esm/SliderImpl.js.map +2 -2
- package/dist/esm/constants.js +0 -0
- package/dist/esm/constants.js.map +0 -0
- package/dist/esm/helpers.js +0 -0
- package/dist/esm/helpers.js.map +2 -2
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +0 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/types.js.map +0 -0
- package/dist/jsx/Slider.js +26 -26
- package/dist/jsx/Slider.js.map +2 -2
- package/dist/jsx/SliderImpl.js +3 -4
- package/dist/jsx/SliderImpl.js.map +2 -2
- package/dist/jsx/constants.js +0 -0
- package/dist/jsx/constants.js.map +0 -0
- package/dist/jsx/helpers.js +0 -0
- package/dist/jsx/helpers.js.map +2 -2
- package/dist/jsx/index.js +0 -0
- package/dist/jsx/index.js.map +0 -0
- package/dist/jsx/types.js +0 -0
- package/dist/jsx/types.js.map +0 -0
- package/package.json +8 -8
- package/src/Slider.tsx +43 -55
- package/src/SliderImpl.tsx +6 -6
- package/src/helpers.tsx +0 -2
- package/src/types.ts +0 -3
- package/types/Slider.d.ts +184 -46
- package/types/Slider.d.ts.map +1 -1
- package/types/SliderImpl.d.ts +17 -16
- package/types/SliderImpl.d.ts.map +1 -1
- package/types/constants.d.ts +0 -1
- package/types/constants.d.ts.map +1 -1
- package/types/helpers.d.ts +0 -0
- package/types/helpers.d.ts.map +1 -1
- package/types/index.d.ts +0 -0
- package/types/index.d.ts.map +0 -0
- package/types/types.d.ts +0 -2
- package/types/types.d.ts.map +1 -1
package/dist/jsx/helpers.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export function getNextSortedValues(prevValues: number[] = [], nextValue: number, atIndex: number) {\n const nextValues = [...prevValues]\n nextValues[atIndex] = nextValue\n return nextValues.sort((a, b) => a - b)\n}\n\nexport function convertValueToPercentage(value: number, min: number, max: number) {\n const maxSteps = max - min\n const percentPerStep = 100 / maxSteps\n return percentPerStep * (value - min)\n}\n\n/**\n * Returns a label for each thumb when there are two or more thumbs\n */\nexport function getLabel(index: number, totalValues: number) {\n if (totalValues > 2) {\n return `Value ${index + 1} of ${totalValues}`\n } else if (totalValues === 2) {\n return ['Minimum', 'Maximum'][index]\n } else {\n return undefined\n }\n}\n\n/**\n * Given a `values` array and a `nextValue`, determine which value in\n * the array is closest to `nextValue` and return its index.\n *\n * @example\n * // returns 1\n * getClosestValueIndex([10, 30], 25);\n */\nexport function getClosestValueIndex(values: number[], nextValue: number) {\n if (values.length === 1) return 0\n const distances = values.map((value) => Math.abs(value - nextValue))\n const closestDistance = Math.min(...distances)\n return distances.indexOf(closestDistance)\n}\n\n/**\n * Offsets the thumb centre point while sliding to ensure it remains\n * within the bounds of the slider when reaching the edges\n */\nexport function getThumbInBoundsOffset(width: number, left: number, direction: number) {\n const halfWidth = width / 2\n const halfPercent = 50\n const offset = linearScale([0, halfPercent], [0, halfWidth])\n return (halfWidth - offset(left) * direction) * direction\n}\n\n/**\n * Gets an array of steps between each value.\n *\n * @example\n * // returns [1, 9]\n * getStepsBetweenValues([10, 11, 20]);\n */\nfunction getStepsBetweenValues(values: number[]) {\n return values.slice(0, -1).map((value, index) => values[index + 1] - value)\n}\n\n/**\n * Verifies the minimum steps between all values is greater than or equal\n * to the expected minimum steps.\n *\n * @example\n * // returns false\n * hasMinStepsBetweenValues([1,2,3], 2);\n *\n * @example\n * // returns true\n * hasMinStepsBetweenValues([1,2,3], 1);\n */\nexport function hasMinStepsBetweenValues(values: number[], minStepsBetweenValues: number) {\n if (minStepsBetweenValues > 0) {\n const stepsBetweenValues = getStepsBetweenValues(values)\n const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues)\n return actualMinStepsBetweenValues >= minStepsBetweenValues\n }\n return true\n}\n\n// https://github.com/tmcw-up-for-adoption/simple-linear-scale/blob/master/index.js\nexport function linearScale(input: readonly [number, number], output: readonly [number, number]) {\n return (value: number) => {\n if (input[0] === input[1] || output[0] === output[1]) return output[0]\n const ratio = (output[1] - output[0]) / (input[1] - input[0])\n return output[0] + ratio * (value - input[0])\n }\n}\n\nexport function getDecimalCount(value: number) {\n return (String(value).split('.')[1] || '').length\n}\n\nexport function roundValue(value: number, decimalCount: number) {\n const rounder = Math.pow(10, decimalCount)\n return Math.round(value * rounder) / rounder\n}\n"],
|
|
5
|
+
"mappings": "AAAO,6BAA6B,aAAuB,CAAC,GAAG,WAAmB,SAAiB;AACjG,QAAM,aAAa,CAAC,GAAG,UAAU;AACjC,aAAW,WAAW;AACtB,SAAO,WAAW,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AACxC;AAEO,kCAAkC,OAAe,KAAa,KAAa;AAChF,QAAM,WAAW,MAAM;AACvB,QAAM,iBAAiB,MAAM;AAC7B,SAAO,iBAAkB,SAAQ;AACnC;AAKO,kBAAkB,OAAe,aAAqB;AAC3D,MAAI,cAAc,GAAG;AACnB,WAAO,SAAS,QAAQ,QAAQ;AAAA,EAClC,WAAW,gBAAgB,GAAG;AAC5B,WAAO,CAAC,WAAW,SAAS,EAAE;AAAA,EAChC,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAUO,8BAA8B,QAAkB,WAAmB;AACxE,MAAI,OAAO,WAAW;AAAG,WAAO;AAChC,QAAM,YAAY,OAAO,IAAI,CAAC,UAAU,KAAK,IAAI,QAAQ,SAAS,CAAC;AACnE,QAAM,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAC7C,SAAO,UAAU,QAAQ,eAAe;AAC1C;AAMO,gCAAgC,OAAe,MAAc,WAAmB;AACrF,QAAM,YAAY,QAAQ;AAC1B,QAAM,cAAc;AACpB,QAAM,SAAS,YAAY,CAAC,GAAG,WAAW,GAAG,CAAC,GAAG,SAAS,CAAC;AAC3D,SAAQ,aAAY,OAAO,IAAI,IAAI,aAAa;AAClD;AASA,+BAA+B,QAAkB;AAC/C,SAAO,OAAO,MAAM,GAAG,EAAE,EAAE,IAAI,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,KAAK;AAC5E;AAcO,kCAAkC,QAAkB,uBAA+B;AACxF,MAAI,wBAAwB,GAAG;AAC7B,UAAM,qBAAqB,sBAAsB,MAAM;AACvD,UAAM,8BAA8B,KAAK,IAAI,GAAG,kBAAkB;AAClE,WAAO,+BAA+B;AAAA,EACxC;AACA,SAAO;AACT;AAGO,qBAAqB,OAAkC,QAAmC;AAC/F,SAAO,CAAC,UAAkB;AACxB,QAAI,MAAM,OAAO,MAAM,MAAM,OAAO,OAAO,OAAO;AAAI,aAAO,OAAO;AACpE,UAAM,QAAS,QAAO,KAAK,OAAO,MAAO,OAAM,KAAK,MAAM;AAC1D,WAAO,OAAO,KAAK,QAAS,SAAQ,MAAM;AAAA,EAC5C;AACF;AAEO,yBAAyB,OAAe;AAC7C,SAAQ,QAAO,KAAK,EAAE,MAAM,GAAG,EAAE,MAAM,IAAI;AAC7C;AAEO,oBAAoB,OAAe,cAAsB;AAC9D,QAAM,UAAU,KAAK,IAAI,IAAI,YAAY;AACzC,SAAO,KAAK,MAAM,QAAQ,OAAO,IAAI;AACvC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js
CHANGED
|
File without changes
|
package/dist/jsx/index.js.map
CHANGED
|
File without changes
|
package/dist/jsx/types.js
CHANGED
|
File without changes
|
package/dist/jsx/types.js.map
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/slider",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.98",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
25
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
29
|
-
"@tamagui/use-direction": "^1.0.1-beta.
|
|
24
|
+
"@tamagui/compose-refs": "^1.0.1-beta.98",
|
|
25
|
+
"@tamagui/core": "^1.0.1-beta.98",
|
|
26
|
+
"@tamagui/create-context": "^1.0.1-beta.98",
|
|
27
|
+
"@tamagui/stacks": "^1.0.1-beta.98",
|
|
28
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.98",
|
|
29
|
+
"@tamagui/use-direction": "^1.0.1-beta.98"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "*",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"react-native": "*"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
37
|
+
"@tamagui/build": "^1.0.1-beta.98",
|
|
38
38
|
"@types/react-native": "^0.67.3",
|
|
39
39
|
"react": "*",
|
|
40
40
|
"react-dom": "*",
|
package/src/Slider.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// forked from radix-ui
|
|
2
2
|
|
|
3
|
-
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
3
|
+
import { composeRefs, useComposedRefs } from '@tamagui/compose-refs'
|
|
4
4
|
import {
|
|
5
|
+
GetProps,
|
|
5
6
|
SizeTokens,
|
|
6
7
|
getSize,
|
|
7
8
|
getVariableValue,
|
|
@@ -10,11 +11,11 @@ import {
|
|
|
10
11
|
withStaticProperties,
|
|
11
12
|
} from '@tamagui/core'
|
|
12
13
|
import { clamp, composeEventHandlers } from '@tamagui/helpers'
|
|
13
|
-
import { SizableStackProps, ThemeableStack
|
|
14
|
+
import { SizableStackProps, ThemeableStack } from '@tamagui/stacks'
|
|
14
15
|
import { useControllableState } from '@tamagui/use-controllable-state'
|
|
15
16
|
import { useDirection } from '@tamagui/use-direction'
|
|
16
17
|
import * as React from 'react'
|
|
17
|
-
import {
|
|
18
|
+
import { View } from 'react-native'
|
|
18
19
|
|
|
19
20
|
import {
|
|
20
21
|
ARROW_KEYS,
|
|
@@ -42,7 +43,6 @@ import {
|
|
|
42
43
|
ScopedProps,
|
|
43
44
|
SliderContextValue,
|
|
44
45
|
SliderHorizontalProps,
|
|
45
|
-
SliderImplElement,
|
|
46
46
|
SliderProps,
|
|
47
47
|
SliderTrackProps,
|
|
48
48
|
SliderVerticalProps,
|
|
@@ -52,20 +52,16 @@ import {
|
|
|
52
52
|
* SliderHorizontal
|
|
53
53
|
* -----------------------------------------------------------------------------------------------*/
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizontalProps>(
|
|
55
|
+
const SliderHorizontal = React.forwardRef<View, SliderHorizontalProps>(
|
|
58
56
|
(props: ScopedProps<SliderHorizontalProps>, forwardedRef) => {
|
|
59
57
|
const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props
|
|
60
58
|
const direction = useDirection(dir)
|
|
61
59
|
const isDirectionLTR = direction === 'ltr'
|
|
62
|
-
const
|
|
63
|
-
const [
|
|
60
|
+
const sliderRef = React.useRef<View>(null)
|
|
61
|
+
const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }))
|
|
64
62
|
|
|
65
63
|
function getValueFromPointer(pointerPosition: number) {
|
|
66
|
-
const
|
|
67
|
-
if (!layout) return
|
|
68
|
-
const input: [number, number] = [0, layout.width]
|
|
64
|
+
const input: [number, number] = [0, state.size]
|
|
69
65
|
const output: [number, number] = isDirectionLTR ? [min, max] : [max, min]
|
|
70
66
|
const value = linearScale(input, output)
|
|
71
67
|
return value(pointerPosition)
|
|
@@ -78,17 +74,20 @@ const SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizon
|
|
|
78
74
|
endEdge={isDirectionLTR ? 'right' : 'left'}
|
|
79
75
|
direction={isDirectionLTR ? 1 : -1}
|
|
80
76
|
sizeProp="width"
|
|
81
|
-
size={size}
|
|
77
|
+
size={state.size}
|
|
82
78
|
>
|
|
83
79
|
<SliderImpl
|
|
84
|
-
ref={forwardedRef}
|
|
80
|
+
ref={composeRefs(forwardedRef, sliderRef)}
|
|
85
81
|
dir={direction}
|
|
86
82
|
{...sliderProps}
|
|
87
83
|
orientation="horizontal"
|
|
88
|
-
onLayout={(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
onLayout={() => {
|
|
85
|
+
sliderRef.current?.measure((_x, _y, width, _height, pageX, _pageY) => {
|
|
86
|
+
setState({
|
|
87
|
+
size: width,
|
|
88
|
+
offset: pageX,
|
|
89
|
+
})
|
|
90
|
+
})
|
|
92
91
|
}}
|
|
93
92
|
onSlideStart={(event, target) => {
|
|
94
93
|
const value = getValueFromPointer(event.nativeEvent.locationX)
|
|
@@ -97,7 +96,7 @@ const SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizon
|
|
|
97
96
|
}
|
|
98
97
|
}}
|
|
99
98
|
onSlideMove={(event) => {
|
|
100
|
-
const value = getValueFromPointer(event.nativeEvent.
|
|
99
|
+
const value = getValueFromPointer(event.nativeEvent.pageX - state.offset)
|
|
101
100
|
if (value) {
|
|
102
101
|
onSlideMove?.(value)
|
|
103
102
|
}
|
|
@@ -117,18 +116,14 @@ const SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizon
|
|
|
117
116
|
* SliderVertical
|
|
118
117
|
* -----------------------------------------------------------------------------------------------*/
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalProps>(
|
|
119
|
+
const SliderVertical = React.forwardRef<View, SliderVerticalProps>(
|
|
123
120
|
(props: ScopedProps<SliderVerticalProps>, forwardedRef) => {
|
|
124
121
|
const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props
|
|
125
|
-
const
|
|
126
|
-
const
|
|
122
|
+
const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }))
|
|
123
|
+
const sliderRef = React.useRef<View>(null)
|
|
127
124
|
|
|
128
125
|
function getValueFromPointer(pointerPosition: number) {
|
|
129
|
-
const
|
|
130
|
-
if (!layout) return
|
|
131
|
-
const input: [number, number] = [0, layout.height]
|
|
126
|
+
const input: [number, number] = [0, state.size]
|
|
132
127
|
const output: [number, number] = [max, min]
|
|
133
128
|
const value = linearScale(input, output)
|
|
134
129
|
return value(pointerPosition)
|
|
@@ -140,17 +135,20 @@ const SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalPro
|
|
|
140
135
|
startEdge="bottom"
|
|
141
136
|
endEdge="top"
|
|
142
137
|
sizeProp="height"
|
|
143
|
-
size={size}
|
|
138
|
+
size={state.size}
|
|
144
139
|
direction={1}
|
|
145
140
|
>
|
|
146
141
|
<SliderImpl
|
|
147
|
-
ref={forwardedRef}
|
|
142
|
+
ref={composeRefs(forwardedRef, sliderRef)}
|
|
148
143
|
{...sliderProps}
|
|
149
144
|
orientation="vertical"
|
|
150
|
-
onLayout={(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
onLayout={() => {
|
|
146
|
+
sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {
|
|
147
|
+
setState({
|
|
148
|
+
size: height,
|
|
149
|
+
offset: pageY,
|
|
150
|
+
})
|
|
151
|
+
})
|
|
154
152
|
}}
|
|
155
153
|
onSlideStart={(event, target) => {
|
|
156
154
|
const value = getValueFromPointer(event.nativeEvent.locationY)
|
|
@@ -159,7 +157,7 @@ const SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalPro
|
|
|
159
157
|
}
|
|
160
158
|
}}
|
|
161
159
|
onSlideMove={(event) => {
|
|
162
|
-
const value = getValueFromPointer(event.nativeEvent.
|
|
160
|
+
const value = getValueFromPointer(event.nativeEvent.pageY - state.offset)
|
|
163
161
|
if (value) {
|
|
164
162
|
onSlideMove?.(value)
|
|
165
163
|
}
|
|
@@ -218,21 +216,20 @@ SliderTrack.displayName = TRACK_NAME
|
|
|
218
216
|
|
|
219
217
|
const RANGE_NAME = 'SliderTrackActive'
|
|
220
218
|
|
|
221
|
-
type SliderTrackActiveElement = HTMLElement | View
|
|
222
|
-
interface SliderTrackActiveProps extends YStackProps {}
|
|
223
|
-
|
|
224
219
|
export const SliderTrackActiveFrame = styled(SliderFrame, {
|
|
225
220
|
name: 'SliderTrackActive',
|
|
226
221
|
backgroundColor: '$background',
|
|
227
222
|
position: 'absolute',
|
|
228
223
|
})
|
|
229
224
|
|
|
230
|
-
|
|
225
|
+
type SliderTrackActiveProps = GetProps<typeof SliderTrackActiveFrame>
|
|
226
|
+
|
|
227
|
+
const SliderTrackActive = React.forwardRef<View, SliderTrackActiveProps>(
|
|
231
228
|
(props: ScopedProps<SliderTrackActiveProps>, forwardedRef) => {
|
|
232
229
|
const { __scopeSlider, ...rangeProps } = props
|
|
233
230
|
const context = useSliderContext(RANGE_NAME, __scopeSlider)
|
|
234
231
|
const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider)
|
|
235
|
-
const ref = React.useRef<
|
|
232
|
+
const ref = React.useRef<View>(null)
|
|
236
233
|
const composedRefs = useComposedRefs(forwardedRef, ref)
|
|
237
234
|
const valuesCount = context.values.length
|
|
238
235
|
const percentages = context.values.map((value) =>
|
|
@@ -305,12 +302,11 @@ export const SliderThumbFrame = styled(ThemeableStack, {
|
|
|
305
302
|
},
|
|
306
303
|
})
|
|
307
304
|
|
|
308
|
-
type SliderThumbElement = HTMLElement | View
|
|
309
305
|
interface SliderThumbProps extends SizableStackProps {
|
|
310
306
|
index: number
|
|
311
307
|
}
|
|
312
308
|
|
|
313
|
-
const SliderThumb = React.forwardRef<
|
|
309
|
+
const SliderThumb = React.forwardRef<View, SliderThumbProps>(
|
|
314
310
|
(props: ScopedProps<SliderThumbProps>, forwardedRef) => {
|
|
315
311
|
const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props
|
|
316
312
|
const context = useSliderContext(THUMB_NAME, __scopeSlider)
|
|
@@ -355,8 +351,6 @@ const SliderThumb = React.forwardRef<SliderThumbElement, SliderThumbProps>(
|
|
|
355
351
|
aria-orientation={context.orientation}
|
|
356
352
|
data-orientation={context.orientation}
|
|
357
353
|
data-disabled={context.disabled ? '' : undefined}
|
|
358
|
-
// TODO
|
|
359
|
-
// @ts-ignore
|
|
360
354
|
tabIndex={context.disabled ? undefined : 0}
|
|
361
355
|
{...thumbProps}
|
|
362
356
|
{...(context.orientation === 'horizontal'
|
|
@@ -395,11 +389,6 @@ const SliderThumb = React.forwardRef<SliderThumbElement, SliderThumbProps>(
|
|
|
395
389
|
onFocus={composeEventHandlers(props.onFocus, () => {
|
|
396
390
|
context.valueIndexToChangeRef.current = index
|
|
397
391
|
})}
|
|
398
|
-
// temp fix to make slider work nicely on native
|
|
399
|
-
// we just let the events propagate to the track
|
|
400
|
-
{...(!isWeb && {
|
|
401
|
-
pointerEvents: 'none',
|
|
402
|
-
})}
|
|
403
392
|
/>
|
|
404
393
|
)
|
|
405
394
|
}
|
|
@@ -411,10 +400,8 @@ SliderThumb.displayName = THUMB_NAME
|
|
|
411
400
|
* Slider
|
|
412
401
|
* -----------------------------------------------------------------------------------------------*/
|
|
413
402
|
|
|
414
|
-
type SliderElement = SliderHorizontalElement | SliderVerticalElement
|
|
415
|
-
|
|
416
403
|
const Slider = withStaticProperties(
|
|
417
|
-
React.forwardRef<
|
|
404
|
+
React.forwardRef<View, SliderProps>((props: ScopedProps<SliderProps>, forwardedRef) => {
|
|
418
405
|
const {
|
|
419
406
|
name,
|
|
420
407
|
min = 0,
|
|
@@ -429,14 +416,14 @@ const Slider = withStaticProperties(
|
|
|
429
416
|
size: sizeProp,
|
|
430
417
|
...sliderProps
|
|
431
418
|
} = props
|
|
432
|
-
const sliderRef = React.useRef<
|
|
419
|
+
const sliderRef = React.useRef<View>(null)
|
|
433
420
|
const composedRefs = useComposedRefs(sliderRef, forwardedRef)
|
|
434
421
|
const thumbRefs = React.useRef<SliderContextValue['thumbs']>(new Set())
|
|
435
422
|
const valueIndexToChangeRef = React.useRef<number>(0)
|
|
436
423
|
const isHorizontal = orientation === 'horizontal'
|
|
437
424
|
// We set this to true by default so that events bubble to forms without JS (SSR)
|
|
438
|
-
//
|
|
439
|
-
//
|
|
425
|
+
// const isFormControl =
|
|
426
|
+
// sliderRef.current instanceof HTMLElement ? Boolean(sliderRef.current.closest('form')) : true
|
|
440
427
|
|
|
441
428
|
const [values = [], setValues] = useControllableState({
|
|
442
429
|
prop: value,
|
|
@@ -452,6 +439,7 @@ const Slider = withStaticProperties(
|
|
|
452
439
|
|
|
453
440
|
if (isWeb) {
|
|
454
441
|
React.useEffect(() => {
|
|
442
|
+
// @ts-ignore
|
|
455
443
|
const node = sliderRef.current as HTMLElement
|
|
456
444
|
if (!node) return
|
|
457
445
|
const preventDefault = (e) => {
|
|
@@ -553,7 +541,7 @@ Slider.displayName = SLIDER_NAME
|
|
|
553
541
|
|
|
554
542
|
/* -----------------------------------------------------------------------------------------------*/
|
|
555
543
|
|
|
556
|
-
// TODO
|
|
544
|
+
// // TODO
|
|
557
545
|
// const BubbleInput = (props: any) => {
|
|
558
546
|
// const { value, ...inputProps } = props
|
|
559
547
|
// const ref = React.useRef<HTMLInputElement>(null)
|
package/src/SliderImpl.tsx
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import { composeEventHandlers, getSize, getVariableValue, isWeb, styled } from '@tamagui/core'
|
|
6
6
|
import { YStack } from '@tamagui/stacks'
|
|
7
7
|
import * as React from 'react'
|
|
8
|
+
import { View } from 'react-native'
|
|
8
9
|
|
|
9
10
|
import { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from './constants'
|
|
10
|
-
import { ScopedProps,
|
|
11
|
+
import { ScopedProps, SliderImplProps } from './types'
|
|
11
12
|
|
|
12
13
|
export const DirectionalYStack = styled(YStack, {
|
|
13
14
|
variants: {
|
|
@@ -41,7 +42,7 @@ export const SliderFrame = styled(DirectionalYStack, {
|
|
|
41
42
|
},
|
|
42
43
|
})
|
|
43
44
|
|
|
44
|
-
export const SliderImpl = React.forwardRef<
|
|
45
|
+
export const SliderImpl = React.forwardRef<View, SliderImplProps>(
|
|
45
46
|
(props: ScopedProps<SliderImplProps>, forwardedRef) => {
|
|
46
47
|
const {
|
|
47
48
|
__scopeSlider,
|
|
@@ -82,14 +83,14 @@ export const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(
|
|
|
82
83
|
onScrollShouldSetResponderCapture={() => true}
|
|
83
84
|
onMoveShouldSetResponder={() => true}
|
|
84
85
|
onStartShouldSetResponder={() => true}
|
|
85
|
-
onStartShouldSetResponderCapture={() => true}
|
|
86
|
+
// onStartShouldSetResponderCapture={() => true}
|
|
86
87
|
onResponderTerminationRequest={() => {
|
|
87
|
-
console.log('got??/')
|
|
88
88
|
return false
|
|
89
89
|
}}
|
|
90
90
|
onResponderGrant={composeEventHandlers(props.onResponderGrant, (event) => {
|
|
91
91
|
const target = event.target as HTMLElement | number
|
|
92
|
-
|
|
92
|
+
console.log('target', target, context.thumbs.has(target), context.thumbs)
|
|
93
|
+
const isStartingOnThumb = context.thumbs.has(target)
|
|
93
94
|
// // Prevent browser focus behaviour because we focus a thumb manually when values change.
|
|
94
95
|
// Touch devices have a delay before focusing so won't focus if touch immediately moves
|
|
95
96
|
// away from target (sliding). We want thumb to focus regardless.
|
|
@@ -101,7 +102,6 @@ export const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(
|
|
|
101
102
|
onSlideStart(event, isStartingOnThumb ? 'thumb' : 'track')
|
|
102
103
|
})}
|
|
103
104
|
onResponderMove={composeEventHandlers(props.onResponderMove, (event) => {
|
|
104
|
-
console.log('gogo')
|
|
105
105
|
event.preventDefault()
|
|
106
106
|
event.stopPropagation()
|
|
107
107
|
|
package/src/helpers.tsx
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { GestureReponderEvent, SizeTokens } from '@tamagui/core'
|
|
2
2
|
import type { Scope } from '@tamagui/create-context'
|
|
3
3
|
import type { SizableStackProps } from '@tamagui/stacks'
|
|
4
|
-
import type { View } from 'react-native'
|
|
5
4
|
|
|
6
5
|
export type ScopedProps<P> = P & { __scopeSlider?: Scope }
|
|
7
6
|
|
|
8
7
|
export type Direction = 'ltr' | 'rtl'
|
|
9
8
|
|
|
10
|
-
export type SliderImplElement = HTMLElement | View
|
|
11
|
-
|
|
12
9
|
type SliderImplPrivateProps = {
|
|
13
10
|
onSlideStart(event: GestureReponderEvent, target: 'thumb' | 'track'): void
|
|
14
11
|
onSlideMove(event: GestureReponderEvent): void
|