@tamagui/slider 1.0.1-beta.26 → 1.0.1-beta.29
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 +106 -85
- package/dist/cjs/Slider.js.map +2 -2
- package/dist/cjs/SliderImpl.js +29 -9
- package/dist/cjs/SliderImpl.js.map +2 -2
- package/dist/cjs/constants.js +62 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/Slider.js +91 -66
- package/dist/esm/Slider.js.map +2 -2
- package/dist/esm/SliderImpl.js +27 -7
- package/dist/esm/SliderImpl.js.map +2 -2
- package/dist/esm/constants.js +30 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/jsx/Slider.js +83 -58
- package/dist/jsx/SliderImpl.js +27 -8
- package/dist/jsx/constants.js +29 -0
- package/dist/jsx/index.js +0 -1
- package/package.json +8 -8
- package/types/Slider.d.ts.map +1 -1
- package/types/SliderImpl.d.ts.map +1 -1
- package/types/constants.d.ts +53 -0
- package/types/constants.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +3 -3
- package/types/types.d.ts.map +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
ARROW_KEYS: () => ARROW_KEYS,
|
|
21
|
+
BACK_KEYS: () => BACK_KEYS,
|
|
22
|
+
PAGE_KEYS: () => PAGE_KEYS,
|
|
23
|
+
SLIDER_NAME: () => SLIDER_NAME,
|
|
24
|
+
SliderOrientationProvider: () => SliderOrientationProvider,
|
|
25
|
+
SliderProvider: () => SliderProvider,
|
|
26
|
+
createSliderContext: () => createSliderContext,
|
|
27
|
+
createSliderScope: () => createSliderScope,
|
|
28
|
+
useSliderContext: () => useSliderContext,
|
|
29
|
+
useSliderOrientationContext: () => useSliderOrientationContext
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(constants_exports);
|
|
32
|
+
var import_create_context = require("@tamagui/create-context");
|
|
33
|
+
const SLIDER_NAME = "Slider";
|
|
34
|
+
const [createSliderContext, createSliderScope] = (0, import_create_context.createContextScope)(SLIDER_NAME);
|
|
35
|
+
const [SliderProvider, useSliderContext] = createSliderContext(SLIDER_NAME);
|
|
36
|
+
const [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext(SLIDER_NAME, {
|
|
37
|
+
startEdge: "left",
|
|
38
|
+
endEdge: "right",
|
|
39
|
+
sizeProp: "width",
|
|
40
|
+
size: 0,
|
|
41
|
+
direction: 1
|
|
42
|
+
});
|
|
43
|
+
const PAGE_KEYS = ["PageUp", "PageDown"];
|
|
44
|
+
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
45
|
+
const BACK_KEYS = {
|
|
46
|
+
ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
|
|
47
|
+
rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
ARROW_KEYS,
|
|
52
|
+
BACK_KEYS,
|
|
53
|
+
PAGE_KEYS,
|
|
54
|
+
SLIDER_NAME,
|
|
55
|
+
SliderOrientationProvider,
|
|
56
|
+
SliderProvider,
|
|
57
|
+
createSliderContext,
|
|
58
|
+
createSliderScope,
|
|
59
|
+
useSliderContext,
|
|
60
|
+
useSliderOrientationContext
|
|
61
|
+
});
|
|
62
|
+
//# 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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAAmC;AAI5B,MAAM,cAAc;AAEpB,MAAM,CAAC,qBAAqB,qBAAqB,8CAAmB,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
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,5 +15,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
15
|
var src_exports = {};
|
|
16
16
|
module.exports = __toCommonJS(src_exports);
|
|
17
17
|
__reExport(src_exports, require("./Slider"), module.exports);
|
|
18
|
-
__reExport(src_exports, require("./types"), module.exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './Slider'\nexport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;
|
|
4
|
+
"sourcesContent": ["export * from './Slider'\nexport type {\n SliderProps,\n SliderHorizontalProps,\n SliderVerticalProps,\n SliderTrackProps,\n} from './types'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["import type { GestureReponderEvent, SizeTokens } from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport type { SizableStackProps
|
|
4
|
+
"sourcesContent": ["import type { GestureReponderEvent, SizeTokens } from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport type { SizableStackProps } from '@tamagui/stacks'\nimport type { View } from 'react-native'\n\nexport type ScopedProps<P> = P & { __scopeSlider?: Scope }\n\nexport type Direction = 'ltr' | 'rtl'\n\nexport type SliderImplElement = HTMLElement | View\n\ntype SliderImplPrivateProps = {\n onSlideStart(event: GestureReponderEvent, target: 'thumb' | 'track'): void\n onSlideMove(event: GestureReponderEvent): void\n onSlideEnd(event: GestureReponderEvent): void\n onHomeKeyDown(event: React.KeyboardEvent): void\n onEndKeyDown(event: React.KeyboardEvent): void\n onStepKeyDown(event: React.KeyboardEvent): void\n}\n\nexport interface SliderTrackProps extends SizableStackProps {}\n\nexport interface SliderImplProps extends SliderTrackProps, SliderImplPrivateProps {\n dir?: Direction\n orientation: 'horizontal' | 'vertical'\n}\n\ntype SliderOrientationPrivateProps = {\n min: number\n max: number\n onSlideStart?(value: number, target: 'thumb' | 'track'): void\n onSlideMove?(value: number): void\n onHomeKeyDown(event: React.KeyboardEvent): void\n onEndKeyDown(event: React.KeyboardEvent): void\n onStepKeyDown(step: { event: React.KeyboardEvent; direction: number }): void\n}\n\ninterface SliderOrientationProps\n extends Omit<SliderImplProps, keyof SliderImplPrivateProps | 'orientation'>,\n SliderOrientationPrivateProps {}\n\nexport interface SliderHorizontalProps extends SliderOrientationProps {\n dir?: Direction\n}\n\nexport interface SliderVerticalProps extends SliderOrientationProps {\n dir?: Direction\n}\n\nexport interface SliderProps\n extends Omit<\n SliderHorizontalProps | SliderVerticalProps,\n keyof SliderOrientationPrivateProps | 'defaultValue'\n > {\n size?: SizeTokens\n name?: string\n disabled?: boolean\n orientation?: React.AriaAttributes['aria-orientation']\n dir?: Direction\n min?: number\n max?: number\n step?: number\n minStepsBetweenThumbs?: number\n value?: number[]\n defaultValue?: number[]\n onValueChange?(value: number[]): void\n}\n\nexport type SliderContextValue = {\n size?: SizeTokens | number | null\n disabled?: boolean\n min: number\n max: number\n values: number[]\n valueIndexToChangeRef: React.MutableRefObject<number>\n thumbs: Set<any>\n orientation: SliderProps['orientation']\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Slider.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { usePrevious } from "@radix-ui/react-use-previous";
|
|
4
3
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
5
4
|
import { styled, withStaticProperties } from "@tamagui/core";
|
|
6
5
|
import { clamp, composeEventHandlers } from "@tamagui/helpers";
|
|
7
|
-
import {
|
|
6
|
+
import { ThemeableSizableStack } from "@tamagui/stacks";
|
|
8
7
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
9
8
|
import { useDirection } from "@tamagui/use-direction";
|
|
10
9
|
import * as React from "react";
|
|
11
10
|
import {
|
|
11
|
+
ARROW_KEYS,
|
|
12
|
+
BACK_KEYS,
|
|
13
|
+
PAGE_KEYS,
|
|
12
14
|
SLIDER_NAME,
|
|
13
15
|
SliderOrientationProvider,
|
|
14
16
|
SliderProvider,
|
|
15
17
|
useSliderContext,
|
|
16
18
|
useSliderOrientationContext
|
|
17
|
-
} from "./
|
|
19
|
+
} from "./constants";
|
|
18
20
|
import {
|
|
19
21
|
convertValueToPercentage,
|
|
20
22
|
getClosestValueIndex,
|
|
@@ -27,17 +29,11 @@ import {
|
|
|
27
29
|
roundValue
|
|
28
30
|
} from "./helpers";
|
|
29
31
|
import { SliderFrame, SliderImpl } from "./SliderImpl";
|
|
30
|
-
const PAGE_KEYS = ["PageUp", "PageDown"];
|
|
31
|
-
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
32
|
-
const BACK_KEYS = {
|
|
33
|
-
ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
|
|
34
|
-
rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
|
|
35
|
-
};
|
|
36
32
|
const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
37
33
|
const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
38
|
-
const layoutRef = React.useRef(null);
|
|
39
34
|
const direction = useDirection(dir);
|
|
40
35
|
const isDirectionLTR = direction === "ltr";
|
|
36
|
+
const layoutRef = React.useRef(null);
|
|
41
37
|
const [size, setSize] = React.useState(0);
|
|
42
38
|
function getValueFromPointer(pointerPosition) {
|
|
43
39
|
const layout = layoutRef.current;
|
|
@@ -46,7 +42,7 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
46
42
|
const input = [0, layout.width];
|
|
47
43
|
const output = isDirectionLTR ? [min, max] : [max, min];
|
|
48
44
|
const value = linearScale(input, output);
|
|
49
|
-
return value(pointerPosition
|
|
45
|
+
return value(pointerPosition);
|
|
50
46
|
}
|
|
51
47
|
__name(getValueFromPointer, "getValueFromPointer");
|
|
52
48
|
return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
|
|
@@ -57,23 +53,23 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
57
53
|
sizeProp: "width",
|
|
58
54
|
size
|
|
59
55
|
}, /* @__PURE__ */ React.createElement(SliderImpl, {
|
|
56
|
+
ref: forwardedRef,
|
|
60
57
|
dir: direction,
|
|
61
|
-
orientation: "horizontal",
|
|
62
58
|
...sliderProps,
|
|
59
|
+
orientation: "horizontal",
|
|
63
60
|
onLayout: (e) => {
|
|
64
61
|
const layout = e.nativeEvent.layout;
|
|
65
62
|
layoutRef.current = layout;
|
|
66
63
|
setSize(layout.height);
|
|
67
64
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const value = getValueFromPointer(event.nativeEvent.pageX);
|
|
65
|
+
onSlideStart: (event, target) => {
|
|
66
|
+
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
71
67
|
if (value) {
|
|
72
|
-
onSlideStart == null ? void 0 : onSlideStart(value);
|
|
68
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
73
69
|
}
|
|
74
70
|
},
|
|
75
71
|
onSlideMove: (event) => {
|
|
76
|
-
const value = getValueFromPointer(event.nativeEvent.
|
|
72
|
+
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
77
73
|
if (value) {
|
|
78
74
|
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
79
75
|
}
|
|
@@ -88,16 +84,16 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
88
84
|
});
|
|
89
85
|
const SliderVertical = React.forwardRef((props, forwardedRef) => {
|
|
90
86
|
const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const rectRef = React.useRef();
|
|
87
|
+
const layoutRef = React.useRef(null);
|
|
88
|
+
const [size, setSize] = React.useState(0);
|
|
94
89
|
function getValueFromPointer(pointerPosition) {
|
|
95
|
-
const
|
|
96
|
-
|
|
90
|
+
const layout = layoutRef.current;
|
|
91
|
+
if (!layout)
|
|
92
|
+
return;
|
|
93
|
+
const input = [0, layout.height];
|
|
97
94
|
const output = [max, min];
|
|
98
95
|
const value = linearScale(input, output);
|
|
99
|
-
|
|
100
|
-
return value(pointerPosition - rect.top);
|
|
96
|
+
return value(pointerPosition);
|
|
101
97
|
}
|
|
102
98
|
__name(getValueFromPointer, "getValueFromPointer");
|
|
103
99
|
return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
|
|
@@ -105,21 +101,31 @@ const SliderVertical = React.forwardRef((props, forwardedRef) => {
|
|
|
105
101
|
startEdge: "bottom",
|
|
106
102
|
endEdge: "top",
|
|
107
103
|
sizeProp: "height",
|
|
108
|
-
size
|
|
104
|
+
size,
|
|
109
105
|
direction: 1
|
|
110
106
|
}, /* @__PURE__ */ React.createElement(SliderImpl, {
|
|
107
|
+
ref: forwardedRef,
|
|
111
108
|
...sliderProps,
|
|
112
109
|
orientation: "vertical",
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
onLayout: (e) => {
|
|
111
|
+
const layout = e.nativeEvent.layout;
|
|
112
|
+
layoutRef.current = layout;
|
|
113
|
+
setSize(layout.height);
|
|
114
|
+
},
|
|
115
|
+
onSlideStart: (event, target) => {
|
|
115
116
|
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
116
|
-
|
|
117
|
+
if (value) {
|
|
118
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
119
|
+
}
|
|
117
120
|
},
|
|
118
121
|
onSlideMove: (event) => {
|
|
119
122
|
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
120
|
-
|
|
123
|
+
if (value) {
|
|
124
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
onSlideEnd: () => {
|
|
121
128
|
},
|
|
122
|
-
onSlideEnd: () => rectRef.current = void 0,
|
|
123
129
|
onStepKeyDown: (event) => {
|
|
124
130
|
const isBackKey = BACK_KEYS.ltr.includes(event.key);
|
|
125
131
|
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
@@ -128,7 +134,12 @@ const SliderVertical = React.forwardRef((props, forwardedRef) => {
|
|
|
128
134
|
});
|
|
129
135
|
const TRACK_NAME = "SliderTrack";
|
|
130
136
|
const SliderTrackFrame = styled(SliderFrame, {
|
|
131
|
-
name: "
|
|
137
|
+
name: "SliderTrack",
|
|
138
|
+
height: "100%",
|
|
139
|
+
width: "100%",
|
|
140
|
+
backgroundColor: "$background",
|
|
141
|
+
position: "relative",
|
|
142
|
+
borderRadius: 1e5
|
|
132
143
|
});
|
|
133
144
|
const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
134
145
|
const { __scopeSlider, ...trackProps } = props;
|
|
@@ -137,6 +148,7 @@ const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
|
137
148
|
"data-disabled": context.disabled ? "" : void 0,
|
|
138
149
|
"data-orientation": context.orientation,
|
|
139
150
|
orientation: context.orientation,
|
|
151
|
+
size: context.size,
|
|
140
152
|
...trackProps,
|
|
141
153
|
ref: forwardedRef
|
|
142
154
|
});
|
|
@@ -144,7 +156,9 @@ const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
|
144
156
|
SliderTrack.displayName = TRACK_NAME;
|
|
145
157
|
const RANGE_NAME = "SliderTrackActive";
|
|
146
158
|
const SliderTrackActiveFrame = styled(SliderFrame, {
|
|
147
|
-
name: "SliderTrackActive"
|
|
159
|
+
name: "SliderTrackActive",
|
|
160
|
+
backgroundColor: "$background",
|
|
161
|
+
position: "absolute"
|
|
148
162
|
});
|
|
149
163
|
const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
|
|
150
164
|
const { __scopeSlider, ...rangeProps } = props;
|
|
@@ -160,33 +174,55 @@ const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
|
|
|
160
174
|
orientation: context.orientation,
|
|
161
175
|
"data-orientation": context.orientation,
|
|
162
176
|
"data-disabled": context.disabled ? "" : void 0,
|
|
177
|
+
size: context.size,
|
|
163
178
|
...rangeProps,
|
|
164
179
|
ref: composedRefs,
|
|
165
180
|
...{
|
|
166
181
|
[orientation.startEdge]: offsetStart + "%",
|
|
167
182
|
[orientation.endEdge]: offsetEnd + "%"
|
|
183
|
+
},
|
|
184
|
+
...orientation.sizeProp === "width" ? {
|
|
185
|
+
height: "100%"
|
|
186
|
+
} : {
|
|
187
|
+
left: 0,
|
|
188
|
+
right: 0
|
|
168
189
|
}
|
|
169
190
|
});
|
|
170
191
|
});
|
|
171
192
|
SliderTrackActive.displayName = RANGE_NAME;
|
|
172
193
|
const THUMB_NAME = "SliderThumb";
|
|
173
|
-
const SliderThumbFrame = styled(
|
|
194
|
+
const SliderThumbFrame = styled(ThemeableSizableStack, {
|
|
174
195
|
name: "SliderThumb",
|
|
175
|
-
position: "absolute"
|
|
196
|
+
position: "absolute",
|
|
197
|
+
bordered: 2,
|
|
198
|
+
borderWidth: 2,
|
|
199
|
+
pressable: true,
|
|
200
|
+
focusable: true,
|
|
201
|
+
hoverable: true
|
|
176
202
|
});
|
|
177
203
|
const SliderThumb = React.forwardRef((props, forwardedRef) => {
|
|
178
204
|
var _a;
|
|
179
205
|
const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
|
|
180
206
|
const context = useSliderContext(THUMB_NAME, __scopeSlider);
|
|
181
207
|
const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
|
|
208
|
+
const [thumb, setThumb] = React.useState(null);
|
|
209
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
|
|
182
210
|
const value = context.values[index];
|
|
183
211
|
const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
|
|
184
212
|
const label = getLabel(index, context.values.length);
|
|
185
213
|
const [size, setSize] = React.useState(0);
|
|
186
214
|
const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
|
|
187
|
-
|
|
215
|
+
React.useEffect(() => {
|
|
216
|
+
if (thumb) {
|
|
217
|
+
context.thumbs.add(thumb);
|
|
218
|
+
return () => {
|
|
219
|
+
context.thumbs.delete(thumb);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}, [thumb, context.thumbs]);
|
|
188
223
|
return /* @__PURE__ */ React.createElement(SliderThumbFrame, {
|
|
189
|
-
ref:
|
|
224
|
+
ref: composedRefs,
|
|
225
|
+
role: "slider",
|
|
190
226
|
"aria-label": props["aria-label"] || label,
|
|
191
227
|
"aria-valuemin": context.min,
|
|
192
228
|
"aria-valuenow": value,
|
|
@@ -194,9 +230,17 @@ const SliderThumb = React.forwardRef((props, forwardedRef) => {
|
|
|
194
230
|
"aria-orientation": context.orientation,
|
|
195
231
|
"data-orientation": context.orientation,
|
|
196
232
|
"data-disabled": context.disabled ? "" : void 0,
|
|
233
|
+
tabIndex: context.disabled ? void 0 : 0,
|
|
197
234
|
...thumbProps,
|
|
198
|
-
|
|
199
|
-
|
|
235
|
+
...context.orientation === "horizontal" ? {
|
|
236
|
+
x: thumbInBoundsOffset - size / 2,
|
|
237
|
+
y: -size / 2,
|
|
238
|
+
top: "50%"
|
|
239
|
+
} : {
|
|
240
|
+
x: -size / 2,
|
|
241
|
+
y: size / 2,
|
|
242
|
+
left: "50%"
|
|
243
|
+
},
|
|
200
244
|
size: (_a = sizeProp != null ? sizeProp : context.size) != null ? _a : 30,
|
|
201
245
|
onLayout: (e) => {
|
|
202
246
|
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
@@ -234,14 +278,12 @@ const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
|
234
278
|
prop: value,
|
|
235
279
|
defaultProp: defaultValue,
|
|
236
280
|
onChange: (value2) => {
|
|
281
|
+
var _a;
|
|
282
|
+
const thumbs = [...thumbRefs.current];
|
|
283
|
+
(_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
|
|
237
284
|
onValueChange(value2);
|
|
238
285
|
}
|
|
239
286
|
});
|
|
240
|
-
function handleSlideStart(value2) {
|
|
241
|
-
const closestIndex = getClosestValueIndex(values, value2);
|
|
242
|
-
updateValues(value2, closestIndex);
|
|
243
|
-
}
|
|
244
|
-
__name(handleSlideStart, "handleSlideStart");
|
|
245
287
|
function handleSlideMove(value2) {
|
|
246
288
|
updateValues(value2, valueIndexToChangeRef.current);
|
|
247
289
|
}
|
|
@@ -279,7 +321,12 @@ const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
|
279
321
|
ref: forwardedRef,
|
|
280
322
|
min,
|
|
281
323
|
max,
|
|
282
|
-
onSlideStart: disabled ? void 0 :
|
|
324
|
+
onSlideStart: disabled ? void 0 : (value2, target) => {
|
|
325
|
+
if (target !== "thumb") {
|
|
326
|
+
const closestIndex = getClosestValueIndex(values, value2);
|
|
327
|
+
updateValues(value2, closestIndex);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
283
330
|
onSlideMove: disabled ? void 0 : handleSlideMove,
|
|
284
331
|
onHomeKeyDown: () => !disabled && updateValues(min, 0),
|
|
285
332
|
onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
|
|
@@ -301,28 +348,6 @@ const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
|
301
348
|
Thumb: SliderThumb
|
|
302
349
|
});
|
|
303
350
|
Slider.displayName = SLIDER_NAME;
|
|
304
|
-
const BubbleInput = /* @__PURE__ */ __name((props) => {
|
|
305
|
-
const { value, ...inputProps } = props;
|
|
306
|
-
const ref = React.useRef(null);
|
|
307
|
-
const prevValue = usePrevious(value);
|
|
308
|
-
React.useEffect(() => {
|
|
309
|
-
const input = ref.current;
|
|
310
|
-
const inputProto = window.HTMLInputElement.prototype;
|
|
311
|
-
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "value");
|
|
312
|
-
const setValue = descriptor.set;
|
|
313
|
-
if (prevValue !== value && setValue) {
|
|
314
|
-
const event = new Event("input", { bubbles: true });
|
|
315
|
-
setValue.call(input, value);
|
|
316
|
-
input.dispatchEvent(event);
|
|
317
|
-
}
|
|
318
|
-
}, [prevValue, value]);
|
|
319
|
-
return /* @__PURE__ */ React.createElement("input", {
|
|
320
|
-
style: { display: "none" },
|
|
321
|
-
...inputProps,
|
|
322
|
-
ref,
|
|
323
|
-
defaultValue: value
|
|
324
|
-
});
|
|
325
|
-
}, "BubbleInput");
|
|
326
351
|
const Track = SliderTrack;
|
|
327
352
|
const Range = SliderTrackActive;
|
|
328
353
|
const Thumb = SliderThumb;
|
package/dist/esm/Slider.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Slider.tsx"],
|
|
4
|
-
"sourcesContent": ["// forked from radix-ui\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { getVariantExtras, styled, withStaticProperties } from '@tamagui/core'\nimport { clamp, composeEventHandlers } from '@tamagui/helpers'\n// import { useSize } from '@tamagui/react-use-size'\nimport { SizableStack, SizableStackProps, YStackProps, getCircleSize } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { useDirection } from '@tamagui/use-direction'\nimport * as React from 'react'\nimport { LayoutRectangle, View } from 'react-native'\n\nimport {\n SLIDER_NAME,\n SliderOrientationProvider,\n SliderProvider,\n useSliderContext,\n useSliderOrientationContext,\n} from './context'\nimport {\n convertValueToPercentage,\n getClosestValueIndex,\n getDecimalCount,\n getLabel,\n getNextSortedValues,\n getSize,\n getThumbInBoundsOffset,\n hasMinStepsBetweenValues,\n linearScale,\n roundValue,\n} from './helpers'\nimport { SliderFrame, SliderImpl } from './SliderImpl'\nimport {\n Direction,\n ScopedProps,\n SliderContextValue,\n SliderHorizontalProps,\n SliderImplElement,\n SliderProps,\n SliderTrackProps,\n SliderVerticalProps,\n} from './types'\n\nconst PAGE_KEYS = ['PageUp', 'PageDown']\nconst ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']\nconst BACK_KEYS: Record<Direction, string[]> = {\n ltr: ['ArrowDown', 'Home', 'ArrowLeft', 'PageDown'],\n rtl: ['ArrowDown', 'Home', 'ArrowRight', 'PageDown'],\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SliderHorizontal\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderHorizontalElement = SliderImplElement\n\nconst SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizontalProps>(\n (props: ScopedProps<SliderHorizontalProps>, forwardedRef) => {\n const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const layoutRef = React.useRef<LayoutRectangle | null>(null)\n const direction = useDirection(dir)\n const isDirectionLTR = direction === 'ltr'\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.width]\n const output: [number, number] = isDirectionLTR ? [min, max] : [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition - layout.x)\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={size}\n >\n <SliderImpl\n dir={direction}\n orientation=\"horizontal\"\n {...sliderProps}\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\n }}\n ref={forwardedRef}\n onSlideStart={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageX)\n if (value) {\n onSlideStart?.(value)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageX)\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\ntype SliderVerticalElement = SliderImplElement\n\nconst SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalProps>(\n (props: ScopedProps<SliderVerticalProps>, forwardedRef) => {\n const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const sliderRef = React.useRef<SliderImplElement>(null)\n const ref = useComposedRefs(forwardedRef, sliderRef)\n const rectRef = React.useRef<ClientRect>()\n\n function getValueFromPointer(pointerPosition: number) {\n // @ts-ignore\n const rect = rectRef.current || sliderRef.current!.getBoundingClientRect()\n const input: [number, number] = [0, rect.height]\n const output: [number, number] = [max, min]\n const value = linearScale(input, output)\n rectRef.current = rect\n return value(pointerPosition - rect.top)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge=\"bottom\"\n endEdge=\"top\"\n sizeProp=\"height\"\n size={0}\n direction={1}\n >\n <SliderImpl\n {...sliderProps}\n orientation=\"vertical\"\n ref={ref}\n onSlideStart={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n onSlideStart?.(value)\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n onSlideMove?.(value)\n }}\n onSlideEnd={() => (rectRef.current = undefined)}\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\nconst SliderTrackFrame = styled(SliderFrame, {\n name: 'SliderTrackFrame',\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 {...trackProps}\n ref={forwardedRef}\n />\n )\n }\n)\n\nSliderTrack.displayName = TRACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrackActive\n * -----------------------------------------------------------------------------------------------*/\n\nconst RANGE_NAME = 'SliderTrackActive'\n\ntype SliderTrackActiveElement = HTMLElement | View\ninterface SliderTrackActiveProps extends YStackProps {}\n\nconst SliderTrackActiveFrame = styled(SliderFrame, {\n name: 'SliderTrackActive',\n})\n\nconst SliderTrackActive = React.forwardRef<SliderTrackActiveElement, 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<HTMLSpanElement>(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 {...rangeProps}\n ref={composedRefs}\n {...{\n [orientation.startEdge]: offsetStart + '%',\n [orientation.endEdge]: offsetEnd + '%',\n }}\n />\n )\n }\n)\n\nSliderTrackActive.displayName = RANGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SliderThumb'\n\nconst SliderThumbFrame = styled(SizableStack, {\n name: 'SliderThumb',\n position: 'absolute',\n})\n\ntype SliderThumbElement = HTMLElement | View\ninterface SliderThumbProps extends SizableStackProps {\n index: number\n}\n\nconst SliderThumb = React.forwardRef<SliderThumbElement, 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<HTMLSpanElement | 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(0)\n\n const thumbInBoundsOffset = size\n ? getThumbInBoundsOffset(size, percent, orientation.direction)\n : 0\n\n console.log('thumbInBoundsOffset', thumbInBoundsOffset, size, percent)\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={forwardedRef}\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 x={thumbInBoundsOffset}\n y={-size / 2}\n size={sizeProp ?? context.size ?? 30}\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\ntype SliderElement = SliderHorizontalElement | SliderVerticalElement\n\nconst Slider = withStaticProperties(\n React.forwardRef<SliderElement, 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 [slider, setSlider] = React.useState<HTMLElement | View | null>(null)\n // const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node))\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 // TODO\n // const isFormControl = slider ? Boolean(slider.closest('form')) : true\n\n const [values = [], setValues] = useControllableState({\n prop: value,\n defaultProp: defaultValue,\n onChange: (value) => {\n // const thumbs = [...thumbRefs.current]\n // thumbs[valueIndexToChangeRef.current]?.focus()\n onValueChange(value)\n },\n })\n\n function handleSlideStart(value: number) {\n const closestIndex = getClosestValueIndex(values, value)\n updateValues(value, closestIndex)\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 // @ts-ignore\n size={sizeProp || 20}\n >\n <SliderOriented\n aria-disabled={disabled}\n data-disabled={disabled ? '' : undefined}\n {...sliderProps}\n ref={forwardedRef}\n min={min}\n max={max}\n onSlideStart={disabled ? undefined : handleSlideStart}\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\nconst 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}\nexport type { SliderProps, SliderTrackProps, SliderTrackActiveProps, SliderThumbProps }\n"],
|
|
5
|
-
"mappings": ";;AAEA;AACA;AACA;AACA;
|
|
4
|
+
"sourcesContent": ["// forked from radix-ui\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { styled, withStaticProperties } from '@tamagui/core'\nimport { clamp, composeEventHandlers } from '@tamagui/helpers'\nimport { SizableStackProps, ThemeableSizableStack, YStackProps } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { useDirection } from '@tamagui/use-direction'\nimport * as React from 'react'\nimport { LayoutRectangle, 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 Direction,\n ScopedProps,\n SliderContextValue,\n SliderHorizontalProps,\n SliderImplElement,\n SliderProps,\n SliderTrackProps,\n SliderVerticalProps,\n} from './types'\n\n/* -------------------------------------------------------------------------------------------------\n * SliderHorizontal\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderHorizontalElement = SliderImplElement\n\nconst SliderHorizontal = React.forwardRef<SliderHorizontalElement, 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 layoutRef = React.useRef<LayoutRectangle | null>(null)\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.width]\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={size}\n >\n <SliderImpl\n ref={forwardedRef}\n dir={direction}\n {...sliderProps}\n orientation=\"horizontal\"\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\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.locationX)\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\ntype SliderVerticalElement = SliderImplElement\n\nconst SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalProps>(\n (props: ScopedProps<SliderVerticalProps>, forwardedRef) => {\n const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const layoutRef = React.useRef<LayoutRectangle | null>(null)\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.height]\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={size}\n direction={1}\n >\n <SliderImpl\n ref={forwardedRef}\n {...sliderProps}\n orientation=\"vertical\"\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\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.locationY)\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\nconst SliderTrackFrame = styled(SliderFrame, {\n name: 'SliderTrack',\n height: '100%',\n width: '100%',\n backgroundColor: '$background',\n position: 'relative',\n borderRadius: 100_000,\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\ntype SliderTrackActiveElement = HTMLElement | View\ninterface SliderTrackActiveProps extends YStackProps {}\n\nconst SliderTrackActiveFrame = styled(SliderFrame, {\n name: 'SliderTrackActive',\n backgroundColor: '$background',\n position: 'absolute',\n})\n\nconst SliderTrackActive = React.forwardRef<SliderTrackActiveElement, 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<HTMLSpanElement>(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\nconst SliderThumbFrame = styled(ThemeableSizableStack, {\n name: 'SliderThumb',\n position: 'absolute',\n // TODO not taking up 2\n bordered: 2,\n // OR THIS\n borderWidth: 2,\n pressable: true,\n focusable: true,\n hoverable: true,\n})\n\ntype SliderThumbElement = HTMLElement | View\ninterface SliderThumbProps extends SizableStackProps {\n index: number\n}\n\nconst SliderThumb = React.forwardRef<SliderThumbElement, 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(0)\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 // TODO\n // @ts-ignore\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 }\n : {\n x: -size / 2,\n y: size / 2,\n left: '50%',\n })}\n size={sizeProp ?? context.size ?? 30}\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\ntype SliderElement = SliderHorizontalElement | SliderVerticalElement\n\nconst Slider = withStaticProperties(\n React.forwardRef<SliderElement, 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 [slider, setSlider] = React.useState<HTMLElement | View | null>(null)\n // const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node))\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 // TODO\n // const isFormControl = slider ? Boolean(slider.closest('form')) : true\n\n const [values = [], setValues] = useControllableState({\n prop: value,\n defaultProp: defaultValue,\n onChange: (value) => {\n const thumbs = [...thumbRefs.current]\n thumbs[valueIndexToChangeRef.current]?.focus()\n onValueChange(value)\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 || 20}\n >\n <SliderOriented\n aria-disabled={disabled}\n data-disabled={disabled ? '' : undefined}\n {...sliderProps}\n ref={forwardedRef}\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}\nexport type { SliderProps, SliderTrackProps, SliderTrackActiveProps, SliderThumbProps }\n"],
|
|
5
|
+
"mappings": ";;AAEA;AACA;AACA;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;AAkBA,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,OAA+B,IAAI;AAC3D,QAAM,CAAC,MAAM,WAAW,MAAM,SAAS,CAAC;AAExC,+BAA6B,iBAAyB;AACpD,UAAM,SAAS,UAAU;AACzB,QAAI,CAAC;AAAQ;AACb,UAAM,QAA0B,CAAC,GAAG,OAAO,KAAK;AAChD,UAAM,SAA2B,iBA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E,eAAe,CAAC,EAAE,OAAO,WAAW,oBAAoB;AACtD,UAAI,CAAC,UAAU;AACb,cAAM,YAAY,UAAU,SAAS,MAAM,GAAG;AAC9C,cAAM,YAAY,aAAc,MAAM,YAAY,WAAW,SAAS,MAAM,GAAG;AAC/E,cAAM,aAAa,YAAY,KAAK;AACpC,cAAM,UAAU,sBAAsB;AACtC,cAAM,SAAQ,OAAO;AACrB,cAAM,kBAAkB,OAAO,aAAa;AAC5C,qBAAa,SAAQ,iBAAiB,OAAO;AAAA,MAC/C;AAAA,IACF;AAAA,GACF,CASF;AAEJ,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
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/SliderImpl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { composeEventHandlers, styled } from "@tamagui/core";
|
|
1
|
+
import { composeEventHandlers, isWeb, styled } from "@tamagui/core";
|
|
2
2
|
import { YStack, getCircleSize } from "@tamagui/stacks";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import { SLIDER_NAME, useSliderContext } from "./
|
|
4
|
+
import { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from "./constants";
|
|
5
5
|
const DirectionalYStack = styled(YStack, {
|
|
6
6
|
variants: {
|
|
7
7
|
orientation: {
|
|
@@ -11,22 +11,21 @@ const DirectionalYStack = styled(YStack, {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
const SliderFrame = styled(DirectionalYStack, {
|
|
14
|
-
name: "Slider",
|
|
15
14
|
position: "relative",
|
|
16
15
|
variants: {
|
|
17
16
|
size: (val, extras) => {
|
|
18
17
|
const orientation = extras.props.orientation;
|
|
19
18
|
const circleSize = getCircleSize(val, extras);
|
|
20
|
-
const size = circleSize /
|
|
19
|
+
const size = circleSize / 10;
|
|
21
20
|
if (orientation === "horizontal") {
|
|
22
21
|
return {
|
|
23
22
|
height: size,
|
|
24
|
-
|
|
23
|
+
borderRadius: size
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
return {
|
|
28
27
|
width: size,
|
|
29
|
-
|
|
28
|
+
borderRadius: size
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -48,10 +47,31 @@ const SliderImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
48
47
|
...sliderProps,
|
|
49
48
|
"data-orientation": sliderProps.orientation,
|
|
50
49
|
ref: forwardedRef,
|
|
50
|
+
...isWeb && {
|
|
51
|
+
onKeyDown: (event) => {
|
|
52
|
+
if (event.key === "Home") {
|
|
53
|
+
onHomeKeyDown(event);
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
} else if (event.key === "End") {
|
|
56
|
+
onEndKeyDown(event);
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
} else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {
|
|
59
|
+
onStepKeyDown(event);
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
51
64
|
onStartShouldSetResponder: () => true,
|
|
52
65
|
onResponderGrant: composeEventHandlers(props.onResponderGrant, (event) => {
|
|
66
|
+
const target = event.target;
|
|
67
|
+
const isStartingOnThumb = context.thumbs.has(event.target);
|
|
53
68
|
event.preventDefault();
|
|
54
|
-
|
|
69
|
+
if (target instanceof HTMLElement) {
|
|
70
|
+
if (context.thumbs.has(target)) {
|
|
71
|
+
target.focus();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
onSlideStart(event, isStartingOnThumb ? "thumb" : "track");
|
|
55
75
|
}),
|
|
56
76
|
onResponderMove: composeEventHandlers(props.onResponderMove, (event) => {
|
|
57
77
|
onSlideMove(event);
|