@tamagui/slider 1.0.1-beta.100

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.
Files changed (55) hide show
  1. package/dist/cjs/Slider.js +456 -0
  2. package/dist/cjs/Slider.js.map +7 -0
  3. package/dist/cjs/SliderImpl.js +163 -0
  4. package/dist/cjs/SliderImpl.js.map +7 -0
  5. package/dist/cjs/constants.js +62 -0
  6. package/dist/cjs/constants.js.map +7 -0
  7. package/dist/cjs/helpers.js +101 -0
  8. package/dist/cjs/helpers.js.map +7 -0
  9. package/dist/cjs/index.js +32 -0
  10. package/dist/cjs/index.js.map +7 -0
  11. package/dist/cjs/types.js +16 -0
  12. package/dist/cjs/types.js.map +7 -0
  13. package/dist/esm/Slider.js +448 -0
  14. package/dist/esm/Slider.js.map +7 -0
  15. package/dist/esm/SliderImpl.js +137 -0
  16. package/dist/esm/SliderImpl.js.map +7 -0
  17. package/dist/esm/constants.js +30 -0
  18. package/dist/esm/constants.js.map +7 -0
  19. package/dist/esm/helpers.js +70 -0
  20. package/dist/esm/helpers.js.map +7 -0
  21. package/dist/esm/index.js +7 -0
  22. package/dist/esm/index.js.map +7 -0
  23. package/dist/esm/types.js +1 -0
  24. package/dist/esm/types.js.map +7 -0
  25. package/dist/jsx/Slider.js +324 -0
  26. package/dist/jsx/Slider.js.map +7 -0
  27. package/dist/jsx/SliderImpl.js +84 -0
  28. package/dist/jsx/SliderImpl.js.map +7 -0
  29. package/dist/jsx/constants.js +30 -0
  30. package/dist/jsx/constants.js.map +7 -0
  31. package/dist/jsx/helpers.js +70 -0
  32. package/dist/jsx/helpers.js.map +7 -0
  33. package/dist/jsx/index.js +7 -0
  34. package/dist/jsx/index.js.map +7 -0
  35. package/dist/jsx/types.js +1 -0
  36. package/dist/jsx/types.js.map +7 -0
  37. package/package.json +46 -0
  38. package/src/Slider.tsx +592 -0
  39. package/src/SliderImpl.tsx +118 -0
  40. package/src/constants.tsx +32 -0
  41. package/src/helpers.tsx +100 -0
  42. package/src/index.ts +9 -0
  43. package/src/types.ts +75 -0
  44. package/types/Slider.d.ts +357 -0
  45. package/types/Slider.d.ts.map +1 -0
  46. package/types/SliderImpl.d.ts +55 -0
  47. package/types/SliderImpl.d.ts.map +1 -0
  48. package/types/constants.d.ts +52 -0
  49. package/types/constants.d.ts.map +1 -0
  50. package/types/helpers.d.ts +10 -0
  51. package/types/helpers.d.ts.map +1 -0
  52. package/types/index.d.ts +4 -0
  53. package/types/index.d.ts.map +1 -0
  54. package/types/types.d.ts +68 -0
  55. package/types/types.d.ts.map +1 -0
@@ -0,0 +1,30 @@
1
+ import { createContextScope } from "@tamagui/create-context";
2
+ const SLIDER_NAME = "Slider";
3
+ const [createSliderContext, createSliderScope] = createContextScope(SLIDER_NAME);
4
+ const [SliderProvider, useSliderContext] = createSliderContext(SLIDER_NAME);
5
+ const [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext(SLIDER_NAME, {
6
+ startEdge: "left",
7
+ endEdge: "right",
8
+ sizeProp: "width",
9
+ size: 0,
10
+ direction: 1
11
+ });
12
+ const PAGE_KEYS = ["PageUp", "PageDown"];
13
+ const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
14
+ const BACK_KEYS = {
15
+ ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
16
+ rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
17
+ };
18
+ export {
19
+ ARROW_KEYS,
20
+ BACK_KEYS,
21
+ PAGE_KEYS,
22
+ SLIDER_NAME,
23
+ SliderOrientationProvider,
24
+ SliderProvider,
25
+ createSliderContext,
26
+ createSliderScope,
27
+ useSliderContext,
28
+ useSliderOrientationContext
29
+ };
30
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/constants.tsx"],
4
+ "sourcesContent": ["import { SizeTokens } from '@tamagui/core'\nimport { createContextScope } from '@tamagui/create-context'\n\nimport { Direction, SliderContextValue } from './types'\n\nexport const SLIDER_NAME = 'Slider'\n\nexport const [createSliderContext, createSliderScope] = createContextScope(SLIDER_NAME)\n\nexport const [SliderProvider, useSliderContext] =\n createSliderContext<SliderContextValue>(SLIDER_NAME)\n\nexport const [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext<{\n startEdge: 'bottom' | 'left' | 'right'\n endEdge: 'top' | 'right' | 'left'\n sizeProp: 'width' | 'height'\n size: number | SizeTokens\n direction: number\n}>(SLIDER_NAME, {\n startEdge: 'left',\n endEdge: 'right',\n sizeProp: 'width',\n size: 0,\n direction: 1,\n})\n\nexport const PAGE_KEYS = ['PageUp', 'PageDown']\nexport const ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']\nexport const BACK_KEYS: Record<Direction, string[]> = {\n ltr: ['ArrowDown', 'Home', 'ArrowLeft', 'PageDown'],\n rtl: ['ArrowDown', 'Home', 'ArrowRight', 'PageDown'],\n}\n"],
5
+ "mappings": "AACA;AAIO,MAAM,cAAc;AAEpB,MAAM,CAAC,qBAAqB,qBAAqB,mBAAmB,WAAW;AAE/E,MAAM,CAAC,gBAAgB,oBAC5B,oBAAwC,WAAW;AAE9C,MAAM,CAAC,2BAA2B,+BAA+B,oBAMrE,aAAa;AAAA,EACd,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,WAAW;AACb,CAAC;AAEM,MAAM,YAAY,CAAC,UAAU,UAAU;AACvC,MAAM,aAAa,CAAC,WAAW,aAAa,aAAa,YAAY;AACrE,MAAM,YAAyC;AAAA,EACpD,KAAK,CAAC,aAAa,QAAQ,aAAa,UAAU;AAAA,EAClD,KAAK,CAAC,aAAa,QAAQ,cAAc,UAAU;AACrD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,70 @@
1
+ function getNextSortedValues(prevValues = [], nextValue, atIndex) {
2
+ const nextValues = [...prevValues];
3
+ nextValues[atIndex] = nextValue;
4
+ return nextValues.sort((a, b) => a - b);
5
+ }
6
+ function convertValueToPercentage(value, min, max) {
7
+ const maxSteps = max - min;
8
+ const percentPerStep = 100 / maxSteps;
9
+ return percentPerStep * (value - min);
10
+ }
11
+ function getLabel(index, totalValues) {
12
+ if (totalValues > 2) {
13
+ return `Value ${index + 1} of ${totalValues}`;
14
+ } else if (totalValues === 2) {
15
+ return ["Minimum", "Maximum"][index];
16
+ } else {
17
+ return void 0;
18
+ }
19
+ }
20
+ function getClosestValueIndex(values, nextValue) {
21
+ if (values.length === 1)
22
+ return 0;
23
+ const distances = values.map((value) => Math.abs(value - nextValue));
24
+ const closestDistance = Math.min(...distances);
25
+ return distances.indexOf(closestDistance);
26
+ }
27
+ function getThumbInBoundsOffset(width, left, direction) {
28
+ const halfWidth = width / 2;
29
+ const halfPercent = 50;
30
+ const offset = linearScale([0, halfPercent], [0, halfWidth]);
31
+ return (halfWidth - offset(left) * direction) * direction;
32
+ }
33
+ function getStepsBetweenValues(values) {
34
+ return values.slice(0, -1).map((value, index) => values[index + 1] - value);
35
+ }
36
+ function hasMinStepsBetweenValues(values, minStepsBetweenValues) {
37
+ if (minStepsBetweenValues > 0) {
38
+ const stepsBetweenValues = getStepsBetweenValues(values);
39
+ const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
40
+ return actualMinStepsBetweenValues >= minStepsBetweenValues;
41
+ }
42
+ return true;
43
+ }
44
+ function linearScale(input, output) {
45
+ return (value) => {
46
+ if (input[0] === input[1] || output[0] === output[1])
47
+ return output[0];
48
+ const ratio = (output[1] - output[0]) / (input[1] - input[0]);
49
+ return output[0] + ratio * (value - input[0]);
50
+ };
51
+ }
52
+ function getDecimalCount(value) {
53
+ return (String(value).split(".")[1] || "").length;
54
+ }
55
+ function roundValue(value, decimalCount) {
56
+ const rounder = Math.pow(10, decimalCount);
57
+ return Math.round(value * rounder) / rounder;
58
+ }
59
+ export {
60
+ convertValueToPercentage,
61
+ getClosestValueIndex,
62
+ getDecimalCount,
63
+ getLabel,
64
+ getNextSortedValues,
65
+ getThumbInBoundsOffset,
66
+ hasMinStepsBetweenValues,
67
+ linearScale,
68
+ roundValue
69
+ };
70
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers.tsx"],
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
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./Slider";
2
+ import { SliderFrame, DirectionalYStack } from "./SliderImpl";
3
+ export {
4
+ DirectionalYStack,
5
+ SliderFrame
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Slider'\n// for static extract to find, must export\nexport { SliderFrame, DirectionalYStack } from './SliderImpl'\nexport type {\n SliderProps,\n SliderHorizontalProps,\n SliderVerticalProps,\n SliderTrackProps,\n} from './types'\n"],
5
+ "mappings": "AAAA;AAEA;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,324 @@
1
+ import { composeRefs, useComposedRefs } from "@tamagui/compose-refs";
2
+ import {
3
+ getSize,
4
+ getVariableValue,
5
+ isWeb,
6
+ styled,
7
+ withStaticProperties
8
+ } from "@tamagui/core";
9
+ import { clamp, composeEventHandlers } from "@tamagui/helpers";
10
+ import { ThemeableStack } from "@tamagui/stacks";
11
+ import { useControllableState } from "@tamagui/use-controllable-state";
12
+ import { useDirection } from "@tamagui/use-direction";
13
+ import * as React from "react";
14
+ import {
15
+ ARROW_KEYS,
16
+ BACK_KEYS,
17
+ PAGE_KEYS,
18
+ SLIDER_NAME,
19
+ SliderOrientationProvider,
20
+ SliderProvider,
21
+ useSliderContext,
22
+ useSliderOrientationContext
23
+ } from "./constants";
24
+ import {
25
+ convertValueToPercentage,
26
+ getClosestValueIndex,
27
+ getDecimalCount,
28
+ getLabel,
29
+ getNextSortedValues,
30
+ getThumbInBoundsOffset,
31
+ hasMinStepsBetweenValues,
32
+ linearScale,
33
+ roundValue
34
+ } from "./helpers";
35
+ import { SliderFrame, SliderImpl } from "./SliderImpl";
36
+ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
37
+ const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
38
+ const direction = useDirection(dir);
39
+ const isDirectionLTR = direction === "ltr";
40
+ const sliderRef = React.useRef(null);
41
+ const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
42
+ function getValueFromPointer(pointerPosition) {
43
+ const input = [0, state.size];
44
+ const output = isDirectionLTR ? [min, max] : [max, min];
45
+ const value = linearScale(input, output);
46
+ return value(pointerPosition);
47
+ }
48
+ return <SliderOrientationProvider scope={props.__scopeSlider} startEdge={isDirectionLTR ? "left" : "right"} endEdge={isDirectionLTR ? "right" : "left"} direction={isDirectionLTR ? 1 : -1} sizeProp="width" size={state.size}><SliderImpl ref={composeRefs(forwardedRef, sliderRef)} dir={direction} {...sliderProps} orientation="horizontal" onLayout={() => {
49
+ var _a;
50
+ (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, width, _height, pageX, _pageY) => {
51
+ setState({
52
+ size: width,
53
+ offset: pageX
54
+ });
55
+ });
56
+ }} onSlideStart={(event, target) => {
57
+ const value = getValueFromPointer(event.nativeEvent.locationX);
58
+ if (value) {
59
+ onSlideStart == null ? void 0 : onSlideStart(value, target);
60
+ }
61
+ }} onSlideMove={(event) => {
62
+ const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
63
+ if (value) {
64
+ onSlideMove == null ? void 0 : onSlideMove(value);
65
+ }
66
+ }} onSlideEnd={() => {
67
+ }} onStepKeyDown={(event) => {
68
+ const isBackKey = BACK_KEYS[direction].includes(event.key);
69
+ onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
70
+ }} /></SliderOrientationProvider>;
71
+ });
72
+ const SliderVertical = React.forwardRef((props, forwardedRef) => {
73
+ const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
74
+ const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
75
+ const sliderRef = React.useRef(null);
76
+ function getValueFromPointer(pointerPosition) {
77
+ const input = [0, state.size];
78
+ const output = [max, min];
79
+ const value = linearScale(input, output);
80
+ return value(pointerPosition);
81
+ }
82
+ return <SliderOrientationProvider scope={props.__scopeSlider} startEdge="bottom" endEdge="top" sizeProp="height" size={state.size} direction={1}><SliderImpl ref={composeRefs(forwardedRef, sliderRef)} {...sliderProps} orientation="vertical" onLayout={() => {
83
+ var _a;
84
+ (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height, _pageX, pageY) => {
85
+ setState({
86
+ size: height,
87
+ offset: pageY
88
+ });
89
+ });
90
+ }} onSlideStart={(event, target) => {
91
+ const value = getValueFromPointer(event.nativeEvent.locationY);
92
+ if (value) {
93
+ onSlideStart == null ? void 0 : onSlideStart(value, target);
94
+ }
95
+ }} onSlideMove={(event) => {
96
+ const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
97
+ if (value) {
98
+ onSlideMove == null ? void 0 : onSlideMove(value);
99
+ }
100
+ }} onSlideEnd={() => {
101
+ }} onStepKeyDown={(event) => {
102
+ const isBackKey = BACK_KEYS.ltr.includes(event.key);
103
+ onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
104
+ }} /></SliderOrientationProvider>;
105
+ });
106
+ const TRACK_NAME = "SliderTrack";
107
+ const SliderTrackFrame = styled(SliderFrame, {
108
+ name: "SliderTrack",
109
+ height: "100%",
110
+ width: "100%",
111
+ backgroundColor: "$background",
112
+ position: "relative",
113
+ borderRadius: 1e5,
114
+ overflow: "hidden"
115
+ });
116
+ const SliderTrack = React.forwardRef((props, forwardedRef) => {
117
+ const { __scopeSlider, ...trackProps } = props;
118
+ const context = useSliderContext(TRACK_NAME, __scopeSlider);
119
+ return <SliderTrackFrame data-disabled={context.disabled ? "" : void 0} data-orientation={context.orientation} orientation={context.orientation} size={context.size} {...trackProps} ref={forwardedRef} />;
120
+ });
121
+ SliderTrack.displayName = TRACK_NAME;
122
+ const RANGE_NAME = "SliderTrackActive";
123
+ const SliderTrackActiveFrame = styled(SliderFrame, {
124
+ name: "SliderTrackActive",
125
+ backgroundColor: "$background",
126
+ position: "absolute"
127
+ });
128
+ const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
129
+ const { __scopeSlider, ...rangeProps } = props;
130
+ const context = useSliderContext(RANGE_NAME, __scopeSlider);
131
+ const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider);
132
+ const ref = React.useRef(null);
133
+ const composedRefs = useComposedRefs(forwardedRef, ref);
134
+ const valuesCount = context.values.length;
135
+ const percentages = context.values.map((value) => convertValueToPercentage(value, context.min, context.max));
136
+ const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
137
+ const offsetEnd = 100 - Math.max(...percentages);
138
+ return <SliderTrackActiveFrame orientation={context.orientation} data-orientation={context.orientation} data-disabled={context.disabled ? "" : void 0} size={context.size} {...rangeProps} ref={composedRefs} {...{
139
+ [orientation.startEdge]: offsetStart + "%",
140
+ [orientation.endEdge]: offsetEnd + "%"
141
+ }} {...orientation.sizeProp === "width" ? {
142
+ height: "100%"
143
+ } : {
144
+ left: 0,
145
+ right: 0
146
+ }} />;
147
+ });
148
+ SliderTrackActive.displayName = RANGE_NAME;
149
+ const THUMB_NAME = "SliderThumb";
150
+ const getThumbSize = (val) => {
151
+ const size = typeof val === "number" ? val : getSize(val, -1);
152
+ return {
153
+ width: size,
154
+ height: size,
155
+ minWidth: size,
156
+ minHeight: size
157
+ };
158
+ };
159
+ const SliderThumbFrame = styled(ThemeableStack, {
160
+ name: "SliderThumb",
161
+ position: "absolute",
162
+ bordered: 2,
163
+ borderWidth: 2,
164
+ backgrounded: true,
165
+ pressTheme: isWeb,
166
+ focusTheme: isWeb,
167
+ hoverTheme: isWeb,
168
+ variants: {
169
+ size: {
170
+ "...size": getThumbSize
171
+ }
172
+ }
173
+ });
174
+ const SliderThumb = React.forwardRef((props, forwardedRef) => {
175
+ var _a;
176
+ const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
177
+ const context = useSliderContext(THUMB_NAME, __scopeSlider);
178
+ const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
179
+ const [thumb, setThumb] = React.useState(null);
180
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
181
+ const value = context.values[index];
182
+ const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
183
+ const label = getLabel(index, context.values.length);
184
+ const [size, setSize] = React.useState(() => {
185
+ const estimatedSize = getVariableValue(getThumbSize(sizeProp).width);
186
+ return estimatedSize;
187
+ });
188
+ const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
189
+ React.useEffect(() => {
190
+ if (thumb) {
191
+ context.thumbs.add(thumb);
192
+ return () => {
193
+ context.thumbs.delete(thumb);
194
+ };
195
+ }
196
+ }, [thumb, context.thumbs]);
197
+ return <SliderThumbFrame ref={composedRefs} role="slider" aria-label={props["aria-label"] || label} aria-valuemin={context.min} aria-valuenow={value} aria-valuemax={context.max} aria-orientation={context.orientation} data-orientation={context.orientation} data-disabled={context.disabled ? "" : void 0} tabIndex={context.disabled ? void 0 : 0} {...thumbProps} {...context.orientation === "horizontal" ? {
198
+ x: thumbInBoundsOffset - size / 2,
199
+ y: -size / 2,
200
+ top: "50%",
201
+ ...size === 0 && {
202
+ top: "auto",
203
+ bottom: "auto"
204
+ }
205
+ } : {
206
+ x: -size / 2,
207
+ y: size / 2,
208
+ left: "50%",
209
+ ...size === 0 && {
210
+ left: "auto",
211
+ right: "auto"
212
+ }
213
+ }} size={(_a = sizeProp != null ? sizeProp : context.size) != null ? _a : "$4"} onLayout={(e) => {
214
+ setSize(e.nativeEvent.layout[orientation.sizeProp]);
215
+ }} {...{
216
+ [orientation.startEdge]: `${percent}%`
217
+ }} onFocus={composeEventHandlers(props.onFocus, () => {
218
+ context.valueIndexToChangeRef.current = index;
219
+ })} />;
220
+ });
221
+ SliderThumb.displayName = THUMB_NAME;
222
+ const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
223
+ const {
224
+ name,
225
+ min = 0,
226
+ max = 100,
227
+ step = 1,
228
+ orientation = "horizontal",
229
+ disabled = false,
230
+ minStepsBetweenThumbs = 0,
231
+ defaultValue = [min],
232
+ value,
233
+ onValueChange = () => {
234
+ },
235
+ size: sizeProp,
236
+ ...sliderProps
237
+ } = props;
238
+ const sliderRef = React.useRef(null);
239
+ const composedRefs = useComposedRefs(sliderRef, forwardedRef);
240
+ const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
241
+ const valueIndexToChangeRef = React.useRef(0);
242
+ const isHorizontal = orientation === "horizontal";
243
+ const [values = [], setValues] = useControllableState({
244
+ prop: value,
245
+ defaultProp: defaultValue,
246
+ onChange: (value2) => {
247
+ var _a;
248
+ if (isWeb) {
249
+ const thumbs = [...thumbRefs.current];
250
+ (_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
251
+ }
252
+ onValueChange(value2);
253
+ }
254
+ });
255
+ if (isWeb) {
256
+ React.useEffect(() => {
257
+ const node = sliderRef.current;
258
+ if (!node)
259
+ return;
260
+ const preventDefault = (e) => {
261
+ e.preventDefault();
262
+ };
263
+ node.addEventListener("touchstart", preventDefault);
264
+ return () => {
265
+ node.removeEventListener("touchstart", preventDefault);
266
+ };
267
+ }, []);
268
+ }
269
+ function handleSlideMove(value2) {
270
+ updateValues(value2, valueIndexToChangeRef.current);
271
+ }
272
+ function updateValues(value2, atIndex) {
273
+ const decimalCount = getDecimalCount(step);
274
+ const snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount);
275
+ const nextValue = clamp(snapToStep, [min, max]);
276
+ setValues((prevValues = []) => {
277
+ const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
278
+ if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
279
+ valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
280
+ return String(nextValues) === String(prevValues) ? prevValues : nextValues;
281
+ } else {
282
+ return prevValues;
283
+ }
284
+ });
285
+ }
286
+ const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
287
+ return <SliderProvider scope={props.__scopeSlider} disabled={disabled} min={min} max={max} valueIndexToChangeRef={valueIndexToChangeRef} thumbs={thumbRefs.current} values={values} orientation={orientation} size={sizeProp}><SliderOriented aria-disabled={disabled} data-disabled={disabled ? "" : void 0} {...sliderProps} ref={composedRefs} min={min} max={max} onSlideStart={disabled ? void 0 : (value2, target) => {
288
+ if (target !== "thumb") {
289
+ const closestIndex = getClosestValueIndex(values, value2);
290
+ updateValues(value2, closestIndex);
291
+ }
292
+ }} onSlideMove={disabled ? void 0 : handleSlideMove} onHomeKeyDown={() => !disabled && updateValues(min, 0)} onEndKeyDown={() => !disabled && updateValues(max, values.length - 1)} onStepKeyDown={({ event, direction: stepDirection }) => {
293
+ if (!disabled) {
294
+ const isPageKey = PAGE_KEYS.includes(event.key);
295
+ const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
296
+ const multiplier = isSkipKey ? 10 : 1;
297
+ const atIndex = valueIndexToChangeRef.current;
298
+ const value2 = values[atIndex];
299
+ const stepInDirection = step * multiplier * stepDirection;
300
+ updateValues(value2 + stepInDirection, atIndex);
301
+ }
302
+ }} /></SliderProvider>;
303
+ }), {
304
+ Track: SliderTrack,
305
+ TrackActive: SliderTrackActive,
306
+ Thumb: SliderThumb
307
+ });
308
+ Slider.displayName = SLIDER_NAME;
309
+ const Track = SliderTrack;
310
+ const Range = SliderTrackActive;
311
+ const Thumb = SliderThumb;
312
+ export {
313
+ Range,
314
+ Slider,
315
+ SliderThumb,
316
+ SliderThumbFrame,
317
+ SliderTrack,
318
+ SliderTrackActive,
319
+ SliderTrackActiveFrame,
320
+ SliderTrackFrame,
321
+ Thumb,
322
+ Track
323
+ };
324
+ //# sourceMappingURL=Slider.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/Slider.tsx"],
4
+ "sourcesContent": ["// forked from radix-ui\n\nimport { composeRefs, useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n SizeTokens,\n getSize,\n getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { clamp, composeEventHandlers } from '@tamagui/helpers'\nimport { SizableStackProps, ThemeableStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { useDirection } from '@tamagui/use-direction'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nimport {\n ARROW_KEYS,\n BACK_KEYS,\n PAGE_KEYS,\n SLIDER_NAME,\n SliderOrientationProvider,\n SliderProvider,\n useSliderContext,\n useSliderOrientationContext,\n} from './constants'\nimport {\n convertValueToPercentage,\n getClosestValueIndex,\n getDecimalCount,\n getLabel,\n getNextSortedValues,\n getThumbInBoundsOffset,\n hasMinStepsBetweenValues,\n linearScale,\n roundValue,\n} from './helpers'\nimport { SliderFrame, SliderImpl } from './SliderImpl'\nimport {\n ScopedProps,\n SliderContextValue,\n SliderHorizontalProps,\n SliderProps,\n SliderTrackProps,\n SliderVerticalProps,\n} from './types'\n\n/* -------------------------------------------------------------------------------------------------\n * SliderHorizontal\n * -----------------------------------------------------------------------------------------------*/\n\nconst SliderHorizontal = React.forwardRef<View, SliderHorizontalProps>(\n (props: ScopedProps<SliderHorizontalProps>, forwardedRef) => {\n const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const direction = useDirection(dir)\n const isDirectionLTR = direction === 'ltr'\n const sliderRef = React.useRef<View>(null)\n const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }))\n\n function getValueFromPointer(pointerPosition: number) {\n const input: [number, number] = [0, state.size]\n const output: [number, number] = isDirectionLTR ? [min, max] : [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge={isDirectionLTR ? 'left' : 'right'}\n endEdge={isDirectionLTR ? 'right' : 'left'}\n direction={isDirectionLTR ? 1 : -1}\n sizeProp=\"width\"\n size={state.size}\n >\n <SliderImpl\n ref={composeRefs(forwardedRef, sliderRef)}\n dir={direction}\n {...sliderProps}\n orientation=\"horizontal\"\n onLayout={() => {\n sliderRef.current?.measure((_x, _y, width, _height, pageX, _pageY) => {\n setState({\n size: width,\n offset: pageX,\n })\n })\n }}\n onSlideStart={(event, target) => {\n const value = getValueFromPointer(event.nativeEvent.locationX)\n if (value) {\n onSlideStart?.(value, target)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageX - state.offset)\n if (value) {\n onSlideMove?.(value)\n }\n }}\n onSlideEnd={() => {}}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS[direction].includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderVertical\n * -----------------------------------------------------------------------------------------------*/\n\nconst SliderVertical = React.forwardRef<View, SliderVerticalProps>(\n (props: ScopedProps<SliderVerticalProps>, forwardedRef) => {\n const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }))\n const sliderRef = React.useRef<View>(null)\n\n function getValueFromPointer(pointerPosition: number) {\n const input: [number, number] = [0, state.size]\n const output: [number, number] = [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge=\"bottom\"\n endEdge=\"top\"\n sizeProp=\"height\"\n size={state.size}\n direction={1}\n >\n <SliderImpl\n ref={composeRefs(forwardedRef, sliderRef)}\n {...sliderProps}\n orientation=\"vertical\"\n onLayout={() => {\n sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {\n setState({\n size: height,\n offset: pageY,\n })\n })\n }}\n onSlideStart={(event, target) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n if (value) {\n onSlideStart?.(value, target)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageY - state.offset)\n if (value) {\n onSlideMove?.(value)\n }\n }}\n onSlideEnd={() => {}}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS.ltr.includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrack\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRACK_NAME = 'SliderTrack'\n\ntype SliderTrackElement = HTMLElement | View\n\nexport const SliderTrackFrame = styled(SliderFrame, {\n name: 'SliderTrack',\n height: '100%',\n width: '100%',\n backgroundColor: '$background',\n position: 'relative',\n borderRadius: 100_000,\n overflow: 'hidden',\n})\n\nconst SliderTrack = React.forwardRef<SliderTrackElement, SliderTrackProps>(\n (props: ScopedProps<SliderTrackProps>, forwardedRef) => {\n const { __scopeSlider, ...trackProps } = props\n const context = useSliderContext(TRACK_NAME, __scopeSlider)\n return (\n <SliderTrackFrame\n data-disabled={context.disabled ? '' : undefined}\n data-orientation={context.orientation}\n orientation={context.orientation}\n size={context.size}\n {...trackProps}\n ref={forwardedRef}\n />\n )\n }\n)\n\nSliderTrack.displayName = TRACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrackActive\n * -----------------------------------------------------------------------------------------------*/\n\nconst RANGE_NAME = 'SliderTrackActive'\n\nexport const SliderTrackActiveFrame = styled(SliderFrame, {\n name: 'SliderTrackActive',\n backgroundColor: '$background',\n position: 'absolute',\n})\n\ntype SliderTrackActiveProps = GetProps<typeof SliderTrackActiveFrame>\n\nconst SliderTrackActive = React.forwardRef<View, SliderTrackActiveProps>(\n (props: ScopedProps<SliderTrackActiveProps>, forwardedRef) => {\n const { __scopeSlider, ...rangeProps } = props\n const context = useSliderContext(RANGE_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider)\n const ref = React.useRef<View>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const valuesCount = context.values.length\n const percentages = context.values.map((value) =>\n convertValueToPercentage(value, context.min, context.max)\n )\n const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0\n const offsetEnd = 100 - Math.max(...percentages)\n\n return (\n <SliderTrackActiveFrame\n orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n size={context.size}\n {...rangeProps}\n ref={composedRefs}\n {...{\n [orientation.startEdge]: offsetStart + '%',\n [orientation.endEdge]: offsetEnd + '%',\n }}\n {...(orientation.sizeProp === 'width'\n ? {\n height: '100%',\n }\n : {\n left: 0,\n right: 0,\n })}\n />\n )\n }\n)\n\nSliderTrackActive.displayName = RANGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SliderThumb'\n\n// TODO make this customizable through tamagui\n// so we can accurately use it for estimatedSize below\nconst getThumbSize = (val?: SizeTokens | number) => {\n const size = typeof val === 'number' ? val : getSize(val, -1)\n return {\n width: size,\n height: size,\n minWidth: size,\n minHeight: size,\n }\n}\n\nexport const SliderThumbFrame = styled(ThemeableStack, {\n name: 'SliderThumb',\n position: 'absolute',\n // TODO not taking up 2\n bordered: 2,\n // OR THIS\n borderWidth: 2,\n backgrounded: true,\n pressTheme: isWeb,\n focusTheme: isWeb,\n hoverTheme: isWeb,\n\n variants: {\n size: {\n '...size': getThumbSize,\n },\n },\n})\n\ninterface SliderThumbProps extends SizableStackProps {\n index: number\n}\n\nconst SliderThumb = React.forwardRef<View, SliderThumbProps>(\n (props: ScopedProps<SliderThumbProps>, forwardedRef) => {\n const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props\n const context = useSliderContext(THUMB_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider)\n const [thumb, setThumb] = React.useState<View | HTMLElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node))\n\n // We cast because index could be `-1` which would return undefined\n const value = context.values[index] as number | undefined\n const percent =\n value === undefined ? 0 : convertValueToPercentage(value, context.min, context.max)\n const label = getLabel(index, context.values.length)\n const [size, setSize] = React.useState(() => {\n // for SSR\n const estimatedSize = getVariableValue(getThumbSize(sizeProp).width)\n return estimatedSize\n })\n\n const thumbInBoundsOffset = size\n ? getThumbInBoundsOffset(size, percent, orientation.direction)\n : 0\n\n React.useEffect(() => {\n if (thumb) {\n context.thumbs.add(thumb)\n return () => {\n context.thumbs.delete(thumb)\n }\n }\n }, [thumb, context.thumbs])\n\n return (\n <SliderThumbFrame\n ref={composedRefs}\n // TODO\n // @ts-ignore\n role=\"slider\"\n aria-label={props['aria-label'] || label}\n aria-valuemin={context.min}\n aria-valuenow={value}\n aria-valuemax={context.max}\n aria-orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n tabIndex={context.disabled ? undefined : 0}\n {...thumbProps}\n {...(context.orientation === 'horizontal'\n ? {\n x: thumbInBoundsOffset - size / 2,\n y: -size / 2,\n top: '50%',\n ...(size === 0 && {\n top: 'auto',\n bottom: 'auto',\n }),\n }\n : {\n x: -size / 2,\n y: size / 2,\n left: '50%',\n ...(size === 0 && {\n left: 'auto',\n right: 'auto',\n }),\n })}\n size={sizeProp ?? context.size ?? '$4'}\n onLayout={(e) => {\n setSize(e.nativeEvent.layout[orientation.sizeProp])\n }}\n {...{\n [orientation.startEdge]: `${percent}%`,\n }}\n /**\n * There will be no value on initial render while we work out the index so we hide thumbs\n * without a value, otherwise SSR will render them in the wrong position before they\n * snap into the correct position during hydration which would be visually jarring for\n * slower connections.\n */\n // style={value === undefined ? { display: 'none' } : props.style}\n onFocus={composeEventHandlers(props.onFocus, () => {\n context.valueIndexToChangeRef.current = index\n })}\n />\n )\n }\n)\n\nSliderThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Slider\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slider = withStaticProperties(\n React.forwardRef<View, SliderProps>((props: ScopedProps<SliderProps>, forwardedRef) => {\n const {\n name,\n min = 0,\n max = 100,\n step = 1,\n orientation = 'horizontal',\n disabled = false,\n minStepsBetweenThumbs = 0,\n defaultValue = [min],\n value,\n onValueChange = () => {},\n size: sizeProp,\n ...sliderProps\n } = props\n const sliderRef = React.useRef<View>(null)\n const composedRefs = useComposedRefs(sliderRef, forwardedRef)\n const thumbRefs = React.useRef<SliderContextValue['thumbs']>(new Set())\n const valueIndexToChangeRef = React.useRef<number>(0)\n const isHorizontal = orientation === 'horizontal'\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // const isFormControl =\n // sliderRef.current instanceof HTMLElement ? Boolean(sliderRef.current.closest('form')) : true\n\n const [values = [], setValues] = useControllableState({\n prop: value,\n defaultProp: defaultValue,\n onChange: (value) => {\n if (isWeb) {\n const thumbs = [...thumbRefs.current]\n thumbs[valueIndexToChangeRef.current]?.focus()\n }\n onValueChange(value)\n },\n })\n\n if (isWeb) {\n React.useEffect(() => {\n // @ts-ignore\n const node = sliderRef.current as HTMLElement\n if (!node) return\n const preventDefault = (e) => {\n e.preventDefault()\n }\n node.addEventListener('touchstart', preventDefault)\n return () => {\n node.removeEventListener('touchstart', preventDefault)\n }\n }, [])\n }\n\n function handleSlideMove(value: number) {\n updateValues(value, valueIndexToChangeRef.current)\n }\n\n function updateValues(value: number, atIndex: number) {\n const decimalCount = getDecimalCount(step)\n const snapToStep = roundValue(Math.round((value - min) / step) * step + min, decimalCount)\n const nextValue = clamp(snapToStep, [min, max])\n setValues((prevValues = []) => {\n const nextValues = getNextSortedValues(prevValues, nextValue, atIndex)\n if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {\n valueIndexToChangeRef.current = nextValues.indexOf(nextValue)\n return String(nextValues) === String(prevValues) ? prevValues : nextValues\n } else {\n return prevValues\n }\n })\n }\n\n const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical\n\n return (\n <SliderProvider\n scope={props.__scopeSlider}\n disabled={disabled}\n min={min}\n max={max}\n valueIndexToChangeRef={valueIndexToChangeRef}\n thumbs={thumbRefs.current}\n values={values}\n orientation={orientation}\n size={sizeProp}\n >\n <SliderOriented\n aria-disabled={disabled}\n data-disabled={disabled ? '' : undefined}\n {...sliderProps}\n ref={composedRefs}\n min={min}\n max={max}\n onSlideStart={\n disabled\n ? undefined\n : (value: number, target) => {\n // when starting on the track, move it right away\n // when starting on thumb, dont jump until movemenet as it feels weird\n if (target !== 'thumb') {\n const closestIndex = getClosestValueIndex(values, value)\n updateValues(value, closestIndex)\n }\n }\n }\n onSlideMove={disabled ? undefined : handleSlideMove}\n onHomeKeyDown={() => !disabled && updateValues(min, 0)}\n onEndKeyDown={() => !disabled && updateValues(max, values.length - 1)}\n onStepKeyDown={({ event, direction: stepDirection }) => {\n if (!disabled) {\n const isPageKey = PAGE_KEYS.includes(event.key)\n const isSkipKey = isPageKey || (event.shiftKey && ARROW_KEYS.includes(event.key))\n const multiplier = isSkipKey ? 10 : 1\n const atIndex = valueIndexToChangeRef.current\n const value = values[atIndex]\n const stepInDirection = step * multiplier * stepDirection\n updateValues(value + stepInDirection, atIndex)\n }\n }}\n />\n {/* {isFormControl &&\n values.map((value, index) => (\n <BubbleInput\n key={index}\n name={name ? name + (values.length > 1 ? '[]' : '') : undefined}\n value={value}\n />\n ))} */}\n </SliderProvider>\n )\n }),\n {\n Track: SliderTrack,\n TrackActive: SliderTrackActive,\n Thumb: SliderThumb,\n }\n)\n\nSlider.displayName = SLIDER_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// // TODO\n// const BubbleInput = (props: any) => {\n// const { value, ...inputProps } = props\n// const ref = React.useRef<HTMLInputElement>(null)\n// const prevValue = usePrevious(value)\n\n// // Bubble value change to parents (e.g form change event)\n// React.useEffect(() => {\n// const input = ref.current!\n// const inputProto = window.HTMLInputElement.prototype\n// const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value') as PropertyDescriptor\n// const setValue = descriptor.set\n// if (prevValue !== value && setValue) {\n// const event = new Event('input', { bubbles: true })\n// setValue.call(input, value)\n// input.dispatchEvent(event)\n// }\n// }, [prevValue, value])\n\n// /**\n// * We purposefully do not use `type=\"hidden\"` here otherwise forms that\n// * wrap it will not be able to access its value via the FormData API.\n// *\n// * We purposefully do not add the `value` attribute here to allow the value\n// * to be set programatically and bubble to any parent form `onChange` event.\n// * Adding the `value` will cause React to consider the programatic\n// * dispatch a duplicate and it will get swallowed.\n// */\n// return <input style={{ display: 'none' }} {...inputProps} ref={ref} defaultValue={value} />\n// }\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Track = SliderTrack\nconst Range = SliderTrackActive\nconst Thumb = SliderThumb\n\nexport {\n Slider,\n SliderTrack,\n SliderTrackActive,\n SliderThumb,\n //\n Track,\n Range,\n Thumb,\n}\n\nexport type { SliderProps, SliderTrackProps, SliderTrackActiveProps, SliderThumbProps }\n"],
5
+ "mappings": "AAEA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AACA;AACA;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAcA,MAAM,mBAAmB,MAAM,WAC7B,CAAC,OAA2C,iBAAiB;AAC3D,QAAM,EAAE,KAAK,KAAK,KAAK,cAAc,aAAa,kBAAkB,gBAAgB;AACpF,QAAM,YAAY,aAAa,GAAG;AAClC,QAAM,iBAAiB,cAAc;AACrC,QAAM,YAAY,MAAM,OAAa,IAAI;AACzC,QAAM,CAAC,OAAO,YAAY,MAAM,SAAS,MAAO,GAAE,MAAM,GAAG,QAAQ,EAAE,EAAE;AAEvE,+BAA6B,iBAAyB;AACpD,UAAM,QAA0B,CAAC,GAAG,MAAM,IAAI;AAC9C,UAAM,SAA2B,iBAAiB,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;AACxE,UAAM,QAAQ,YAAY,OAAO,MAAM;AACvC,WAAO,MAAM,eAAe;AAAA,EAC9B;AAEA,SACE,CAAC,0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ACb,UAAU,UACV,KAAK,KACL,KAAK,KACL,uBAAuB,uBACvB,QAAQ,UAAU,SAClB,QAAQ,QACR,aAAa,aACb,MAAM,UAEN,CAAC,eACC,eAAe,UACf,eAAe,WAAW,KAAK,YAC3B,aACJ,KAAK,cACL,KAAK,KACL,KAAK,KACL,cACE,WACI,SACA,CAAC,QAAe,WAAW;AAGzB,QAAI,WAAW,SAAS;AACtB,YAAM,eAAe,qBAAqB,QAAQ,MAAK;AACvD,mBAAa,QAAO,YAAY;AAAA,IAClC;AAAA,EACF,GAEN,aAAa,WAAW,SAAY,iBACpC,eAAe,MAAM,CAAC,YAAY,aAAa,KAAK,CAAC,GACrD,cAAc,MAAM,CAAC,YAAY,aAAa,KAAK,OAAO,SAAS,CAAC,GACpE,eAAe,CAAC,EAAE,OAAO,WAAW,oBAAoB;AACtD,QAAI,CAAC,UAAU;AACb,YAAM,YAAY,UAAU,SAAS,MAAM,GAAG;AAC9C,YAAM,YAAY,aAAc,MAAM,YAAY,WAAW,SAAS,MAAM,GAAG;AAC/E,YAAM,aAAa,YAAY,KAAK;AACpC,YAAM,UAAU,sBAAsB;AACtC,YAAM,SAAQ,OAAO;AACrB,YAAM,kBAAkB,OAAO,aAAa;AAC5C,mBAAa,SAAQ,iBAAiB,OAAO;AAAA,IAC/C;AAAA,EACF,GACF,EASF,EArDC;AAuDL,CAAC,GACD;AAAA,EACE,OAAO;AAAA,EACP,aAAa;AAAA,EACb,OAAO;AACT,CACF;AAEA,OAAO,cAAc;AAqCrB,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,84 @@
1
+ import { composeEventHandlers, getSize, getVariableValue, isWeb, styled } from "@tamagui/core";
2
+ import { YStack } from "@tamagui/stacks";
3
+ import * as React from "react";
4
+ import { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from "./constants";
5
+ const DirectionalYStack = styled(YStack, {
6
+ variants: {
7
+ orientation: {
8
+ horizontal: {},
9
+ vertical: {}
10
+ }
11
+ }
12
+ });
13
+ const SliderFrame = styled(DirectionalYStack, {
14
+ position: "relative",
15
+ variants: {
16
+ size: (val, extras) => {
17
+ const orientation = extras.props.orientation;
18
+ const size = Math.round(getVariableValue(getSize(val)) / 6);
19
+ if (orientation === "horizontal") {
20
+ return {
21
+ height: size,
22
+ borderRadius: size,
23
+ justifyContent: "center"
24
+ };
25
+ }
26
+ return {
27
+ width: size,
28
+ borderRadius: size,
29
+ alignItems: "center"
30
+ };
31
+ }
32
+ }
33
+ });
34
+ const SliderImpl = React.forwardRef((props, forwardedRef) => {
35
+ const {
36
+ __scopeSlider,
37
+ onSlideStart,
38
+ onSlideMove,
39
+ onSlideEnd,
40
+ onHomeKeyDown,
41
+ onEndKeyDown,
42
+ onStepKeyDown,
43
+ ...sliderProps
44
+ } = props;
45
+ const context = useSliderContext(SLIDER_NAME, __scopeSlider);
46
+ return <SliderFrame size="$4" {...sliderProps} data-orientation={sliderProps.orientation} ref={forwardedRef} {...isWeb && {
47
+ onKeyDown: (event) => {
48
+ if (event.key === "Home") {
49
+ onHomeKeyDown(event);
50
+ event.preventDefault();
51
+ } else if (event.key === "End") {
52
+ onEndKeyDown(event);
53
+ event.preventDefault();
54
+ } else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {
55
+ onStepKeyDown(event);
56
+ event.preventDefault();
57
+ }
58
+ }
59
+ }} onMoveShouldSetResponderCapture={() => true} onScrollShouldSetResponder={() => true} onScrollShouldSetResponderCapture={() => true} onMoveShouldSetResponder={() => true} onStartShouldSetResponder={() => true} onResponderTerminationRequest={() => {
60
+ return false;
61
+ }} onResponderGrant={composeEventHandlers(props.onResponderGrant, (event) => {
62
+ const target = event.target;
63
+ console.log("target", target, context.thumbs.has(target), context.thumbs);
64
+ const isStartingOnThumb = context.thumbs.has(target);
65
+ if (isWeb && target instanceof HTMLElement) {
66
+ if (context.thumbs.has(target)) {
67
+ target.focus();
68
+ }
69
+ }
70
+ onSlideStart(event, isStartingOnThumb ? "thumb" : "track");
71
+ })} onResponderMove={composeEventHandlers(props.onResponderMove, (event) => {
72
+ event.preventDefault();
73
+ event.stopPropagation();
74
+ onSlideMove(event);
75
+ })} onResponderRelease={composeEventHandlers(props.onResponderRelease, (event) => {
76
+ onSlideEnd(event);
77
+ })} />;
78
+ });
79
+ export {
80
+ DirectionalYStack,
81
+ SliderFrame,
82
+ SliderImpl
83
+ };
84
+ //# sourceMappingURL=SliderImpl.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/SliderImpl.tsx"],
4
+ "sourcesContent": ["/* -------------------------------------------------------------------------------------------------\n * SliderImpl\n * -----------------------------------------------------------------------------------------------*/\n\nimport { composeEventHandlers, getSize, getVariableValue, isWeb, styled } from '@tamagui/core'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nimport { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from './constants'\nimport { ScopedProps, SliderImplProps } from './types'\n\nexport const DirectionalYStack = styled(YStack, {\n variants: {\n orientation: {\n horizontal: {},\n vertical: {},\n },\n },\n})\n\nexport const SliderFrame = styled(DirectionalYStack, {\n position: 'relative',\n\n variants: {\n size: (val, extras) => {\n const orientation = extras.props.orientation\n const size = Math.round(getVariableValue(getSize(val)) / 6)\n if (orientation === 'horizontal') {\n return {\n height: size,\n borderRadius: size,\n justifyContent: 'center',\n }\n }\n return {\n width: size,\n borderRadius: size,\n alignItems: 'center',\n }\n },\n },\n})\n\nexport const SliderImpl = React.forwardRef<View, SliderImplProps>(\n (props: ScopedProps<SliderImplProps>, forwardedRef) => {\n const {\n __scopeSlider,\n onSlideStart,\n onSlideMove,\n onSlideEnd,\n onHomeKeyDown,\n onEndKeyDown,\n onStepKeyDown,\n ...sliderProps\n } = props\n const context = useSliderContext(SLIDER_NAME, __scopeSlider)\n return (\n <SliderFrame\n size=\"$4\"\n {...sliderProps}\n data-orientation={sliderProps.orientation}\n ref={forwardedRef}\n {...(isWeb && {\n onKeyDown: (event) => {\n if (event.key === 'Home') {\n onHomeKeyDown(event)\n // Prevent scrolling to page start\n event.preventDefault()\n } else if (event.key === 'End') {\n onEndKeyDown(event)\n // Prevent scrolling to page end\n event.preventDefault()\n } else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {\n onStepKeyDown(event)\n // Prevent scrolling for directional key presses\n event.preventDefault()\n }\n },\n })}\n onMoveShouldSetResponderCapture={() => true}\n onScrollShouldSetResponder={() => true}\n onScrollShouldSetResponderCapture={() => true}\n onMoveShouldSetResponder={() => true}\n onStartShouldSetResponder={() => true}\n // onStartShouldSetResponderCapture={() => true}\n onResponderTerminationRequest={() => {\n return false\n }}\n onResponderGrant={composeEventHandlers(props.onResponderGrant, (event) => {\n const target = event.target as HTMLElement | number\n console.log('target', target, context.thumbs.has(target), context.thumbs)\n const isStartingOnThumb = context.thumbs.has(target)\n // // Prevent browser focus behaviour because we focus a thumb manually when values change.\n // Touch devices have a delay before focusing so won't focus if touch immediately moves\n // away from target (sliding). We want thumb to focus regardless.\n if (isWeb && target instanceof HTMLElement) {\n if (context.thumbs.has(target)) {\n target.focus()\n }\n }\n onSlideStart(event, isStartingOnThumb ? 'thumb' : 'track')\n })}\n onResponderMove={composeEventHandlers(props.onResponderMove, (event) => {\n event.preventDefault()\n event.stopPropagation()\n\n // const target = event.target as HTMLElement\n onSlideMove(event)\n })}\n onResponderRelease={composeEventHandlers(props.onResponderRelease, (event) => {\n // const target = event.target as HTMLElement\n onSlideEnd(event)\n })}\n />\n )\n }\n)\n"],
5
+ "mappings": "AAIA;AACA;AACA;AAGA;AAGO,MAAM,oBAAoB,OAAO,QAAQ;AAAA,EAC9C,UAAU;AAAA,IACR,aAAa;AAAA,MACX,YAAY,CAAC;AAAA,MACb,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AACF,CAAC;AAEM,MAAM,cAAc,OAAO,mBAAmB;AAAA,EACnD,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