@nutui/nutui-react-taro 2.0.0-alpha.7 → 2.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/esm/Address.js +2 -2
  3. package/dist/esm/Audio.js +7 -6
  4. package/dist/esm/Card.js +5 -5
  5. package/dist/esm/Cascader.js +2 -2
  6. package/dist/esm/DatePicker.js +2 -3
  7. package/dist/esm/Elevator.js +1 -1
  8. package/dist/esm/ImagePreview.js +4 -7
  9. package/dist/esm/Indicator.js +1 -1
  10. package/dist/esm/InputNumber.js +1 -1
  11. package/dist/esm/Notify.js +2 -3
  12. package/dist/esm/NumberKeyboard.js +3 -5
  13. package/dist/esm/Picker.js +1 -2
  14. package/dist/esm/Price.js +2 -3
  15. package/dist/esm/PullToRefresh.js +4 -6
  16. package/dist/esm/Radio.js +3 -3
  17. package/dist/esm/RadioGroup.js +3 -3
  18. package/dist/esm/Range/style/index.js +1 -1
  19. package/dist/esm/Range.js +5 -7
  20. package/dist/esm/Sticky.js +1 -2
  21. package/dist/esm/Swiper.js +3 -5
  22. package/dist/esm/SwiperItem.js +1 -5
  23. package/dist/esm/Tabs.js +1 -1
  24. package/dist/esm/{address.taro-1c534feb.js → address.taro-1a8ab3f1.js} +1 -1
  25. package/dist/esm/{audio.taro-ec96ef80.js → audio.taro-bbd39f93.js} +2 -2
  26. package/dist/esm/{card.taro-a46fdf25.js → card.taro-2080f4d2.js} +1 -1
  27. package/dist/esm/{cascader.taro-0a2694ed.js → cascader.taro-fb7a0230.js} +21 -13
  28. package/dist/esm/{datepicker.taro-3f718964.js → datepicker.taro-65dbeceb.js} +1 -1
  29. package/dist/esm/{elevator.taro-bc162e4f.js → elevator.taro-df8fde9d.js} +20 -15
  30. package/dist/esm/{imagepreview.taro-8832dc01.js → imagepreview.taro-2508d412.js} +8 -5
  31. package/dist/esm/{indicator.taro-f2bd212f.js → indicator.taro-edbc71df.js} +3 -3
  32. package/dist/esm/{inputnumber.taro-877dc947.js → inputnumber.taro-6657d2c1.js} +1 -1
  33. package/dist/esm/{notify.taro-6b6eb6bf.js → notify.taro-5768403d.js} +11 -18
  34. package/dist/esm/numberkeyboard.taro-ad8afaf9.js +136 -0
  35. package/dist/esm/nutui-react.es.js +20 -25
  36. package/dist/esm/{picker.taro-a5603921.js → picker.taro-0570ec32.js} +14 -1
  37. package/dist/esm/{price.taro-c4f45310.js → price.taro-479f1b82.js} +17 -17
  38. package/dist/esm/pulltorefresh.taro-6afe4805.js +138 -0
  39. package/dist/esm/radio.taro-5d6ca4ad.js +153 -0
  40. package/dist/esm/range.taro-615e193a.js +259 -0
  41. package/dist/esm/{sticky.taro-3c03eb0a.js → sticky.taro-f8ae8d5e.js} +21 -1
  42. package/dist/esm/swiper.taro-53a36427.js +83 -0
  43. package/dist/esm/swiperitem.taro-ef7342e8.js +14 -0
  44. package/dist/esm/{tabs.taro-b75f20ff.js → tabs.taro-66164782.js} +8 -1
  45. package/dist/locales/base.js +1 -1
  46. package/dist/locales/en-US.js +1 -1
  47. package/dist/locales/id-ID.js +1 -1
  48. package/dist/locales/zh-CN.js +1 -1
  49. package/dist/locales/zh-TW.js +1 -1
  50. package/dist/locales/zh-UG.js +1 -1
  51. package/dist/nutui.react.mjs +1634 -6666
  52. package/dist/nutui.react.umd.js +2047 -7095
  53. package/dist/packages/imagepreview/imagepreview.scss +5 -0
  54. package/dist/packages/notify/notify.scss +1 -1
  55. package/dist/packages/numberkeyboard/numberkeyboard.scss +29 -77
  56. package/dist/packages/price/price.scss +8 -0
  57. package/dist/packages/pulltorefresh/pulltorefresh.scss +0 -8
  58. package/dist/packages/radio/radio.scss +13 -32
  59. package/dist/packages/radiogroup/radiogroup.scss +17 -51
  60. package/dist/packages/range/range.scss +24 -49
  61. package/dist/packages/swiper/swiper.scss +0 -15
  62. package/dist/style.css +1 -1
  63. package/dist/style.mjs +1 -1
  64. package/dist/styles/variables-jmapp.scss +61 -61
  65. package/dist/styles/variables.scss +61 -60
  66. package/dist/types/index.d.ts +83 -118
  67. package/package.json +1 -1
  68. package/dist/esm/UserContext-735db09f.js +0 -5
  69. package/dist/esm/get-scroll-parent-8da04f2e.js +0 -24
  70. package/dist/esm/numberkeyboard.taro-0a0e866a.js +0 -183
  71. package/dist/esm/pulltorefresh.taro-c611fd92.js +0 -179
  72. package/dist/esm/radio.taro-3a54f4c8.js +0 -152
  73. package/dist/esm/range.taro-52cda918.js +0 -325
  74. package/dist/esm/supports-passive-aaaf0eff.js +0 -17
  75. package/dist/esm/swiper.taro-74cf9306.js +0 -430
  76. package/dist/esm/swiperitem-80df464a.js +0 -29
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import React__default, { CSSProperties, ReactNode, FunctionComponent, MouseEvent as MouseEvent$1, MouseEventHandler, HTMLInputTypeAttribute, ChangeEvent, FocusEvent, RefObject, Component } from 'react';
3
- import { ButtonProps as ButtonProps$1, ITouchEvent, InputProps as InputProps$1, TextareaProps } from '@tarojs/components';
2
+ import React__default, { CSSProperties, ReactNode, FunctionComponent, MouseEvent as MouseEvent$1, HTMLInputTypeAttribute, ChangeEvent, FocusEvent, RefObject, Component } from 'react';
3
+ import { ButtonProps as ButtonProps$1, ITouchEvent, InputProps as InputProps$1, TextareaProps, SwiperProps as SwiperProps$1 } from '@tarojs/components';
4
4
  import Taro, { InnerAudioContext } from '@tarojs/taro';
5
5
 
6
6
  interface BasicComponent {
@@ -304,7 +304,7 @@ interface ElevatorProps extends BasicComponent {
304
304
  sticky: boolean;
305
305
  spaceHeight: number;
306
306
  titleHeight: number;
307
- style: React__default.CSSProperties;
307
+ showKeys: boolean;
308
308
  children: React__default.ReactNode;
309
309
  onClickItem: (key: string, item: ElevatorData) => void;
310
310
  onClickIndex: (key: string) => void;
@@ -601,6 +601,7 @@ interface CascaderOption {
601
601
  loading?: boolean;
602
602
  root?: boolean;
603
603
  }
604
+ type CascaderValue = Exclude<CascaderOption['value'], undefined>[];
604
605
  interface optionKey {
605
606
  textKey: string;
606
607
  valueKey: string;
@@ -613,7 +614,8 @@ interface CascaderProps extends BasicComponent {
613
614
  activeColor: string;
614
615
  activeIcon: string;
615
616
  options: CascaderOption[];
616
- value: string[];
617
+ value?: CascaderValue;
618
+ defaultValue?: CascaderValue;
617
619
  title: string;
618
620
  optionKey: optionKey;
619
621
  format: Record<string, string | number | null>;
@@ -623,8 +625,8 @@ interface CascaderProps extends BasicComponent {
623
625
  lazy: boolean;
624
626
  onLoad: (node: any, resolve: any) => void;
625
627
  onClose?: () => void;
626
- onChange: (value: any, params: any) => void;
627
- onPathChange: (value: any, params: any) => void;
628
+ onChange: (value: CascaderValue, params?: any) => void;
629
+ onPathChange: (value: CascaderValue, params: any) => void;
628
630
  }
629
631
  declare const Cascader: React__default.ForwardRefExoticComponent<Partial<CascaderProps> & {
630
632
  children?: React__default.ReactNode;
@@ -634,7 +636,7 @@ interface RadioGroupOptionType {
634
636
  label: string;
635
637
  value: string;
636
638
  disabled?: boolean;
637
- onChange?: MouseEventHandler<HTMLDivElement>;
639
+ onChange?: (checked: boolean) => void;
638
640
  }
639
641
 
640
642
  type CheckboxLabelPosition = 'left' | 'right';
@@ -865,22 +867,39 @@ interface MenuItemProps extends BasicComponent {
865
867
  }
866
868
  declare const MenuItem: React__default.ForwardRefExoticComponent<Partial<MenuItemProps> & React__default.RefAttributes<unknown>>;
867
869
 
868
- interface NumberKeyboardProps {
869
- confirmText: string;
870
- title: string;
871
- visible: boolean;
870
+ type Teleport = HTMLElement | (() => HTMLElement) | null;
871
+ interface PopupProps extends OverlayProps {
872
+ position: string;
873
+ transition: string;
874
+ overlayStyle: React__default.CSSProperties;
875
+ overlayClassName: string;
876
+ closeable: boolean;
877
+ closeIconPosition: string;
878
+ closeIcon: React__default.ReactNode;
879
+ destroyOnClose: boolean;
880
+ portal: Teleport;
872
881
  overlay: boolean;
873
- type: string;
874
- customKey: Array<string>;
875
- randomKeys: boolean;
876
- popClass: string;
877
- className: string;
878
- style?: CSSProperties;
882
+ round: boolean;
883
+ onOpen: () => void;
884
+ onClose: () => void;
885
+ onClickOverlay: (e: ITouchEvent) => boolean | void;
886
+ onClickCloseIcon: (e: ITouchEvent) => boolean | void;
887
+ }
888
+ declare const Popup: FunctionComponent<Partial<PopupProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onClick'>>;
889
+
890
+ interface NumberKeyboardProps extends PopupProps {
891
+ visible: boolean;
892
+ title?: ReactNode;
893
+ confirmText?: string;
894
+ type: 'default' | 'rightColumn';
895
+ custom: Array<string>;
896
+ random: boolean;
879
897
  onChange?: (value: string) => void;
880
898
  onDelete?: () => void;
881
899
  onClose: () => void;
900
+ onConfirm?: () => void;
882
901
  }
883
- declare const NumberKeyboard: FunctionComponent<Partial<NumberKeyboardProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onChange'>>;
902
+ declare const NumberKeyboard: FunctionComponent<Partial<NumberKeyboardProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onChange' | 'onClick' | 'title'>>;
884
903
 
885
904
  interface PickerOption {
886
905
  text: string | number;
@@ -908,61 +927,53 @@ declare const Picker: React__default.ForwardRefExoticComponent<Partial<PickerPro
908
927
  type Position$1 = 'left' | 'right';
909
928
  type Direction$1 = 'horizontal' | 'vertical';
910
929
  interface RadioGroupProps {
911
- value: string | number | boolean | null;
912
- textPosition: Position$1;
930
+ value?: string | number;
931
+ defaultValue?: string | number;
932
+ labelPosition: Position$1;
913
933
  direction: Direction$1;
914
- onChange: (value: string | number | boolean) => void;
934
+ disabled?: boolean;
915
935
  options: RadioGroupOptionType[];
936
+ onChange: (value: string | number) => void;
916
937
  }
917
938
  declare const RadioGroup: React__default.ForwardRefExoticComponent<Partial<RadioGroupProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, "onChange"> & React__default.RefAttributes<unknown>>;
918
939
 
919
940
  type Shape = 'button' | 'round';
920
941
  type Position = 'right' | 'left';
921
942
  interface RadioProps extends BasicComponent {
922
- className: string;
923
- style: React__default.CSSProperties;
924
943
  disabled: boolean;
925
944
  checked: boolean;
945
+ defaultChecked: boolean;
926
946
  shape: Shape;
927
- textPosition: Position;
928
- value: string | number | boolean;
947
+ labelPosition: Position;
929
948
  icon: React__default.ReactNode;
930
- checkedIcon: React__default.ReactNode;
931
- iconSize: string | number;
932
- onChange: MouseEventHandler<HTMLDivElement>;
949
+ activeIcon: React__default.ReactNode;
950
+ value: string | number;
951
+ onChange: (checked: boolean) => void;
933
952
  }
934
- declare const Radio: FunctionComponent<Partial<RadioProps> & React__default.HTMLAttributes<HTMLDivElement>> & {
935
- RadioGroup: typeof RadioGroup;
953
+ declare const Radio: FunctionComponent<Partial<RadioProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onChange'>> & {
954
+ Group: typeof RadioGroup;
936
955
  };
937
956
 
938
- type SliderValue = number | number[];
939
- interface RangeProps {
940
- className: string;
941
- style: CSSProperties;
957
+ type RangeValue = number | number[];
958
+ interface RangeProps extends BasicComponent {
959
+ value: RangeValue;
960
+ defaultValue: RangeValue;
942
961
  range: boolean;
943
962
  disabled: boolean;
944
- activeColor: string;
945
- inactiveColor: string;
946
- buttonColor: string;
947
- hiddenRange: boolean;
948
- hiddenTag: boolean;
949
- min: number | string;
950
- max: number | string;
951
- minDesc: number | string;
952
- maxDesc: number | string;
953
- curValueDesc: number | string;
954
- step: number | string;
955
- modelValue: SliderValue;
956
- button: React__default.ReactNode;
963
+ min: number;
964
+ max: number;
965
+ step: number;
966
+ minDescription: ReactNode;
967
+ maxDescription: ReactNode;
968
+ button: ReactNode;
957
969
  vertical: boolean;
958
970
  marks: Record<string, unknown>;
959
- dragStart?: () => void;
960
- dragEnd?: () => void;
961
- onChange?: (value: number) => void;
962
- onDragStart?: () => void;
963
- onDragEnd?: () => void;
971
+ currentDescription: ((value: RangeValue) => ReactNode) | null;
972
+ onChange: (value: RangeValue) => void;
973
+ onStart: () => void;
974
+ onEnd: (value: RangeValue) => void;
964
975
  }
965
- declare const Range: FunctionComponent<Partial<RangeProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onClick' | 'onChange'>>;
976
+ declare const Range: FunctionComponent<Partial<RangeProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onClick' | 'onChange' | 'defaultValue'>>;
966
977
 
967
978
  interface RateProps extends BasicComponent {
968
979
  count: number;
@@ -1335,19 +1346,13 @@ interface NoticeBarProps extends BasicComponent {
1335
1346
  }
1336
1347
  declare const NoticeBar: FunctionComponent<Partial<NoticeBarProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onClick'>>;
1337
1348
 
1338
- interface NotifyProps {
1349
+ interface NotifyProps extends BasicComponent {
1339
1350
  id?: string;
1340
- style?: React__default.CSSProperties;
1341
- msg: string;
1342
- color: string;
1343
1351
  duration: number;
1344
1352
  type: string;
1345
- className: string;
1346
- background: string;
1347
1353
  position: string;
1348
- isWrapTeleport: boolean;
1349
1354
  visible: boolean;
1350
- onClosed: () => void;
1355
+ onClose: () => void;
1351
1356
  onClick: () => void;
1352
1357
  }
1353
1358
  declare const Notify: FunctionComponent<Partial<NotifyProps> & React__default.HTMLAttributes<HTMLDivElement>>;
@@ -1374,9 +1379,7 @@ interface PopoverProps extends BasicComponent {
1374
1379
  declare const Popover: FunctionComponent<Partial<PopoverProps> & React__default.HTMLAttributes<HTMLDivElement>>;
1375
1380
 
1376
1381
  type PullStatus = 'pulling' | 'canRelease' | 'refreshing' | 'complete';
1377
- interface PullToRefreshProps {
1378
- className: string;
1379
- style: React__default.CSSProperties;
1382
+ interface PullToRefreshProps extends BasicComponent {
1380
1383
  onRefresh: () => Promise<any>;
1381
1384
  pullingText: ReactNode;
1382
1385
  canReleaseText: ReactNode;
@@ -1386,8 +1389,8 @@ interface PullToRefreshProps {
1386
1389
  headHeight: number;
1387
1390
  threshold: number;
1388
1391
  disabled: boolean;
1392
+ scrollTop: number;
1389
1393
  renderText: (status: PullStatus) => ReactNode;
1390
- children: React__default.ReactNode;
1391
1394
  }
1392
1395
  declare const PullToRefresh: FunctionComponent<Partial<PullToRefreshProps>>;
1393
1396
 
@@ -1448,26 +1451,6 @@ interface SwipeProps {
1448
1451
  }
1449
1452
  declare const Swipe: React__default.ForwardRefExoticComponent<Partial<SwipeProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, "onTouchStart" | "onTouchMove" | "onTouchEnd"> & React__default.RefAttributes<SwipeInstance>>;
1450
1453
 
1451
- type Teleport = HTMLElement | (() => HTMLElement) | null;
1452
- interface PopupProps extends OverlayProps {
1453
- position: string;
1454
- transition: string;
1455
- overlayStyle: React__default.CSSProperties;
1456
- overlayClassName: string;
1457
- closeable: boolean;
1458
- closeIconPosition: string;
1459
- closeIcon: React__default.ReactNode;
1460
- destroyOnClose: boolean;
1461
- portal: Teleport;
1462
- overlay: boolean;
1463
- round: boolean;
1464
- onOpen: () => void;
1465
- onClose: () => void;
1466
- onClickOverlay: (e: ITouchEvent) => boolean | void;
1467
- onClickCloseIcon: (e: ITouchEvent) => boolean | void;
1468
- }
1469
- declare const Popup: FunctionComponent<Partial<PopupProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onClick'>>;
1470
-
1471
1454
  interface ToastProps {
1472
1455
  id?: string;
1473
1456
  style?: React__default.CSSProperties;
@@ -1650,7 +1633,7 @@ interface ImagePreviewProps {
1650
1633
  };
1651
1634
  }>;
1652
1635
  show: boolean;
1653
- autoplay: number | string;
1636
+ autoPlay: boolean;
1654
1637
  initNo: number;
1655
1638
  contentClose: boolean;
1656
1639
  paginationVisible: boolean;
@@ -1697,16 +1680,14 @@ interface PaginationProps extends BasicComponent {
1697
1680
  }
1698
1681
  declare const Pagination: FunctionComponent<Partial<PaginationProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, 'onChange'>>;
1699
1682
 
1700
- interface PriceProps {
1683
+ interface PriceProps extends BasicComponent {
1701
1684
  price: number | string;
1702
- needSymbol: boolean;
1703
1685
  symbol: string;
1704
- decimalDigits: number;
1686
+ digits: number;
1705
1687
  thousands: boolean;
1706
1688
  position: string;
1707
1689
  size: string;
1708
- className: string;
1709
- style: React__default.CSSProperties;
1690
+ line: boolean;
1710
1691
  }
1711
1692
  declare const Price: FunctionComponent<Partial<PriceProps>>;
1712
1693
 
@@ -1742,38 +1723,22 @@ interface StepsProps {
1742
1723
  }
1743
1724
  declare const Steps: FunctionComponent<Partial<StepsProps> & React__default.HTMLAttributes<HTMLDivElement>>;
1744
1725
 
1745
- type SwiperRef = {
1746
- to: (index: number) => void;
1747
- next: () => void;
1748
- prev: () => void;
1749
- };
1750
- interface SwiperProps {
1751
- width: number | string;
1752
- height: number | string;
1753
- duration: number | string;
1754
- initPage: number | string;
1755
- autoPlay: number | string;
1726
+ interface SwiperProps extends Omit<SwiperProps$1, 'ref'> {
1727
+ width: number;
1728
+ height: number;
1756
1729
  direction: 'horizontal' | 'vertical';
1757
- paginationColor: string;
1758
- paginationBgColor: string;
1759
- paginationVisible: boolean;
1730
+ indicator: ReactNode;
1731
+ autoPlay: boolean;
1760
1732
  loop: boolean;
1761
- touchable: boolean;
1762
- isPreventDefault: boolean;
1763
- isStopPropagation: boolean;
1764
- isCenter: boolean;
1765
- className?: string;
1766
- style?: React__default.CSSProperties;
1767
- pageContent?: React__default.ReactNode;
1768
- onChange?: (currPage: number) => void;
1733
+ defaultValue: number;
1769
1734
  }
1770
- declare const Swiper: React__default.ForwardRefExoticComponent<Partial<SwiperProps> & Omit<React__default.HTMLAttributes<HTMLDivElement>, "onChange"> & React__default.RefAttributes<SwiperRef>>;
1735
+ declare const Swiper: React__default.ForwardRefExoticComponent<Partial<SwiperProps> & React__default.RefAttributes<unknown>>;
1771
1736
 
1772
- interface SwiperItemProps {
1773
- direction?: string;
1774
- size?: 0;
1737
+ interface SwiperItemProps extends BasicComponent {
1738
+ itemId?: string;
1739
+ skipHiddenItemLayout?: boolean;
1775
1740
  }
1776
- declare const SwiperItem: React__default.ForwardRefExoticComponent<Partial<SwiperItemProps> & React__default.HTMLAttributes<HTMLDivElement> & React__default.RefAttributes<HTMLDivElement>>;
1741
+ declare const SwiperItem: FunctionComponent<Partial<SwiperItemProps>>;
1777
1742
 
1778
1743
  interface BasicTableProps extends BasicComponent {
1779
1744
  columns: Array<TableColumnProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nutui/nutui-react-taro",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.9",
4
4
  "style": "dist/style.css",
5
5
  "main": "dist/nutui.react.umd.js",
6
6
  "module": "dist/esm/nutui-react.es.js",
@@ -1,5 +0,0 @@
1
- import { createContext } from "react";
2
- const DataContext = createContext({});
3
- export {
4
- DataContext as D
5
- };
@@ -1,24 +0,0 @@
1
- import { c as canUseDom } from "./can-use-dom-0e539bd3.js";
2
- const defaultRoot = canUseDom ? window : void 0;
3
- const overflowStylePatterns = ["scroll", "auto", "overlay"];
4
- function isElement(node) {
5
- const ELEMENT_NODE_TYPE = 1;
6
- return node.nodeType === ELEMENT_NODE_TYPE;
7
- }
8
- function getScrollParent(el, root = defaultRoot) {
9
- let node = el;
10
- while (node && node !== root && isElement(node)) {
11
- if (node === document.body) {
12
- return root;
13
- }
14
- const { overflowY } = window.getComputedStyle(node);
15
- if (overflowStylePatterns.includes(overflowY) && node.scrollHeight > node.clientHeight) {
16
- return node;
17
- }
18
- node = node.parentNode;
19
- }
20
- return root;
21
- }
22
- export {
23
- getScrollParent as g
24
- };
@@ -1,183 +0,0 @@
1
- import React, { useState, useEffect } from "react";
2
- import classNames from "classnames";
3
- import { c as cn } from "./bem-cdccae08.js";
4
- import { P as Popup } from "./popup.taro-e756f3fc.js";
5
- import { u as useConfig } from "./configprovider.taro-25758d9f.js";
6
- const defaultProps = {
7
- confirmText: "",
8
- title: "",
9
- visible: false,
10
- overlay: false,
11
- type: "default",
12
- customKey: [],
13
- className: "",
14
- randomKeys: false,
15
- popClass: "",
16
- onClose: () => {
17
- }
18
- };
19
- const NumberKeyboard = (props) => {
20
- const { locale } = useConfig();
21
- const { title, confirmText, visible, overlay, type, customKey, randomKeys, popClass, style, className, onChange, onDelete, onClose } = props;
22
- const b = cn("numberkeyboard");
23
- const [show, setShow] = useState(visible);
24
- const [clickKeyIndex, setClickKeyIndex] = useState(void 0);
25
- const [keysList, setKeysList] = useState([]);
26
- useEffect(() => {
27
- setShow(visible);
28
- }, [visible]);
29
- const defaultKey = () => {
30
- let leftBottomKey = {
31
- id: "lock",
32
- type: "lock"
33
- };
34
- if (customKey) {
35
- const customKeys = Array.isArray(customKey) ? customKey : [customKey];
36
- if (customKeys.length > 0) {
37
- const newCustomKey = customKeys[0];
38
- leftBottomKey = {
39
- id: newCustomKey,
40
- type: "custom"
41
- };
42
- }
43
- }
44
- return [
45
- ...getBasicKeys(),
46
- leftBottomKey,
47
- { id: 0, type: "number" },
48
- { id: "delete", type: "delete" }
49
- ];
50
- };
51
- const getBasicKeys = () => {
52
- const keys = [];
53
- for (let i = 1; i <= 9; i++) {
54
- keys.push({ id: i, type: "number" });
55
- }
56
- if (randomKeys) {
57
- return keys.sort(() => Math.random() > 0.5 ? 1 : -1);
58
- }
59
- return keys;
60
- };
61
- const genCustomKeys = () => {
62
- const keys = getBasicKeys();
63
- if (!customKey)
64
- return [];
65
- let customKeys = Array.isArray(customKey) ? customKey : [customKey];
66
- if (customKeys.length > 2) {
67
- customKeys = [customKeys[0], customKeys[1]];
68
- }
69
- if (customKeys.length === 2 && props.title && props.type !== "rightColumn") {
70
- customKeys = [customKeys[0]];
71
- }
72
- if (customKeys.length === 1) {
73
- if (props.title && props.type !== "rightColumn") {
74
- keys.push({ id: customKeys[0], type: "custom" }, { id: 0, type: "number" }, { id: "delete", type: "delete" });
75
- } else {
76
- keys.push({ id: 0, type: "number" }, { id: customKeys[0], type: "custom" });
77
- }
78
- } else if (customKeys.length === 2) {
79
- keys.push({ id: customKeys[0], type: "custom" }, { id: 0, type: "number" }, { id: customKeys[1], type: "custom" });
80
- }
81
- return keys;
82
- };
83
- useEffect(() => {
84
- if (props.type === "rightColumn" || props.title !== "") {
85
- setKeysList(genCustomKeys());
86
- } else {
87
- setKeysList(defaultKey());
88
- }
89
- }, []);
90
- const onTouchstart = (item, event) => {
91
- event.stopPropagation();
92
- setClickKeyIndex(item.id);
93
- if (item.type === "number" || item.type === "custom") {
94
- onChange && onChange(item.id);
95
- }
96
- if (item.type === "lock") {
97
- onClose && onClose();
98
- }
99
- if (item.type === "delete") {
100
- onDelete && onDelete();
101
- }
102
- };
103
- const onTouchMove = (event) => {
104
- event.stopPropagation();
105
- };
106
- const onTouchEnd = (event) => {
107
- event.preventDefault();
108
- setClickKeyIndex(void 0);
109
- };
110
- return React.createElement(
111
- "div",
112
- null,
113
- React.createElement(
114
- Popup,
115
- { visible: show, overlay, position: "bottom", className: popClass, onClickOverlay: onClose, onClickCloseIcon: onClose, overlayStyle: { backgroundColor: "rgba(0, 0, 0, 0)" } },
116
- React.createElement(
117
- "div",
118
- { className: `${b()} ${className}`, style: { ...style } },
119
- title ? React.createElement(
120
- "div",
121
- { className: b("header") },
122
- React.createElement("h3", { className: b("header__tit") }, title),
123
- type === "default" ? React.createElement("span", { className: b("header__close"), onClick: onClose }, locale.done) : null
124
- ) : null,
125
- React.createElement(
126
- "div",
127
- { className: b("body") },
128
- React.createElement("div", { className: b("body__keys") }, keysList == null ? void 0 : keysList.map((item, index) => {
129
- return React.createElement(
130
- "div",
131
- { key: index, className: classNames({
132
- "key-board-wrapper": true,
133
- "key-board-wrapper-large": item.id === 0 && type === "rightColumn" && Array.isArray(customKey) && customKey.length === 1
134
- }) },
135
- React.createElement(
136
- "div",
137
- { className: classNames({
138
- key: true,
139
- active: item.id === clickKeyIndex,
140
- lock: item.type === "lock",
141
- delete: item.type === "delete"
142
- }), onTouchStart: (event) => onTouchstart(item, event), onTouchMove, onTouchEnd },
143
- item.type === "number" || item.type === "custom" ? React.createElement("div", null, item.id) : null,
144
- item.type === "lock" ? React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/146371/38/8485/738/5f606425Eca239740/14f4b4f5f20d8a68.png", alt: "" }) : null,
145
- item.type === "delete" ? React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/129395/8/12735/2030/5f61ac37E70cab338/fb477dc11f46056c.png", alt: "" }) : null
146
- )
147
- );
148
- })),
149
- type === "rightColumn" ? React.createElement(
150
- "div",
151
- { className: b("sidebar") },
152
- React.createElement(
153
- "div",
154
- { className: "key-board-wrapper" },
155
- React.createElement(
156
- "div",
157
- { className: classNames({
158
- key: true,
159
- active: clickKeyIndex === "delete"
160
- }), onTouchStart: (event) => onTouchstart({ id: "delete", type: "delete" }, event), onTouchMove, onTouchEnd },
161
- React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/129395/8/12735/2030/5f61ac37E70cab338/fb477dc11f46056c.png", alt: "" })
162
- )
163
- ),
164
- React.createElement(
165
- "div",
166
- { className: "key-board-wrapper key-board-finish", onClick: onClose },
167
- React.createElement("div", { className: classNames({
168
- key: true,
169
- finish: true,
170
- activeFinsh: clickKeyIndex === "finish"
171
- }) }, confirmText || locale.done)
172
- )
173
- ) : null
174
- )
175
- )
176
- )
177
- );
178
- };
179
- NumberKeyboard.defaultProps = defaultProps;
180
- NumberKeyboard.displayName = "NutNumberKeyboard";
181
- export {
182
- NumberKeyboard as N
183
- };