@nutui/nutui-react-taro 2.0.2 → 2.0.3-beta.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/esm/Avatar.js +3 -3
  3. package/dist/esm/Calendar.js +2 -2
  4. package/dist/esm/CalendarItem.js +1 -1
  5. package/dist/esm/Image.js +3 -2
  6. package/dist/esm/InputNumber/style/style.css +1 -1
  7. package/dist/esm/Menu/style/style.css +1 -1
  8. package/dist/esm/Menu.js +3 -3
  9. package/dist/esm/MenuItem/style/style.css +1 -1
  10. package/dist/esm/MenuItem.js +2 -2
  11. package/dist/esm/Skeleton.js +4 -4
  12. package/dist/esm/{avatar.taro-31362306.js → avatar.taro-a45e2e71.js} +2 -2
  13. package/dist/esm/{calendar.taro-1fbc673a.js → calendar.taro-ac2a1c47.js} +1 -1
  14. package/dist/esm/{calendaritem.taro-39463c08.js → calendaritem.taro-1af09287.js} +2 -2
  15. package/dist/esm/image.taro-c4be8323.js +81 -0
  16. package/dist/esm/{menu.taro-6450a3ae.js → menu.taro-f412b55d.js} +14 -3
  17. package/dist/esm/{menuitem.taro-11bd648e.js → menuitem.taro-f145c755.js} +41 -27
  18. package/dist/esm/nutui-react.es.js +8 -8
  19. package/dist/esm/{skeleton.taro-49046def.js → skeleton.taro-9ac4b4b8.js} +1 -1
  20. package/dist/esm/types/src/packages/configprovider/types.d.ts +1 -1
  21. package/dist/esm/types/src/packages/image/image.taro.d.ts +9 -21
  22. package/dist/esm/types/src/packages/menu/menu.d.ts +2 -0
  23. package/dist/esm/types/src/packages/menu/menu.taro.d.ts +2 -0
  24. package/dist/locales/base.js +1 -1
  25. package/dist/locales/en-US.js +1 -1
  26. package/dist/locales/id-ID.js +1 -1
  27. package/dist/locales/tr-TR.js +1 -1
  28. package/dist/locales/zh-CN.js +1 -1
  29. package/dist/locales/zh-TW.js +1 -1
  30. package/dist/locales/zh-UG.js +1 -1
  31. package/dist/nutui.react.es.js +162 -156
  32. package/dist/nutui.react.umd.js +161 -155
  33. package/dist/packages/menuitem/menuitem.scss +2 -2
  34. package/dist/style.css +1 -1
  35. package/dist/style.mjs +1 -1
  36. package/dist/styles/variables-jmapp.scss +1 -0
  37. package/dist/styles/variables.scss +2 -1
  38. package/dist/types/index.d.ts +92 -0
  39. package/dist/types/packages/configprovider/types.d.ts +1 -1
  40. package/dist/types/packages/image/image.taro.d.ts +30 -22
  41. package/dist/types/packages/menu/menu.taro.d.ts +2 -0
  42. package/package.json +1 -1
  43. package/dist/esm/image.taro-567edf0f.js +0 -65
@@ -8,7 +8,7 @@ var __publicField = (obj, key, value) => {
8
8
  return value;
9
9
  };
10
10
  /*!
11
- * @nutui/nutui-react-taro v2.0.2 Fri Jul 07 2023 13:52:14 GMT+0800 (China Standard Time)
11
+ * @nutui/nutui-react-taro v2.0.3 Wed Jul 12 2023 17:55:25 GMT+0800 (China Standard Time)
12
12
  * (c) 2023 @jdf2e.
13
13
  * Released under the MIT License.
14
14
  */
@@ -2489,94 +2489,84 @@ var __publicField = (obj, key, value) => {
2489
2489
  ConfigProvider.defaultProps = defaultProps$1p;
2490
2490
  ConfigProvider.displayName = "NutConfigProvider";
2491
2491
  const defaultProps$1o = {
2492
- fit: "fill",
2493
- position: "center",
2494
- alt: "",
2495
- width: "center",
2496
- height: "",
2497
- round: false,
2498
- showError: true,
2499
- showLoading: true
2492
+ src: "",
2493
+ error: true,
2494
+ loading: true
2500
2495
  };
2501
2496
  const Image$1 = (props) => {
2502
- useConfig();
2497
+ const classPrefix2 = "nut-image";
2503
2498
  const {
2504
- children,
2505
2499
  className,
2506
2500
  style,
2507
2501
  src,
2508
- fit,
2509
- position,
2510
- alt,
2511
2502
  width,
2512
2503
  height,
2513
- round,
2514
2504
  radius,
2515
- showError,
2516
- showLoading,
2517
- slotError,
2518
- slotLoding,
2519
- onClick,
2505
+ error,
2506
+ loading,
2520
2507
  onLoad,
2521
- onError
2508
+ onError,
2509
+ ...rest
2522
2510
  } = { ...defaultProps$1o, ...props };
2523
- const [loading, setLoading] = React.useState(true);
2511
+ const [innerLoading, setInnerLoading] = React.useState(true);
2524
2512
  const [isError, setIsError] = React.useState(false);
2525
- React.useEffect(() => {
2513
+ const handleLoad = (e) => {
2514
+ setIsError(false);
2515
+ setInnerLoading(false);
2516
+ onLoad && onLoad(e);
2517
+ };
2518
+ const handleError = (e) => {
2526
2519
  if (src) {
2527
- setIsError(false);
2528
- setLoading(true);
2520
+ setIsError(true);
2521
+ setInnerLoading(false);
2522
+ onError && onError(e);
2529
2523
  }
2530
- }, [src]);
2531
- const load = () => {
2532
- setLoading(false);
2533
- onLoad && onLoad();
2534
- };
2535
- const error = () => {
2536
- setIsError(true);
2537
- setLoading(false);
2538
- onError && onError();
2539
2524
  };
2540
2525
  const pxCheck2 = (value) => {
2541
2526
  return Number.isNaN(Number(value)) ? String(value) : `${value}px`;
2542
2527
  };
2543
- const stylebox = {
2528
+ const containerStyle = {
2544
2529
  height: height ? pxCheck2(height) : "",
2545
2530
  width: width ? pxCheck2(width) : "",
2546
2531
  overflow: radius !== void 0 && radius !== null ? "hidden" : "",
2547
2532
  borderRadius: radius !== void 0 && radius !== null ? pxCheck2(radius) : ""
2548
2533
  };
2549
- const styles = {
2550
- objectFit: fit,
2551
- objectPosition: position,
2534
+ const imgStyle = {
2552
2535
  ...style
2553
2536
  };
2554
- const imageClick = (event) => {
2555
- onClick && onClick(event);
2556
- };
2557
- return /* @__PURE__ */ React.createElement(
2558
- "div",
2537
+ const renderErrorImg = React.useCallback(() => {
2538
+ if (!isError)
2539
+ return null;
2540
+ if (typeof error === "boolean" && error === true && !innerLoading) {
2541
+ return /* @__PURE__ */ React.createElement("div", { className: "nut-img-error" }, /* @__PURE__ */ React.createElement(a$l, null));
2542
+ }
2543
+ if (React.isValidElement(error) && !innerLoading) {
2544
+ return /* @__PURE__ */ React.createElement("div", { className: "nut-img-error" }, error);
2545
+ }
2546
+ return null;
2547
+ }, [error, isError]);
2548
+ const renderLoading = React.useCallback(() => {
2549
+ if (!loading)
2550
+ return null;
2551
+ if (typeof loading === "boolean" && loading === true && innerLoading) {
2552
+ return /* @__PURE__ */ React.createElement("div", { className: "nut-img-loading" }, /* @__PURE__ */ React.createElement(r$k, null));
2553
+ }
2554
+ if (React.isValidElement(loading) && innerLoading) {
2555
+ return /* @__PURE__ */ React.createElement("div", { className: "nut-img-loading" }, loading);
2556
+ }
2557
+ return null;
2558
+ }, [loading, innerLoading]);
2559
+ return /* @__PURE__ */ React.createElement("div", { className: classNames(classPrefix2, className), style: containerStyle }, /* @__PURE__ */ React.createElement(
2560
+ components.Image,
2559
2561
  {
2560
- className: `nut-image ${round ? "nut-image-round" : ""}`,
2561
- style: stylebox,
2562
- onClick: (e) => {
2563
- imageClick(e);
2564
- }
2565
- },
2566
- /* @__PURE__ */ React.createElement(
2567
- "img",
2568
- {
2569
- className: "nut-img",
2570
- style: styles,
2571
- src,
2572
- alt,
2573
- onLoad: load,
2574
- onError: error
2575
- }
2576
- ),
2577
- showLoading && loading ? /* @__PURE__ */ React.createElement("div", { className: "nut-img-loading" }, slotLoding || children || /* @__PURE__ */ React.createElement(r$k, null)) : null,
2578
- showError && isError && !loading ? /* @__PURE__ */ React.createElement("div", { className: "nut-img-error" }, slotError || children || /* @__PURE__ */ React.createElement(a$l, null)) : null
2579
- );
2562
+ ...rest,
2563
+ className: "nut-img",
2564
+ style: imgStyle,
2565
+ src,
2566
+ onLoad: (e) => handleLoad(e),
2567
+ onError: (e) => handleError(e)
2568
+ }
2569
+ ), renderLoading(), renderErrorImg());
2580
2570
  };
2581
2571
  Image$1.defaultProps = defaultProps$1o;
2582
2572
  Image$1.displayName = "NutImage";
@@ -6965,9 +6955,9 @@ var __publicField = (obj, key, value) => {
6965
6955
  });
6966
6956
  return months.slice(preDates - days);
6967
6957
  };
6968
- const _window = window;
6969
6958
  function requestAniFrame() {
6970
- if (typeof _window !== "undefined") {
6959
+ if (typeof window !== "undefined") {
6960
+ const _window = window;
6971
6961
  return _window.requestAnimationFrame || _window.webkitRequestAnimationFrame || function(callback) {
6972
6962
  _window.setTimeout(callback, 1e3 / 60);
6973
6963
  };
@@ -10812,14 +10802,27 @@ var __publicField = (obj, key, value) => {
10812
10802
  ...defaultProps$S,
10813
10803
  ...props
10814
10804
  };
10815
- const [_showPopup, setShowPopup] = React.useState(show);
10816
- const [_value, setValue] = React.useState(value);
10805
+ const [showPopup, setShowPopup] = React.useState(show);
10806
+ const [innerValue, setValue] = React.useState(value);
10817
10807
  React.useEffect(() => {
10818
10808
  setShowPopup(show);
10819
10809
  }, [show]);
10820
10810
  React.useEffect(() => {
10821
10811
  getParentOffset();
10822
- }, [_showPopup]);
10812
+ }, [showPopup]);
10813
+ const windowHeight = React.useMemo(() => Taro.getSystemInfoSync().windowHeight, []);
10814
+ const updateItemOffset = React.useCallback(() => {
10815
+ const p = parent.menuRef.current;
10816
+ p.getBoundingClientRect().then((rect) => {
10817
+ if (rect) {
10818
+ setPosition({
10819
+ height: rect.height,
10820
+ top: rect.top
10821
+ });
10822
+ }
10823
+ });
10824
+ }, [direction, windowHeight]);
10825
+ Taro.usePageScroll(updateItemOffset);
10823
10826
  React.useImperativeHandle(ref, () => ({
10824
10827
  toggle: parent.toggleMenuItem
10825
10828
  }));
@@ -10855,120 +10858,111 @@ var __publicField = (obj, key, value) => {
10855
10858
  }, 100);
10856
10859
  };
10857
10860
  const isShow = () => {
10858
- if (_showPopup)
10861
+ if (showPopup)
10859
10862
  return {};
10860
10863
  return { display: "none" };
10861
10864
  };
10862
10865
  const getPosition = () => {
10863
- return direction === "down" ? { position: "absolute", height: `${window.innerHeight}px` } : {
10864
- position: "absolute",
10865
- bottom: "100%",
10866
- top: "auto",
10867
- height: `${window.innerHeight}px`
10866
+ return direction === "down" ? {
10867
+ top: `${position.top + position.height}px`,
10868
+ bottom: "0",
10869
+ height: "initial"
10870
+ } : {
10871
+ bottom: `${Taro.getSystemInfoSync().windowHeight - position.top}px`,
10872
+ top: "0",
10873
+ height: "initial"
10868
10874
  };
10869
10875
  };
10870
10876
  const placeholderStyle = () => {
10871
10877
  if (direction === "down") {
10872
10878
  return {
10873
10879
  height: `${position.top + position.height}px`,
10874
- top: "auto",
10875
- bottom: "-100%",
10876
10880
  ...isShow()
10877
10881
  };
10878
10882
  }
10879
10883
  return {
10880
10884
  height: `${Taro.getSystemInfoSync().windowHeight - position.top}px`,
10881
- bottom: `auto`,
10882
- top: "0",
10885
+ top: "auto",
10883
10886
  ...isShow()
10884
10887
  };
10885
10888
  };
10886
- return /* @__PURE__ */ React.createElement(
10887
- "div",
10889
+ return /* @__PURE__ */ React.createElement(components.View, { className: "nut-menu-item-container" }, closeOnClickAway ? /* @__PURE__ */ React.createElement(
10890
+ components.View,
10888
10891
  {
10889
- className: "nut-menu-item-container",
10890
- style: { position: "absolute", left: 0, right: 0 }
10891
- },
10892
- closeOnClickAway ? /* @__PURE__ */ React.createElement(
10893
- "div",
10894
- {
10895
- className: `placeholder-element ${classNames({
10896
- up: direction === "up"
10897
- })}`,
10898
- style: placeholderStyle(),
10899
- onClick: () => parent.toggleMenuItem(index)
10892
+ className: `placeholder-element ${classNames({
10893
+ up: direction === "up"
10894
+ })}`,
10895
+ style: placeholderStyle(),
10896
+ onClick: () => parent.toggleMenuItem(index)
10897
+ }
10898
+ ) : null, /* @__PURE__ */ React.createElement(
10899
+ Overlay,
10900
+ {
10901
+ className: "nut-menu__overlay",
10902
+ style: getPosition(),
10903
+ lockScroll: parent.lockScroll,
10904
+ visible: showPopup,
10905
+ closeOnOverlayClick: parent.closeOnOverlayClick,
10906
+ onClick: () => {
10907
+ parent.closeOnOverlayClick && parent.toggleMenuItem(index);
10900
10908
  }
10901
- ) : null,
10902
- /* @__PURE__ */ React.createElement(
10903
- Overlay,
10904
- {
10905
- className: "nut-menu__overlay",
10906
- style: getPosition(),
10907
- lockScroll: parent.lockScroll,
10908
- visible: _showPopup,
10909
- closeOnOverlayClick: parent.closeOnOverlayClick,
10910
- onClick: () => {
10911
- parent.closeOnOverlayClick && parent.toggleMenuItem(index);
10912
- }
10909
+ }
10910
+ ), /* @__PURE__ */ React.createElement(
10911
+ components.View,
10912
+ {
10913
+ className: classNames(className, {
10914
+ "nut-menu-item__wrap": direction === "down",
10915
+ "nut-menu-item__wrap-up": direction !== "down"
10916
+ }),
10917
+ style: {
10918
+ ...style,
10919
+ ...isShow()
10913
10920
  }
10914
- ),
10921
+ },
10915
10922
  /* @__PURE__ */ React.createElement(
10916
- "div",
10923
+ CSSTransition$1,
10917
10924
  {
10918
- className: classNames(className, {
10919
- "nut-menu-item__wrap": direction === "down",
10920
- "nut-menu-item__wrap-up": direction !== "down"
10921
- }),
10922
- style: {
10923
- ...style,
10924
- ...isShow()
10925
- }
10925
+ in: showPopup,
10926
+ timeout: 100,
10927
+ classNames: direction === "down" ? "menu-item" : "menu-item-up"
10926
10928
  },
10927
- /* @__PURE__ */ React.createElement(
10928
- CSSTransition$1,
10929
- {
10930
- in: _showPopup,
10931
- timeout: 100,
10932
- classNames: direction === "down" ? "menu-item" : "menu-item-up"
10933
- },
10934
- /* @__PURE__ */ React.createElement("div", { className: "nut-menu-item__content" }, options == null ? void 0 : options.map((item, index2) => {
10935
- return /* @__PURE__ */ React.createElement(
10936
- "div",
10929
+ /* @__PURE__ */ React.createElement(components.View, { className: "nut-menu-item__content" }, options == null ? void 0 : options.map((item, index2) => {
10930
+ return /* @__PURE__ */ React.createElement(
10931
+ components.View,
10932
+ {
10933
+ className: `nut-menu-item__option ${classNames({
10934
+ active: item.value === innerValue
10935
+ })}`,
10936
+ key: item.text,
10937
+ style: {
10938
+ flexBasis: `${100 / columns}%`
10939
+ },
10940
+ onClick: () => {
10941
+ handleClick(item);
10942
+ }
10943
+ },
10944
+ item.value === innerValue ? /* @__PURE__ */ React.createElement(React.Fragment, null, icon || /* @__PURE__ */ React.createElement(
10945
+ a$t,
10946
+ {
10947
+ color: activeColor,
10948
+ size: 10,
10949
+ className: getIconCName(item.value, value)
10950
+ }
10951
+ )) : null,
10952
+ /* @__PURE__ */ React.createElement(
10953
+ components.View,
10937
10954
  {
10938
- className: `nut-menu-item__option ${classNames({
10939
- active: item.value === _value
10940
- })}`,
10941
- key: item.text,
10955
+ className: getIconCName(item.value, value),
10942
10956
  style: {
10943
- flexBasis: `${100 / columns}%`
10944
- },
10945
- onClick: () => {
10946
- handleClick(item);
10957
+ color: `${item.value === innerValue ? activeColor : ""}`
10947
10958
  }
10948
10959
  },
10949
- item.value === _value ? /* @__PURE__ */ React.createElement(React.Fragment, null, icon || /* @__PURE__ */ React.createElement(
10950
- a$t,
10951
- {
10952
- color: activeColor,
10953
- size: 10,
10954
- className: getIconCName(item.value, value)
10955
- }
10956
- )) : null,
10957
- /* @__PURE__ */ React.createElement(
10958
- "div",
10959
- {
10960
- className: getIconCName(item.value, value),
10961
- style: {
10962
- color: `${item.value === _value ? activeColor : ""}`
10963
- }
10964
- },
10965
- item.text
10966
- )
10967
- );
10968
- }), children)
10969
- )
10960
+ item.text
10961
+ )
10962
+ );
10963
+ }), children)
10970
10964
  )
10971
- );
10965
+ ));
10972
10966
  });
10973
10967
  MenuItem.defaultProps = defaultProps$S;
10974
10968
  MenuItem.displayName = "NutMenuItem";
@@ -10978,7 +10972,11 @@ var __publicField = (obj, key, value) => {
10978
10972
  closeOnOverlayClick: true,
10979
10973
  scrollFixed: false,
10980
10974
  lockScroll: true,
10981
- icon: null
10975
+ icon: null,
10976
+ onOpen: () => {
10977
+ },
10978
+ onClose: () => {
10979
+ }
10982
10980
  };
10983
10981
  const Menu = (props) => {
10984
10982
  const {
@@ -10989,6 +10987,8 @@ var __publicField = (obj, key, value) => {
10989
10987
  closeOnOverlayClick,
10990
10988
  children,
10991
10989
  activeColor,
10990
+ onClose,
10991
+ onOpen,
10992
10992
  ...rest
10993
10993
  } = {
10994
10994
  ...defaultProps$R,
@@ -11015,6 +11015,11 @@ var __publicField = (obj, key, value) => {
11015
11015
  const [menuItemTitle, setMenuItemTitle] = React.useState([]);
11016
11016
  const toggleMenuItem = (index) => {
11017
11017
  showMenuItem[index] = !showMenuItem[index];
11018
+ if (showMenuItem[index]) {
11019
+ onOpen && onOpen();
11020
+ } else {
11021
+ onClose && onClose();
11022
+ }
11018
11023
  const temp = showMenuItem.map(
11019
11024
  (i, idx) => idx === index ? i : false
11020
11025
  );
@@ -11023,6 +11028,7 @@ var __publicField = (obj, key, value) => {
11023
11028
  const hideMenuItem = (index) => {
11024
11029
  showMenuItem[index] = false;
11025
11030
  setShowMenuItem([...showMenuItem]);
11031
+ onClose && onClose();
11026
11032
  };
11027
11033
  const updateTitle = (text, index) => {
11028
11034
  menuItemTitle[index] = text;
@@ -11031,6 +11037,7 @@ var __publicField = (obj, key, value) => {
11031
11037
  const cloneChildren = () => {
11032
11038
  return React.Children.map(children, (child, index) => {
11033
11039
  return React.cloneElement(child, {
11040
+ ...child.props,
11034
11041
  show: showMenuItem[index],
11035
11042
  index,
11036
11043
  activeColor,
@@ -14620,7 +14627,6 @@ var __publicField = (obj, key, value) => {
14620
14627
  className: "avatar-img",
14621
14628
  src,
14622
14629
  style: { objectFit: fit },
14623
- alt,
14624
14630
  onError: errorEvent
14625
14631
  }
14626
14632
  ), React.isValidElement(icon) ? React.cloneElement(icon, {
@@ -57,8 +57,8 @@
57
57
  }
58
58
 
59
59
  .placeholder-element {
60
- position: absolute;
61
- top: -$menu-bar-line-height;
60
+ position: fixed;
61
+ top: $menu-placeholder-top;
62
62
  left: 0;
63
63
  right: 0;
64
64
  z-index: $menu-bar-opened-z-index;