aio-range 2.0.2 → 2.0.3
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/index.js +92 -27
- package/package.json +2 -3
package/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, createRef, useContext, useEffect, useRef, useState } from "react";
|
|
4
|
-
import
|
|
5
|
-
import { $ } from 'aio-deps';
|
|
4
|
+
import { Swip } from 'aio-class';
|
|
6
5
|
import './index.css';
|
|
7
6
|
const RangeContext = createContext({});
|
|
8
7
|
const RangeProvider = ({ value, children }) => _jsx(RangeContext.Provider, { value: value, children: children });
|
|
@@ -16,7 +15,7 @@ export const AIOSpinner = (props) => {
|
|
|
16
15
|
return (_jsx(RangeProvider, { value: { rangeHook }, children: _jsxs("div", Object.assign({}, rangeHook.getRootProps(props, 'spinner'), { children: [_jsx(SpinnerText, { text: props.text }), _jsx(SpinnerSvg, {}), _jsx(RangeLabels, { type: 'spinner' }), _jsx(RangeValues, { type: 'spinner' })] })) }));
|
|
17
16
|
};
|
|
18
17
|
const SliderGroove = ({ grooveAttrs }) => {
|
|
19
|
-
return _jsx("div", Object.assign({},
|
|
18
|
+
return _jsx("div", Object.assign({}, AddToAttrs(grooveAttrs, { className: 'ai-slider-groove' })));
|
|
20
19
|
};
|
|
21
20
|
const SpinnerText = ({ text }) => {
|
|
22
21
|
if (text === undefined || text === null) {
|
|
@@ -84,7 +83,7 @@ const SliderFills = () => {
|
|
|
84
83
|
const SliderRect = ({ range }) => {
|
|
85
84
|
let { rangeHook } = useRangeProvider();
|
|
86
85
|
let { color, from, to, className, style, offset, thickness, roundCap } = range;
|
|
87
|
-
className =
|
|
86
|
+
className = classListToString(['ai-slider-range', range.className]);
|
|
88
87
|
const { vertical, reverse } = rangeHook.rootProps;
|
|
89
88
|
let startSide = rangeHook.getXPByValue(from), endSide = rangeHook.getXPByValue(to);
|
|
90
89
|
let Style = Object.assign({ [vertical ? 'height' : 'width']: (endSide - startSide) + '%', [vertical ? 'width' : 'height']: range.thickness, [vertical ? (reverse ? 'bottom' : 'top') : (reverse ? 'right' : 'left')]: startSide + '%', [vertical ? 'left' : 'top']: `calc(50% - ${(thickness / 2) + offset}px)`, borderRadius: roundCap ? 48 : 0, background: color }, style);
|
|
@@ -113,7 +112,7 @@ const SpinnerArc = ({ range }) => {
|
|
|
113
112
|
a = endAngle;
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
|
-
return _jsx("path", { d:
|
|
115
|
+
return _jsx("path", { d: svgArc(x, y, radius, a, b), stroke: color, strokeWidth: thickness, fill: 'transparent', strokeLinecap: roundCap ? 'round' : undefined, className: range.className }, `from${from}to${to}`);
|
|
117
116
|
};
|
|
118
117
|
const SpinnerHandle = ({ rangeValue }) => {
|
|
119
118
|
let { rangeHook } = useRangeProvider();
|
|
@@ -142,7 +141,7 @@ const SpinnerHandle = ({ rangeValue }) => {
|
|
|
142
141
|
return { width, height, left: offset, background: color };
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
|
-
let PROPS =
|
|
144
|
+
let PROPS = AddToAttrs({}, { className: 'ai-spinner-handle', style: getStyle(), attrs: { draggable: false } });
|
|
146
145
|
return (_createElement("div", Object.assign({}, PROPS, { key: 'rangehandle' + rangeValue.index })));
|
|
147
146
|
};
|
|
148
147
|
const RangeLabel = (props) => {
|
|
@@ -156,9 +155,9 @@ const RangeLabel = (props) => {
|
|
|
156
155
|
if (props.type !== "spinner" || !label.autoHide || vertical) {
|
|
157
156
|
return;
|
|
158
157
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!labels.length) {
|
|
158
|
+
const container = rangeHook.mainDom.current;
|
|
159
|
+
const labels = container.querySelectorAll('.ai-range-label');
|
|
160
|
+
if (!labels || !labels.length) {
|
|
162
161
|
return;
|
|
163
162
|
}
|
|
164
163
|
let firstLabel = labels.eq(0);
|
|
@@ -189,7 +188,10 @@ const RangeLabel = (props) => {
|
|
|
189
188
|
}
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
useEffect(() => {
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
window.addEventListener('resize', updateLabels);
|
|
193
|
+
return () => { window.removeEventListener('resize', updateLabels); };
|
|
194
|
+
}, []);
|
|
193
195
|
useEffect(() => { updateLabels(); });
|
|
194
196
|
function RENDER(init) {
|
|
195
197
|
if (!init && !dynamic) {
|
|
@@ -237,22 +239,18 @@ const useRange = (PROPS, type) => {
|
|
|
237
239
|
}
|
|
238
240
|
clearTimeout(temp.timeOut);
|
|
239
241
|
temp.timeOut = setTimeout(() => {
|
|
240
|
-
new
|
|
242
|
+
new Swip({
|
|
241
243
|
reverseX: !!props.reverse,
|
|
242
|
-
//vertical condition
|
|
243
244
|
reverseY: !!props.reverse && !!props.vertical,
|
|
244
|
-
dom:
|
|
245
|
-
|
|
245
|
+
dom: mainDom.current,
|
|
246
|
+
childIndexAttr: 'data-range-index',
|
|
247
|
+
start: ({ index }) => {
|
|
246
248
|
const { disabled } = propsRef.current;
|
|
247
249
|
if (disabled === true) {
|
|
248
250
|
return false;
|
|
249
251
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
let index = UT.GetAttr($(event.target), 'data-range-index');
|
|
253
|
-
temp.index = index === null ? false : +index;
|
|
254
|
-
temp.start = [...values];
|
|
255
|
-
}
|
|
252
|
+
temp.index = index;
|
|
253
|
+
temp.start = [...values];
|
|
256
254
|
return [0, 0];
|
|
257
255
|
},
|
|
258
256
|
move: (p) => {
|
|
@@ -479,7 +477,9 @@ const useRange = (PROPS, type) => {
|
|
|
479
477
|
return xp * (end - start) / 100;
|
|
480
478
|
}
|
|
481
479
|
function getXPByX(x) {
|
|
482
|
-
|
|
480
|
+
const container = mainDom.current;
|
|
481
|
+
const size = vertical ? container.clientHeight : container.clientWidth;
|
|
482
|
+
return (x * 100) / size;
|
|
483
483
|
}
|
|
484
484
|
const getArc = (rc) => {
|
|
485
485
|
let roundCap = rc.roundCap || false, full = rc.full || false, offset = rc.offset, color = rc.color || '#000', className = rc.className;
|
|
@@ -490,9 +490,12 @@ const useRange = (PROPS, type) => {
|
|
|
490
490
|
return { thickness, radius, color, roundCap, full, className, from, to };
|
|
491
491
|
};
|
|
492
492
|
function handleZIndex(index) {
|
|
493
|
-
|
|
494
|
-
containers.
|
|
495
|
-
containers.
|
|
493
|
+
const dom = mainDom.current;
|
|
494
|
+
const containers = dom.querySelectorAll('.ai-range-value-container');
|
|
495
|
+
containers === null || containers === void 0 ? void 0 : containers.forEach((container) => { container.style.zIndex = '10'; });
|
|
496
|
+
if (containers === null || containers === void 0 ? void 0 : containers[index]) {
|
|
497
|
+
containers[index].style.zIndex = '100';
|
|
498
|
+
}
|
|
496
499
|
}
|
|
497
500
|
function getOffset(rangeValue) {
|
|
498
501
|
const { pointOffset = (() => 0) } = props.rangeOption || {};
|
|
@@ -535,7 +538,7 @@ const useRange = (PROPS, type) => {
|
|
|
535
538
|
function getRootProps(props, type) {
|
|
536
539
|
let { attrs = {} } = props;
|
|
537
540
|
let rootStyle = getRootStyle(props, type);
|
|
538
|
-
return
|
|
541
|
+
return AddToAttrs(attrs, { className: getRootClassName(props, type), style: rootStyle, attrs: { ref: mainDom } });
|
|
539
542
|
}
|
|
540
543
|
function getDistance(labelItem, type) {
|
|
541
544
|
let { offset = 0 } = labelItem;
|
|
@@ -560,7 +563,7 @@ const useRange = (PROPS, type) => {
|
|
|
560
563
|
background: config.color
|
|
561
564
|
} }));
|
|
562
565
|
}
|
|
563
|
-
const htmlProps =
|
|
566
|
+
const htmlProps = AddToAttrs({}, { className: ['ai-range-label'], attrs: { draggable: false } });
|
|
564
567
|
const containerStyle = Object.assign({ [getSide()]: getXPByValue(itemValue) + '%' }, getDistance(labelItem, 'slider'));
|
|
565
568
|
const containerProps = { className: 'ai-range-label-container', style: containerStyle, draggable: false };
|
|
566
569
|
return (_jsx("div", Object.assign({}, containerProps, { children: _jsx("div", Object.assign({}, htmlProps, { children: html })) })));
|
|
@@ -595,7 +598,7 @@ const useRange = (PROPS, type) => {
|
|
|
595
598
|
let containerProps = { className: 'ai-range-label-container', style: containerStyle, draggable: false };
|
|
596
599
|
const distance = getDistance(labelItem, "spinner");
|
|
597
600
|
let textStyle = Object.assign(Object.assign({}, distance), { transform: labelItem.fixAngle ? `rotate(${-angle}deg)` : undefined });
|
|
598
|
-
const htmlProps =
|
|
601
|
+
const htmlProps = AddToAttrs({}, { className: ['ai-range-label'], style: textStyle, attrs: { draggable: false } });
|
|
599
602
|
return (_jsx("div", Object.assign({}, containerProps, { children: _jsx("div", Object.assign({}, htmlProps, { children: html })) })));
|
|
600
603
|
}
|
|
601
604
|
return {
|
|
@@ -605,3 +608,65 @@ const useRange = (PROPS, type) => {
|
|
|
605
608
|
getSliderLabel
|
|
606
609
|
};
|
|
607
610
|
};
|
|
611
|
+
function svgArcRange(centerX, centerY, radius, angleInDegrees) {
|
|
612
|
+
let angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
|
|
613
|
+
return {
|
|
614
|
+
x: centerX + (radius * Math.cos(angleInRadians)),
|
|
615
|
+
y: centerY + (radius * Math.sin(angleInRadians))
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function svgArc(x, y, radius, startAngle, endAngle) {
|
|
619
|
+
if (startAngle === endAngle || endAngle - startAngle === 360) {
|
|
620
|
+
startAngle = 0;
|
|
621
|
+
endAngle = 360;
|
|
622
|
+
}
|
|
623
|
+
if (startAngle === 360) {
|
|
624
|
+
startAngle = 359.99;
|
|
625
|
+
}
|
|
626
|
+
if (endAngle === 360) {
|
|
627
|
+
endAngle = 359.99;
|
|
628
|
+
}
|
|
629
|
+
let start = svgArcRange(x, y, radius, endAngle);
|
|
630
|
+
let end = svgArcRange(x, y, radius, startAngle);
|
|
631
|
+
let largeArcFlag;
|
|
632
|
+
if (endAngle - startAngle < -180) {
|
|
633
|
+
largeArcFlag = '0';
|
|
634
|
+
}
|
|
635
|
+
else if (endAngle - startAngle < 0) {
|
|
636
|
+
largeArcFlag = '1';
|
|
637
|
+
}
|
|
638
|
+
else if (endAngle - startAngle <= 180) {
|
|
639
|
+
largeArcFlag = '0';
|
|
640
|
+
}
|
|
641
|
+
else if (endAngle - startAngle <= 360) {
|
|
642
|
+
largeArcFlag = '1';
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
largeArcFlag = '0';
|
|
646
|
+
}
|
|
647
|
+
return ["M", start.x, start.y, "A", radius, radius, 0, largeArcFlag, 0, end.x, end.y].join(" ");
|
|
648
|
+
}
|
|
649
|
+
function classListToString(classes) {
|
|
650
|
+
let list = [];
|
|
651
|
+
const getClasses = (cls) => {
|
|
652
|
+
if (Array.isArray(cls)) {
|
|
653
|
+
return cls.filter((o) => !!o && typeof o === 'string');
|
|
654
|
+
}
|
|
655
|
+
else if (!!cls && typeof cls === 'string') {
|
|
656
|
+
return cls.split(' ');
|
|
657
|
+
}
|
|
658
|
+
return [];
|
|
659
|
+
};
|
|
660
|
+
for (let i = 0; i < classes.length; i++) {
|
|
661
|
+
const cls = classes[i];
|
|
662
|
+
list = [...list, ...getClasses(cls)];
|
|
663
|
+
}
|
|
664
|
+
return list.length ? list.join(' ') : '';
|
|
665
|
+
}
|
|
666
|
+
function AddToAttrs(attrs, p) {
|
|
667
|
+
attrs = attrs || {};
|
|
668
|
+
const className = classListToString([attrs.className, p === null || p === void 0 ? void 0 : p.className]);
|
|
669
|
+
let newStyle = Object.assign(Object.assign({}, attrs.style), p === null || p === void 0 ? void 0 : p.style);
|
|
670
|
+
const res = Object.assign(Object.assign(Object.assign({}, attrs), { className, style: newStyle }), p === null || p === void 0 ? void 0 : p.attrs);
|
|
671
|
+
return res;
|
|
672
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-range",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "linear and circular range input",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"url": "git+https://github.com/mohammadFeiz/aio-range.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"aio-
|
|
16
|
-
"aio-utils": "latest"
|
|
15
|
+
"aio-class":"latest"
|
|
17
16
|
},
|
|
18
17
|
"keywords": [
|
|
19
18
|
"range",
|