@blerp/design 1.4.2 → 1.4.4
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/neo-components/Dialog.js +5 -0
- package/dist/cjs/neo-components/FormControls.js +125 -32
- package/dist/cjs/neo-components/Text.js +2 -2
- package/dist/esm/neo-components/Dialog.js +5 -0
- package/dist/esm/neo-components/FormControls.js +125 -32
- package/dist/esm/neo-components/Text.js +2 -2
- package/package.json +1 -1
|
@@ -244,6 +244,11 @@ const BaseModal = /*#__PURE__*/React__default["default"].forwardRef((_ref2, ref)
|
|
|
244
244
|
|
|
245
245
|
if (disablePortal) {
|
|
246
246
|
return modalContent;
|
|
247
|
+
} // SSR check - don't use createPortal on the server
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
if (typeof window === 'undefined') {
|
|
251
|
+
return null;
|
|
247
252
|
}
|
|
248
253
|
|
|
249
254
|
return /*#__PURE__*/ReactDOM.createPortal(modalContent, container || document.body);
|
|
@@ -21,7 +21,7 @@ const _excluded = ["checked", "defaultChecked", "disabled", "onChange", "color",
|
|
|
21
21
|
_excluded2 = ["checked", "defaultChecked", "disabled", "onChange", "color", "size", "name", "value", "inputProps", "style"],
|
|
22
22
|
_excluded3 = ["checked", "defaultChecked", "disabled", "onChange", "color", "size", "name", "value", "inputProps", "style"],
|
|
23
23
|
_excluded4 = ["value", "defaultValue", "onChange", "children", "disabled", "multiple", "native", "variant", "label", "fullWidth", "size", "error", "displayEmpty", "renderValue", "MenuProps", "inputProps", "style", "IconComponent", "disableBorder", "color"],
|
|
24
|
-
_excluded5 = ["value", "defaultValue", "onChange", "onChangeCommitted", "min", "max", "step", "marks", "disabled", "orientation", "color", "size", "valueLabelDisplay", "valueLabelFormat", "getAriaValueText", "track", "style"],
|
|
24
|
+
_excluded5 = ["value", "defaultValue", "onChange", "onChangeCommitted", "min", "max", "step", "marks", "disabled", "orientation", "color", "size", "valueLabelDisplay", "valueLabelFormat", "getAriaValueText", "track", "disableSwap", "style"],
|
|
25
25
|
_excluded6 = ["value", "defaultValue", "onChange", "max", "precision", "disabled", "readOnly", "size", "emptyIcon", "icon", "name", "style"];
|
|
26
26
|
|
|
27
27
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -764,6 +764,7 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
764
764
|
valueLabelFormat,
|
|
765
765
|
getAriaValueText,
|
|
766
766
|
track = "normal",
|
|
767
|
+
disableSwap = false,
|
|
767
768
|
style
|
|
768
769
|
} = _ref5,
|
|
769
770
|
props = _objectWithoutProperties__default["default"](_ref5, _excluded5);
|
|
@@ -771,55 +772,103 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
771
772
|
const {
|
|
772
773
|
colors
|
|
773
774
|
} = ThemeProvider.useTheme();
|
|
775
|
+
const isRange = Array.isArray(value) || Array.isArray(defaultValue);
|
|
774
776
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
775
777
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
778
|
+
const [activeThumb, setActiveThumb] = React.useState(-1);
|
|
776
779
|
const sliderRef = React.useRef(null);
|
|
777
780
|
const currentValue = value !== undefined ? value : internalValue;
|
|
778
781
|
const colorValue = colors[color] || colors.primary;
|
|
779
782
|
const mainColor = typeof colorValue === "object" ? colorValue.main : colorValue;
|
|
780
783
|
const trackThickness = 4;
|
|
781
|
-
const thumbSize = 20;
|
|
782
|
-
const percentage = (currentValue - min) / (max - min) * 100;
|
|
784
|
+
const thumbSize = 20; // Calculate percentages for range or single
|
|
783
785
|
|
|
784
|
-
const
|
|
785
|
-
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
786
|
-
const steppedValue = Math.round(clampedValue / step) * step;
|
|
786
|
+
const getPercentage = val => (val - min) / (max - min) * 100;
|
|
787
787
|
|
|
788
|
-
|
|
789
|
-
setInternalValue(steppedValue);
|
|
790
|
-
}
|
|
788
|
+
const percentage = isRange ? [getPercentage(currentValue[0]), getPercentage(currentValue[1])] : getPercentage(currentValue);
|
|
791
789
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
790
|
+
const handleChange = (newValue, thumbIndex) => {
|
|
791
|
+
if (isRange) {
|
|
792
|
+
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
793
|
+
const steppedValue = Math.round(clampedValue / step) * step;
|
|
794
|
+
let newRange = [...currentValue];
|
|
795
|
+
newRange[thumbIndex] = steppedValue; // Handle swap prevention
|
|
796
|
+
|
|
797
|
+
if (disableSwap) {
|
|
798
|
+
if (thumbIndex === 0 && steppedValue > currentValue[1]) {
|
|
799
|
+
newRange[0] = currentValue[1];
|
|
800
|
+
} else if (thumbIndex === 1 && steppedValue < currentValue[0]) {
|
|
801
|
+
newRange[1] = currentValue[0];
|
|
802
|
+
}
|
|
803
|
+
} else {
|
|
804
|
+
// Auto-swap if needed
|
|
805
|
+
if (newRange[0] > newRange[1]) {
|
|
806
|
+
newRange = [newRange[1], newRange[0]];
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (value === undefined) {
|
|
811
|
+
setInternalValue(newRange);
|
|
795
812
|
}
|
|
796
|
-
|
|
813
|
+
|
|
814
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
815
|
+
target: {
|
|
816
|
+
value: newRange
|
|
817
|
+
}
|
|
818
|
+
}, newRange, thumbIndex);
|
|
819
|
+
} else {
|
|
820
|
+
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
821
|
+
const steppedValue = Math.round(clampedValue / step) * step;
|
|
822
|
+
|
|
823
|
+
if (value === undefined) {
|
|
824
|
+
setInternalValue(steppedValue);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
828
|
+
target: {
|
|
829
|
+
value: steppedValue
|
|
830
|
+
}
|
|
831
|
+
}, steppedValue);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const getClosestThumb = clientX => {
|
|
836
|
+
if (!sliderRef.current || !isRange) return 0;
|
|
837
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
|
838
|
+
const percent = (clientX - rect.left) / rect.width;
|
|
839
|
+
const clickValue = min + percent * (max - min);
|
|
840
|
+
const dist0 = Math.abs(currentValue[0] - clickValue);
|
|
841
|
+
const dist1 = Math.abs(currentValue[1] - clickValue);
|
|
842
|
+
return dist0 <= dist1 ? 0 : 1;
|
|
797
843
|
};
|
|
798
844
|
|
|
799
|
-
const updateValue = e => {
|
|
845
|
+
const updateValue = (e, thumbIdx) => {
|
|
800
846
|
if (!sliderRef.current) return;
|
|
801
847
|
const rect = sliderRef.current.getBoundingClientRect();
|
|
802
848
|
const percent = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
803
849
|
const newValue = min + percent * (max - min);
|
|
804
|
-
handleChange(newValue);
|
|
850
|
+
handleChange(newValue, thumbIdx);
|
|
805
851
|
};
|
|
806
852
|
|
|
807
853
|
const handleMouseDown = e => {
|
|
808
854
|
if (disabled) return;
|
|
809
855
|
e.preventDefault();
|
|
856
|
+
const thumbIdx = isRange ? getClosestThumb(e.clientX) : 0;
|
|
857
|
+
setActiveThumb(thumbIdx);
|
|
810
858
|
setIsDragging(true);
|
|
811
|
-
updateValue(e);
|
|
859
|
+
updateValue(e, thumbIdx);
|
|
812
860
|
};
|
|
813
861
|
|
|
814
862
|
React.useEffect(() => {
|
|
815
863
|
if (!isDragging) return;
|
|
816
864
|
|
|
817
865
|
const handleMouseMove = e => {
|
|
818
|
-
updateValue(e);
|
|
866
|
+
updateValue(e, activeThumb);
|
|
819
867
|
};
|
|
820
868
|
|
|
821
869
|
const handleMouseUp = () => {
|
|
822
870
|
setIsDragging(false);
|
|
871
|
+
setActiveThumb(-1);
|
|
823
872
|
onChangeCommitted === null || onChangeCommitted === void 0 ? void 0 : onChangeCommitted({
|
|
824
873
|
target: {
|
|
825
874
|
value: currentValue
|
|
@@ -833,7 +882,7 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
833
882
|
document.removeEventListener("mousemove", handleMouseMove);
|
|
834
883
|
document.removeEventListener("mouseup", handleMouseUp);
|
|
835
884
|
};
|
|
836
|
-
}, [isDragging, currentValue, min, max, step]);
|
|
885
|
+
}, [isDragging, activeThumb, currentValue, min, max, step]);
|
|
837
886
|
|
|
838
887
|
const containerStyle = _objectSpread(_objectSpread({
|
|
839
888
|
position: "relative",
|
|
@@ -855,7 +904,17 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
855
904
|
borderRadius: "".concat(trackThickness / 2, "px"),
|
|
856
905
|
backgroundColor: "rgba(255, 255, 255, 0.3)"
|
|
857
906
|
};
|
|
858
|
-
const trackStyle = {
|
|
907
|
+
const trackStyle = isRange ? {
|
|
908
|
+
position: "absolute",
|
|
909
|
+
left: "".concat(percentage[0], "%"),
|
|
910
|
+
width: "".concat(percentage[1] - percentage[0], "%"),
|
|
911
|
+
height: "".concat(trackThickness, "px"),
|
|
912
|
+
top: "50%",
|
|
913
|
+
transform: "translateY(-50%)",
|
|
914
|
+
borderRadius: "".concat(trackThickness / 2, "px"),
|
|
915
|
+
backgroundColor: mainColor,
|
|
916
|
+
transition: isDragging ? "none" : "left 150ms, width 150ms"
|
|
917
|
+
} : {
|
|
859
918
|
position: "absolute",
|
|
860
919
|
width: "".concat(percentage, "%"),
|
|
861
920
|
height: "".concat(trackThickness, "px"),
|
|
@@ -866,22 +925,22 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
866
925
|
transition: isDragging ? "none" : "width 150ms"
|
|
867
926
|
};
|
|
868
927
|
|
|
869
|
-
const
|
|
928
|
+
const getThumbStyle = (pct, idx) => _objectSpread({
|
|
870
929
|
position: "absolute",
|
|
871
930
|
width: "".concat(thumbSize, "px"),
|
|
872
931
|
height: "".concat(thumbSize, "px"),
|
|
873
932
|
borderRadius: "50%",
|
|
874
933
|
backgroundColor: mainColor,
|
|
875
934
|
boxShadow: "0px 2px 1px -1px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 1px 3px 0px rgba(0,0,0,0.12)",
|
|
876
|
-
left: "calc(".concat(
|
|
935
|
+
left: "calc(".concat(pct, "% - ").concat(thumbSize / 2, "px)"),
|
|
877
936
|
top: "50%",
|
|
878
937
|
transform: "translateY(-50%)",
|
|
879
|
-
transition: isDragging ? "none" : "left 150ms",
|
|
880
|
-
cursor: "grab"
|
|
881
|
-
|
|
938
|
+
transition: isDragging && activeThumb === idx ? "none" : "left 150ms",
|
|
939
|
+
cursor: "grab",
|
|
940
|
+
zIndex: activeThumb === idx ? 2 : 1
|
|
941
|
+
}, isDragging && activeThumb === idx && {
|
|
882
942
|
cursor: "grabbing"
|
|
883
|
-
});
|
|
884
|
-
|
|
943
|
+
});
|
|
885
944
|
|
|
886
945
|
const renderMarks = () => {
|
|
887
946
|
if (!marks) return null;
|
|
@@ -919,7 +978,12 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
919
978
|
});
|
|
920
979
|
};
|
|
921
980
|
|
|
922
|
-
const
|
|
981
|
+
const formatDisplayValue = val => {
|
|
982
|
+
if (valueLabelFormat) return valueLabelFormat(val);
|
|
983
|
+
if (getAriaValueText) return getAriaValueText(val);
|
|
984
|
+
return val;
|
|
985
|
+
};
|
|
986
|
+
|
|
923
987
|
return /*#__PURE__*/React__default["default"].createElement("div", _extends__default["default"]({
|
|
924
988
|
ref: node => {
|
|
925
989
|
sliderRef.current = node;
|
|
@@ -935,15 +999,44 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
935
999
|
role: "slider",
|
|
936
1000
|
"aria-valuemin": min,
|
|
937
1001
|
"aria-valuemax": max,
|
|
938
|
-
"aria-valuenow": currentValue,
|
|
939
|
-
"aria-valuetext": getAriaValueText === null || getAriaValueText === void 0 ? void 0 : getAriaValueText(currentValue),
|
|
1002
|
+
"aria-valuenow": isRange ? currentValue[0] : currentValue,
|
|
940
1003
|
tabIndex: disabled ? -1 : 0
|
|
941
1004
|
}, props), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
942
1005
|
style: railStyle
|
|
943
1006
|
}), track !== false && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
944
1007
|
style: trackStyle
|
|
945
|
-
}), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
946
|
-
style:
|
|
1008
|
+
}), isRange ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1009
|
+
style: getThumbStyle(percentage[0], 0)
|
|
1010
|
+
}, valueLabelDisplay === "on" || valueLabelDisplay === "auto" && isDragging && activeThumb === 0 ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1011
|
+
style: {
|
|
1012
|
+
position: "absolute",
|
|
1013
|
+
bottom: "calc(100% + 8px)",
|
|
1014
|
+
left: "50%",
|
|
1015
|
+
transform: "translateX(-50%)",
|
|
1016
|
+
padding: "4px 8px",
|
|
1017
|
+
borderRadius: "4px",
|
|
1018
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)",
|
|
1019
|
+
color: "#fff",
|
|
1020
|
+
fontSize: "12px",
|
|
1021
|
+
whiteSpace: "nowrap"
|
|
1022
|
+
}
|
|
1023
|
+
}, formatDisplayValue(currentValue[0])) : null), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1024
|
+
style: getThumbStyle(percentage[1], 1)
|
|
1025
|
+
}, valueLabelDisplay === "on" || valueLabelDisplay === "auto" && isDragging && activeThumb === 1 ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1026
|
+
style: {
|
|
1027
|
+
position: "absolute",
|
|
1028
|
+
bottom: "calc(100% + 8px)",
|
|
1029
|
+
left: "50%",
|
|
1030
|
+
transform: "translateX(-50%)",
|
|
1031
|
+
padding: "4px 8px",
|
|
1032
|
+
borderRadius: "4px",
|
|
1033
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)",
|
|
1034
|
+
color: "#fff",
|
|
1035
|
+
fontSize: "12px",
|
|
1036
|
+
whiteSpace: "nowrap"
|
|
1037
|
+
}
|
|
1038
|
+
}, formatDisplayValue(currentValue[1])) : null)) : /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1039
|
+
style: getThumbStyle(percentage, 0)
|
|
947
1040
|
}, valueLabelDisplay === "on" && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
948
1041
|
style: {
|
|
949
1042
|
position: "absolute",
|
|
@@ -957,7 +1050,7 @@ const BaseSlider = /*#__PURE__*/React__default["default"].forwardRef((_ref5, ref
|
|
|
957
1050
|
fontSize: "12px",
|
|
958
1051
|
whiteSpace: "nowrap"
|
|
959
1052
|
}
|
|
960
|
-
},
|
|
1053
|
+
}, formatDisplayValue(currentValue))), renderMarks());
|
|
961
1054
|
});
|
|
962
1055
|
BaseSlider.displayName = "BaseSlider";
|
|
963
1056
|
const Slider = withSx.withSx(BaseSlider);
|
|
@@ -194,8 +194,8 @@ const BaseText = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
|
|
|
194
194
|
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "notblack") return "#FFFFFF";
|
|
195
195
|
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "notblack.main") return "#FFFFFF"; // Hardcode plain white / black detection
|
|
196
196
|
|
|
197
|
-
if (colorValue.toLowerCase() === "white") return "#FFFFFF";
|
|
198
|
-
if (colorValue.toLowerCase() === "black") return "#000000"; // Handle "white.override" or similar
|
|
197
|
+
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "white") return "#FFFFFF";
|
|
198
|
+
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "black") return "#000000"; // Handle "white.override" or similar
|
|
199
199
|
|
|
200
200
|
if (colorValue === "white.override" || colorValue === "whiteOverride") {
|
|
201
201
|
var _colors$whiteOverride;
|
|
@@ -233,6 +233,11 @@ const BaseModal = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
233
233
|
|
|
234
234
|
if (disablePortal) {
|
|
235
235
|
return modalContent;
|
|
236
|
+
} // SSR check - don't use createPortal on the server
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
if (typeof window === 'undefined') {
|
|
240
|
+
return null;
|
|
236
241
|
}
|
|
237
242
|
|
|
238
243
|
return /*#__PURE__*/createPortal(modalContent, container || document.body);
|
|
@@ -10,7 +10,7 @@ const _excluded = ["checked", "defaultChecked", "disabled", "onChange", "color",
|
|
|
10
10
|
_excluded2 = ["checked", "defaultChecked", "disabled", "onChange", "color", "size", "name", "value", "inputProps", "style"],
|
|
11
11
|
_excluded3 = ["checked", "defaultChecked", "disabled", "onChange", "color", "size", "name", "value", "inputProps", "style"],
|
|
12
12
|
_excluded4 = ["value", "defaultValue", "onChange", "children", "disabled", "multiple", "native", "variant", "label", "fullWidth", "size", "error", "displayEmpty", "renderValue", "MenuProps", "inputProps", "style", "IconComponent", "disableBorder", "color"],
|
|
13
|
-
_excluded5 = ["value", "defaultValue", "onChange", "onChangeCommitted", "min", "max", "step", "marks", "disabled", "orientation", "color", "size", "valueLabelDisplay", "valueLabelFormat", "getAriaValueText", "track", "style"],
|
|
13
|
+
_excluded5 = ["value", "defaultValue", "onChange", "onChangeCommitted", "min", "max", "step", "marks", "disabled", "orientation", "color", "size", "valueLabelDisplay", "valueLabelFormat", "getAriaValueText", "track", "disableSwap", "style"],
|
|
14
14
|
_excluded6 = ["value", "defaultValue", "onChange", "max", "precision", "disabled", "readOnly", "size", "emptyIcon", "icon", "name", "style"];
|
|
15
15
|
|
|
16
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -753,6 +753,7 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
753
753
|
valueLabelFormat,
|
|
754
754
|
getAriaValueText,
|
|
755
755
|
track = "normal",
|
|
756
|
+
disableSwap = false,
|
|
756
757
|
style
|
|
757
758
|
} = _ref5,
|
|
758
759
|
props = _objectWithoutProperties(_ref5, _excluded5);
|
|
@@ -760,55 +761,103 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
760
761
|
const {
|
|
761
762
|
colors
|
|
762
763
|
} = useTheme();
|
|
764
|
+
const isRange = Array.isArray(value) || Array.isArray(defaultValue);
|
|
763
765
|
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
764
766
|
const [isDragging, setIsDragging] = useState(false);
|
|
767
|
+
const [activeThumb, setActiveThumb] = useState(-1);
|
|
765
768
|
const sliderRef = useRef(null);
|
|
766
769
|
const currentValue = value !== undefined ? value : internalValue;
|
|
767
770
|
const colorValue = colors[color] || colors.primary;
|
|
768
771
|
const mainColor = typeof colorValue === "object" ? colorValue.main : colorValue;
|
|
769
772
|
const trackThickness = 4;
|
|
770
|
-
const thumbSize = 20;
|
|
771
|
-
const percentage = (currentValue - min) / (max - min) * 100;
|
|
773
|
+
const thumbSize = 20; // Calculate percentages for range or single
|
|
772
774
|
|
|
773
|
-
const
|
|
774
|
-
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
775
|
-
const steppedValue = Math.round(clampedValue / step) * step;
|
|
775
|
+
const getPercentage = val => (val - min) / (max - min) * 100;
|
|
776
776
|
|
|
777
|
-
|
|
778
|
-
setInternalValue(steppedValue);
|
|
779
|
-
}
|
|
777
|
+
const percentage = isRange ? [getPercentage(currentValue[0]), getPercentage(currentValue[1])] : getPercentage(currentValue);
|
|
780
778
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
779
|
+
const handleChange = (newValue, thumbIndex) => {
|
|
780
|
+
if (isRange) {
|
|
781
|
+
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
782
|
+
const steppedValue = Math.round(clampedValue / step) * step;
|
|
783
|
+
let newRange = [...currentValue];
|
|
784
|
+
newRange[thumbIndex] = steppedValue; // Handle swap prevention
|
|
785
|
+
|
|
786
|
+
if (disableSwap) {
|
|
787
|
+
if (thumbIndex === 0 && steppedValue > currentValue[1]) {
|
|
788
|
+
newRange[0] = currentValue[1];
|
|
789
|
+
} else if (thumbIndex === 1 && steppedValue < currentValue[0]) {
|
|
790
|
+
newRange[1] = currentValue[0];
|
|
791
|
+
}
|
|
792
|
+
} else {
|
|
793
|
+
// Auto-swap if needed
|
|
794
|
+
if (newRange[0] > newRange[1]) {
|
|
795
|
+
newRange = [newRange[1], newRange[0]];
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (value === undefined) {
|
|
800
|
+
setInternalValue(newRange);
|
|
784
801
|
}
|
|
785
|
-
|
|
802
|
+
|
|
803
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
804
|
+
target: {
|
|
805
|
+
value: newRange
|
|
806
|
+
}
|
|
807
|
+
}, newRange, thumbIndex);
|
|
808
|
+
} else {
|
|
809
|
+
const clampedValue = Math.min(max, Math.max(min, newValue));
|
|
810
|
+
const steppedValue = Math.round(clampedValue / step) * step;
|
|
811
|
+
|
|
812
|
+
if (value === undefined) {
|
|
813
|
+
setInternalValue(steppedValue);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
817
|
+
target: {
|
|
818
|
+
value: steppedValue
|
|
819
|
+
}
|
|
820
|
+
}, steppedValue);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
const getClosestThumb = clientX => {
|
|
825
|
+
if (!sliderRef.current || !isRange) return 0;
|
|
826
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
|
827
|
+
const percent = (clientX - rect.left) / rect.width;
|
|
828
|
+
const clickValue = min + percent * (max - min);
|
|
829
|
+
const dist0 = Math.abs(currentValue[0] - clickValue);
|
|
830
|
+
const dist1 = Math.abs(currentValue[1] - clickValue);
|
|
831
|
+
return dist0 <= dist1 ? 0 : 1;
|
|
786
832
|
};
|
|
787
833
|
|
|
788
|
-
const updateValue = e => {
|
|
834
|
+
const updateValue = (e, thumbIdx) => {
|
|
789
835
|
if (!sliderRef.current) return;
|
|
790
836
|
const rect = sliderRef.current.getBoundingClientRect();
|
|
791
837
|
const percent = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
792
838
|
const newValue = min + percent * (max - min);
|
|
793
|
-
handleChange(newValue);
|
|
839
|
+
handleChange(newValue, thumbIdx);
|
|
794
840
|
};
|
|
795
841
|
|
|
796
842
|
const handleMouseDown = e => {
|
|
797
843
|
if (disabled) return;
|
|
798
844
|
e.preventDefault();
|
|
845
|
+
const thumbIdx = isRange ? getClosestThumb(e.clientX) : 0;
|
|
846
|
+
setActiveThumb(thumbIdx);
|
|
799
847
|
setIsDragging(true);
|
|
800
|
-
updateValue(e);
|
|
848
|
+
updateValue(e, thumbIdx);
|
|
801
849
|
};
|
|
802
850
|
|
|
803
851
|
useEffect(() => {
|
|
804
852
|
if (!isDragging) return;
|
|
805
853
|
|
|
806
854
|
const handleMouseMove = e => {
|
|
807
|
-
updateValue(e);
|
|
855
|
+
updateValue(e, activeThumb);
|
|
808
856
|
};
|
|
809
857
|
|
|
810
858
|
const handleMouseUp = () => {
|
|
811
859
|
setIsDragging(false);
|
|
860
|
+
setActiveThumb(-1);
|
|
812
861
|
onChangeCommitted === null || onChangeCommitted === void 0 ? void 0 : onChangeCommitted({
|
|
813
862
|
target: {
|
|
814
863
|
value: currentValue
|
|
@@ -822,7 +871,7 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
822
871
|
document.removeEventListener("mousemove", handleMouseMove);
|
|
823
872
|
document.removeEventListener("mouseup", handleMouseUp);
|
|
824
873
|
};
|
|
825
|
-
}, [isDragging, currentValue, min, max, step]);
|
|
874
|
+
}, [isDragging, activeThumb, currentValue, min, max, step]);
|
|
826
875
|
|
|
827
876
|
const containerStyle = _objectSpread(_objectSpread({
|
|
828
877
|
position: "relative",
|
|
@@ -844,7 +893,17 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
844
893
|
borderRadius: "".concat(trackThickness / 2, "px"),
|
|
845
894
|
backgroundColor: "rgba(255, 255, 255, 0.3)"
|
|
846
895
|
};
|
|
847
|
-
const trackStyle = {
|
|
896
|
+
const trackStyle = isRange ? {
|
|
897
|
+
position: "absolute",
|
|
898
|
+
left: "".concat(percentage[0], "%"),
|
|
899
|
+
width: "".concat(percentage[1] - percentage[0], "%"),
|
|
900
|
+
height: "".concat(trackThickness, "px"),
|
|
901
|
+
top: "50%",
|
|
902
|
+
transform: "translateY(-50%)",
|
|
903
|
+
borderRadius: "".concat(trackThickness / 2, "px"),
|
|
904
|
+
backgroundColor: mainColor,
|
|
905
|
+
transition: isDragging ? "none" : "left 150ms, width 150ms"
|
|
906
|
+
} : {
|
|
848
907
|
position: "absolute",
|
|
849
908
|
width: "".concat(percentage, "%"),
|
|
850
909
|
height: "".concat(trackThickness, "px"),
|
|
@@ -855,22 +914,22 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
855
914
|
transition: isDragging ? "none" : "width 150ms"
|
|
856
915
|
};
|
|
857
916
|
|
|
858
|
-
const
|
|
917
|
+
const getThumbStyle = (pct, idx) => _objectSpread({
|
|
859
918
|
position: "absolute",
|
|
860
919
|
width: "".concat(thumbSize, "px"),
|
|
861
920
|
height: "".concat(thumbSize, "px"),
|
|
862
921
|
borderRadius: "50%",
|
|
863
922
|
backgroundColor: mainColor,
|
|
864
923
|
boxShadow: "0px 2px 1px -1px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 1px 3px 0px rgba(0,0,0,0.12)",
|
|
865
|
-
left: "calc(".concat(
|
|
924
|
+
left: "calc(".concat(pct, "% - ").concat(thumbSize / 2, "px)"),
|
|
866
925
|
top: "50%",
|
|
867
926
|
transform: "translateY(-50%)",
|
|
868
|
-
transition: isDragging ? "none" : "left 150ms",
|
|
869
|
-
cursor: "grab"
|
|
870
|
-
|
|
927
|
+
transition: isDragging && activeThumb === idx ? "none" : "left 150ms",
|
|
928
|
+
cursor: "grab",
|
|
929
|
+
zIndex: activeThumb === idx ? 2 : 1
|
|
930
|
+
}, isDragging && activeThumb === idx && {
|
|
871
931
|
cursor: "grabbing"
|
|
872
|
-
});
|
|
873
|
-
|
|
932
|
+
});
|
|
874
933
|
|
|
875
934
|
const renderMarks = () => {
|
|
876
935
|
if (!marks) return null;
|
|
@@ -908,7 +967,12 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
908
967
|
});
|
|
909
968
|
};
|
|
910
969
|
|
|
911
|
-
const
|
|
970
|
+
const formatDisplayValue = val => {
|
|
971
|
+
if (valueLabelFormat) return valueLabelFormat(val);
|
|
972
|
+
if (getAriaValueText) return getAriaValueText(val);
|
|
973
|
+
return val;
|
|
974
|
+
};
|
|
975
|
+
|
|
912
976
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
913
977
|
ref: node => {
|
|
914
978
|
sliderRef.current = node;
|
|
@@ -924,15 +988,44 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
924
988
|
role: "slider",
|
|
925
989
|
"aria-valuemin": min,
|
|
926
990
|
"aria-valuemax": max,
|
|
927
|
-
"aria-valuenow": currentValue,
|
|
928
|
-
"aria-valuetext": getAriaValueText === null || getAriaValueText === void 0 ? void 0 : getAriaValueText(currentValue),
|
|
991
|
+
"aria-valuenow": isRange ? currentValue[0] : currentValue,
|
|
929
992
|
tabIndex: disabled ? -1 : 0
|
|
930
993
|
}, props), /*#__PURE__*/React.createElement("span", {
|
|
931
994
|
style: railStyle
|
|
932
995
|
}), track !== false && /*#__PURE__*/React.createElement("span", {
|
|
933
996
|
style: trackStyle
|
|
934
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
935
|
-
style:
|
|
997
|
+
}), isRange ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
998
|
+
style: getThumbStyle(percentage[0], 0)
|
|
999
|
+
}, valueLabelDisplay === "on" || valueLabelDisplay === "auto" && isDragging && activeThumb === 0 ? /*#__PURE__*/React.createElement("span", {
|
|
1000
|
+
style: {
|
|
1001
|
+
position: "absolute",
|
|
1002
|
+
bottom: "calc(100% + 8px)",
|
|
1003
|
+
left: "50%",
|
|
1004
|
+
transform: "translateX(-50%)",
|
|
1005
|
+
padding: "4px 8px",
|
|
1006
|
+
borderRadius: "4px",
|
|
1007
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)",
|
|
1008
|
+
color: "#fff",
|
|
1009
|
+
fontSize: "12px",
|
|
1010
|
+
whiteSpace: "nowrap"
|
|
1011
|
+
}
|
|
1012
|
+
}, formatDisplayValue(currentValue[0])) : null), /*#__PURE__*/React.createElement("span", {
|
|
1013
|
+
style: getThumbStyle(percentage[1], 1)
|
|
1014
|
+
}, valueLabelDisplay === "on" || valueLabelDisplay === "auto" && isDragging && activeThumb === 1 ? /*#__PURE__*/React.createElement("span", {
|
|
1015
|
+
style: {
|
|
1016
|
+
position: "absolute",
|
|
1017
|
+
bottom: "calc(100% + 8px)",
|
|
1018
|
+
left: "50%",
|
|
1019
|
+
transform: "translateX(-50%)",
|
|
1020
|
+
padding: "4px 8px",
|
|
1021
|
+
borderRadius: "4px",
|
|
1022
|
+
backgroundColor: "rgba(0, 0, 0, 0.87)",
|
|
1023
|
+
color: "#fff",
|
|
1024
|
+
fontSize: "12px",
|
|
1025
|
+
whiteSpace: "nowrap"
|
|
1026
|
+
}
|
|
1027
|
+
}, formatDisplayValue(currentValue[1])) : null)) : /*#__PURE__*/React.createElement("span", {
|
|
1028
|
+
style: getThumbStyle(percentage, 0)
|
|
936
1029
|
}, valueLabelDisplay === "on" && /*#__PURE__*/React.createElement("span", {
|
|
937
1030
|
style: {
|
|
938
1031
|
position: "absolute",
|
|
@@ -946,7 +1039,7 @@ const BaseSlider = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
946
1039
|
fontSize: "12px",
|
|
947
1040
|
whiteSpace: "nowrap"
|
|
948
1041
|
}
|
|
949
|
-
},
|
|
1042
|
+
}, formatDisplayValue(currentValue))), renderMarks());
|
|
950
1043
|
});
|
|
951
1044
|
BaseSlider.displayName = "BaseSlider";
|
|
952
1045
|
const Slider = withSx(BaseSlider);
|
|
@@ -183,8 +183,8 @@ const BaseText = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
183
183
|
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "notblack") return "#FFFFFF";
|
|
184
184
|
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "notblack.main") return "#FFFFFF"; // Hardcode plain white / black detection
|
|
185
185
|
|
|
186
|
-
if (colorValue.toLowerCase() === "white") return "#FFFFFF";
|
|
187
|
-
if (colorValue.toLowerCase() === "black") return "#000000"; // Handle "white.override" or similar
|
|
186
|
+
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "white") return "#FFFFFF";
|
|
187
|
+
if ((colorValue === null || colorValue === void 0 ? void 0 : colorValue.toLowerCase()) === "black") return "#000000"; // Handle "white.override" or similar
|
|
188
188
|
|
|
189
189
|
if (colorValue === "white.override" || colorValue === "whiteOverride") {
|
|
190
190
|
var _colors$whiteOverride;
|