@tamagui/slider 1.0.1-beta.26
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 +390 -0
- package/dist/cjs/Slider.js.map +7 -0
- package/dist/cjs/SliderImpl.js +133 -0
- package/dist/cjs/SliderImpl.js.map +7 -0
- package/dist/cjs/context.js +50 -0
- package/dist/cjs/context.js.map +7 -0
- package/dist/cjs/helpers.js +120 -0
- package/dist/cjs/helpers.js.map +7 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/Slider.js +338 -0
- package/dist/esm/Slider.js.map +7 -0
- package/dist/esm/SliderImpl.js +69 -0
- package/dist/esm/SliderImpl.js.map +7 -0
- package/dist/esm/context.js +21 -0
- package/dist/esm/context.js.map +7 -0
- package/dist/esm/helpers.js +89 -0
- package/dist/esm/helpers.js.map +7 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/jsx/Slider.js +248 -0
- package/dist/jsx/SliderImpl.js +59 -0
- package/dist/jsx/context.js +20 -0
- package/dist/jsx/helpers.js +88 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +44 -0
- package/types/Slider.d.ts +29 -0
- package/types/Slider.d.ts.map +1 -0
- package/types/SliderImpl.d.ts +54 -0
- package/types/SliderImpl.d.ts.map +1 -0
- package/types/context.d.ts +50 -0
- package/types/context.d.ts.map +1 -0
- package/types/helpers.d.ts +12 -0
- package/types/helpers.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
- package/types/types.d.ts +70 -0
- package/types/types.d.ts.map +1 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var helpers_exports = {};
|
|
20
|
+
__export(helpers_exports, {
|
|
21
|
+
convertValueToPercentage: () => convertValueToPercentage,
|
|
22
|
+
getClosestValueIndex: () => getClosestValueIndex,
|
|
23
|
+
getDecimalCount: () => getDecimalCount,
|
|
24
|
+
getLabel: () => getLabel,
|
|
25
|
+
getNextSortedValues: () => getNextSortedValues,
|
|
26
|
+
getSize: () => getSize,
|
|
27
|
+
getThumbInBoundsOffset: () => getThumbInBoundsOffset,
|
|
28
|
+
hasMinStepsBetweenValues: () => hasMinStepsBetweenValues,
|
|
29
|
+
linearScale: () => linearScale,
|
|
30
|
+
roundValue: () => roundValue
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
33
|
+
var import_core = require("@tamagui/core");
|
|
34
|
+
function getNextSortedValues(prevValues = [], nextValue, atIndex) {
|
|
35
|
+
const nextValues = [...prevValues];
|
|
36
|
+
nextValues[atIndex] = nextValue;
|
|
37
|
+
return nextValues.sort((a, b) => a - b);
|
|
38
|
+
}
|
|
39
|
+
__name(getNextSortedValues, "getNextSortedValues");
|
|
40
|
+
function convertValueToPercentage(value, min, max) {
|
|
41
|
+
const maxSteps = max - min;
|
|
42
|
+
const percentPerStep = 100 / maxSteps;
|
|
43
|
+
return percentPerStep * (value - min);
|
|
44
|
+
}
|
|
45
|
+
__name(convertValueToPercentage, "convertValueToPercentage");
|
|
46
|
+
function getLabel(index, totalValues) {
|
|
47
|
+
if (totalValues > 2) {
|
|
48
|
+
return `Value ${index + 1} of ${totalValues}`;
|
|
49
|
+
} else if (totalValues === 2) {
|
|
50
|
+
return ["Minimum", "Maximum"][index];
|
|
51
|
+
} else {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
__name(getLabel, "getLabel");
|
|
56
|
+
function getClosestValueIndex(values, nextValue) {
|
|
57
|
+
if (values.length === 1)
|
|
58
|
+
return 0;
|
|
59
|
+
const distances = values.map((value) => Math.abs(value - nextValue));
|
|
60
|
+
const closestDistance = Math.min(...distances);
|
|
61
|
+
return distances.indexOf(closestDistance);
|
|
62
|
+
}
|
|
63
|
+
__name(getClosestValueIndex, "getClosestValueIndex");
|
|
64
|
+
function getThumbInBoundsOffset(width, left, direction) {
|
|
65
|
+
const halfWidth = width / 2;
|
|
66
|
+
const halfPercent = 50;
|
|
67
|
+
const offset = linearScale([0, halfPercent], [0, halfWidth]);
|
|
68
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
69
|
+
}
|
|
70
|
+
__name(getThumbInBoundsOffset, "getThumbInBoundsOffset");
|
|
71
|
+
function getStepsBetweenValues(values) {
|
|
72
|
+
return values.slice(0, -1).map((value, index) => values[index + 1] - value);
|
|
73
|
+
}
|
|
74
|
+
__name(getStepsBetweenValues, "getStepsBetweenValues");
|
|
75
|
+
function hasMinStepsBetweenValues(values, minStepsBetweenValues) {
|
|
76
|
+
if (minStepsBetweenValues > 0) {
|
|
77
|
+
const stepsBetweenValues = getStepsBetweenValues(values);
|
|
78
|
+
const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
|
|
79
|
+
return actualMinStepsBetweenValues >= minStepsBetweenValues;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
__name(hasMinStepsBetweenValues, "hasMinStepsBetweenValues");
|
|
84
|
+
function linearScale(input, output) {
|
|
85
|
+
return (value) => {
|
|
86
|
+
if (input[0] === input[1] || output[0] === output[1])
|
|
87
|
+
return output[0];
|
|
88
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
89
|
+
return output[0] + ratio * (value - input[0]);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
__name(linearScale, "linearScale");
|
|
93
|
+
function getDecimalCount(value) {
|
|
94
|
+
return (String(value).split(".")[1] || "").length;
|
|
95
|
+
}
|
|
96
|
+
__name(getDecimalCount, "getDecimalCount");
|
|
97
|
+
function roundValue(value, decimalCount) {
|
|
98
|
+
const rounder = Math.pow(10, decimalCount);
|
|
99
|
+
return Math.round(value * rounder) / rounder;
|
|
100
|
+
}
|
|
101
|
+
__name(roundValue, "roundValue");
|
|
102
|
+
function getSize(size) {
|
|
103
|
+
const tokens = (0, import_core.getTokens)();
|
|
104
|
+
return typeof size === "number" ? size : size ? (0, import_core.getVariableValue)(tokens.size[size]) : null;
|
|
105
|
+
}
|
|
106
|
+
__name(getSize, "getSize");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
convertValueToPercentage,
|
|
110
|
+
getClosestValueIndex,
|
|
111
|
+
getDecimalCount,
|
|
112
|
+
getLabel,
|
|
113
|
+
getNextSortedValues,
|
|
114
|
+
getSize,
|
|
115
|
+
getThumbInBoundsOffset,
|
|
116
|
+
hasMinStepsBetweenValues,
|
|
117
|
+
linearScale,
|
|
118
|
+
roundValue
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers.tsx"],
|
|
4
|
+
"sourcesContent": ["import { SizeTokens, getTokens, getVariableValue } from '@tamagui/core'\n\nexport 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\nexport function getSize(size?: SizeTokens) {\n const tokens = getTokens()\n return typeof size === 'number'\n ? size\n : size\n ? (getVariableValue(tokens.size[size]) as number)\n : null\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwD;AAEjD,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;AAJgB;AAMT,kCAAkC,OAAe,KAAa,KAAa;AAChF,QAAM,WAAW,MAAM;AACvB,QAAM,iBAAiB,MAAM;AAC7B,SAAO,iBAAkB,SAAQ;AACnC;AAJgB;AAST,kBAAkB,OAAe,aAAqB;AAC3D,MAAI,cAAc,GAAG;AACnB,WAAO,SAAS,QAAQ,QAAQ;AAAA,EAClC,WAAW,gBAAgB,GAAG;AAC5B,WAAO,CAAC,WAAW,SAAS,E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I,YAAY;AACzC,SAAO,KAAK,MAAM,QAAQ,OAAO,IAAI;AACvC;AAHgB;AAKT,iBAAiB,MAAmB;AACzC,QAAM,SAAS,2BAAU;AACzB,SAAO,OAAO,SAAS,WACnB,OACA,OACC,kCAAiB,OAAO,KAAK,KAAK,IACnC;AACN;AAPgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./Slider"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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, YStackProps } 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): 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): 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?: 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
|
+
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { usePrevious } from "@radix-ui/react-use-previous";
|
|
4
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
5
|
+
import { styled, withStaticProperties } from "@tamagui/core";
|
|
6
|
+
import { clamp, composeEventHandlers } from "@tamagui/helpers";
|
|
7
|
+
import { SizableStack } from "@tamagui/stacks";
|
|
8
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
9
|
+
import { useDirection } from "@tamagui/use-direction";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import {
|
|
12
|
+
SLIDER_NAME,
|
|
13
|
+
SliderOrientationProvider,
|
|
14
|
+
SliderProvider,
|
|
15
|
+
useSliderContext,
|
|
16
|
+
useSliderOrientationContext
|
|
17
|
+
} from "./context";
|
|
18
|
+
import {
|
|
19
|
+
convertValueToPercentage,
|
|
20
|
+
getClosestValueIndex,
|
|
21
|
+
getDecimalCount,
|
|
22
|
+
getLabel,
|
|
23
|
+
getNextSortedValues,
|
|
24
|
+
getThumbInBoundsOffset,
|
|
25
|
+
hasMinStepsBetweenValues,
|
|
26
|
+
linearScale,
|
|
27
|
+
roundValue
|
|
28
|
+
} from "./helpers";
|
|
29
|
+
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
|
+
const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
37
|
+
const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
38
|
+
const layoutRef = React.useRef(null);
|
|
39
|
+
const direction = useDirection(dir);
|
|
40
|
+
const isDirectionLTR = direction === "ltr";
|
|
41
|
+
const [size, setSize] = React.useState(0);
|
|
42
|
+
function getValueFromPointer(pointerPosition) {
|
|
43
|
+
const layout = layoutRef.current;
|
|
44
|
+
if (!layout)
|
|
45
|
+
return;
|
|
46
|
+
const input = [0, layout.width];
|
|
47
|
+
const output = isDirectionLTR ? [min, max] : [max, min];
|
|
48
|
+
const value = linearScale(input, output);
|
|
49
|
+
return value(pointerPosition - layout.x);
|
|
50
|
+
}
|
|
51
|
+
__name(getValueFromPointer, "getValueFromPointer");
|
|
52
|
+
return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
|
|
53
|
+
scope: props.__scopeSlider,
|
|
54
|
+
startEdge: isDirectionLTR ? "left" : "right",
|
|
55
|
+
endEdge: isDirectionLTR ? "right" : "left",
|
|
56
|
+
direction: isDirectionLTR ? 1 : -1,
|
|
57
|
+
sizeProp: "width",
|
|
58
|
+
size
|
|
59
|
+
}, /* @__PURE__ */ React.createElement(SliderImpl, {
|
|
60
|
+
dir: direction,
|
|
61
|
+
orientation: "horizontal",
|
|
62
|
+
...sliderProps,
|
|
63
|
+
onLayout: (e) => {
|
|
64
|
+
const layout = e.nativeEvent.layout;
|
|
65
|
+
layoutRef.current = layout;
|
|
66
|
+
setSize(layout.height);
|
|
67
|
+
},
|
|
68
|
+
ref: forwardedRef,
|
|
69
|
+
onSlideStart: (event) => {
|
|
70
|
+
const value = getValueFromPointer(event.nativeEvent.pageX);
|
|
71
|
+
if (value) {
|
|
72
|
+
onSlideStart == null ? void 0 : onSlideStart(value);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
onSlideMove: (event) => {
|
|
76
|
+
const value = getValueFromPointer(event.nativeEvent.pageX);
|
|
77
|
+
if (value) {
|
|
78
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
onSlideEnd: () => {
|
|
82
|
+
},
|
|
83
|
+
onStepKeyDown: (event) => {
|
|
84
|
+
const isBackKey = BACK_KEYS[direction].includes(event.key);
|
|
85
|
+
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
});
|
|
89
|
+
const SliderVertical = React.forwardRef((props, forwardedRef) => {
|
|
90
|
+
const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
91
|
+
const sliderRef = React.useRef(null);
|
|
92
|
+
const ref = useComposedRefs(forwardedRef, sliderRef);
|
|
93
|
+
const rectRef = React.useRef();
|
|
94
|
+
function getValueFromPointer(pointerPosition) {
|
|
95
|
+
const rect = rectRef.current || sliderRef.current.getBoundingClientRect();
|
|
96
|
+
const input = [0, rect.height];
|
|
97
|
+
const output = [max, min];
|
|
98
|
+
const value = linearScale(input, output);
|
|
99
|
+
rectRef.current = rect;
|
|
100
|
+
return value(pointerPosition - rect.top);
|
|
101
|
+
}
|
|
102
|
+
__name(getValueFromPointer, "getValueFromPointer");
|
|
103
|
+
return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
|
|
104
|
+
scope: props.__scopeSlider,
|
|
105
|
+
startEdge: "bottom",
|
|
106
|
+
endEdge: "top",
|
|
107
|
+
sizeProp: "height",
|
|
108
|
+
size: 0,
|
|
109
|
+
direction: 1
|
|
110
|
+
}, /* @__PURE__ */ React.createElement(SliderImpl, {
|
|
111
|
+
...sliderProps,
|
|
112
|
+
orientation: "vertical",
|
|
113
|
+
ref,
|
|
114
|
+
onSlideStart: (event) => {
|
|
115
|
+
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
116
|
+
onSlideStart == null ? void 0 : onSlideStart(value);
|
|
117
|
+
},
|
|
118
|
+
onSlideMove: (event) => {
|
|
119
|
+
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
120
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
121
|
+
},
|
|
122
|
+
onSlideEnd: () => rectRef.current = void 0,
|
|
123
|
+
onStepKeyDown: (event) => {
|
|
124
|
+
const isBackKey = BACK_KEYS.ltr.includes(event.key);
|
|
125
|
+
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
const TRACK_NAME = "SliderTrack";
|
|
130
|
+
const SliderTrackFrame = styled(SliderFrame, {
|
|
131
|
+
name: "SliderTrackFrame"
|
|
132
|
+
});
|
|
133
|
+
const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
134
|
+
const { __scopeSlider, ...trackProps } = props;
|
|
135
|
+
const context = useSliderContext(TRACK_NAME, __scopeSlider);
|
|
136
|
+
return /* @__PURE__ */ React.createElement(SliderTrackFrame, {
|
|
137
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
138
|
+
"data-orientation": context.orientation,
|
|
139
|
+
orientation: context.orientation,
|
|
140
|
+
...trackProps,
|
|
141
|
+
ref: forwardedRef
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
SliderTrack.displayName = TRACK_NAME;
|
|
145
|
+
const RANGE_NAME = "SliderTrackActive";
|
|
146
|
+
const SliderTrackActiveFrame = styled(SliderFrame, {
|
|
147
|
+
name: "SliderTrackActive"
|
|
148
|
+
});
|
|
149
|
+
const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
|
|
150
|
+
const { __scopeSlider, ...rangeProps } = props;
|
|
151
|
+
const context = useSliderContext(RANGE_NAME, __scopeSlider);
|
|
152
|
+
const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider);
|
|
153
|
+
const ref = React.useRef(null);
|
|
154
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
155
|
+
const valuesCount = context.values.length;
|
|
156
|
+
const percentages = context.values.map((value) => convertValueToPercentage(value, context.min, context.max));
|
|
157
|
+
const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
|
|
158
|
+
const offsetEnd = 100 - Math.max(...percentages);
|
|
159
|
+
return /* @__PURE__ */ React.createElement(SliderTrackActiveFrame, {
|
|
160
|
+
orientation: context.orientation,
|
|
161
|
+
"data-orientation": context.orientation,
|
|
162
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
163
|
+
...rangeProps,
|
|
164
|
+
ref: composedRefs,
|
|
165
|
+
...{
|
|
166
|
+
[orientation.startEdge]: offsetStart + "%",
|
|
167
|
+
[orientation.endEdge]: offsetEnd + "%"
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
SliderTrackActive.displayName = RANGE_NAME;
|
|
172
|
+
const THUMB_NAME = "SliderThumb";
|
|
173
|
+
const SliderThumbFrame = styled(SizableStack, {
|
|
174
|
+
name: "SliderThumb",
|
|
175
|
+
position: "absolute"
|
|
176
|
+
});
|
|
177
|
+
const SliderThumb = React.forwardRef((props, forwardedRef) => {
|
|
178
|
+
var _a;
|
|
179
|
+
const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
|
|
180
|
+
const context = useSliderContext(THUMB_NAME, __scopeSlider);
|
|
181
|
+
const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
|
|
182
|
+
const value = context.values[index];
|
|
183
|
+
const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
|
|
184
|
+
const label = getLabel(index, context.values.length);
|
|
185
|
+
const [size, setSize] = React.useState(0);
|
|
186
|
+
const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
|
|
187
|
+
console.log("thumbInBoundsOffset", thumbInBoundsOffset, size, percent);
|
|
188
|
+
return /* @__PURE__ */ React.createElement(SliderThumbFrame, {
|
|
189
|
+
ref: forwardedRef,
|
|
190
|
+
"aria-label": props["aria-label"] || label,
|
|
191
|
+
"aria-valuemin": context.min,
|
|
192
|
+
"aria-valuenow": value,
|
|
193
|
+
"aria-valuemax": context.max,
|
|
194
|
+
"aria-orientation": context.orientation,
|
|
195
|
+
"data-orientation": context.orientation,
|
|
196
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
197
|
+
...thumbProps,
|
|
198
|
+
x: thumbInBoundsOffset,
|
|
199
|
+
y: -size / 2,
|
|
200
|
+
size: (_a = sizeProp != null ? sizeProp : context.size) != null ? _a : 30,
|
|
201
|
+
onLayout: (e) => {
|
|
202
|
+
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
203
|
+
},
|
|
204
|
+
...{
|
|
205
|
+
[orientation.startEdge]: `${percent}%`
|
|
206
|
+
},
|
|
207
|
+
style: value === void 0 ? { display: "none" } : props.style,
|
|
208
|
+
onFocus: composeEventHandlers(props.onFocus, () => {
|
|
209
|
+
context.valueIndexToChangeRef.current = index;
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
SliderThumb.displayName = THUMB_NAME;
|
|
214
|
+
const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
215
|
+
const {
|
|
216
|
+
name,
|
|
217
|
+
min = 0,
|
|
218
|
+
max = 100,
|
|
219
|
+
step = 1,
|
|
220
|
+
orientation = "horizontal",
|
|
221
|
+
disabled = false,
|
|
222
|
+
minStepsBetweenThumbs = 0,
|
|
223
|
+
defaultValue = [min],
|
|
224
|
+
value,
|
|
225
|
+
onValueChange = /* @__PURE__ */ __name(() => {
|
|
226
|
+
}, "onValueChange"),
|
|
227
|
+
size: sizeProp,
|
|
228
|
+
...sliderProps
|
|
229
|
+
} = props;
|
|
230
|
+
const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
|
|
231
|
+
const valueIndexToChangeRef = React.useRef(0);
|
|
232
|
+
const isHorizontal = orientation === "horizontal";
|
|
233
|
+
const [values = [], setValues] = useControllableState({
|
|
234
|
+
prop: value,
|
|
235
|
+
defaultProp: defaultValue,
|
|
236
|
+
onChange: (value2) => {
|
|
237
|
+
onValueChange(value2);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
function handleSlideStart(value2) {
|
|
241
|
+
const closestIndex = getClosestValueIndex(values, value2);
|
|
242
|
+
updateValues(value2, closestIndex);
|
|
243
|
+
}
|
|
244
|
+
__name(handleSlideStart, "handleSlideStart");
|
|
245
|
+
function handleSlideMove(value2) {
|
|
246
|
+
updateValues(value2, valueIndexToChangeRef.current);
|
|
247
|
+
}
|
|
248
|
+
__name(handleSlideMove, "handleSlideMove");
|
|
249
|
+
function updateValues(value2, atIndex) {
|
|
250
|
+
const decimalCount = getDecimalCount(step);
|
|
251
|
+
const snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount);
|
|
252
|
+
const nextValue = clamp(snapToStep, [min, max]);
|
|
253
|
+
setValues((prevValues = []) => {
|
|
254
|
+
const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
|
|
255
|
+
if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
|
|
256
|
+
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
|
|
257
|
+
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
|
|
258
|
+
} else {
|
|
259
|
+
return prevValues;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
__name(updateValues, "updateValues");
|
|
264
|
+
const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
|
|
265
|
+
return /* @__PURE__ */ React.createElement(SliderProvider, {
|
|
266
|
+
scope: props.__scopeSlider,
|
|
267
|
+
disabled,
|
|
268
|
+
min,
|
|
269
|
+
max,
|
|
270
|
+
valueIndexToChangeRef,
|
|
271
|
+
thumbs: thumbRefs.current,
|
|
272
|
+
values,
|
|
273
|
+
orientation,
|
|
274
|
+
size: sizeProp || 20
|
|
275
|
+
}, /* @__PURE__ */ React.createElement(SliderOriented, {
|
|
276
|
+
"aria-disabled": disabled,
|
|
277
|
+
"data-disabled": disabled ? "" : void 0,
|
|
278
|
+
...sliderProps,
|
|
279
|
+
ref: forwardedRef,
|
|
280
|
+
min,
|
|
281
|
+
max,
|
|
282
|
+
onSlideStart: disabled ? void 0 : handleSlideStart,
|
|
283
|
+
onSlideMove: disabled ? void 0 : handleSlideMove,
|
|
284
|
+
onHomeKeyDown: () => !disabled && updateValues(min, 0),
|
|
285
|
+
onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
|
|
286
|
+
onStepKeyDown: ({ event, direction: stepDirection }) => {
|
|
287
|
+
if (!disabled) {
|
|
288
|
+
const isPageKey = PAGE_KEYS.includes(event.key);
|
|
289
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
|
|
290
|
+
const multiplier = isSkipKey ? 10 : 1;
|
|
291
|
+
const atIndex = valueIndexToChangeRef.current;
|
|
292
|
+
const value2 = values[atIndex];
|
|
293
|
+
const stepInDirection = step * multiplier * stepDirection;
|
|
294
|
+
updateValues(value2 + stepInDirection, atIndex);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}));
|
|
298
|
+
}), {
|
|
299
|
+
Track: SliderTrack,
|
|
300
|
+
TrackActive: SliderTrackActive,
|
|
301
|
+
Thumb: SliderThumb
|
|
302
|
+
});
|
|
303
|
+
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
|
+
const Track = SliderTrack;
|
|
327
|
+
const Range = SliderTrackActive;
|
|
328
|
+
const Thumb = SliderThumb;
|
|
329
|
+
export {
|
|
330
|
+
Range,
|
|
331
|
+
Slider,
|
|
332
|
+
SliderThumb,
|
|
333
|
+
SliderTrack,
|
|
334
|
+
SliderTrackActive,
|
|
335
|
+
Thumb,
|
|
336
|
+
Track
|
|
337
|
+
};
|
|
338
|
+
//# 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 { 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, Slider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a;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;AAKrB,MAAM,cAAc,wBAAC,UAAe;AAClC,QAAM,EAAE,UAAU,eAAe;AACjC,QAAM,MAAM,MAAM,OAAyB,IAAI;AAC/C,QAAM,YAAY,YAAY,KAAK;AAGnC,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI;AAClB,UAAM,aAAa,OAAO,iBAAiB;AAC3C,UAAM,aAAa,OAAO,yBAAyB,YAAY,OAAO;AACtE,UAAM,WAAW,WAAW;AAC5B,QAAI,cAAc,SAAS,UAAU;AACnC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC;AAClD,eAAS,KAAK,OAAO,KAAK;AAC1B,YAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAWrB,SAAO,oCAAC;AAAA,IAAM,OAAO,EAAE,SAAS,OAAO;AAAA,OAAO;AAAA,IAAY;AAAA,IAAU,cAAc;AAAA,GAAO;AAC3F,GA5BoB;AAgCpB,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { composeEventHandlers, styled } from "@tamagui/core";
|
|
2
|
+
import { YStack, getCircleSize } from "@tamagui/stacks";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { SLIDER_NAME, useSliderContext } from "./context";
|
|
5
|
+
const DirectionalYStack = styled(YStack, {
|
|
6
|
+
variants: {
|
|
7
|
+
orientation: {
|
|
8
|
+
horizontal: {},
|
|
9
|
+
vertical: {}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const SliderFrame = styled(DirectionalYStack, {
|
|
14
|
+
name: "Slider",
|
|
15
|
+
position: "relative",
|
|
16
|
+
variants: {
|
|
17
|
+
size: (val, extras) => {
|
|
18
|
+
const orientation = extras.props.orientation;
|
|
19
|
+
const circleSize = getCircleSize(val, extras);
|
|
20
|
+
const size = circleSize / 4;
|
|
21
|
+
if (orientation === "horizontal") {
|
|
22
|
+
return {
|
|
23
|
+
height: size,
|
|
24
|
+
width: 100
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
width: size,
|
|
29
|
+
height: 100
|
|
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 /* @__PURE__ */ React.createElement(SliderFrame, {
|
|
47
|
+
size: "$4",
|
|
48
|
+
...sliderProps,
|
|
49
|
+
"data-orientation": sliderProps.orientation,
|
|
50
|
+
ref: forwardedRef,
|
|
51
|
+
onStartShouldSetResponder: () => true,
|
|
52
|
+
onResponderGrant: composeEventHandlers(props.onResponderGrant, (event) => {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
onSlideStart(event);
|
|
55
|
+
}),
|
|
56
|
+
onResponderMove: composeEventHandlers(props.onResponderMove, (event) => {
|
|
57
|
+
onSlideMove(event);
|
|
58
|
+
}),
|
|
59
|
+
onResponderRelease: composeEventHandlers(props.onResponderRelease, (event) => {
|
|
60
|
+
onSlideEnd(event);
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
export {
|
|
65
|
+
DirectionalYStack,
|
|
66
|
+
SliderFrame,
|
|
67
|
+
SliderImpl
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=SliderImpl.js.map
|