iglooform 2.5.2 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/es/checkbox/index.d.ts +7 -7
  2. package/es/checkbox/index.js +85 -5
  3. package/es/form/elements.js +3 -1
  4. package/es/index.d.ts +1 -0
  5. package/es/index.js +1 -0
  6. package/es/locale/en-US/messages.json +4 -0
  7. package/es/locale/id-ID/messages.json +4 -0
  8. package/es/locale/th-TH/messages.json +4 -0
  9. package/es/locale/vi-VN/messages.json +4 -0
  10. package/es/locale/zh-CN/messages.json +4 -0
  11. package/es/locale/zh-TW/messages.json +5 -0
  12. package/es/radio/index.d.ts +6 -6
  13. package/es/radio/index.js +79 -22
  14. package/es/radio/radio-group-with-other.d.ts +1 -1
  15. package/es/radio/radio-group-with-other.js +41 -4
  16. package/es/radio/style/empty.svg +12 -0
  17. package/es/search-box/index.d.ts +31 -0
  18. package/es/search-box/index.js +266 -0
  19. package/es/search-box/style/index.d.ts +1 -0
  20. package/es/search-box/style/index.js +1 -0
  21. package/es/search-box/style/index.less +162 -0
  22. package/es/select/attached-select.d.ts +2 -12
  23. package/es/select/attached-select.js +28 -198
  24. package/es/utils/option-utils.d.ts +24 -0
  25. package/es/utils/option-utils.js +233 -0
  26. package/lib/checkbox/index.d.ts +7 -7
  27. package/lib/checkbox/index.js +87 -5
  28. package/lib/form/elements.js +4 -1
  29. package/lib/index.d.ts +1 -0
  30. package/lib/index.js +9 -0
  31. package/lib/locale/en-US/messages.json +4 -0
  32. package/lib/locale/id-ID/messages.json +4 -0
  33. package/lib/locale/th-TH/messages.json +4 -0
  34. package/lib/locale/vi-VN/messages.json +4 -0
  35. package/lib/locale/zh-CN/messages.json +4 -0
  36. package/lib/locale/zh-TW/messages.json +5 -0
  37. package/lib/radio/index.d.ts +6 -6
  38. package/lib/radio/index.js +83 -22
  39. package/lib/radio/radio-group-with-other.d.ts +1 -1
  40. package/lib/radio/radio-group-with-other.js +41 -3
  41. package/lib/radio/style/empty.svg +12 -0
  42. package/lib/search-box/index.d.ts +31 -0
  43. package/lib/search-box/index.js +287 -0
  44. package/lib/search-box/style/index.d.ts +1 -0
  45. package/lib/search-box/style/index.js +3 -0
  46. package/lib/search-box/style/index.less +162 -0
  47. package/lib/select/attached-select.d.ts +2 -12
  48. package/lib/select/attached-select.js +27 -198
  49. package/lib/utils/option-utils.d.ts +24 -0
  50. package/lib/utils/option-utils.js +250 -0
  51. package/package.json +10 -9
@@ -1,21 +1,21 @@
1
1
  import { CheckboxProps, CheckboxGroupProps } from 'antd/es/checkbox';
2
2
  import { FC, IglooComponentProps } from '@/types';
3
+ import { ComponentProps } from '../utils/option-utils';
4
+ import { DefaultOptionType } from 'rc-select/lib/Select';
3
5
  import './style/index.less';
4
6
  interface Props extends IglooComponentProps, CheckboxProps {
5
7
  }
6
- interface Option {
7
- label?: any;
8
- value?: string;
9
- disabled?: boolean;
8
+ export interface Option extends DefaultOptionType {
10
9
  extraInfo?: {
11
10
  content: any;
12
11
  shownTrigger: 'unchecked' | 'checked' | 'all';
13
12
  };
14
13
  }
15
- export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'options'> {
16
- options: Option[];
14
+ export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'options'>, ComponentProps {
17
15
  className?: string;
16
+ radioType?: string;
17
+ options: Option[];
18
18
  }
19
19
  declare const IglooCheckbox: FC<Props>;
20
20
  export default IglooCheckbox;
21
- export declare const CheckboxGroup: FC<IProps>;
21
+ export declare const CheckboxGroup: FC<import("../utils/option-utils").HOCProps & IProps>;
@@ -4,9 +4,21 @@ import "antd/es/row/style";
4
4
  import _Row from "antd/es/row";
5
5
  import "antd/es/checkbox/style";
6
6
  import _Checkbox from "antd/es/checkbox";
7
- var _excluded = ["className", "options", "value"],
7
+ var _excluded = ["className", "options", "value", "clearWhenOptionsUpdated"],
8
8
  _excluded2 = ["label", "value", "extraInfo"];
9
9
 
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17
+
18
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19
+
20
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
+
10
22
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
23
 
12
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -18,10 +30,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
30
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
31
 
20
32
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
33
+ import { useState, useEffect, useRef, useContext } from 'react';
21
34
  import Typography from '../typography';
22
35
  import formMethods from '../utils/form-methods';
23
36
  import omit from 'omit.js';
24
37
  import classnames from 'classnames';
38
+ import { compareOptions, optionsHOC } from '../utils/option-utils';
39
+ import LocaleContext from '../locale/locale-context';
40
+ import emptyIcon from '../radio/style/empty.svg';
25
41
  import './style/index.less';
26
42
 
27
43
  var IglooCheckbox = function IglooCheckbox(props) {
@@ -38,17 +54,55 @@ IglooCheckbox.formItemPropsHandler = function (config) {
38
54
  };
39
55
 
40
56
  export default IglooCheckbox;
41
- export var CheckboxGroup = function CheckboxGroup(_ref) {
57
+
58
+ var InnerCheckboxGroup = function InnerCheckboxGroup(_ref) {
42
59
  var className = _ref.className,
43
60
  _ref$options = _ref.options,
44
61
  options = _ref$options === void 0 ? [] : _ref$options,
45
62
  value = _ref.value,
63
+ _ref$clearWhenOptions = _ref.clearWhenOptionsUpdated,
64
+ clearWhenOptionsUpdated = _ref$clearWhenOptions === void 0 ? false : _ref$clearWhenOptions,
46
65
  rest = _objectWithoutProperties(_ref, _excluded);
47
66
 
48
- return _jsx(_Checkbox.Group, _objectSpread(_objectSpread({}, omit(rest, formMethods)), {}, {
67
+ var _useState = useState(value),
68
+ _useState2 = _slicedToArray(_useState, 2),
69
+ selected = _useState2[0],
70
+ setSelected = _useState2[1];
71
+
72
+ var originOptions = useRef(options);
73
+
74
+ var _useContext = useContext(LocaleContext),
75
+ formatMessage = _useContext.formatMessage;
76
+
77
+ useEffect(function () {
78
+ typeof rest.onChange === 'function' && value !== selected && rest.onChange(selected);
79
+ }, [selected]);
80
+ useEffect(function () {
81
+ setSelected(value);
82
+ }, [value]);
83
+ useEffect(function () {
84
+ var setFieldValue = rest.setFieldValue;
85
+
86
+ if (compareOptions(options, originOptions.current)) {
87
+ if (clearWhenOptionsUpdated) {
88
+ typeof setFieldValue === 'function' && setFieldValue();
89
+ } else {
90
+ var foundValue = options.find(function (option) {
91
+ return Array.isArray(value) ? value.includes(option.value) : option.value === value;
92
+ });
93
+
94
+ if (!foundValue && value !== undefined) {
95
+ typeof setFieldValue === 'function' && setFieldValue();
96
+ }
97
+ }
98
+
99
+ originOptions.current = options;
100
+ }
101
+ }, [options]);
102
+ return _jsxs(_Checkbox.Group, _objectSpread(_objectSpread({}, omit(rest, formMethods)), {}, {
49
103
  className: classnames('igloo-checkbox-group', className),
50
104
  value: value,
51
- children: _jsx(_Row, {
105
+ children: [_jsx(_Row, {
52
106
  gutter: [8, 8],
53
107
  children: options.map(function (_ref2) {
54
108
  var label = _ref2.label,
@@ -72,10 +126,36 @@ export var CheckboxGroup = function CheckboxGroup(_ref) {
72
126
  })]
73
127
  }, key);
74
128
  })
75
- })
129
+ }), !options.length && _jsxs("div", {
130
+ style: {
131
+ display: 'flex',
132
+ flexDirection: 'column',
133
+ background: '#f9f9f9',
134
+ padding: 16,
135
+ alignItems: 'center'
136
+ },
137
+ children: [_jsx("img", {
138
+ src: emptyIcon,
139
+ style: {
140
+ width: 32,
141
+ height: 24
142
+ }
143
+ }), _jsx(Typography, {
144
+ level: "h5",
145
+ style: {
146
+ color: '#212121',
147
+ marginTop: 8
148
+ },
149
+ children: formatMessage({
150
+ id: 'There are no options available currently'
151
+ })
152
+ })]
153
+ })]
76
154
  }));
77
155
  };
78
156
 
157
+ export var CheckboxGroup = optionsHOC(InnerCheckboxGroup);
158
+
79
159
  CheckboxGroup.formItemPropsHandler = function () {
80
160
  return {};
81
161
  };
@@ -12,6 +12,7 @@ import Divider from './divider';
12
12
  import UploadPhoto from '../upload-photo';
13
13
  import RenderElement from './render';
14
14
  import Typography from '../typography';
15
+ import SearchBox from '../search-box';
15
16
  var elementMap = {
16
17
  Input: Input,
17
18
  PhoneNumber: PhoneNumber,
@@ -42,7 +43,8 @@ var elementMap = {
42
43
  InputDate: InputDate,
43
44
  Confirmation: Confirmation,
44
45
  ExpiryDate: ExpiryDate,
45
- Typography: Typography
46
+ Typography: Typography,
47
+ SearchBox: SearchBox
46
48
  };
47
49
 
48
50
  var Unknown = function Unknown() {
package/es/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export { default as MobileInsurerDetail } from './mobile-insurer-detail';
35
35
  export { default as Layout } from './layout';
36
36
  export { default as DetailPanel } from './detail-panel';
37
37
  export { default as message } from './global-message';
38
+ export { default as SearchBox } from './search-box';
38
39
  export { default as FreeForm } from './free-form';
39
40
  export { default as FormItem } from './free-form/element';
40
41
  export { default as FormPages } from './free-form/pages';
package/es/index.js CHANGED
@@ -35,6 +35,7 @@ export { default as MobileInsurerDetail } from './mobile-insurer-detail';
35
35
  export { default as Layout } from './layout';
36
36
  export { default as DetailPanel } from './detail-panel';
37
37
  export { default as message } from './global-message';
38
+ export { default as SearchBox } from './search-box';
38
39
  export { default as FreeForm } from './free-form';
39
40
  export { default as FormItem } from './free-form/element';
40
41
  export { default as FormPages } from './free-form/pages';
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "Data Processed",
22
22
  "Data Processing...": "Data Processing...",
23
23
  "Date": "Date",
24
+ "Done": "Done",
24
25
  "Drag and drop a file here": "Drag and drop a file here",
25
26
  "Edit": "Edit",
26
27
  "Error Report": "Error Report",
@@ -56,10 +57,13 @@
56
57
  "Result": "Result",
57
58
  "Result: Success {success_num}; Error {fail_num}": "Result: Success {success_num}; Error {fail_num}",
58
59
  "Rows per page": "Rows per page",
60
+ "Search": "Search",
61
+ "Searching...": "Searching...",
59
62
  "Select All": "Select All",
60
63
  "Send OTP": "Send OTP",
61
64
  "Submit": "Submit",
62
65
  "The file type is not supported.": "The file type is not supported.",
66
+ "There are no options available currently": "There are no options available currently",
63
67
  "This Month": "This Month",
64
68
  "Unselect All": "Unselect All",
65
69
  "Uploading": "Uploading",
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "Data Terproses",
22
22
  "Data Processing...": "Data Diproses",
23
23
  "Date": "Tanggal",
24
+ "Done": "Selesai",
24
25
  "Drag and drop a file here": "Geser dan Letakkan Dokumen disini",
25
26
  "Edit": "Ubah",
26
27
  "Error Report": "Laporan Kesalahan",
@@ -56,10 +57,13 @@
56
57
  "Result": "Hasil",
57
58
  "Result: Success {success_num}; Error {fail_num}": "Hasil: Sukses {success_num}; Kesalahan {fail_num}",
58
59
  "Rows per page": "Baris per halaman",
60
+ "Search": "Mencari",
61
+ "Searching...": "Mencari...",
59
62
  "Select All": "Pilih Semua",
60
63
  "Send OTP": "Kirim OTP",
61
64
  "Submit": "Ajukan",
62
65
  "The file type is not supported.": "Jenis file tidak didukung.",
66
+ "There are no options available currently": "Tidak ada opsi yang tersedia saat ini",
63
67
  "This Month": "Bulan ini",
64
68
  "Unselect All": "Batalkan semua",
65
69
  "Uploading": "Mengunggah",
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "ประมวลข้อมูลสำเร็จแล้ว",
22
22
  "Data Processing...": "กำลังประมวลผลข้อมูล...",
23
23
  "Date": "วันที่",
24
+ "Done": "เสร็จแล้ว",
24
25
  "Drag and drop a file here": "ลากและวางไฟล์มาที่นี่",
25
26
  "Edit": "แก้ไข",
26
27
  "Error Report": "รายงานข้อผิดพลาด",
@@ -56,10 +57,13 @@
56
57
  "Result": "ผลลัพธ์",
57
58
  "Result: Success {success_num}; Error {fail_num}": "ผลลัพธ์: สำเร็จ {success_num}; ข้อผิดพลาด {fail_num}",
58
59
  "Rows per page": "แถวต่อหน้า",
60
+ "Search": "ค้นหา",
61
+ "Searching...": "กำลังค้นหา...",
59
62
  "Select All": "เลือกทั้งหมด",
60
63
  "Send OTP": "ส่ง OTP",
61
64
  "Submit": "ส่ง/ยืนยัน",
62
65
  "The file type is not supported.": "ประเภทไฟล์ไม่รองรับ",
66
+ "There are no options available currently": "ไม่มีตัวเลือกในขณะนี้",
63
67
  "This Month": "เดือนนี้",
64
68
  "Unselect All": "ไม่เลือกทั้งหมด",
65
69
  "Uploading": "กำลังอัพโหลด",
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "Dữ liệu đã xử lý",
22
22
  "Data Processing...": "Đang xử lý dữ liệu...",
23
23
  "Date": "Ngày",
24
+ "Done": "Xong",
24
25
  "Drag and drop a file here": "Thả tệp tin vào đây",
25
26
  "Edit": "Sửa",
26
27
  "Error Report": "Báo cáo lỗi",
@@ -56,10 +57,13 @@
56
57
  "Result": "Kết quả",
57
58
  "Result: Success {success_num}; Error {fail_num}": "Kết quả: sự thành công {success_num}; lỗi {fail_num}",
58
59
  "Rows per page": "Dòng trên trang",
60
+ "Search": "Tìm kiếm",
61
+ "Searching...": "Đang tìm kiếm...",
59
62
  "Select All": "Chọn tất cả",
60
63
  "Send OTP": "Gửi OTP",
61
64
  "Submit": "Gửi",
62
65
  "The file type is not supported.": "Loại tệp không được hỗ trợ.",
66
+ "There are no options available currently": "Hiện tại không có tùy chọn nào",
63
67
  "This Month": "Tháng này",
64
68
  "Unselect All": "Hủy chọn tất cả",
65
69
  "Uploading": "Đang tải lên",
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "已导入",
22
22
  "Data Processing...": "导入中",
23
23
  "Date": "日期",
24
+ "Done": "完成",
24
25
  "Drag and drop a file here": "拖拽一个文件到这里",
25
26
  "Edit": "编辑",
26
27
  "Error Report": "错误报告",
@@ -56,10 +57,13 @@
56
57
  "Result": "结果",
57
58
  "Result: Success {success_num}; Error {fail_num}": "结果:成功 {success_num}; 失败 {fail_num}",
58
59
  "Rows per page": "每页条数",
60
+ "Search": "搜索",
61
+ "Searching...": "正在搜索...",
59
62
  "Select All": "全选",
60
63
  "Send OTP": "发送OTP",
61
64
  "Submit": "提交",
62
65
  "The file type is not supported.": "不支持上传该类型的文件。",
66
+ "There are no options available currently": "当前没有可用的选项",
63
67
  "This Month": "当月",
64
68
  "Unselect All": "反选",
65
69
  "Uploading": "上传中",
@@ -21,6 +21,7 @@
21
21
  "Data Processed": "數據已處理",
22
22
  "Data Processing...": "數據處理中。。。",
23
23
  "Date": "日期",
24
+ "Done": "完成",
24
25
  "Drag and drop a file here": "拖放文件至此",
25
26
  "Edit": "編輯",
26
27
  "Error Report": "錯誤報告",
@@ -38,6 +39,7 @@
38
39
  "OK": "好",
39
40
  "Once you’re happy with the above, and you’ve checked the declaration, please go ahead and submit your claim.": "一旦您對上述內容感到滿意,您已檢查聲明,請繼續並提交您的索賠。",
40
41
  "Optional": "可選項",
42
+ "Other Reason": "其他原因",
41
43
  "Please enter a valid date.": "請輸入有效的日期。",
42
44
  "Please enter a valid time.": "請輸入有效的時間。",
43
45
  "Please select": "請選擇",
@@ -55,10 +57,13 @@
55
57
  "Result": "結果",
56
58
  "Result: Success {success_num}; Error {fail_num}": "結果:成功{success_num};錯誤{fail_num}",
57
59
  "Rows per page": "每頁行數",
60
+ "Search": "檢索",
61
+ "Searching...": "正在檢索...",
58
62
  "Select All": "全選",
59
63
  "Send OTP": "發送OTP.",
60
64
  "Submit": "提交",
61
65
  "The file type is not supported.": "不支持文件類型。",
66
+ "There are no options available currently": "當前沒有可用的選項",
62
67
  "This Month": "本月",
63
68
  "Unselect All": "全部取消選擇",
64
69
  "Uploading": "上傳",
@@ -1,22 +1,22 @@
1
1
  import { RadioProps, RadioGroupProps } from 'antd/es/radio';
2
2
  import { FC, IglooComponentProps } from '../types';
3
3
  import './style/index.less';
4
- import { FormInstance } from 'antd/es/form';
4
+ import { ComponentProps } from '../utils/option-utils';
5
+ import { DefaultOptionType } from 'rc-select/lib/Select';
5
6
  declare type Props = RadioProps & IglooComponentProps;
6
7
  declare const IglooRadio: FC<Props>;
7
- export interface Option extends RadioProps {
8
+ export interface Option extends DefaultOptionType {
8
9
  extraInfo?: {
9
10
  content: any;
10
11
  shownTrigger: 'unchecked' | 'checked' | 'all';
11
12
  };
12
- label: any;
13
13
  }
14
- export interface IProps extends IglooComponentProps, Omit<RadioGroupProps, 'options'> {
14
+ export interface IProps extends IglooComponentProps, Omit<RadioGroupProps, 'options'>, ComponentProps {
15
15
  className?: string;
16
16
  radioType?: string;
17
- getOptions?: (form: FormInstance) => Option[];
18
17
  options: Option[];
19
18
  }
20
- export declare const RadioGroup: FC<IProps>;
19
+ export declare const InnerRadioGroup: FC<IProps>;
20
+ export declare const RadioGroup: FC<import("../utils/option-utils").HOCProps & IProps>;
21
21
  export default IglooRadio;
22
22
  export { default as RadioGroupWithOther } from './radio-group-with-other';
package/es/radio/index.js CHANGED
@@ -4,9 +4,21 @@ import "antd/es/row/style";
4
4
  import _Row from "antd/es/row";
5
5
  import "antd/es/radio/style";
6
6
  import _Radio from "antd/es/radio";
7
- var _excluded = ["className", "options", "radioType", "getOptions", "value"],
7
+ var _excluded = ["className", "options", "radioType", "value", "clearWhenOptionsUpdated"],
8
8
  _excluded2 = ["label", "value", "extraInfo"];
9
9
 
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17
+
18
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19
+
20
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
+
10
22
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
23
 
12
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -18,12 +30,15 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
30
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
31
 
20
32
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
- import { useEffect } from 'react';
33
+ import { useEffect, useState, useRef, useContext } from 'react';
22
34
  import omit from 'omit.js';
23
35
  import classnames from 'classnames';
24
36
  import formMethods from '../utils/form-methods';
25
37
  import './style/index.less';
26
38
  import Typography from '../typography';
39
+ import LocaleContext from '../locale/locale-context';
40
+ import emptyIcon from './style/empty.svg';
41
+ import { compareOptions, optionsHOC } from '../utils/option-utils';
27
42
 
28
43
  var IglooRadio = function IglooRadio(props) {
29
44
  return _jsx(_Radio, _objectSpread({}, omit(props, formMethods)));
@@ -33,38 +48,55 @@ IglooRadio.formItemPropsHandler = function () {
33
48
  return {};
34
49
  };
35
50
 
36
- export var RadioGroup = function RadioGroup(_ref) {
51
+ export var InnerRadioGroup = function InnerRadioGroup(_ref) {
37
52
  var className = _ref.className,
38
- optionsProp = _ref.options,
53
+ options = _ref.options,
39
54
  _ref$radioType = _ref.radioType,
40
55
  radioType = _ref$radioType === void 0 ? 'normal' : _ref$radioType,
41
- getOptionsProp = _ref.getOptions,
42
56
  value = _ref.value,
57
+ _ref$clearWhenOptions = _ref.clearWhenOptionsUpdated,
58
+ clearWhenOptionsUpdated = _ref$clearWhenOptions === void 0 ? false : _ref$clearWhenOptions,
43
59
  rest = _objectWithoutProperties(_ref, _excluded);
44
60
 
45
- var getOptions = function getOptions() {
46
- var getFormInstance = rest.getFormInstance;
47
- var form = typeof getFormInstance === 'function' && getFormInstance();
48
- if (!form) return [];
49
- var options = typeof getOptionsProp === 'function' && getOptionsProp(form);
50
- return options || [];
51
- };
61
+ var _useState = useState(value),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ selected = _useState2[0],
64
+ setSelected = _useState2[1];
52
65
 
53
- var options = optionsProp || getOptions();
66
+ var originOptions = useRef(options);
67
+
68
+ var _useContext = useContext(LocaleContext),
69
+ formatMessage = _useContext.formatMessage;
70
+
71
+ useEffect(function () {
72
+ typeof rest.onChange === 'function' && value !== selected && rest.onChange(selected);
73
+ }, [selected]);
74
+ useEffect(function () {
75
+ setSelected(value);
76
+ }, [value]);
54
77
  useEffect(function () {
55
78
  var setFieldValue = rest.setFieldValue;
56
- var foundValue = options.find(function (option) {
57
- return option.value === value;
58
- });
59
79
 
60
- if (!foundValue) {
61
- typeof setFieldValue === 'function' && setFieldValue(undefined);
80
+ if (compareOptions(options, originOptions.current)) {
81
+ if (clearWhenOptionsUpdated) {
82
+ typeof setFieldValue === 'function' && setFieldValue();
83
+ } else {
84
+ var foundValue = options.find(function (option) {
85
+ return Array.isArray(value) ? value.includes(option.value) : option.value === value;
86
+ });
87
+
88
+ if (!foundValue && value !== undefined) {
89
+ typeof setFieldValue === 'function' && setFieldValue();
90
+ }
91
+ }
92
+
93
+ originOptions.current = options;
62
94
  }
63
- }, [value, options]);
64
- return _jsx(_Radio.Group, _objectSpread(_objectSpread({}, omit(rest, formMethods)), {}, {
95
+ }, [options]);
96
+ return _jsxs(_Radio.Group, _objectSpread(_objectSpread({}, omit(rest, formMethods)), {}, {
65
97
  className: classnames('igloo-radio-group', className),
66
98
  value: value,
67
- children: _jsx(_Row, {
99
+ children: [_jsx(_Row, {
68
100
  gutter: [8, 8],
69
101
  children: options.map(function (_ref2) {
70
102
  var label = _ref2.label,
@@ -108,9 +140,34 @@ export var RadioGroup = function RadioGroup(_ref) {
108
140
  }))
109
141
  }, key);
110
142
  })
111
- })
143
+ }), !options.length && _jsxs("div", {
144
+ style: {
145
+ display: 'flex',
146
+ flexDirection: 'column',
147
+ background: '#f9f9f9',
148
+ padding: 16,
149
+ alignItems: 'center'
150
+ },
151
+ children: [_jsx("img", {
152
+ src: emptyIcon,
153
+ style: {
154
+ width: 32,
155
+ height: 24
156
+ }
157
+ }), _jsx(Typography, {
158
+ level: "h5",
159
+ style: {
160
+ color: '#212121',
161
+ marginTop: 8
162
+ },
163
+ children: formatMessage({
164
+ id: 'There are no options available currently'
165
+ })
166
+ })]
167
+ })]
112
168
  }));
113
169
  };
170
+ export var RadioGroup = optionsHOC(InnerRadioGroup);
114
171
 
115
172
  RadioGroup.formItemPropsHandler = function () {
116
173
  return {};
@@ -1,6 +1,6 @@
1
1
  import { IProps as RadioGroupProps } from './index';
2
2
  import { FC } from '../types';
3
- declare const RadioGroupWithOther: FC<RadioGroupProps & {
3
+ declare const RadioGroupWithOther: FC<import("../utils/option-utils").HOCProps & RadioGroupProps & {
4
4
  otherOptionLabel: string;
5
5
  }>;
6
6
  export default RadioGroupWithOther;
@@ -1,4 +1,4 @@
1
- var _excluded = ["value", "onChange", "options", "otherOptionLabel"];
1
+ var _excluded = ["value", "onChange", "options", "otherOptionLabel", "clearWhenOptionsUpdated"];
2
2
 
3
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
4
 
@@ -31,17 +31,21 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
31
31
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
32
32
 
33
33
  import { jsx as _jsx } from "react/jsx-runtime";
34
- import { useContext, useState } from 'react';
34
+ import { useContext, useState, useEffect, useRef } from 'react';
35
35
  import { RadioGroup } from './index';
36
36
  import { TextArea } from '../input';
37
37
  import { LocaleContext } from '../locale';
38
+ import { compareOptions, optionsHOC } from '../utils/option-utils';
38
39
  var otherKey = 'iglooRadioGroupOther';
39
40
 
40
- var RadioGroupWithOther = function RadioGroupWithOther(_ref) {
41
+ var InnerRadioGroupWithOther = function InnerRadioGroupWithOther(_ref) {
41
42
  var value = _ref.value,
42
43
  onChange = _ref.onChange,
43
- options = _ref.options,
44
+ _ref$options = _ref.options,
45
+ options = _ref$options === void 0 ? [] : _ref$options,
44
46
  otherOptionLabel = _ref.otherOptionLabel,
47
+ _ref$clearWhenOptions = _ref.clearWhenOptionsUpdated,
48
+ clearWhenOptionsUpdated = _ref$clearWhenOptions === void 0 ? false : _ref$clearWhenOptions,
45
49
  rest = _objectWithoutProperties(_ref, _excluded);
46
50
 
47
51
  var _useState = useState(false),
@@ -49,6 +53,38 @@ var RadioGroupWithOther = function RadioGroupWithOther(_ref) {
49
53
  otherEnabled = _useState2[0],
50
54
  enableOther = _useState2[1];
51
55
 
56
+ var _useState3 = useState(value),
57
+ _useState4 = _slicedToArray(_useState3, 2),
58
+ selected = _useState4[0],
59
+ setSelected = _useState4[1];
60
+
61
+ var originOptions = useRef(options);
62
+ useEffect(function () {
63
+ typeof onChange === 'function' && value !== selected && onChange(selected);
64
+ }, [selected]);
65
+ useEffect(function () {
66
+ setSelected(value);
67
+ }, [value]);
68
+ useEffect(function () {
69
+ var setFieldValue = rest.setFieldValue;
70
+
71
+ if (compareOptions(options, originOptions.current)) {
72
+ if (clearWhenOptionsUpdated) {
73
+ typeof setFieldValue === 'function' && setFieldValue();
74
+ } else {
75
+ var foundValue = options.find(function (option) {
76
+ return Array.isArray(value) ? value.includes(option.value) : option.value === value;
77
+ });
78
+
79
+ if (!foundValue && value !== undefined) {
80
+ typeof setFieldValue === 'function' && setFieldValue();
81
+ }
82
+ }
83
+
84
+ originOptions.current = options;
85
+ }
86
+ }, [options]);
87
+
52
88
  var handleChange = function handleChange(e) {
53
89
  onChange && onChange(e);
54
90
  };
@@ -82,4 +118,5 @@ var RadioGroupWithOther = function RadioGroupWithOther(_ref) {
82
118
  });
83
119
  };
84
120
 
121
+ var RadioGroupWithOther = optionsHOC(InnerRadioGroupWithOther);
85
122
  export default RadioGroupWithOther;
@@ -0,0 +1,12 @@
1
+ <svg width="32" height="25" viewBox="0 0 32 25" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path
3
+ d="M30.6663 18.3333V12.5846C30.6663 12.0654 30.5316 11.5551 30.2752 11.1035L25.4017 2.51891C24.8687 1.58006 23.8724 1 22.7928 1H8.99351C7.89503 1 6.88439 1.60036 6.35896 2.56503L1.69846 11.1215C1.45865 11.5618 1.33301 12.0551 1.33301 12.5565V18.3333"
4
+ stroke="#212121" stroke-width="2" />
5
+ <mask id="path-2-inside-1_8603_29999" fill="white">
6
+ <path fill-rule="evenodd" clip-rule="evenodd"
7
+ d="M9.22038 11.3468C9.22038 10.5263 8.5552 9.86108 7.73467 9.86108H3C1.34315 9.86108 0 11.2042 0 12.8611V22C0 23.6568 1.34315 25 3 25H29C30.6569 25 32 23.6568 32 22V12.8611C32 11.2042 30.6569 9.86108 29 9.86108H24.2654C23.4449 9.86108 22.7797 10.5263 22.7797 11.3468C22.7797 13.0036 21.4366 14.3468 19.7797 14.3468H12.2204C10.5635 14.3468 9.22038 13.0036 9.22038 11.3468Z" />
8
+ </mask>
9
+ <path
10
+ d="M3 11.8611H7.73467V7.86108H3V11.8611ZM2 22V12.8611H-2V22H2ZM29 23H3V27H29V23ZM30 12.8611V22H34V12.8611H30ZM24.2654 11.8611H29V7.86108H24.2654V11.8611ZM20.7797 11.3468C20.7797 11.8991 20.332 12.3468 19.7797 12.3468V16.3468C22.5411 16.3468 24.7797 14.1082 24.7797 11.3468H20.7797ZM19.7797 12.3468H12.2204V16.3468H19.7797V12.3468ZM12.2204 12.3468C11.6681 12.3468 11.2204 11.8991 11.2204 11.3468H7.22038C7.22038 14.1082 9.45895 16.3468 12.2204 16.3468V12.3468ZM24.2654 7.86108C22.3403 7.86108 20.7797 9.42169 20.7797 11.3468H24.7797C24.7797 11.6308 24.5494 11.8611 24.2654 11.8611V7.86108ZM34 12.8611C34 10.0997 31.7614 7.86108 29 7.86108V11.8611C29.5523 11.8611 30 12.3088 30 12.8611H34ZM29 27C31.7614 27 34 24.7614 34 22H30C30 22.5523 29.5523 23 29 23V27ZM-2 22C-2 24.7614 0.238576 27 3 27V23C2.44772 23 2 22.5523 2 22H-2ZM7.73467 11.8611C7.45064 11.8611 7.22038 11.6308 7.22038 11.3468H11.2204C11.2204 9.42168 9.65977 7.86108 7.73467 7.86108V11.8611ZM3 7.86108C0.238578 7.86108 -2 10.0997 -2 12.8611H2C2 12.3088 2.44771 11.8611 3 11.8611V7.86108Z"
11
+ fill="#212121" mask="url(#path-2-inside-1_8603_29999)" />
12
+ </svg>