@choice-ui/react 1.8.7 → 1.8.9
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/components/button/dist/index.js +7 -0
- package/dist/components/checkbox/dist/index.d.ts +10 -1
- package/dist/components/checkbox/dist/index.js +49 -5
- package/dist/components/checkbox/src/checkbox-icon.d.ts +8 -0
- package/dist/components/checkbox/src/checkbox-icon.js +41 -0
- package/dist/components/checkbox/src/checkbox.d.ts +2 -0
- package/dist/components/checkbox/src/checkbox.js +18 -5
- package/dist/components/checkbox/src/index.d.ts +2 -0
- package/dist/components/colors/src/color-image-paint/color-image-paint.js +3 -3
- package/dist/components/dropdown/dist/index.d.ts +6 -0
- package/dist/components/dropdown/dist/index.js +12 -8
- package/dist/components/emoji-picker/dist/index.d.ts +29 -1
- package/dist/components/emoji-picker/dist/index.js +144 -42
- package/dist/components/form/src/adapters/range-adapter.js +2 -2
- package/dist/components/icon-button/dist/index.d.ts +1 -1
- package/dist/components/icon-button/dist/index.js +39 -0
- package/dist/components/menus/dist/index.d.ts +5 -0
- package/dist/components/menus/dist/index.js +18 -1
- package/dist/components/radio/dist/index.d.ts +9 -1
- package/dist/components/radio/dist/index.js +50 -6
- package/dist/components/radio/src/context.d.ts +2 -0
- package/dist/components/radio/src/index.d.ts +2 -0
- package/dist/components/radio/src/radio-icon.d.ts +7 -0
- package/dist/components/radio/src/radio-icon.js +41 -0
- package/dist/components/radio/src/radio.d.ts +2 -0
- package/dist/components/radio/src/radio.js +19 -6
- package/dist/components/range/dist/index.d.ts +276 -20
- package/dist/components/range/dist/index.js +1030 -602
- package/dist/components/range/src/components/connects.d.ts +26 -0
- package/dist/components/range/src/components/connects.js +192 -0
- package/dist/components/range/src/components/dot.d.ts +8 -0
- package/dist/components/range/src/components/dot.js +148 -0
- package/dist/components/range/src/components/thumb.d.ts +14 -0
- package/dist/components/range/src/components/thumb.js +159 -0
- package/dist/components/range/src/context/index.d.ts +4 -0
- package/dist/components/range/src/context/range-context.d.ts +35 -0
- package/dist/components/range/src/context/range-context.js +13 -0
- package/dist/components/range/src/context/range-tuple-context.d.ts +42 -0
- package/dist/components/range/src/context/range-tuple-context.js +15 -0
- package/dist/components/range/src/index.d.ts +4 -2
- package/dist/components/range/src/range-tuple.d.ts +17 -9
- package/dist/components/range/src/range-tuple.js +375 -441
- package/dist/components/range/src/range.d.ts +17 -9
- package/dist/components/range/src/range.js +164 -154
- package/dist/components/range/src/tv.d.ts +15 -3
- package/dist/components/range/src/tv.js +10 -7
- package/dist/components/textarea/dist/index.js +3 -1
- package/dist/components/tooltip/dist/index.d.ts +2 -0
- package/dist/components/tooltip/dist/index.js +23 -5
- package/dist/components/virtual-select/dist/index.d.ts +48 -0
- package/dist/index.js +6 -0
- package/package.json +20 -32
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface RangeConnectsProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const RangeConnects: import('react').ForwardRefExoticComponent<RangeConnectsProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export interface RangeContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
height?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function RangeContainer(props: RangeContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare namespace RangeContainer {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RangeTupleConnectsProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const RangeTupleConnects: import('react').ForwardRefExoticComponent<RangeTupleConnectsProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
18
|
+
export interface RangeTupleContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
height?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function RangeTupleContainer(props: RangeTupleContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export declare namespace RangeTupleContainer {
|
|
25
|
+
var displayName: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { useRangeContext } from "../context/range-context.js";
|
|
4
|
+
import { useRangeTupleContext } from "../context/range-tuple-context.js";
|
|
5
|
+
import { rangeTv } from "../tv.js";
|
|
6
|
+
import { tcx } from "../../../../shared/utils/tcx/tcx.js";
|
|
7
|
+
const RangeConnects = forwardRef(
|
|
8
|
+
function RangeConnects2(props, ref) {
|
|
9
|
+
const { className } = props;
|
|
10
|
+
const { currentValue, disabled, min, transforms, thumbSize, trackHeight, tv } = useRangeContext();
|
|
11
|
+
const connectsStatus = useMemo(() => {
|
|
12
|
+
if (disabled) return "disabled";
|
|
13
|
+
if (currentValue < 0) return "negative";
|
|
14
|
+
return "positive";
|
|
15
|
+
}, [disabled, currentValue]);
|
|
16
|
+
const connectStyle = useMemo(() => {
|
|
17
|
+
return {
|
|
18
|
+
left: min < 0 ? currentValue < 0 ? `${transforms.transformX + thumbSize / 2}px` : "50%" : trackHeight / 2 + "px",
|
|
19
|
+
right: min < 0 ? currentValue >= 0 ? `calc(100% - ${transforms.transformX + thumbSize / 2}px)` : "50%" : `calc(100% - ${transforms.transformX + thumbSize / 2}px)`,
|
|
20
|
+
height: trackHeight
|
|
21
|
+
};
|
|
22
|
+
}, [min, currentValue, transforms.transformX, thumbSize, trackHeight]);
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
"div",
|
|
25
|
+
{
|
|
26
|
+
ref,
|
|
27
|
+
className: tcx(tv.connect(), disabled && "bg-disabled-background", className),
|
|
28
|
+
"data-connect-status": connectsStatus,
|
|
29
|
+
style: connectStyle
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
RangeConnects.displayName = "RangeConnects";
|
|
35
|
+
function RangeContainer(props) {
|
|
36
|
+
const { children, className, height: _height, ...rest } = props;
|
|
37
|
+
const {
|
|
38
|
+
currentValue,
|
|
39
|
+
step,
|
|
40
|
+
transforms,
|
|
41
|
+
thumbSize,
|
|
42
|
+
defaultStepValue,
|
|
43
|
+
dotsData,
|
|
44
|
+
defaultDotPosition,
|
|
45
|
+
defaultValue,
|
|
46
|
+
tv,
|
|
47
|
+
hasCustomDot,
|
|
48
|
+
hasCustomConnects
|
|
49
|
+
} = useRangeContext();
|
|
50
|
+
const hasStepOrDefault = step > 1 || defaultValue !== void 0;
|
|
51
|
+
const renderDots = () => {
|
|
52
|
+
if (dotsData) {
|
|
53
|
+
const { minTransform, maxTransform } = transforms;
|
|
54
|
+
return dotsData.map(({ value: dotValue, position: dotPosition }) => {
|
|
55
|
+
const dotTransform = minTransform + dotPosition * (maxTransform - minTransform);
|
|
56
|
+
const { dot } = rangeTv({
|
|
57
|
+
defaultStepValue: defaultStepValue === dotValue,
|
|
58
|
+
overStepValue: dotValue <= currentValue
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
"div",
|
|
62
|
+
{
|
|
63
|
+
className: dot(),
|
|
64
|
+
style: {
|
|
65
|
+
left: dotTransform + thumbSize / 2
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
dotValue
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (defaultDotPosition !== null && defaultDotPosition !== void 0) {
|
|
73
|
+
return /* @__PURE__ */ jsx(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
className: rangeTv({ defaultStepValue: true }).dot(),
|
|
77
|
+
style: {
|
|
78
|
+
left: transforms.minTransform + defaultDotPosition * (transforms.maxTransform - transforms.minTransform) + thumbSize / 2
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
86
|
+
!hasCustomConnects && /* @__PURE__ */ jsx(
|
|
87
|
+
RangeConnects,
|
|
88
|
+
{
|
|
89
|
+
className: tcx(tv.connect(), className),
|
|
90
|
+
...rest
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
children,
|
|
94
|
+
hasStepOrDefault && !hasCustomDot && /* @__PURE__ */ jsx("div", { className: tv.dotContainer(), children: renderDots() })
|
|
95
|
+
] });
|
|
96
|
+
}
|
|
97
|
+
RangeContainer.displayName = "RangeContainer";
|
|
98
|
+
const RangeTupleConnects = forwardRef(
|
|
99
|
+
function RangeTupleConnects2(props, ref) {
|
|
100
|
+
const { className, ...rest } = props;
|
|
101
|
+
const { transforms, thumbSize, trackHeight, tv } = useRangeTupleContext();
|
|
102
|
+
const connectStyle = useMemo(() => {
|
|
103
|
+
return {
|
|
104
|
+
left: `${transforms.transformX0 + thumbSize / 2}px`,
|
|
105
|
+
right: `calc(100% - ${transforms.transformX1 + thumbSize / 2}px)`,
|
|
106
|
+
height: trackHeight
|
|
107
|
+
};
|
|
108
|
+
}, [transforms.transformX0, transforms.transformX1, thumbSize, trackHeight]);
|
|
109
|
+
return /* @__PURE__ */ jsx(
|
|
110
|
+
"div",
|
|
111
|
+
{
|
|
112
|
+
ref,
|
|
113
|
+
className: tcx(tv.connect(), className),
|
|
114
|
+
style: connectStyle,
|
|
115
|
+
...rest
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
RangeTupleConnects.displayName = "RangeTupleConnects";
|
|
121
|
+
function RangeTupleContainer(props) {
|
|
122
|
+
const { children, className, height: _height, ...rest } = props;
|
|
123
|
+
const {
|
|
124
|
+
currentValue,
|
|
125
|
+
step,
|
|
126
|
+
transforms,
|
|
127
|
+
thumbSize,
|
|
128
|
+
defaultStepValue,
|
|
129
|
+
dotsData,
|
|
130
|
+
defaultDotPositions,
|
|
131
|
+
normalizedDefaultValue,
|
|
132
|
+
tv,
|
|
133
|
+
hasCustomDot,
|
|
134
|
+
hasCustomConnects
|
|
135
|
+
} = useRangeTupleContext();
|
|
136
|
+
const hasStepOrDefault = step > 1 || normalizedDefaultValue !== void 0;
|
|
137
|
+
const renderDots = () => {
|
|
138
|
+
if (dotsData) {
|
|
139
|
+
const { minTransform, maxTransform } = transforms;
|
|
140
|
+
return dotsData.map(({ value: dotValue, position: dotPosition }) => {
|
|
141
|
+
const dotTransform = minTransform + dotPosition * (maxTransform - minTransform);
|
|
142
|
+
const isWithinRange = dotValue >= currentValue[0] && dotValue <= currentValue[1];
|
|
143
|
+
const isDefaultValue = defaultStepValue == null ? void 0 : defaultStepValue.includes(dotValue);
|
|
144
|
+
const { dot } = rangeTv({
|
|
145
|
+
defaultStepValue: isDefaultValue,
|
|
146
|
+
overStepValue: isWithinRange
|
|
147
|
+
});
|
|
148
|
+
return /* @__PURE__ */ jsx(
|
|
149
|
+
"div",
|
|
150
|
+
{
|
|
151
|
+
className: dot(),
|
|
152
|
+
style: {
|
|
153
|
+
left: dotTransform + thumbSize / 2
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
dotValue
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (defaultDotPositions) {
|
|
161
|
+
return defaultDotPositions.map((position, idx) => /* @__PURE__ */ jsx(
|
|
162
|
+
"div",
|
|
163
|
+
{
|
|
164
|
+
className: rangeTv({ defaultStepValue: true }).dot(),
|
|
165
|
+
style: {
|
|
166
|
+
left: transforms.minTransform + position * (transforms.maxTransform - transforms.minTransform) + thumbSize / 2
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
`default-${idx}`
|
|
170
|
+
));
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
};
|
|
174
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
175
|
+
!hasCustomConnects && /* @__PURE__ */ jsx(
|
|
176
|
+
RangeTupleConnects,
|
|
177
|
+
{
|
|
178
|
+
className: tcx(tv.connect(), className),
|
|
179
|
+
...rest
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
children,
|
|
183
|
+
hasStepOrDefault && !hasCustomDot && /* @__PURE__ */ jsx("div", { className: tv.dotContainer(), children: renderDots() })
|
|
184
|
+
] });
|
|
185
|
+
}
|
|
186
|
+
RangeTupleContainer.displayName = "RangeTupleContainer";
|
|
187
|
+
export {
|
|
188
|
+
RangeConnects,
|
|
189
|
+
RangeContainer,
|
|
190
|
+
RangeTupleConnects,
|
|
191
|
+
RangeTupleContainer
|
|
192
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface RangeDotProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
className?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface RangeTupleDotProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const RangeDot: import('react').ForwardRefExoticComponent<RangeDotProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export declare const RangeTupleDot: import('react').ForwardRefExoticComponent<RangeTupleDotProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { useRangeContext } from "../context/range-context.js";
|
|
4
|
+
import { useRangeTupleContext } from "../context/range-tuple-context.js";
|
|
5
|
+
import { rangeTv } from "../tv.js";
|
|
6
|
+
import { tcx } from "../../../../shared/utils/tcx/tcx.js";
|
|
7
|
+
function getDotStatus(isOver, isDefault) {
|
|
8
|
+
if (isOver && isDefault) return "default-over";
|
|
9
|
+
if (isOver) return "over";
|
|
10
|
+
if (isDefault) return "default";
|
|
11
|
+
return "under";
|
|
12
|
+
}
|
|
13
|
+
const RangeDot = forwardRef(function RangeDot2(props, ref) {
|
|
14
|
+
const { className, ...rest } = props;
|
|
15
|
+
const {
|
|
16
|
+
currentValue,
|
|
17
|
+
step,
|
|
18
|
+
transforms,
|
|
19
|
+
thumbSize,
|
|
20
|
+
defaultStepValue,
|
|
21
|
+
dotsData,
|
|
22
|
+
defaultDotPosition,
|
|
23
|
+
defaultValue,
|
|
24
|
+
tv
|
|
25
|
+
} = useRangeContext();
|
|
26
|
+
const hasStepOrDefault = step > 1 || defaultValue !== void 0;
|
|
27
|
+
if (!hasStepOrDefault) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const renderDots = () => {
|
|
31
|
+
if (dotsData) {
|
|
32
|
+
const { minTransform, maxTransform } = transforms;
|
|
33
|
+
return dotsData.map(({ value: dotValue, position: dotPosition }, idx) => {
|
|
34
|
+
const dotTransform = minTransform + dotPosition * (maxTransform - minTransform);
|
|
35
|
+
const isDefault = defaultStepValue === dotValue;
|
|
36
|
+
const isOver = dotValue <= currentValue;
|
|
37
|
+
const { dot } = rangeTv({
|
|
38
|
+
defaultStepValue: isDefault,
|
|
39
|
+
overStepValue: isOver
|
|
40
|
+
});
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
ref: idx === 0 ? ref : void 0,
|
|
45
|
+
className: tcx(dot(), className),
|
|
46
|
+
"data-status": getDotStatus(isOver, isDefault),
|
|
47
|
+
style: {
|
|
48
|
+
left: dotTransform + thumbSize / 2
|
|
49
|
+
},
|
|
50
|
+
...rest
|
|
51
|
+
},
|
|
52
|
+
dotValue
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (defaultDotPosition !== null && defaultDotPosition !== void 0 && defaultStepValue) {
|
|
57
|
+
const isOver = defaultStepValue <= currentValue;
|
|
58
|
+
return /* @__PURE__ */ jsx(
|
|
59
|
+
"div",
|
|
60
|
+
{
|
|
61
|
+
ref,
|
|
62
|
+
className: tcx(rangeTv({ defaultStepValue: true }).dot(), className),
|
|
63
|
+
"data-status": isOver ? "over" : "default",
|
|
64
|
+
style: {
|
|
65
|
+
left: transforms.minTransform + defaultDotPosition * (transforms.maxTransform - transforms.minTransform) + thumbSize / 2
|
|
66
|
+
},
|
|
67
|
+
...rest
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
return /* @__PURE__ */ jsx("div", { className: tv.dotContainer(), children: renderDots() });
|
|
74
|
+
});
|
|
75
|
+
RangeDot.displayName = "RangeDot";
|
|
76
|
+
const RangeTupleDot = forwardRef(
|
|
77
|
+
function RangeTupleDot2(props, ref) {
|
|
78
|
+
const { className, ...rest } = props;
|
|
79
|
+
const {
|
|
80
|
+
currentValue,
|
|
81
|
+
step,
|
|
82
|
+
transforms,
|
|
83
|
+
thumbSize,
|
|
84
|
+
defaultStepValue,
|
|
85
|
+
dotsData,
|
|
86
|
+
defaultDotPositions,
|
|
87
|
+
normalizedDefaultValue,
|
|
88
|
+
tv
|
|
89
|
+
} = useRangeTupleContext();
|
|
90
|
+
const hasStepOrDefault = step > 1 || normalizedDefaultValue !== void 0;
|
|
91
|
+
if (!hasStepOrDefault) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const renderDots = () => {
|
|
95
|
+
if (dotsData) {
|
|
96
|
+
const { minTransform, maxTransform } = transforms;
|
|
97
|
+
return dotsData.map(({ value: dotValue, position: dotPosition }, idx) => {
|
|
98
|
+
const dotTransform = minTransform + dotPosition * (maxTransform - minTransform);
|
|
99
|
+
const isWithinRange = dotValue >= currentValue[0] && dotValue <= currentValue[1];
|
|
100
|
+
const isDefaultValue = defaultStepValue == null ? void 0 : defaultStepValue.includes(dotValue);
|
|
101
|
+
const { dot } = rangeTv({
|
|
102
|
+
defaultStepValue: isDefaultValue,
|
|
103
|
+
overStepValue: isWithinRange
|
|
104
|
+
});
|
|
105
|
+
return /* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: idx === 0 ? ref : void 0,
|
|
109
|
+
className: tcx(dot(), className),
|
|
110
|
+
"data-status": getDotStatus(isWithinRange, !!isDefaultValue),
|
|
111
|
+
"data-position": idx === 0 ? "left" : "right",
|
|
112
|
+
style: {
|
|
113
|
+
left: dotTransform + thumbSize / 2
|
|
114
|
+
},
|
|
115
|
+
...rest
|
|
116
|
+
},
|
|
117
|
+
dotValue
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (defaultDotPositions && defaultStepValue) {
|
|
122
|
+
const leftIsOver = defaultStepValue[0] >= currentValue[0];
|
|
123
|
+
const rightIsOver = defaultStepValue[1] <= currentValue[1];
|
|
124
|
+
return defaultDotPositions.map((position, idx) => /* @__PURE__ */ jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
ref: idx === 0 ? ref : void 0,
|
|
128
|
+
className: tcx(rangeTv({ defaultStepValue: true }).dot(), className),
|
|
129
|
+
"data-status": leftIsOver && idx === 0 ? "left-over" : rightIsOver && idx === 1 ? "right-over" : "default",
|
|
130
|
+
"data-position": idx === 0 ? "left" : "right",
|
|
131
|
+
style: {
|
|
132
|
+
left: transforms.minTransform + position * (transforms.maxTransform - transforms.minTransform) + thumbSize / 2
|
|
133
|
+
},
|
|
134
|
+
...rest
|
|
135
|
+
},
|
|
136
|
+
`default-${idx}`
|
|
137
|
+
));
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
141
|
+
return /* @__PURE__ */ jsx("div", { className: tv.dotContainer(), children: renderDots() });
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
RangeTupleDot.displayName = "RangeTupleDot";
|
|
145
|
+
export {
|
|
146
|
+
RangeDot,
|
|
147
|
+
RangeTupleDot
|
|
148
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface RangeThumbProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
size?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const RangeThumb: React.ForwardRefExoticComponent<RangeThumbProps & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
type ThumbIndex = 0 | 1;
|
|
8
|
+
export interface RangeTupleThumbProps {
|
|
9
|
+
className?: string;
|
|
10
|
+
size?: number;
|
|
11
|
+
index: ThumbIndex;
|
|
12
|
+
}
|
|
13
|
+
export declare const RangeTupleThumb: React.ForwardRefExoticComponent<RangeTupleThumbProps & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import { useRangeContext } from "../context/range-context.js";
|
|
4
|
+
import { useRangeTupleContext } from "../context/range-tuple-context.js";
|
|
5
|
+
import { tcx } from "../../../../shared/utils/tcx/tcx.js";
|
|
6
|
+
const BaseThumb = forwardRef(function BaseThumb2(props, ref) {
|
|
7
|
+
const {
|
|
8
|
+
className,
|
|
9
|
+
thumbRef,
|
|
10
|
+
inputRef,
|
|
11
|
+
thumbSize,
|
|
12
|
+
transformX,
|
|
13
|
+
isDragging,
|
|
14
|
+
disabled,
|
|
15
|
+
readOnly,
|
|
16
|
+
tv,
|
|
17
|
+
thumbTv,
|
|
18
|
+
onPointerDown,
|
|
19
|
+
onKeyDown,
|
|
20
|
+
isDefaultValue
|
|
21
|
+
} = props;
|
|
22
|
+
const thumbStyle = useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
width: thumbSize,
|
|
25
|
+
height: thumbSize,
|
|
26
|
+
transform: `translate(${transformX}px, -50%)`,
|
|
27
|
+
willChange: isDragging ? "transform" : "auto"
|
|
28
|
+
}),
|
|
29
|
+
[thumbSize, transformX, isDragging]
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
ref: (node) => {
|
|
35
|
+
if (thumbRef && "current" in thumbRef) {
|
|
36
|
+
thumbRef.current = node;
|
|
37
|
+
}
|
|
38
|
+
if (typeof ref === "function") {
|
|
39
|
+
ref(node);
|
|
40
|
+
} else if (ref) {
|
|
41
|
+
ref.current = node;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
onPointerDown,
|
|
45
|
+
className: tv.thumbWrapper(),
|
|
46
|
+
style: thumbStyle,
|
|
47
|
+
children: /* @__PURE__ */ jsx(
|
|
48
|
+
"div",
|
|
49
|
+
{
|
|
50
|
+
className: tcx(thumbTv.thumb(), className),
|
|
51
|
+
"data-status": isDefaultValue ? "default" : void 0,
|
|
52
|
+
children: /* @__PURE__ */ jsx(
|
|
53
|
+
"input",
|
|
54
|
+
{
|
|
55
|
+
ref: (node) => {
|
|
56
|
+
if (inputRef && "current" in inputRef) {
|
|
57
|
+
inputRef.current = node;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
type: "text",
|
|
61
|
+
onKeyDown,
|
|
62
|
+
className: tv.input(),
|
|
63
|
+
tabIndex: disabled || readOnly ? -1 : 0,
|
|
64
|
+
readOnly: true
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
const RangeThumb = forwardRef(
|
|
73
|
+
function RangeThumb2(props, ref) {
|
|
74
|
+
const { className, size: _size } = props;
|
|
75
|
+
const {
|
|
76
|
+
disabled,
|
|
77
|
+
readOnly,
|
|
78
|
+
transforms,
|
|
79
|
+
thumbSize,
|
|
80
|
+
thumbRef,
|
|
81
|
+
inputRef,
|
|
82
|
+
isDragging,
|
|
83
|
+
isDefaultValue,
|
|
84
|
+
handlePointerDown,
|
|
85
|
+
handleKeyDown,
|
|
86
|
+
tv
|
|
87
|
+
} = useRangeContext();
|
|
88
|
+
return /* @__PURE__ */ jsx(
|
|
89
|
+
BaseThumb,
|
|
90
|
+
{
|
|
91
|
+
ref,
|
|
92
|
+
className,
|
|
93
|
+
thumbRef,
|
|
94
|
+
inputRef,
|
|
95
|
+
thumbSize,
|
|
96
|
+
transformX: transforms.transformX,
|
|
97
|
+
isDragging: isDragging.current,
|
|
98
|
+
disabled,
|
|
99
|
+
readOnly,
|
|
100
|
+
tv,
|
|
101
|
+
thumbTv: tv,
|
|
102
|
+
onPointerDown: handlePointerDown,
|
|
103
|
+
onKeyDown: handleKeyDown,
|
|
104
|
+
isDefaultValue
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
RangeThumb.displayName = "RangeThumb";
|
|
110
|
+
const RangeTupleThumb = forwardRef(
|
|
111
|
+
function RangeTupleThumb2(props, ref) {
|
|
112
|
+
const { className, size: _size, index } = props;
|
|
113
|
+
const {
|
|
114
|
+
disabled,
|
|
115
|
+
readOnly,
|
|
116
|
+
transforms,
|
|
117
|
+
thumbSize,
|
|
118
|
+
thumb0Ref,
|
|
119
|
+
thumb1Ref,
|
|
120
|
+
input0Ref,
|
|
121
|
+
input1Ref,
|
|
122
|
+
isDragging,
|
|
123
|
+
isDefaultValue,
|
|
124
|
+
handlePointerDown,
|
|
125
|
+
handleKeyDown,
|
|
126
|
+
tv,
|
|
127
|
+
thumbTv0,
|
|
128
|
+
thumbTv1
|
|
129
|
+
} = useRangeTupleContext();
|
|
130
|
+
const thumbRef = index === 0 ? thumb0Ref : thumb1Ref;
|
|
131
|
+
const inputRef = index === 0 ? input0Ref : input1Ref;
|
|
132
|
+
const thumbTv = index === 0 ? thumbTv0 : thumbTv1;
|
|
133
|
+
const transformX = index === 0 ? transforms.transformX0 : transforms.transformX1;
|
|
134
|
+
return /* @__PURE__ */ jsx(
|
|
135
|
+
BaseThumb,
|
|
136
|
+
{
|
|
137
|
+
ref,
|
|
138
|
+
className,
|
|
139
|
+
thumbRef,
|
|
140
|
+
inputRef,
|
|
141
|
+
thumbSize,
|
|
142
|
+
transformX,
|
|
143
|
+
isDragging: isDragging.current === index,
|
|
144
|
+
disabled,
|
|
145
|
+
readOnly,
|
|
146
|
+
tv,
|
|
147
|
+
thumbTv,
|
|
148
|
+
onPointerDown: (e) => handlePointerDown(e, index),
|
|
149
|
+
onKeyDown: (e) => handleKeyDown(e, index),
|
|
150
|
+
isDefaultValue
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
RangeTupleThumb.displayName = "RangeTupleThumb";
|
|
156
|
+
export {
|
|
157
|
+
RangeThumb,
|
|
158
|
+
RangeTupleThumb
|
|
159
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { RangeContext, useRangeContext } from './range-context';
|
|
2
|
+
export type { RangeContextValue } from './range-context';
|
|
3
|
+
export { RangeTupleContext, useRangeTupleContext } from './range-tuple-context';
|
|
4
|
+
export type { RangeTupleContextValue } from './range-tuple-context';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { rangeTv } from '../tv';
|
|
2
|
+
export interface RangeContextValue {
|
|
3
|
+
currentValue: number;
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
step: number;
|
|
9
|
+
thumbSize: number;
|
|
10
|
+
trackHeight: number;
|
|
11
|
+
transforms: {
|
|
12
|
+
minTransform: number;
|
|
13
|
+
maxTransform: number;
|
|
14
|
+
transformX: number;
|
|
15
|
+
};
|
|
16
|
+
defaultStepValue: number | null;
|
|
17
|
+
currentStepValue: number;
|
|
18
|
+
dotsData: Array<{
|
|
19
|
+
value: number;
|
|
20
|
+
position: number;
|
|
21
|
+
}> | null;
|
|
22
|
+
defaultDotPosition: number | null;
|
|
23
|
+
thumbRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
24
|
+
inputRef: React.MutableRefObject<HTMLInputElement | null>;
|
|
25
|
+
isDragging: React.MutableRefObject<boolean>;
|
|
26
|
+
handlePointerDown: (e: React.PointerEvent) => void;
|
|
27
|
+
handleKeyDown: (e: React.KeyboardEvent) => void;
|
|
28
|
+
tv: ReturnType<typeof rangeTv>;
|
|
29
|
+
defaultValue?: number;
|
|
30
|
+
hasCustomDot: boolean;
|
|
31
|
+
hasCustomConnects: boolean;
|
|
32
|
+
isDefaultValue?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const RangeContext: import('react').Context<RangeContextValue | null>;
|
|
35
|
+
export declare function useRangeContext(): RangeContextValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const RangeContext = createContext(null);
|
|
3
|
+
function useRangeContext() {
|
|
4
|
+
const context = useContext(RangeContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("Range.Connects and Range.Thumb must be used within a Range component");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
RangeContext,
|
|
12
|
+
useRangeContext
|
|
13
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { rangeTv } from '../tv';
|
|
2
|
+
type ThumbIndex = 0 | 1;
|
|
3
|
+
export interface RangeTupleContextValue {
|
|
4
|
+
currentValue: [number, number];
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
min: number;
|
|
8
|
+
max: number;
|
|
9
|
+
step: number;
|
|
10
|
+
thumbSize: number;
|
|
11
|
+
trackHeight: number;
|
|
12
|
+
transforms: {
|
|
13
|
+
minTransform: number;
|
|
14
|
+
maxTransform: number;
|
|
15
|
+
transformX0: number;
|
|
16
|
+
transformX1: number;
|
|
17
|
+
};
|
|
18
|
+
defaultStepValue: [number, number] | null;
|
|
19
|
+
currentStepValue: [number, number];
|
|
20
|
+
dotsData: Array<{
|
|
21
|
+
value: number;
|
|
22
|
+
position: number;
|
|
23
|
+
}> | null;
|
|
24
|
+
defaultDotPositions: [number, number] | null;
|
|
25
|
+
normalizedDefaultValue: [number, number] | undefined;
|
|
26
|
+
thumb0Ref: React.RefObject<HTMLDivElement | null>;
|
|
27
|
+
thumb1Ref: React.RefObject<HTMLDivElement | null>;
|
|
28
|
+
input0Ref: React.RefObject<HTMLInputElement | null>;
|
|
29
|
+
input1Ref: React.RefObject<HTMLInputElement | null>;
|
|
30
|
+
isDragging: React.MutableRefObject<ThumbIndex | null>;
|
|
31
|
+
handlePointerDown: (e: React.PointerEvent, thumbIndex: ThumbIndex) => void;
|
|
32
|
+
handleKeyDown: (e: React.KeyboardEvent, thumbIndex: ThumbIndex) => void;
|
|
33
|
+
tv: ReturnType<typeof rangeTv>;
|
|
34
|
+
thumbTv0: ReturnType<typeof rangeTv>;
|
|
35
|
+
thumbTv1: ReturnType<typeof rangeTv>;
|
|
36
|
+
hasCustomDot: boolean;
|
|
37
|
+
hasCustomConnects: boolean;
|
|
38
|
+
isDefaultValue?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare const RangeTupleContext: import('react').Context<RangeTupleContextValue | null>;
|
|
41
|
+
export declare function useRangeTupleContext(): RangeTupleContextValue;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const RangeTupleContext = createContext(null);
|
|
3
|
+
function useRangeTupleContext() {
|
|
4
|
+
const context = useContext(RangeTupleContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"RangeTuple.Connects and RangeTuple.Thumb must be used within a RangeTuple component"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
RangeTupleContext,
|
|
14
|
+
useRangeTupleContext
|
|
15
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { Range } from './range';
|
|
2
2
|
export { RangeTuple } from './range-tuple';
|
|
3
|
-
export
|
|
4
|
-
export type {
|
|
3
|
+
export { RangeContext, RangeTupleContext, useRangeContext, useRangeTupleContext } from './context';
|
|
4
|
+
export type { RangeContextValue, RangeTupleContextValue } from './context';
|
|
5
|
+
export type { RangeConnectsProps, RangeContainerProps, RangeDotProps, RangeProps, RangeThumbProps, } from './range';
|
|
6
|
+
export type { RangeTupleConnectsProps, RangeTupleContainerProps, RangeTupleDotProps, RangeTupleProps, RangeTupleThumbProps, } from './range-tuple';
|