@kdcloudjs/kdesign 1.7.18 → 1.7.20

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 (88) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/kdesign-complete.less +362 -244
  3. package/dist/kdesign.css +270 -239
  4. package/dist/kdesign.css.map +1 -1
  5. package/dist/kdesign.js +716 -788
  6. package/dist/kdesign.js.map +1 -1
  7. package/dist/kdesign.min.css +2 -2
  8. package/dist/kdesign.min.js +6 -6
  9. package/dist/kdesign.min.js.map +1 -1
  10. package/es/button/style/token.less +1 -0
  11. package/es/carousel/style/index.css +4 -0
  12. package/es/carousel/style/index.less +31 -5
  13. package/es/cascader/cascader.js +4 -2
  14. package/es/checkbox/checkbox.js +5 -5
  15. package/es/checkbox/style/index.css +2 -0
  16. package/es/checkbox/style/index.less +2 -0
  17. package/es/checkbox/style/token.less +1 -1
  18. package/es/city-picker/city-picker.d.ts +3 -23
  19. package/es/city-picker/city-picker.js +351 -124
  20. package/es/city-picker/interface.d.ts +57 -0
  21. package/es/city-picker/interface.js +3 -0
  22. package/es/city-picker/option.d.ts +4 -0
  23. package/es/city-picker/option.js +42 -0
  24. package/es/city-picker/style/index.css +264 -239
  25. package/es/city-picker/style/index.less +262 -218
  26. package/es/city-picker/style/mixin.less +26 -3
  27. package/es/city-picker/style/token.less +42 -14
  28. package/es/collapse/collapse.d.ts +1 -1
  29. package/es/config-provider/compDefaultProps.d.ts +13 -0
  30. package/es/config-provider/compDefaultProps.js +13 -0
  31. package/es/dropdown/dropdown.d.ts +1 -0
  32. package/es/dropdown/dropdown.js +7 -2
  33. package/es/input/style/token.less +2 -8
  34. package/es/upload/upload.js +87 -63
  35. package/lib/button/style/token.less +1 -0
  36. package/lib/carousel/style/index.css +4 -0
  37. package/lib/carousel/style/index.less +31 -5
  38. package/lib/cascader/cascader.js +4 -2
  39. package/lib/checkbox/checkbox.js +4 -4
  40. package/lib/checkbox/style/index.css +2 -0
  41. package/lib/checkbox/style/index.less +2 -0
  42. package/lib/checkbox/style/token.less +1 -1
  43. package/lib/city-picker/city-picker.d.ts +3 -23
  44. package/lib/city-picker/city-picker.js +350 -123
  45. package/lib/city-picker/interface.d.ts +57 -0
  46. package/lib/city-picker/interface.js +11 -0
  47. package/lib/city-picker/option.d.ts +4 -0
  48. package/lib/city-picker/option.js +55 -0
  49. package/lib/city-picker/style/index.css +264 -239
  50. package/lib/city-picker/style/index.less +262 -218
  51. package/lib/city-picker/style/mixin.less +26 -3
  52. package/lib/city-picker/style/token.less +42 -14
  53. package/lib/collapse/collapse.d.ts +1 -1
  54. package/lib/config-provider/compDefaultProps.d.ts +13 -0
  55. package/lib/config-provider/compDefaultProps.js +13 -0
  56. package/lib/dropdown/dropdown.d.ts +1 -0
  57. package/lib/dropdown/dropdown.js +7 -2
  58. package/lib/input/style/token.less +2 -8
  59. package/lib/upload/upload.js +86 -62
  60. package/package.json +1 -1
  61. package/es/city-picker/city-group.d.ts +0 -8
  62. package/es/city-picker/city-group.js +0 -38
  63. package/es/city-picker/city-list.d.ts +0 -12
  64. package/es/city-picker/city-list.js +0 -55
  65. package/es/city-picker/city-panel-item.d.ts +0 -13
  66. package/es/city-picker/city-panel-item.js +0 -22
  67. package/es/city-picker/city-panel.d.ts +0 -17
  68. package/es/city-picker/city-panel.js +0 -153
  69. package/es/city-picker/city-search-panel.d.ts +0 -9
  70. package/es/city-picker/city-search-panel.js +0 -44
  71. package/es/city-picker/no-data.d.ts +0 -3
  72. package/es/city-picker/no-data.js +0 -18
  73. package/es/city-picker/utils/grouping.d.ts +0 -7
  74. package/es/city-picker/utils/grouping.js +0 -24
  75. package/lib/city-picker/city-group.d.ts +0 -8
  76. package/lib/city-picker/city-group.js +0 -51
  77. package/lib/city-picker/city-list.d.ts +0 -12
  78. package/lib/city-picker/city-list.js +0 -68
  79. package/lib/city-picker/city-panel-item.d.ts +0 -13
  80. package/lib/city-picker/city-panel-item.js +0 -35
  81. package/lib/city-picker/city-panel.d.ts +0 -17
  82. package/lib/city-picker/city-panel.js +0 -166
  83. package/lib/city-picker/city-search-panel.d.ts +0 -9
  84. package/lib/city-picker/city-search-panel.js +0 -57
  85. package/lib/city-picker/no-data.d.ts +0 -3
  86. package/lib/city-picker/no-data.js +0 -31
  87. package/lib/city-picker/utils/grouping.d.ts +0 -7
  88. package/lib/city-picker/utils/grouping.js +0 -30
@@ -1,152 +1,379 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/extends";
1
2
  import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
3
+ import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
4
  import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
3
5
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
4
- import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
5
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
6
- import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
7
- import React, { useContext, useState, useRef, useEffect } from 'react';
6
+ import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
7
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
8
+ import React, { useContext, useRef, useEffect, useState, useCallback } from 'react';
9
+ import { useMergedState } from '../_utils/hooks';
8
10
  import classNames from 'classnames';
9
11
  import ConfigContext from '../config-provider/ConfigContext';
10
- import CityPanelItem from './city-panel-item';
11
- import CityPanel from './city-panel';
12
- import SearchPanel from './city-search-panel';
12
+ import { getCompProps } from '../_utils';
13
+ import { Icon, Tabs, Spin } from '../index';
13
14
  import usePopper from '../_utils/usePopper';
14
- var CityPicker = function CityPicker(_ref) {
15
- var cityList = _ref.cityList,
16
- className = _ref.className,
17
- commons = _ref.commons,
18
- disabled = _ref.disabled,
19
- groups = _ref.groups,
20
- inputClassName = _ref.inputClassName,
21
- inputStyle = _ref.inputStyle,
22
- placeholder = _ref.placeholder,
23
- showTitle = _ref.showTitle,
24
- style = _ref.style,
25
- title = _ref.title;
15
+ import Option from './option';
16
+ import escapeRegExp from 'lodash/escapeRegExp';
17
+ var tabsData = [{
18
+ id: 'domestic',
19
+ name: '国内'
20
+ }, {
21
+ id: 'foreign',
22
+ name: '国际/中国港澳台'
23
+ }];
24
+ var InternalSelect = function InternalSelect(props, ref) {
25
+ var _context, _classNames3, _classNames5;
26
26
  var _useContext = useContext(ConfigContext),
27
27
  getPrefixCls = _useContext.getPrefixCls,
28
- prefixCls = _useContext.prefixCls;
29
- var _useState = useState(''),
28
+ prefixCls = _useContext.prefixCls,
29
+ userDefaultProps = _useContext.compDefaultProps;
30
+ var selectProps = getCompProps('CityPicker', userDefaultProps, props);
31
+ var type = selectProps.type,
32
+ size = selectProps.size,
33
+ value = selectProps.value,
34
+ className = selectProps.className,
35
+ defaultOpen = selectProps.defaultOpen,
36
+ disabled = selectProps.disabled,
37
+ borderType = selectProps.borderType,
38
+ _selectProps$showArro = selectProps.showArrow,
39
+ showArrow = _selectProps$showArro === void 0 ? true : _selectProps$showArro,
40
+ allowClear = selectProps.allowClear,
41
+ customPrefixcls = selectProps.prefixCls,
42
+ onFocus = selectProps.onFocus,
43
+ onBlur = selectProps.onBlur,
44
+ onClear = selectProps.onClear,
45
+ onVisibleChange = selectProps.onVisibleChange,
46
+ onChange = selectProps.onChange,
47
+ onSearch = selectProps.onSearch,
48
+ defaultValue = selectProps.defaultValue,
49
+ placeholder = selectProps.placeholder,
50
+ _selectProps$dropdown = selectProps.dropdownStyle,
51
+ dropdownStyle = _selectProps$dropdown === void 0 ? {} : _selectProps$dropdown,
52
+ style = selectProps.style,
53
+ clearIcon = selectProps.clearIcon,
54
+ loading = selectProps.loading,
55
+ showDescription = selectProps.showDescription,
56
+ description = selectProps.description,
57
+ optionHighlightProps = selectProps.optionHighlightProps,
58
+ _selectProps$popperSt = selectProps.popperStyle,
59
+ popperStyle = _selectProps$popperSt === void 0 ? {} : _selectProps$popperSt,
60
+ _selectProps$commonLi = selectProps.commonList,
61
+ commonList = _selectProps$commonLi === void 0 ? [] : _selectProps$commonLi,
62
+ _selectProps$domestic = selectProps.domesticList,
63
+ domesticList = _selectProps$domestic === void 0 ? [] : _selectProps$domestic,
64
+ _selectProps$foreignL = selectProps.foreignList,
65
+ foreignList = _selectProps$foreignL === void 0 ? [] : _selectProps$foreignL,
66
+ itemRender = selectProps.itemRender;
67
+ var _useMergedState = useMergedState(undefined, {
68
+ value: value,
69
+ defaultValue: defaultValue
70
+ }),
71
+ _useMergedState2 = _slicedToArray(_useMergedState, 2),
72
+ initValue = _useMergedState2[0],
73
+ setInitValue = _useMergedState2[1];
74
+ var innerRef = useRef();
75
+ var selectRef = ref || innerRef;
76
+ var searchRef = useRef(null); // 搜索框ref
77
+ var selectionRef = useRef(null);
78
+ var clearRef = useRef(null);
79
+ var _useState = useState(typeof props.visible === 'undefined' ? !!defaultOpen : !!props.visible),
30
80
  _useState2 = _slicedToArray(_useState, 2),
31
- inputVal = _useState2[0],
32
- setInputVal = _useState2[1];
81
+ optionShow = _useState2[0],
82
+ setOptionShow = _useState2[1];
33
83
  var _useState3 = useState(''),
34
84
  _useState4 = _slicedToArray(_useState3, 2),
35
- additionalVal = _useState4[0],
36
- setAdditionalVal = _useState4[1];
85
+ searchValue = _useState4[0],
86
+ setSearchValue = _useState4[1];
37
87
  var _useState5 = useState(false),
38
88
  _useState6 = _slicedToArray(_useState5, 2),
39
- popperVisible = _useState6[0],
40
- setPopperVisible = _useState6[1];
41
- var inputRef = useRef(null);
42
- var allCity = useRef([]);
89
+ focusd = _useState6[0],
90
+ setFocusd = _useState6[1];
91
+ var _useState7 = useState(null),
92
+ _useState8 = _slicedToArray(_useState7, 2),
93
+ seletedCity = _useState8[0],
94
+ setSeletedCity = _useState8[1];
95
+ var _useState9 = useState('domestic'),
96
+ _useState10 = _slicedToArray(_useState9, 2),
97
+ tabsValue = _useState10[0],
98
+ setTabsValue = _useState10[1];
99
+ var isDomestic = function isDomestic(type) {
100
+ return type === 'domestic';
101
+ };
102
+ var selectPrefixCls = getPrefixCls(prefixCls, 'city-picker', customPrefixcls);
103
+ var cityPickerCls = classNames(selectPrefixCls, className, _defineProperty({}, "".concat(selectPrefixCls, "-visible"), optionShow));
104
+ var selectionCls = classNames(_defineProperty({}, "".concat(selectPrefixCls, "-selector"), true));
105
+ // 公共样式
106
+ var commCls = classNames((_classNames3 = {}, _defineProperty(_classNames3, "".concat(selectPrefixCls, "-bordered"), borderType === 'bordered'), _defineProperty(_classNames3, "".concat(selectPrefixCls, "-underline"), borderType === 'underline'), _defineProperty(_classNames3, "".concat(selectPrefixCls, "-borderless"), borderType === 'none'), _defineProperty(_classNames3, _concatInstanceProperty(_context = "".concat(selectPrefixCls, "-size-")).call(_context, size), size), _defineProperty(_classNames3, "".concat(selectPrefixCls, "-wrapper"), true), _defineProperty(_classNames3, "".concat(selectPrefixCls, "-show-search"), focusd), _classNames3));
43
107
  useEffect(function () {
44
- var _context;
45
- if (!cityList) {
46
- return;
108
+ var _context2;
109
+ if (typeof value === 'undefined') return;
110
+ var cityList = _concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(commonList), _toConsumableArray(domesticList), _toConsumableArray(foreignList));
111
+ var city = _findInstanceProperty(cityList).call(cityList, function (city) {
112
+ return city.id === value;
113
+ });
114
+ if (city) {
115
+ setSeletedCity(city);
47
116
  }
48
- var domestic = cityList.domestic,
49
- foreign = cityList.foreign;
50
- allCity.current = _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(_Object$values(domestic)), _toConsumableArray(_Object$values(foreign))).reduce(function (arr, current) {
51
- return _concatInstanceProperty(arr).call(arr, current);
52
- }, []);
53
- }, [cityList]);
54
- var cityPickerPrefixCls = getPrefixCls(prefixCls, 'city-picker');
55
- var containerCls = classNames("".concat(cityPickerPrefixCls, "-container"), className);
56
- var contentCls = classNames("".concat(cityPickerPrefixCls, "-content"));
57
- var titleCls = classNames("".concat(cityPickerPrefixCls, "-title"));
58
- var additionalInfoCls = classNames("".concat(cityPickerPrefixCls, "-info"));
59
- var inputCls = classNames("".concat(cityPickerPrefixCls, "-input"), inputClassName);
60
- var arrowCls = classNames('kdicon kdicon-arrow-down', "".concat(cityPickerPrefixCls, "-arrow"), {
61
- 'arrow-up': popperVisible
62
- });
63
- var handleContainerClick = function handleContainerClick() {
64
- var _a;
65
- if (document.activeElement === inputRef.current) {
66
- return;
117
+ }, [commonList, domesticList, foreignList, value]);
118
+ useEffect(function () {
119
+ if (typeof props.visible !== 'undefined') {
120
+ setOptionShow(props.visible);
121
+ }
122
+ }, [props.visible]);
123
+ useEffect(function () {
124
+ if (optionShow === false) {
125
+ handleClear();
67
126
  }
68
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
127
+ }, [optionShow]);
128
+ var handleFocus = useCallback(function (e) {
129
+ e.stopPropagation();
130
+ setFocusd(true);
131
+ onFocus && onFocus(e);
132
+ }, [onFocus]);
133
+ var handleBlur = useCallback(function (e) {
134
+ e.stopPropagation();
135
+ setFocusd(false);
136
+ onBlur && onBlur(e);
137
+ }, [onBlur]);
138
+ useEffect(function () {
139
+ selectionRef.current.addEventListener('mouseup', function (e) {
140
+ var _a;
141
+ var isCloseBtn = ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.className.indexOf('kd-tag-close-icon')) > -1;
142
+ if (isCloseBtn) {
143
+ e.stopPropagation();
144
+ }
145
+ });
146
+ }, []);
147
+ // 输入框变化搜索内容
148
+ var handleSearchChange = useCallback(function (event) {
149
+ var val = event.currentTarget.value;
150
+ setOptionShow(true);
151
+ setSearchValue(val);
152
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(val);
153
+ }, [onSearch]);
154
+ // 清除搜索内容
155
+ var handleClear = useCallback(function () {
156
+ if (searchRef.current) {
157
+ searchRef.current.value = '';
158
+ setSearchValue('');
159
+ }
160
+ }, [searchRef]);
161
+ // 清空选择器内容
162
+ var handleReset = function handleReset(e) {
163
+ e.stopPropagation();
164
+ onClear && onClear('');
165
+ setInitValue('');
166
+ setSeletedCity(null);
167
+ setSearchValue('');
168
+ onChange && onChange(undefined, '');
169
+ };
170
+ // 渲染后缀图标
171
+ var renderSuffix = function renderSuffix() {
172
+ var _classNames4;
173
+ if (disabled) return null;
174
+ var suffixIcon = selectProps.suffixIcon;
175
+ var arrowIconCls = classNames((_classNames4 = {}, _defineProperty(_classNames4, "".concat(selectPrefixCls, "-icon-arrow"), true), _defineProperty(_classNames4, "".concat(selectPrefixCls, "-icon-arrow-up"), optionShow), _defineProperty(_classNames4, "".concat(selectPrefixCls, "-icon-arrow-down"), !optionShow), _defineProperty(_classNames4, "".concat(selectPrefixCls, "-icon-arrow-focus"), optionShow), _classNames4));
176
+ var iconShow = allowClear && !disabled && ((initValue !== null && initValue !== void 0 ? initValue : '') !== '' || searchValue);
177
+ return /*#__PURE__*/React.createElement(React.Fragment, null, iconShow && /*#__PURE__*/React.createElement("span", {
178
+ onClick: handleReset,
179
+ onMouseDown: function onMouseDown(e) {
180
+ return e.preventDefault();
181
+ },
182
+ className: "".concat(selectPrefixCls, "-icon-clear"),
183
+ ref: clearRef
184
+ }, clearIcon || /*#__PURE__*/React.createElement(Icon, {
185
+ type: "close-solid"
186
+ })), showArrow && /*#__PURE__*/React.createElement("span", {
187
+ className: arrowIconCls
188
+ }, suffixIcon || /*#__PURE__*/React.createElement(Icon, {
189
+ type: "arrow-down"
190
+ })));
69
191
  };
70
- var handleCitySelect = function handleCitySelect(city) {
71
- var _context2, _context3;
72
- setInputVal(city.name || '');
73
- var otherInfoStr = city.country === '中国' ? "".concat(city.province) : _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "".concat(city.province)).call(_context3, city.province ? ',' : '')).call(_context2, city.country);
74
- setAdditionalVal(otherInfoStr);
75
- setPopperVisible(false);
192
+ // 下拉列表为空时显示的内容
193
+ var renderNotContent = function renderNotContent(msg) {
194
+ var notFoundContent = selectProps.notFoundContent;
195
+ var emptyContent = notFoundContent || msg;
196
+ return /*#__PURE__*/React.createElement("div", {
197
+ className: "".concat(selectPrefixCls, "-dropdown-empty")
198
+ }, emptyContent);
199
+ };
200
+ var getHighlightText = function getHighlightText(text, inputValue) {
201
+ if (!inputValue || !text) return text;
202
+ var regex = new RegExp(Array.isArray(inputValue) ? _mapInstanceProperty(inputValue).call(inputValue, function (item) {
203
+ return "(".concat(escapeRegExp(item), ")");
204
+ }).join('|') : "(".concat(escapeRegExp(inputValue), ")"), 'i');
205
+ var strArr = text === null || text === void 0 ? void 0 : text.split(regex);
206
+ return /*#__PURE__*/React.createElement(React.Fragment, null, strArr === null || strArr === void 0 ? void 0 : _mapInstanceProperty(strArr).call(strArr, function (item, index) {
207
+ return (regex === null || regex === void 0 ? void 0 : regex.test(item)) ? /*#__PURE__*/React.createElement("span", {
208
+ key: index,
209
+ className: "".concat(selectPrefixCls, "-highlight")
210
+ }, item) : /*#__PURE__*/React.createElement("span", {
211
+ key: index
212
+ }, item);
213
+ }));
214
+ };
215
+ var handleOption = function handleOption(city) {
216
+ handleVisibleChange(false);
217
+ (city === null || city === void 0 ? void 0 : city.id) !== initValue && (onChange === null || onChange === void 0 ? void 0 : onChange(city === null || city === void 0 ? void 0 : city.id, city));
218
+ if (typeof value === 'undefined') {
219
+ setSeletedCity(city);
220
+ setInitValue(city === null || city === void 0 ? void 0 : city.id);
221
+ }
76
222
  };
77
- var handleFocus = function handleFocus() {
78
- if (popperVisible) {
79
- return;
223
+ var renderNodeList = function renderNodeList(data, notContent) {
224
+ if (!data.length) {
225
+ return renderNotContent(notContent);
80
226
  }
81
- setPopperVisible(true);
227
+ return /*#__PURE__*/React.createElement("div", {
228
+ className: "".concat(selectPrefixCls, "-list")
229
+ }, _mapInstanceProperty(data).call(data, function (item) {
230
+ return /*#__PURE__*/React.createElement(Option, {
231
+ key: item.id,
232
+ value: initValue,
233
+ city: item,
234
+ renderCityInfo: renderCityInfo,
235
+ onChangeSelect: handleOption,
236
+ itemRender: itemRender
237
+ }, searchValue ? getHighlightText(item === null || item === void 0 ? void 0 : item.name, (item === null || item === void 0 ? void 0 : item[optionHighlightProps]) || searchValue) : item === null || item === void 0 ? void 0 : item.name);
238
+ }));
82
239
  };
83
- var handleChange = function handleChange(evt) {
84
- var value = evt.target.value;
85
- setAdditionalVal('');
86
- setInputVal(value);
240
+ var renderLoading = function renderLoading() {
241
+ return /*#__PURE__*/React.createElement("div", {
242
+ className: "".concat(selectPrefixCls, "-dropdown-loading")
243
+ }, /*#__PURE__*/React.createElement(Spin, {
244
+ type: "container"
245
+ }));
87
246
  };
88
- var handlePopperVisibleChange = function handlePopperVisibleChange(visible) {
89
- if (!visible) {
90
- setPopperVisible(false);
247
+ var toggleTabPane = function toggleTabPane(type) {
248
+ setTabsValue(type);
249
+ };
250
+ // 渲染下拉列表框
251
+ var renderContent = function renderContent() {
252
+ return loading ? renderLoading() : /*#__PURE__*/React.createElement(React.Fragment, null, searchValue ? /*#__PURE__*/React.createElement(React.Fragment, null, isDomestic(type) && /*#__PURE__*/React.createElement(Tabs, {
253
+ noContainer: true,
254
+ onChange: toggleTabPane,
255
+ activeKey: tabsValue
256
+ }, _mapInstanceProperty(tabsData).call(tabsData, function (item) {
257
+ return /*#__PURE__*/React.createElement(Tabs.TabPane, {
258
+ key: item.id,
259
+ tab: item.name
260
+ }, item);
261
+ })), tabsValue === 'domestic' ? renderNodeList(domesticList, '暂无数据') : renderNodeList(foreignList, '暂无数据')) : /*#__PURE__*/React.createElement(React.Fragment, null, !!commonList.length && /*#__PURE__*/React.createElement("div", {
262
+ className: "".concat(selectPrefixCls, "-dropdown-common")
263
+ }, "\u5E38\u7528"), renderNodeList(commonList, '无常用城市')));
264
+ };
265
+ var renderCityInfo = useCallback(function (data) {
266
+ var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
267
+ var symbol = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ', ';
268
+ if (!data) return null;
269
+ if (isDomestic(type)) {
270
+ var _context3;
271
+ return _concatInstanceProperty(_context3 = "".concat(flag && (data === null || data === void 0 ? void 0 : data.province) ? symbol : '')).call(_context3, data === null || data === void 0 ? void 0 : data.province);
272
+ } else {
273
+ var _context4, _context5, _context6;
274
+ return _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = _concatInstanceProperty(_context6 = "".concat(flag && (data === null || data === void 0 ? void 0 : data.province) ? symbol : '')).call(_context6, data === null || data === void 0 ? void 0 : data.province)).call(_context5, (data === null || data === void 0 ? void 0 : data.country) ? symbol : '')).call(_context4, data === null || data === void 0 ? void 0 : data.country);
91
275
  }
276
+ }, [type]);
277
+ var renderSingle = function renderSingle() {
278
+ var hiddenStyle = !!searchValue || (initValue !== null && initValue !== void 0 ? initValue : '') !== '' ? {
279
+ visibility: 'hidden'
280
+ } : undefined;
281
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
282
+ className: singleCls,
283
+ ref: selectionRef
284
+ }, /*#__PURE__*/React.createElement("div", {
285
+ className: "".concat(selectPrefixCls, "-content")
286
+ }, /*#__PURE__*/React.createElement("span", {
287
+ className: "".concat(selectPrefixCls, "-content-search")
288
+ }, /*#__PURE__*/React.createElement("input", {
289
+ ref: searchRef,
290
+ value: searchValue,
291
+ className: "".concat(selectPrefixCls, "-content-search-input"),
292
+ onChange: handleSearchChange,
293
+ onFocus: handleFocus,
294
+ onBlur: handleBlur,
295
+ readOnly: !!disabled
296
+ }), !searchValue && /*#__PURE__*/React.createElement("span", {
297
+ className: "".concat(selectPrefixCls, "-content-item"),
298
+ title: seletedCity === null || seletedCity === void 0 ? void 0 : seletedCity.name
299
+ }, seletedCity === null || seletedCity === void 0 ? void 0 : seletedCity.name)), !searchValue && /*#__PURE__*/React.createElement("span", {
300
+ className: "".concat(selectPrefixCls, "-content-info")
301
+ }, renderCityInfo(seletedCity))), /*#__PURE__*/React.createElement("span", {
302
+ className: "".concat(selectPrefixCls, "-placeholder"),
303
+ style: hiddenStyle
304
+ }, placeholder), /*#__PURE__*/React.createElement("span", {
305
+ className: "".concat(selectPrefixCls, "-suffix")
306
+ }, renderSuffix())));
92
307
  };
93
- var inputSelector = /*#__PURE__*/React.createElement("div", {
94
- className: containerCls,
95
- style: style,
96
- onClick: handleContainerClick
97
- }, showTitle && /*#__PURE__*/React.createElement("div", {
98
- className: titleCls
99
- }, title), /*#__PURE__*/React.createElement("div", {
100
- className: contentCls
101
- }, /*#__PURE__*/React.createElement("input", {
102
- ref: inputRef,
103
- type: "text",
104
- readOnly: disabled,
105
- onChange: handleChange,
106
- placeholder: placeholder,
107
- style: inputStyle,
108
- className: inputCls,
109
- title: inputVal,
110
- value: inputVal,
111
- onFocus: handleFocus
112
- }), /*#__PURE__*/React.createElement("span", {
113
- className: additionalInfoCls
114
- }, additionalVal), /*#__PURE__*/React.createElement("i", {
115
- className: arrowCls
116
- })));
117
- var cityPanel = /*#__PURE__*/React.createElement(CityPanel, {
118
- commons: commons,
119
- groups: groups,
120
- cityList: cityList,
121
- onSelect: handleCitySelect
122
- });
123
- var getSearchResults = function getSearchResults() {
124
- var _context4;
125
- if (!allCity.current || allCity.current.length === 0 || !inputVal) {
126
- return [];
308
+ var singleCls = classNames(commCls, (_classNames5 = {}, _defineProperty(_classNames5, "".concat(selectPrefixCls, "-disabled"), disabled), _defineProperty(_classNames5, "".concat(selectPrefixCls, "-focused"), !disabled && focusd || optionShow), _classNames5));
309
+ useEffect(function () {
310
+ if (optionShow && !disabled) {
311
+ var onDropdownVisibleChange = selectProps.onDropdownVisibleChange;
312
+ onDropdownVisibleChange && onDropdownVisibleChange(true);
127
313
  }
128
- return _filterInstanceProperty(_context4 = allCity.current).call(_context4, function (city) {
314
+ }, [optionShow]);
315
+ useEffect(function () {
316
+ var _a;
317
+ var fn = function fn(e) {
318
+ e.stopPropagation();
319
+ };
320
+ (_a = clearRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseup', fn);
321
+ return function () {
129
322
  var _a;
130
- return (_a = city.name) === null || _a === void 0 ? void 0 : _startsWithInstanceProperty(_a).call(_a, inputVal);
131
- });
323
+ (_a = clearRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseup', fn);
324
+ };
325
+ }, [initValue]);
326
+ var renderCityPicker = function renderCityPicker() {
327
+ return /*#__PURE__*/React.createElement("div", {
328
+ className: cityPickerCls,
329
+ ref: selectRef,
330
+ style: style
331
+ }, showDescription && /*#__PURE__*/React.createElement("span", {
332
+ className: "".concat(selectPrefixCls, "-description")
333
+ }, description), /*#__PURE__*/React.createElement("span", {
334
+ className: selectionCls,
335
+ tabIndex: disabled ? -1 : 0,
336
+ onFocus: function onFocus() {
337
+ var _a;
338
+ return (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus();
339
+ },
340
+ onBlur: function onBlur() {
341
+ var _a;
342
+ return (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.blur();
343
+ }
344
+ }, renderSingle()));
132
345
  };
133
- var searchPanel = /*#__PURE__*/React.createElement(SearchPanel, {
134
- keyword: inputVal,
135
- data: getSearchResults(),
136
- onSelect: handleCitySelect
137
- });
138
- var popperProps = {
139
- visible: popperVisible,
140
- placement: 'bottomLeft',
141
- trigger: 'focus',
142
- prefixCls: "".concat(cityPickerPrefixCls, "-panel"),
143
- onVisibleChange: handlePopperVisibleChange
346
+ var catchStyle = function catchStyle() {
347
+ var _a;
348
+ if (selectRef === null || selectRef === void 0 ? void 0 : selectRef.current) {
349
+ var _ref = (_a = selectRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(),
350
+ width = _ref.width;
351
+ return _extends(_extends(_extends({
352
+ minWidth: width,
353
+ maxWidth: 600
354
+ }, dropdownStyle), {
355
+ width: (dropdownStyle === null || dropdownStyle === void 0 ? void 0 : dropdownStyle.width) || 'auto',
356
+ zIndex: 1050
357
+ }), popperStyle);
358
+ }
144
359
  };
145
- var panel = inputVal.length > 0 ? searchPanel : cityPanel;
146
- return usePopper(inputSelector, panel, popperProps);
360
+ var handleVisibleChange = function handleVisibleChange(visible) {
361
+ if (visible !== optionShow) {
362
+ props.visible === undefined && setOptionShow(visible);
363
+ onVisibleChange && onVisibleChange(visible);
364
+ }
365
+ };
366
+ var popperProps = _extends(_extends({}, selectProps), {
367
+ prefixCls: "".concat(selectPrefixCls, "-dropdown"),
368
+ placement: 'bottomLeft',
369
+ popperStyle: catchStyle(),
370
+ defaultVisible: optionShow,
371
+ visible: optionShow,
372
+ onVisibleChange: handleVisibleChange,
373
+ clickToClose: !searchValue
374
+ });
375
+ return usePopper(renderCityPicker(), renderContent(), popperProps);
147
376
  };
148
- CityPicker.displayName = 'CityPicker';
149
- CityPicker.PanelItem = CityPanelItem;
150
- CityPicker.Panel = CityPanel;
151
- CityPicker.SearchPanel = SearchPanel;
152
- export default CityPicker;
377
+ var Select = /*#__PURE__*/React.forwardRef(InternalSelect);
378
+ Select.displayName = 'CityPicker';
379
+ export default Select;
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+ export declare type City = {
3
+ id?: string | number;
4
+ country?: string;
5
+ province?: string;
6
+ name?: string;
7
+ [key: string]: any;
8
+ };
9
+ export declare const BorderTypes: ["none", "underline", "bordered"];
10
+ export declare type BorderType = typeof BorderTypes[number];
11
+ export declare const Sizes: ["large", "middle", "small"];
12
+ export declare type Size = typeof Sizes[number];
13
+ export declare type Type = 'domestic' | 'foreign';
14
+ export declare type CityList = Array<City>;
15
+ export interface CityPickerProps {
16
+ prefixCls?: string;
17
+ size?: Size;
18
+ borderType?: BorderType;
19
+ notFoundContent?: React.ReactNode;
20
+ showArrow?: boolean;
21
+ defaultOpen?: boolean;
22
+ allowClear?: boolean;
23
+ placeholder?: React.ReactNode;
24
+ type?: Type;
25
+ loading?: boolean;
26
+ domesticList?: CityList;
27
+ foreignList?: CityList;
28
+ commonList?: CityList;
29
+ className?: string;
30
+ disabled?: boolean;
31
+ style?: React.CSSProperties;
32
+ title?: string;
33
+ clearIcon?: React.ReactNode;
34
+ suffixIcon?: React.ReactNode;
35
+ optionHighlightProps?: string;
36
+ value?: string | number;
37
+ defaultValue?: string | number;
38
+ description?: React.ReactNode;
39
+ showDescription?: boolean;
40
+ onChange?: (value: string | number, city: City) => void;
41
+ onBlur?: (e: React.ChangeEvent<HTMLSpanElement>) => void;
42
+ onFocus?: () => void;
43
+ onSearch?: (value: string) => void;
44
+ onClear?: () => void;
45
+ itemRender?: (city: City) => React.ReactNode;
46
+ }
47
+ export interface ICityPickerOptionProps {
48
+ disabled?: boolean;
49
+ city?: City;
50
+ value?: string | number;
51
+ children?: React.ReactNode;
52
+ className?: string;
53
+ style?: React.CSSProperties;
54
+ onChangeSelect?: (city: City | null) => void;
55
+ renderCityInfo?: (city: City, flag?: boolean, symbol?: string) => React.ReactNode;
56
+ itemRender?: (city: City) => React.ReactNode;
57
+ }
@@ -0,0 +1,3 @@
1
+ import { tuple } from '../_utils/type';
2
+ export var BorderTypes = tuple('none', 'underline', 'bordered');
3
+ export var Sizes = tuple('large', 'middle', 'small'); // 选择框大小
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { ICityPickerOptionProps } from './interface';
3
+ declare const Option: React.ForwardRefExoticComponent<ICityPickerOptionProps & React.RefAttributes<unknown>>;
4
+ export default Option;
@@ -0,0 +1,42 @@
1
+ import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
+ import React, { useContext, useRef } from 'react';
3
+ import classNames from 'classnames';
4
+ import ConfigContext from '../config-provider/ConfigContext';
5
+ var InternalOption = function InternalOption(props, ref) {
6
+ var _classNames;
7
+ var optionRef = useRef(null) || ref;
8
+ var children = props.children,
9
+ value = props.value,
10
+ disabled = props.disabled,
11
+ onChangeSelect = props.onChangeSelect,
12
+ _props$city = props.city,
13
+ city = _props$city === void 0 ? {} : _props$city,
14
+ renderCityInfo = props.renderCityInfo,
15
+ itemRender = props.itemRender;
16
+ var id = city.id,
17
+ name = city.name;
18
+ var _useContext = useContext(ConfigContext),
19
+ getPrefixCls = _useContext.getPrefixCls,
20
+ prefixCls = _useContext.prefixCls;
21
+ var selectOptionPrefixCls = getPrefixCls(prefixCls, 'city-picker-list-item');
22
+ var isSelected = id !== undefined ? id === value : false;
23
+ var optionCls = classNames(selectOptionPrefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(selectOptionPrefixCls, "-selected"), isSelected), _defineProperty(_classNames, "".concat(selectOptionPrefixCls, "-disabled"), disabled), _classNames));
24
+ var handleClick = function handleClick(e) {
25
+ e.preventDefault();
26
+ if (disabled || id === undefined) return;
27
+ onChangeSelect === null || onChangeSelect === void 0 ? void 0 : onChangeSelect(city);
28
+ };
29
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
30
+ ref: optionRef,
31
+ className: optionCls,
32
+ title: name,
33
+ onClick: handleClick
34
+ }, typeof itemRender === 'function' ? itemRender(city) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
35
+ className: "".concat(selectOptionPrefixCls, "-content")
36
+ }, children), /*#__PURE__*/React.createElement("div", {
37
+ className: "".concat(selectOptionPrefixCls, "-info")
38
+ }, renderCityInfo === null || renderCityInfo === void 0 ? void 0 : renderCityInfo(city, true)))));
39
+ };
40
+ var Option = /*#__PURE__*/React.forwardRef(InternalOption);
41
+ Option.displayName = 'CityPickerOption';
42
+ export default Option;