@nutui/nutui-react 2.3.7 → 2.3.8
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/CHANGELOG.md +23 -0
- package/dist/esm/Address/style/style.css +1 -1
- package/dist/esm/Cascader/style/style.css +1 -1
- package/dist/esm/NavBar/style/style.css +1 -1
- package/dist/esm/NavBar.js +49 -5
- package/dist/esm/Picker.js +1 -13
- package/dist/esm/RadioGroup.js +3 -2
- package/dist/esm/Rate/style/style.css +1 -1
- package/dist/esm/Rate.js +90 -4
- package/dist/esm/Step/style/style.css +1 -1
- package/dist/esm/Step.js +1 -1
- package/dist/esm/Steps/style/style.css +1 -1
- package/dist/esm/Swiper.js +26 -22
- package/dist/esm/Tabs/style/style.css +1 -1
- package/dist/esm/radio2.js +4 -4
- package/dist/esm/types/src/packages/navbar/navbar.taro.d.ts +2 -1
- package/dist/esm/types/src/packages/radio/index.d.ts +2 -1
- package/dist/esm/types/src/packages/radio/index.taro.d.ts +2 -1
- package/dist/esm/types/src/packages/radio/radio.d.ts +1 -2
- package/dist/esm/types/src/packages/radio/radio.taro.d.ts +1 -2
- package/dist/esm/types/src/packages/radio/types.d.ts +2 -0
- package/dist/esm/types/src/packages/radiogroup/context.d.ts +2 -0
- package/dist/esm/types/src/packages/radiogroup/index.d.ts +1 -0
- package/dist/esm/types/src/packages/radiogroup/index.taro.d.ts +1 -0
- package/dist/esm/types/src/packages/radiogroup/radiogroup.d.ts +4 -6
- package/dist/esm/types/src/packages/radiogroup/radiogroup.taro.d.ts +4 -6
- package/dist/esm/types/src/packages/radiogroup/types.d.ts +4 -0
- package/dist/esm/types/src/packages/rate/rate.d.ts +2 -0
- package/dist/esm/types/src/packages/rate/rate.taro.d.ts +2 -0
- package/dist/esm/types/src/packages/video/video.taro.d.ts +4 -5
- package/dist/esm/use-refs.js +17 -0
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +162 -43
- package/dist/nutui.react.umd.js +162 -43
- package/dist/packages/navbar/navbar.scss +7 -0
- package/dist/packages/rate/rate.scss +6 -0
- package/dist/packages/step/step.scss +5 -4
- package/dist/packages/tabs/tabs.scss +1 -0
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/types/packages/navbar/navbar.taro.d.ts +2 -1
- package/dist/types/packages/overlay/overlay.d.ts +5 -1
- package/dist/types/packages/radio/index.d.ts +2 -1
- package/dist/types/packages/radio/index.taro.d.ts +2 -1
- package/dist/types/packages/radio/radio.d.ts +1 -2
- package/dist/types/packages/radio/radio.taro.d.ts +1 -2
- package/dist/types/packages/radio/types.d.ts +2 -0
- package/dist/types/packages/radiogroup/context.d.ts +2 -0
- package/dist/types/packages/radiogroup/index.d.ts +1 -0
- package/dist/types/packages/radiogroup/index.taro.d.ts +1 -0
- package/dist/types/packages/radiogroup/radiogroup.d.ts +8 -6
- package/dist/types/packages/radiogroup/radiogroup.taro.d.ts +4 -6
- package/dist/types/packages/radiogroup/types.d.ts +4 -0
- package/dist/types/packages/rate/rate.d.ts +10 -0
- package/dist/types/packages/rate/rate.taro.d.ts +2 -0
- package/dist/types/packages/video/video.taro.d.ts +4 -5
- package/package.json +1 -1
package/dist/nutui.react.es.js
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
/*!
|
|
8
|
-
* @nutui/nutui-react v2.3.
|
|
8
|
+
* @nutui/nutui-react v2.3.8 Fri Jan 26 2024 15:13:59 GMT+0800 (China Standard Time)
|
|
9
9
|
* (c) 2023 @jdf2e.
|
|
10
10
|
* Released under the MIT License.
|
|
11
11
|
*/
|
|
@@ -10663,8 +10663,38 @@ const NavBar = (props) => {
|
|
|
10663
10663
|
zIndex
|
|
10664
10664
|
};
|
|
10665
10665
|
};
|
|
10666
|
+
const leftRef = useRef(null);
|
|
10667
|
+
const rightRef = useRef(null);
|
|
10668
|
+
const wrapperRef = useRef(null);
|
|
10669
|
+
const [contentWidth, setContentWidth] = useState("50%");
|
|
10670
|
+
const getNodeWidth = (node) => {
|
|
10671
|
+
if (node) {
|
|
10672
|
+
const ele = getRect(node);
|
|
10673
|
+
return ele.width;
|
|
10674
|
+
}
|
|
10675
|
+
return 0;
|
|
10676
|
+
};
|
|
10677
|
+
useEffect(() => {
|
|
10678
|
+
if (titleAlign === "left") {
|
|
10679
|
+
return;
|
|
10680
|
+
}
|
|
10681
|
+
if (!(back || left || right)) {
|
|
10682
|
+
setContentWidth("100%");
|
|
10683
|
+
return;
|
|
10684
|
+
}
|
|
10685
|
+
const leftRectWidth = getNodeWidth(leftRef == null ? void 0 : leftRef.current);
|
|
10686
|
+
const rightRectWidth = getNodeWidth(rightRef == null ? void 0 : rightRef.current);
|
|
10687
|
+
const wrapperWidth = getNodeWidth(wrapperRef == null ? void 0 : wrapperRef.current);
|
|
10688
|
+
let centerWidth = wrapperWidth / 2;
|
|
10689
|
+
if (leftRectWidth && rightRectWidth) {
|
|
10690
|
+
centerWidth = wrapperWidth - (leftRectWidth > rightRectWidth ? leftRectWidth * 2 : rightRectWidth * 2);
|
|
10691
|
+
} else {
|
|
10692
|
+
centerWidth = wrapperWidth - leftRectWidth * 2 - rightRectWidth * 2;
|
|
10693
|
+
}
|
|
10694
|
+
setContentWidth(centerWidth.toFixed(2));
|
|
10695
|
+
}, [left, right, back]);
|
|
10666
10696
|
const renderLeft = () => {
|
|
10667
|
-
return back || left ? /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-left
|
|
10697
|
+
return back || left ? /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-left`, ref: leftRef }, back && /* @__PURE__ */ React__default.createElement(
|
|
10668
10698
|
"div",
|
|
10669
10699
|
{
|
|
10670
10700
|
className: `${classPrefix2}-left-back`,
|
|
@@ -10674,13 +10704,21 @@ const NavBar = (props) => {
|
|
|
10674
10704
|
), left) : null;
|
|
10675
10705
|
};
|
|
10676
10706
|
const renderContent = () => {
|
|
10677
|
-
|
|
10707
|
+
let titleStyle = {};
|
|
10708
|
+
if (titleAlign === "center") {
|
|
10709
|
+
const contentRealWidth = `${contentWidth}${/%$/i.test(contentWidth) ? "" : "px"}`;
|
|
10710
|
+
titleStyle = {
|
|
10711
|
+
minWidth: contentRealWidth,
|
|
10712
|
+
width: contentRealWidth
|
|
10713
|
+
};
|
|
10714
|
+
}
|
|
10715
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-title`, style: titleStyle }, children);
|
|
10678
10716
|
};
|
|
10679
10717
|
const renderRight = () => {
|
|
10680
|
-
return /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-right
|
|
10718
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-right`, ref: rightRef }, right);
|
|
10681
10719
|
};
|
|
10682
10720
|
const renderWrapper = () => {
|
|
10683
|
-
return /* @__PURE__ */ React__default.createElement("div", { className: cls, style: styles() }, renderLeft(), renderContent(), renderRight());
|
|
10721
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: cls, style: styles(), ref: wrapperRef }, renderLeft(), renderContent(), renderRight());
|
|
10684
10722
|
};
|
|
10685
10723
|
const classes = classNames({
|
|
10686
10724
|
[`${classPrefix2}-fixed`]: fixed,
|
|
@@ -17198,6 +17236,7 @@ const RadioGroup = React__default.forwardRef(
|
|
|
17198
17236
|
value,
|
|
17199
17237
|
defaultValue,
|
|
17200
17238
|
onChange,
|
|
17239
|
+
shape,
|
|
17201
17240
|
labelPosition,
|
|
17202
17241
|
direction,
|
|
17203
17242
|
options: options2,
|
|
@@ -17233,6 +17272,7 @@ const RadioGroup = React__default.forwardRef(
|
|
|
17233
17272
|
value: {
|
|
17234
17273
|
labelPosition: labelPosition || "right",
|
|
17235
17274
|
disabled,
|
|
17275
|
+
shape,
|
|
17236
17276
|
value: val2State,
|
|
17237
17277
|
check: (value2) => {
|
|
17238
17278
|
setVal2State(value2);
|
|
@@ -17360,11 +17400,11 @@ const Radio = (props) => {
|
|
|
17360
17400
|
className: classNames(color())
|
|
17361
17401
|
}) : /* @__PURE__ */ React__default.createElement(o$7, { className: classNames(color()) });
|
|
17362
17402
|
};
|
|
17403
|
+
const renderByShape = (shape2) => {
|
|
17404
|
+
return shape2 === "button" ? renderButton() : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, renderIcon(), renderLabel());
|
|
17405
|
+
};
|
|
17363
17406
|
const renderRadioItem = () => {
|
|
17364
|
-
|
|
17365
|
-
return renderButton();
|
|
17366
|
-
}
|
|
17367
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, renderIcon(), renderLabel());
|
|
17407
|
+
return renderByShape(context && context.shape ? context.shape : shape);
|
|
17368
17408
|
};
|
|
17369
17409
|
const handleClick2 = (e2) => {
|
|
17370
17410
|
if (disabled || checkedStatement)
|
|
@@ -17706,7 +17746,8 @@ const defaultProps$N = {
|
|
|
17706
17746
|
uncheckedIcon: null,
|
|
17707
17747
|
disabled: false,
|
|
17708
17748
|
readOnly: false,
|
|
17709
|
-
allowHalf: false
|
|
17749
|
+
allowHalf: false,
|
|
17750
|
+
touchable: false
|
|
17710
17751
|
};
|
|
17711
17752
|
const Rate = (props) => {
|
|
17712
17753
|
const {
|
|
@@ -17721,13 +17762,17 @@ const Rate = (props) => {
|
|
|
17721
17762
|
disabled,
|
|
17722
17763
|
readOnly,
|
|
17723
17764
|
allowHalf,
|
|
17724
|
-
|
|
17765
|
+
touchable,
|
|
17766
|
+
onChange,
|
|
17767
|
+
onTouchEnd
|
|
17725
17768
|
} = {
|
|
17726
17769
|
...defaultProps$N,
|
|
17727
17770
|
...props
|
|
17728
17771
|
};
|
|
17729
17772
|
const classPrefix2 = "nut-rate";
|
|
17730
17773
|
const [countArray, setCountArray] = useState([1, 2, 3, 4, 5]);
|
|
17774
|
+
const [refs, setRefs] = useRefs();
|
|
17775
|
+
const rateRects = useRef([]);
|
|
17731
17776
|
const [score, setScore] = usePropsValue({
|
|
17732
17777
|
value,
|
|
17733
17778
|
defaultValue: Math.max(defaultValue || 0, min),
|
|
@@ -17764,6 +17809,81 @@ const Rate = (props) => {
|
|
|
17764
17809
|
const value2 = Math.max(min, n - 0.5);
|
|
17765
17810
|
setScore(value2);
|
|
17766
17811
|
};
|
|
17812
|
+
const getScoreByPosition = (x) => {
|
|
17813
|
+
var _a2;
|
|
17814
|
+
if ((_a2 = rateRects.current) == null ? void 0 : _a2.length) {
|
|
17815
|
+
for (let index = rateRects.current.length - 1; index >= 0; index--) {
|
|
17816
|
+
const item = rateRects.current[index];
|
|
17817
|
+
if (item && x > item.left) {
|
|
17818
|
+
return allowHalf ? index + (x > item.left + item.width / 2 ? 1 : 0.5) : index + 1;
|
|
17819
|
+
}
|
|
17820
|
+
}
|
|
17821
|
+
return 0;
|
|
17822
|
+
}
|
|
17823
|
+
};
|
|
17824
|
+
const updateRects = () => {
|
|
17825
|
+
for (let index = 0; index < refs.length; index++) {
|
|
17826
|
+
const item = refs[index];
|
|
17827
|
+
if (item) {
|
|
17828
|
+
rateRects.current[index] = getRect(item);
|
|
17829
|
+
}
|
|
17830
|
+
}
|
|
17831
|
+
};
|
|
17832
|
+
const handleTouchStart = (e2) => {
|
|
17833
|
+
if (!touchable || readOnly || disabled) {
|
|
17834
|
+
return;
|
|
17835
|
+
}
|
|
17836
|
+
if (e2.cancelable) {
|
|
17837
|
+
e2.preventDefault();
|
|
17838
|
+
}
|
|
17839
|
+
e2.stopPropagation();
|
|
17840
|
+
updateRects();
|
|
17841
|
+
};
|
|
17842
|
+
const handleTouchMove = (e2) => {
|
|
17843
|
+
if (!touchable || readOnly || disabled) {
|
|
17844
|
+
return;
|
|
17845
|
+
}
|
|
17846
|
+
if (e2.cancelable) {
|
|
17847
|
+
e2.preventDefault();
|
|
17848
|
+
}
|
|
17849
|
+
e2.stopPropagation();
|
|
17850
|
+
const val = getScoreByPosition(e2.touches[0].clientX);
|
|
17851
|
+
if (val !== void 0) {
|
|
17852
|
+
setScore(Math.max(min, val));
|
|
17853
|
+
}
|
|
17854
|
+
};
|
|
17855
|
+
const handleTouchEnd = (e2) => {
|
|
17856
|
+
if (!touchable || readOnly || disabled) {
|
|
17857
|
+
return;
|
|
17858
|
+
}
|
|
17859
|
+
if (e2.cancelable) {
|
|
17860
|
+
e2.preventDefault();
|
|
17861
|
+
}
|
|
17862
|
+
e2.stopPropagation();
|
|
17863
|
+
const val = getScoreByPosition(e2.changedTouches[0].clientX);
|
|
17864
|
+
if (val !== void 0) {
|
|
17865
|
+
setScore(Math.max(min, val));
|
|
17866
|
+
onTouchEnd && onTouchEnd(e2, Math.max(min, val));
|
|
17867
|
+
}
|
|
17868
|
+
};
|
|
17869
|
+
const rateRef = useRef(null);
|
|
17870
|
+
useEffect(() => {
|
|
17871
|
+
const element = rateRef.current;
|
|
17872
|
+
if (element) {
|
|
17873
|
+
element.addEventListener("touchstart", handleTouchStart, {
|
|
17874
|
+
passive: false
|
|
17875
|
+
});
|
|
17876
|
+
element.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
17877
|
+
element.addEventListener("touchend", handleTouchEnd, { passive: false });
|
|
17878
|
+
}
|
|
17879
|
+
return () => {
|
|
17880
|
+
if (element) {
|
|
17881
|
+
element.removeEventListener("touchstart", handleTouchStart);
|
|
17882
|
+
element.removeEventListener("touchmove", handleTouchMove);
|
|
17883
|
+
element.removeEventListener("touchend", handleTouchEnd);
|
|
17884
|
+
}
|
|
17885
|
+
};
|
|
17886
|
+
}, []);
|
|
17767
17887
|
return /* @__PURE__ */ React__default.createElement(
|
|
17768
17888
|
"div",
|
|
17769
17889
|
{
|
|
@@ -17775,14 +17895,16 @@ const Rate = (props) => {
|
|
|
17775
17895
|
},
|
|
17776
17896
|
className
|
|
17777
17897
|
),
|
|
17898
|
+
ref: rateRef,
|
|
17778
17899
|
style
|
|
17779
17900
|
},
|
|
17780
|
-
countArray.map((n) => {
|
|
17901
|
+
countArray.map((n, index) => {
|
|
17781
17902
|
return /* @__PURE__ */ React__default.createElement(
|
|
17782
17903
|
"div",
|
|
17783
17904
|
{
|
|
17784
17905
|
className: `${classPrefix2}-item`,
|
|
17785
17906
|
key: n,
|
|
17907
|
+
ref: setRefs(index),
|
|
17786
17908
|
onClick: (event) => onClick(event, n)
|
|
17787
17909
|
},
|
|
17788
17910
|
/* @__PURE__ */ React__default.createElement(
|
|
@@ -22719,10 +22841,12 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22719
22841
|
resetPosition();
|
|
22720
22842
|
touch.reset();
|
|
22721
22843
|
requestAniFrame$1(() => {
|
|
22722
|
-
|
|
22723
|
-
|
|
22724
|
-
|
|
22725
|
-
|
|
22844
|
+
requestAniFrame$1(() => {
|
|
22845
|
+
swiperRef.current.moving = false;
|
|
22846
|
+
move({
|
|
22847
|
+
pace: -1,
|
|
22848
|
+
isEmit: true
|
|
22849
|
+
});
|
|
22726
22850
|
});
|
|
22727
22851
|
});
|
|
22728
22852
|
};
|
|
@@ -22730,10 +22854,12 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22730
22854
|
resetPosition();
|
|
22731
22855
|
touch.reset();
|
|
22732
22856
|
requestAniFrame$1(() => {
|
|
22733
|
-
|
|
22734
|
-
|
|
22735
|
-
|
|
22736
|
-
|
|
22857
|
+
requestAniFrame$1(() => {
|
|
22858
|
+
swiperRef.current.moving = false;
|
|
22859
|
+
move({
|
|
22860
|
+
pace: 1,
|
|
22861
|
+
isEmit: true
|
|
22862
|
+
});
|
|
22737
22863
|
});
|
|
22738
22864
|
});
|
|
22739
22865
|
};
|
|
@@ -22741,16 +22867,18 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22741
22867
|
resetPosition();
|
|
22742
22868
|
touch.reset();
|
|
22743
22869
|
requestAniFrame$1(() => {
|
|
22744
|
-
|
|
22745
|
-
|
|
22746
|
-
|
|
22747
|
-
|
|
22748
|
-
|
|
22749
|
-
|
|
22750
|
-
|
|
22751
|
-
|
|
22752
|
-
|
|
22753
|
-
|
|
22870
|
+
requestAniFrame$1(() => {
|
|
22871
|
+
swiperRef.current.moving = false;
|
|
22872
|
+
let targetIndex;
|
|
22873
|
+
if (props.loop && swiperItemCount === index) {
|
|
22874
|
+
targetIndex = active === 0 ? 0 : index;
|
|
22875
|
+
} else {
|
|
22876
|
+
targetIndex = index % swiperItemCount;
|
|
22877
|
+
}
|
|
22878
|
+
move({
|
|
22879
|
+
pace: targetIndex - active,
|
|
22880
|
+
isEmit: true
|
|
22881
|
+
});
|
|
22754
22882
|
});
|
|
22755
22883
|
});
|
|
22756
22884
|
};
|
|
@@ -22824,6 +22952,8 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22824
22952
|
});
|
|
22825
22953
|
const getStyle = (moveOffset = offset) => {
|
|
22826
22954
|
const target = innerRef.current;
|
|
22955
|
+
if (!target)
|
|
22956
|
+
return;
|
|
22827
22957
|
let _offset = 0;
|
|
22828
22958
|
if (!center) {
|
|
22829
22959
|
_offset = moveOffset;
|
|
@@ -22932,10 +23062,6 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22932
23062
|
}
|
|
22933
23063
|
return () => setReady(false);
|
|
22934
23064
|
}, [ready]);
|
|
22935
|
-
useEffect(() => {
|
|
22936
|
-
stopAutoPlay();
|
|
22937
|
-
startPlay();
|
|
22938
|
-
}, [children]);
|
|
22939
23065
|
useEffect(() => {
|
|
22940
23066
|
const events = [
|
|
22941
23067
|
{ name: "touchstart", e: onTouchStart },
|
|
@@ -23498,7 +23624,7 @@ const Step = (props) => {
|
|
|
23498
23624
|
}
|
|
23499
23625
|
return `${classPrefix2}-icon`;
|
|
23500
23626
|
};
|
|
23501
|
-
return /* @__PURE__ */ React__default.createElement("div", { className: classes, ...restProps, onClick: handleClickStep }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-head" }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-line" }), /* @__PURE__ */ React__default.createElement("div", { className: renderIconClass() }, icon || !dot && /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-inner" }, value))), /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-main" }, /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-title" }, title), description && /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-description" }, description)));
|
|
23627
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: classes, ...restProps, onClick: handleClickStep }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-head" }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-line" }), /* @__PURE__ */ React__default.createElement("div", { className: renderIconClass() }, icon || !dot && /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-inner" }, value))), (title || description) && /* @__PURE__ */ React__default.createElement("div", { className: "nut-step-main" }, /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-title" }, title), description && /* @__PURE__ */ React__default.createElement("span", { className: "nut-step-description" }, description)));
|
|
23502
23628
|
};
|
|
23503
23629
|
Step.defaultProps = defaultProps$c;
|
|
23504
23630
|
Step.displayName = "NutStep";
|
|
@@ -23531,14 +23657,7 @@ const Steps = (props) => {
|
|
|
23531
23657
|
},
|
|
23532
23658
|
className
|
|
23533
23659
|
);
|
|
23534
|
-
return /* @__PURE__ */ React__default.createElement(DataContext.Provider, { value: parentSteps }, React__default.createElement(
|
|
23535
|
-
"div",
|
|
23536
|
-
{
|
|
23537
|
-
className: classes,
|
|
23538
|
-
...restProps
|
|
23539
|
-
},
|
|
23540
|
-
children
|
|
23541
|
-
));
|
|
23660
|
+
return /* @__PURE__ */ React__default.createElement(DataContext.Provider, { value: parentSteps }, /* @__PURE__ */ React__default.createElement("div", { className: classes, ...restProps }, children));
|
|
23542
23661
|
};
|
|
23543
23662
|
Steps.defaultProps = defaultProps$b;
|
|
23544
23663
|
Steps.displayName = "NutSteps";
|
package/dist/nutui.react.umd.js
CHANGED
|
@@ -8,7 +8,7 @@ var __publicField = (obj, key, value) => {
|
|
|
8
8
|
return value;
|
|
9
9
|
};
|
|
10
10
|
/*!
|
|
11
|
-
* @nutui/nutui-react v2.3.
|
|
11
|
+
* @nutui/nutui-react v2.3.8 Fri Jan 26 2024 15:13:59 GMT+0800 (China Standard Time)
|
|
12
12
|
* (c) 2023 @jdf2e.
|
|
13
13
|
* Released under the MIT License.
|
|
14
14
|
*/
|
|
@@ -10681,8 +10681,38 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
10681
10681
|
zIndex
|
|
10682
10682
|
};
|
|
10683
10683
|
};
|
|
10684
|
+
const leftRef = React.useRef(null);
|
|
10685
|
+
const rightRef = React.useRef(null);
|
|
10686
|
+
const wrapperRef = React.useRef(null);
|
|
10687
|
+
const [contentWidth, setContentWidth] = React.useState("50%");
|
|
10688
|
+
const getNodeWidth = (node) => {
|
|
10689
|
+
if (node) {
|
|
10690
|
+
const ele = getRect(node);
|
|
10691
|
+
return ele.width;
|
|
10692
|
+
}
|
|
10693
|
+
return 0;
|
|
10694
|
+
};
|
|
10695
|
+
React.useEffect(() => {
|
|
10696
|
+
if (titleAlign === "left") {
|
|
10697
|
+
return;
|
|
10698
|
+
}
|
|
10699
|
+
if (!(back || left || right)) {
|
|
10700
|
+
setContentWidth("100%");
|
|
10701
|
+
return;
|
|
10702
|
+
}
|
|
10703
|
+
const leftRectWidth = getNodeWidth(leftRef == null ? void 0 : leftRef.current);
|
|
10704
|
+
const rightRectWidth = getNodeWidth(rightRef == null ? void 0 : rightRef.current);
|
|
10705
|
+
const wrapperWidth = getNodeWidth(wrapperRef == null ? void 0 : wrapperRef.current);
|
|
10706
|
+
let centerWidth = wrapperWidth / 2;
|
|
10707
|
+
if (leftRectWidth && rightRectWidth) {
|
|
10708
|
+
centerWidth = wrapperWidth - (leftRectWidth > rightRectWidth ? leftRectWidth * 2 : rightRectWidth * 2);
|
|
10709
|
+
} else {
|
|
10710
|
+
centerWidth = wrapperWidth - leftRectWidth * 2 - rightRectWidth * 2;
|
|
10711
|
+
}
|
|
10712
|
+
setContentWidth(centerWidth.toFixed(2));
|
|
10713
|
+
}, [left, right, back]);
|
|
10684
10714
|
const renderLeft = () => {
|
|
10685
|
-
return back || left ? /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}-left
|
|
10715
|
+
return back || left ? /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}-left`, ref: leftRef }, back && /* @__PURE__ */ React.createElement(
|
|
10686
10716
|
"div",
|
|
10687
10717
|
{
|
|
10688
10718
|
className: `${classPrefix2}-left-back`,
|
|
@@ -10692,13 +10722,21 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
10692
10722
|
), left) : null;
|
|
10693
10723
|
};
|
|
10694
10724
|
const renderContent = () => {
|
|
10695
|
-
|
|
10725
|
+
let titleStyle = {};
|
|
10726
|
+
if (titleAlign === "center") {
|
|
10727
|
+
const contentRealWidth = `${contentWidth}${/%$/i.test(contentWidth) ? "" : "px"}`;
|
|
10728
|
+
titleStyle = {
|
|
10729
|
+
minWidth: contentRealWidth,
|
|
10730
|
+
width: contentRealWidth
|
|
10731
|
+
};
|
|
10732
|
+
}
|
|
10733
|
+
return /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}-title`, style: titleStyle }, children);
|
|
10696
10734
|
};
|
|
10697
10735
|
const renderRight = () => {
|
|
10698
|
-
return /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}-right
|
|
10736
|
+
return /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}-right`, ref: rightRef }, right);
|
|
10699
10737
|
};
|
|
10700
10738
|
const renderWrapper = () => {
|
|
10701
|
-
return /* @__PURE__ */ React.createElement("div", { className: cls, style: styles() }, renderLeft(), renderContent(), renderRight());
|
|
10739
|
+
return /* @__PURE__ */ React.createElement("div", { className: cls, style: styles(), ref: wrapperRef }, renderLeft(), renderContent(), renderRight());
|
|
10702
10740
|
};
|
|
10703
10741
|
const classes = classNames({
|
|
10704
10742
|
[`${classPrefix2}-fixed`]: fixed,
|
|
@@ -17216,6 +17254,7 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17216
17254
|
value,
|
|
17217
17255
|
defaultValue,
|
|
17218
17256
|
onChange,
|
|
17257
|
+
shape,
|
|
17219
17258
|
labelPosition,
|
|
17220
17259
|
direction,
|
|
17221
17260
|
options: options2,
|
|
@@ -17251,6 +17290,7 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17251
17290
|
value: {
|
|
17252
17291
|
labelPosition: labelPosition || "right",
|
|
17253
17292
|
disabled,
|
|
17293
|
+
shape,
|
|
17254
17294
|
value: val2State,
|
|
17255
17295
|
check: (value2) => {
|
|
17256
17296
|
setVal2State(value2);
|
|
@@ -17378,11 +17418,11 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17378
17418
|
className: classNames(color())
|
|
17379
17419
|
}) : /* @__PURE__ */ React.createElement(o$7, { className: classNames(color()) });
|
|
17380
17420
|
};
|
|
17421
|
+
const renderByShape = (shape2) => {
|
|
17422
|
+
return shape2 === "button" ? renderButton() : /* @__PURE__ */ React.createElement(React.Fragment, null, renderIcon(), renderLabel());
|
|
17423
|
+
};
|
|
17381
17424
|
const renderRadioItem = () => {
|
|
17382
|
-
|
|
17383
|
-
return renderButton();
|
|
17384
|
-
}
|
|
17385
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, renderIcon(), renderLabel());
|
|
17425
|
+
return renderByShape(context && context.shape ? context.shape : shape);
|
|
17386
17426
|
};
|
|
17387
17427
|
const handleClick2 = (e2) => {
|
|
17388
17428
|
if (disabled || checkedStatement)
|
|
@@ -17724,7 +17764,8 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17724
17764
|
uncheckedIcon: null,
|
|
17725
17765
|
disabled: false,
|
|
17726
17766
|
readOnly: false,
|
|
17727
|
-
allowHalf: false
|
|
17767
|
+
allowHalf: false,
|
|
17768
|
+
touchable: false
|
|
17728
17769
|
};
|
|
17729
17770
|
const Rate = (props) => {
|
|
17730
17771
|
const {
|
|
@@ -17739,13 +17780,17 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17739
17780
|
disabled,
|
|
17740
17781
|
readOnly,
|
|
17741
17782
|
allowHalf,
|
|
17742
|
-
|
|
17783
|
+
touchable,
|
|
17784
|
+
onChange,
|
|
17785
|
+
onTouchEnd
|
|
17743
17786
|
} = {
|
|
17744
17787
|
...defaultProps$N,
|
|
17745
17788
|
...props
|
|
17746
17789
|
};
|
|
17747
17790
|
const classPrefix2 = "nut-rate";
|
|
17748
17791
|
const [countArray, setCountArray] = React.useState([1, 2, 3, 4, 5]);
|
|
17792
|
+
const [refs, setRefs] = useRefs();
|
|
17793
|
+
const rateRects = React.useRef([]);
|
|
17749
17794
|
const [score, setScore] = usePropsValue({
|
|
17750
17795
|
value,
|
|
17751
17796
|
defaultValue: Math.max(defaultValue || 0, min),
|
|
@@ -17782,6 +17827,81 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17782
17827
|
const value2 = Math.max(min, n - 0.5);
|
|
17783
17828
|
setScore(value2);
|
|
17784
17829
|
};
|
|
17830
|
+
const getScoreByPosition = (x) => {
|
|
17831
|
+
var _a2;
|
|
17832
|
+
if ((_a2 = rateRects.current) == null ? void 0 : _a2.length) {
|
|
17833
|
+
for (let index = rateRects.current.length - 1; index >= 0; index--) {
|
|
17834
|
+
const item = rateRects.current[index];
|
|
17835
|
+
if (item && x > item.left) {
|
|
17836
|
+
return allowHalf ? index + (x > item.left + item.width / 2 ? 1 : 0.5) : index + 1;
|
|
17837
|
+
}
|
|
17838
|
+
}
|
|
17839
|
+
return 0;
|
|
17840
|
+
}
|
|
17841
|
+
};
|
|
17842
|
+
const updateRects = () => {
|
|
17843
|
+
for (let index = 0; index < refs.length; index++) {
|
|
17844
|
+
const item = refs[index];
|
|
17845
|
+
if (item) {
|
|
17846
|
+
rateRects.current[index] = getRect(item);
|
|
17847
|
+
}
|
|
17848
|
+
}
|
|
17849
|
+
};
|
|
17850
|
+
const handleTouchStart = (e2) => {
|
|
17851
|
+
if (!touchable || readOnly || disabled) {
|
|
17852
|
+
return;
|
|
17853
|
+
}
|
|
17854
|
+
if (e2.cancelable) {
|
|
17855
|
+
e2.preventDefault();
|
|
17856
|
+
}
|
|
17857
|
+
e2.stopPropagation();
|
|
17858
|
+
updateRects();
|
|
17859
|
+
};
|
|
17860
|
+
const handleTouchMove = (e2) => {
|
|
17861
|
+
if (!touchable || readOnly || disabled) {
|
|
17862
|
+
return;
|
|
17863
|
+
}
|
|
17864
|
+
if (e2.cancelable) {
|
|
17865
|
+
e2.preventDefault();
|
|
17866
|
+
}
|
|
17867
|
+
e2.stopPropagation();
|
|
17868
|
+
const val = getScoreByPosition(e2.touches[0].clientX);
|
|
17869
|
+
if (val !== void 0) {
|
|
17870
|
+
setScore(Math.max(min, val));
|
|
17871
|
+
}
|
|
17872
|
+
};
|
|
17873
|
+
const handleTouchEnd = (e2) => {
|
|
17874
|
+
if (!touchable || readOnly || disabled) {
|
|
17875
|
+
return;
|
|
17876
|
+
}
|
|
17877
|
+
if (e2.cancelable) {
|
|
17878
|
+
e2.preventDefault();
|
|
17879
|
+
}
|
|
17880
|
+
e2.stopPropagation();
|
|
17881
|
+
const val = getScoreByPosition(e2.changedTouches[0].clientX);
|
|
17882
|
+
if (val !== void 0) {
|
|
17883
|
+
setScore(Math.max(min, val));
|
|
17884
|
+
onTouchEnd && onTouchEnd(e2, Math.max(min, val));
|
|
17885
|
+
}
|
|
17886
|
+
};
|
|
17887
|
+
const rateRef = React.useRef(null);
|
|
17888
|
+
React.useEffect(() => {
|
|
17889
|
+
const element = rateRef.current;
|
|
17890
|
+
if (element) {
|
|
17891
|
+
element.addEventListener("touchstart", handleTouchStart, {
|
|
17892
|
+
passive: false
|
|
17893
|
+
});
|
|
17894
|
+
element.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
17895
|
+
element.addEventListener("touchend", handleTouchEnd, { passive: false });
|
|
17896
|
+
}
|
|
17897
|
+
return () => {
|
|
17898
|
+
if (element) {
|
|
17899
|
+
element.removeEventListener("touchstart", handleTouchStart);
|
|
17900
|
+
element.removeEventListener("touchmove", handleTouchMove);
|
|
17901
|
+
element.removeEventListener("touchend", handleTouchEnd);
|
|
17902
|
+
}
|
|
17903
|
+
};
|
|
17904
|
+
}, []);
|
|
17785
17905
|
return /* @__PURE__ */ React.createElement(
|
|
17786
17906
|
"div",
|
|
17787
17907
|
{
|
|
@@ -17793,14 +17913,16 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
17793
17913
|
},
|
|
17794
17914
|
className
|
|
17795
17915
|
),
|
|
17916
|
+
ref: rateRef,
|
|
17796
17917
|
style
|
|
17797
17918
|
},
|
|
17798
|
-
countArray.map((n) => {
|
|
17919
|
+
countArray.map((n, index) => {
|
|
17799
17920
|
return /* @__PURE__ */ React.createElement(
|
|
17800
17921
|
"div",
|
|
17801
17922
|
{
|
|
17802
17923
|
className: `${classPrefix2}-item`,
|
|
17803
17924
|
key: n,
|
|
17925
|
+
ref: setRefs(index),
|
|
17804
17926
|
onClick: (event) => onClick(event, n)
|
|
17805
17927
|
},
|
|
17806
17928
|
/* @__PURE__ */ React.createElement(
|
|
@@ -22737,10 +22859,12 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
22737
22859
|
resetPosition();
|
|
22738
22860
|
touch.reset();
|
|
22739
22861
|
requestAniFrame$1(() => {
|
|
22740
|
-
|
|
22741
|
-
|
|
22742
|
-
|
|
22743
|
-
|
|
22862
|
+
requestAniFrame$1(() => {
|
|
22863
|
+
swiperRef.current.moving = false;
|
|
22864
|
+
move({
|
|
22865
|
+
pace: -1,
|
|
22866
|
+
isEmit: true
|
|
22867
|
+
});
|
|
22744
22868
|
});
|
|
22745
22869
|
});
|
|
22746
22870
|
};
|
|
@@ -22748,10 +22872,12 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
22748
22872
|
resetPosition();
|
|
22749
22873
|
touch.reset();
|
|
22750
22874
|
requestAniFrame$1(() => {
|
|
22751
|
-
|
|
22752
|
-
|
|
22753
|
-
|
|
22754
|
-
|
|
22875
|
+
requestAniFrame$1(() => {
|
|
22876
|
+
swiperRef.current.moving = false;
|
|
22877
|
+
move({
|
|
22878
|
+
pace: 1,
|
|
22879
|
+
isEmit: true
|
|
22880
|
+
});
|
|
22755
22881
|
});
|
|
22756
22882
|
});
|
|
22757
22883
|
};
|
|
@@ -22759,16 +22885,18 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
22759
22885
|
resetPosition();
|
|
22760
22886
|
touch.reset();
|
|
22761
22887
|
requestAniFrame$1(() => {
|
|
22762
|
-
|
|
22763
|
-
|
|
22764
|
-
|
|
22765
|
-
|
|
22766
|
-
|
|
22767
|
-
|
|
22768
|
-
|
|
22769
|
-
|
|
22770
|
-
|
|
22771
|
-
|
|
22888
|
+
requestAniFrame$1(() => {
|
|
22889
|
+
swiperRef.current.moving = false;
|
|
22890
|
+
let targetIndex;
|
|
22891
|
+
if (props.loop && swiperItemCount === index) {
|
|
22892
|
+
targetIndex = active === 0 ? 0 : index;
|
|
22893
|
+
} else {
|
|
22894
|
+
targetIndex = index % swiperItemCount;
|
|
22895
|
+
}
|
|
22896
|
+
move({
|
|
22897
|
+
pace: targetIndex - active,
|
|
22898
|
+
isEmit: true
|
|
22899
|
+
});
|
|
22772
22900
|
});
|
|
22773
22901
|
});
|
|
22774
22902
|
};
|
|
@@ -22842,6 +22970,8 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
22842
22970
|
});
|
|
22843
22971
|
const getStyle = (moveOffset = offset) => {
|
|
22844
22972
|
const target = innerRef.current;
|
|
22973
|
+
if (!target)
|
|
22974
|
+
return;
|
|
22845
22975
|
let _offset = 0;
|
|
22846
22976
|
if (!center) {
|
|
22847
22977
|
_offset = moveOffset;
|
|
@@ -22950,10 +23080,6 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
22950
23080
|
}
|
|
22951
23081
|
return () => setReady(false);
|
|
22952
23082
|
}, [ready]);
|
|
22953
|
-
React.useEffect(() => {
|
|
22954
|
-
stopAutoPlay();
|
|
22955
|
-
startPlay();
|
|
22956
|
-
}, [children]);
|
|
22957
23083
|
React.useEffect(() => {
|
|
22958
23084
|
const events = [
|
|
22959
23085
|
{ name: "touchstart", e: onTouchStart },
|
|
@@ -23516,7 +23642,7 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
23516
23642
|
}
|
|
23517
23643
|
return `${classPrefix2}-icon`;
|
|
23518
23644
|
};
|
|
23519
|
-
return /* @__PURE__ */ React.createElement("div", { className: classes, ...restProps, onClick: handleClickStep }, /* @__PURE__ */ React.createElement("div", { className: "nut-step-head" }, /* @__PURE__ */ React.createElement("div", { className: "nut-step-line" }), /* @__PURE__ */ React.createElement("div", { className: renderIconClass() }, icon || !dot && /* @__PURE__ */ React.createElement("span", { className: "nut-step-inner" }, value))), /* @__PURE__ */ React.createElement("div", { className: "nut-step-main" }, /* @__PURE__ */ React.createElement("span", { className: "nut-step-title" }, title), description && /* @__PURE__ */ React.createElement("span", { className: "nut-step-description" }, description)));
|
|
23645
|
+
return /* @__PURE__ */ React.createElement("div", { className: classes, ...restProps, onClick: handleClickStep }, /* @__PURE__ */ React.createElement("div", { className: "nut-step-head" }, /* @__PURE__ */ React.createElement("div", { className: "nut-step-line" }), /* @__PURE__ */ React.createElement("div", { className: renderIconClass() }, icon || !dot && /* @__PURE__ */ React.createElement("span", { className: "nut-step-inner" }, value))), (title || description) && /* @__PURE__ */ React.createElement("div", { className: "nut-step-main" }, /* @__PURE__ */ React.createElement("span", { className: "nut-step-title" }, title), description && /* @__PURE__ */ React.createElement("span", { className: "nut-step-description" }, description)));
|
|
23520
23646
|
};
|
|
23521
23647
|
Step.defaultProps = defaultProps$c;
|
|
23522
23648
|
Step.displayName = "NutStep";
|
|
@@ -23549,14 +23675,7 @@ Please add \`${key}Action\` when creating your handler.`);
|
|
|
23549
23675
|
},
|
|
23550
23676
|
className
|
|
23551
23677
|
);
|
|
23552
|
-
return /* @__PURE__ */ React.createElement(DataContext.Provider, { value: parentSteps }, React.createElement(
|
|
23553
|
-
"div",
|
|
23554
|
-
{
|
|
23555
|
-
className: classes,
|
|
23556
|
-
...restProps
|
|
23557
|
-
},
|
|
23558
|
-
children
|
|
23559
|
-
));
|
|
23678
|
+
return /* @__PURE__ */ React.createElement(DataContext.Provider, { value: parentSteps }, /* @__PURE__ */ React.createElement("div", { className: classes, ...restProps }, children));
|
|
23560
23679
|
};
|
|
23561
23680
|
Steps.defaultProps = defaultProps$b;
|
|
23562
23681
|
Steps.displayName = "NutSteps";
|