@kne/super-select 0.1.16 → 0.1.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.
- package/README.md +289 -43
- package/dist/index.css +20 -5
- package/dist/index.css.map +1 -1
- package/dist/index.js +121 -43
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +121 -43
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +12 -0
- package/dist/locale/en-US.js.map +1 -0
- package/dist/locale/en-US.modern.js +12 -0
- package/dist/locale/en-US.modern.js.map +1 -0
- package/dist/locale/zh-CN.js +12 -0
- package/dist/locale/zh-CN.js.map +1 -0
- package/dist/locale/zh-CN.modern.js +12 -0
- package/dist/locale/zh-CN.modern.js.map +1 -0
- package/package.json +5 -2
package/dist/index.modern.js
CHANGED
|
@@ -8,6 +8,7 @@ import last from 'lodash/last';
|
|
|
8
8
|
import { Modal, App, Dropdown, Flex, Tag, Checkbox, List, Row, Col, Button, Popover } from 'antd';
|
|
9
9
|
import { CloseCircleFilled, DownOutlined, CheckOutlined } from '@ant-design/icons';
|
|
10
10
|
import { isNotEmpty } from '@kne/is-empty';
|
|
11
|
+
import { createWithIntlProvider, useIntl } from '@kne/react-intl';
|
|
11
12
|
import get from 'lodash/get';
|
|
12
13
|
import SimpleBar from 'simplebar-react';
|
|
13
14
|
import 'simplebar-react/dist/simplebar.min.css';
|
|
@@ -42,6 +43,26 @@ const {
|
|
|
42
43
|
|
|
43
44
|
var style$4 = {"select-input":"_d8lGc","disabled":"_3kjwO","wrap":"_dsTM2","select-input-inner":"_NQoX9","large":"_T8ZX8","small":"_1B72H","select-input-icon":"_g8QC-","placeholder":"_r3q69","overlay-content":"_zEqGe","overlay":"_ybN30","select-input-prefix":"_4Pw75","select-input-suffix":"_Wd4pE"};
|
|
44
45
|
|
|
46
|
+
const locale$1 = {
|
|
47
|
+
placeholder: '请选择',
|
|
48
|
+
selectAll: '全选',
|
|
49
|
+
selected: '已选',
|
|
50
|
+
search: '搜索',
|
|
51
|
+
numberOf: '{number}个',
|
|
52
|
+
maxLengthError: '最大数量不能超过{maxLength}',
|
|
53
|
+
defaultChildren: '下拉内容,需要调用方实现'
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const locale = {
|
|
57
|
+
placeholder: 'Please select',
|
|
58
|
+
selectAll: 'Select All',
|
|
59
|
+
selected: 'Selected',
|
|
60
|
+
search: 'Search',
|
|
61
|
+
numberOf: '{number} items',
|
|
62
|
+
maxLengthError: 'The maximum number cannot exceed {maxLength}',
|
|
63
|
+
defaultChildren: 'Dropdown content, to be implemented by the caller'
|
|
64
|
+
};
|
|
65
|
+
|
|
45
66
|
const _excluded$1 = ["children"];
|
|
46
67
|
const numberToPx = val => {
|
|
47
68
|
return typeof val === 'number' ? `${val}px` : val;
|
|
@@ -82,35 +103,46 @@ const ModalContent = _ref => {
|
|
|
82
103
|
value: contextProps
|
|
83
104
|
}, children(contextProps));
|
|
84
105
|
};
|
|
85
|
-
const SelectInput =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
const SelectInput = createWithIntlProvider({
|
|
107
|
+
defaultLocale: 'zh-CN',
|
|
108
|
+
namespace: 'super-select',
|
|
109
|
+
messages: {
|
|
110
|
+
'zh-CN': locale$1,
|
|
111
|
+
'en-US': locale
|
|
112
|
+
}
|
|
113
|
+
})(forwardRef((p, ref) => {
|
|
114
|
+
const intl = useIntl();
|
|
115
|
+
const {
|
|
116
|
+
formatMessage
|
|
117
|
+
} = intl;
|
|
95
118
|
const props = Object.assign({}, {
|
|
96
|
-
children: () =>
|
|
119
|
+
children: () => formatMessage({
|
|
120
|
+
id: 'defaultChildren'
|
|
121
|
+
}),
|
|
97
122
|
maxLength: null,
|
|
98
123
|
defaultOpen: false,
|
|
99
124
|
single: false,
|
|
100
125
|
disabled: false,
|
|
101
126
|
isPopup: true,
|
|
102
|
-
placeholder:
|
|
103
|
-
|
|
127
|
+
placeholder: formatMessage({
|
|
128
|
+
id: 'placeholder'
|
|
129
|
+
}),
|
|
130
|
+
searchPlaceholder: formatMessage({
|
|
131
|
+
id: 'search'
|
|
132
|
+
}),
|
|
133
|
+
completeTips: null,
|
|
104
134
|
allowSelectedAll: false,
|
|
105
135
|
labelKey: 'label',
|
|
106
136
|
valueKey: 'value',
|
|
107
137
|
selectedAllValue: {
|
|
108
138
|
value: 'all',
|
|
109
|
-
label:
|
|
139
|
+
label: formatMessage({
|
|
140
|
+
id: 'selectAll'
|
|
141
|
+
})
|
|
110
142
|
},
|
|
111
143
|
placement: 'bottomLeft',
|
|
112
144
|
labelWrap: false,
|
|
113
|
-
showSelectedTag:
|
|
145
|
+
showSelectedTag: false,
|
|
114
146
|
allowClear: true,
|
|
115
147
|
prefix: null,
|
|
116
148
|
suffix: null,
|
|
@@ -139,9 +171,7 @@ const SelectInput = forwardRef((p, ref) => {
|
|
|
139
171
|
}
|
|
140
172
|
}, children(contextProps));
|
|
141
173
|
}
|
|
142
|
-
}, p
|
|
143
|
-
locale
|
|
144
|
-
});
|
|
174
|
+
}, p);
|
|
145
175
|
props.selectedAllValue = {
|
|
146
176
|
[props.valueKey]: props.selectedAllValue.value,
|
|
147
177
|
[props.labelKey]: props.selectedAllValue.label
|
|
@@ -199,7 +229,11 @@ const SelectInput = forwardRef((p, ref) => {
|
|
|
199
229
|
} = App.useApp();
|
|
200
230
|
const checkMaxLength = (value, maxLength) => {
|
|
201
231
|
if (Number.isInteger(maxLength) && maxLength > 0 && value.length >= maxLength) {
|
|
202
|
-
message.error(
|
|
232
|
+
message.error(formatMessage({
|
|
233
|
+
id: 'maxLengthError'
|
|
234
|
+
}, {
|
|
235
|
+
maxLength
|
|
236
|
+
}));
|
|
203
237
|
return false;
|
|
204
238
|
}
|
|
205
239
|
return true;
|
|
@@ -325,7 +359,7 @@ const SelectInput = forwardRef((p, ref) => {
|
|
|
325
359
|
arrow: false,
|
|
326
360
|
overlayClassName: classnames(style$4['overlay'], overlayClassName),
|
|
327
361
|
trigger: "click",
|
|
328
|
-
|
|
362
|
+
popupRender: () => /*#__PURE__*/React.createElement("div", {
|
|
329
363
|
style: {
|
|
330
364
|
'--overlay-width': popupOverlayWidth
|
|
331
365
|
},
|
|
@@ -339,11 +373,14 @@ const SelectInput = forwardRef((p, ref) => {
|
|
|
339
373
|
setOpen(true);
|
|
340
374
|
}
|
|
341
375
|
}), /*#__PURE__*/React.createElement(ModalContent, contextProps, renderModal)));
|
|
342
|
-
});
|
|
376
|
+
}));
|
|
343
377
|
|
|
344
378
|
var style$3 = {"selected-all":"_prlgN"};
|
|
345
379
|
|
|
346
|
-
const SelectedAll = () => {
|
|
380
|
+
const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
381
|
+
const {
|
|
382
|
+
formatMessage
|
|
383
|
+
} = useIntl();
|
|
347
384
|
const {
|
|
348
385
|
props,
|
|
349
386
|
value,
|
|
@@ -352,10 +389,13 @@ const SelectedAll = () => {
|
|
|
352
389
|
const {
|
|
353
390
|
unit,
|
|
354
391
|
selectedAllValue,
|
|
355
|
-
locale,
|
|
356
392
|
valueKey
|
|
357
393
|
} = Object.assign({}, {
|
|
358
|
-
unit: number =>
|
|
394
|
+
unit: number => formatMessage({
|
|
395
|
+
id: 'numberOf'
|
|
396
|
+
}, {
|
|
397
|
+
number
|
|
398
|
+
})
|
|
359
399
|
}, props);
|
|
360
400
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
361
401
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
@@ -363,7 +403,9 @@ const SelectedAll = () => {
|
|
|
363
403
|
className: classnames(style$3['selected-all'], 'selected-all')
|
|
364
404
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
365
405
|
gap: 8
|
|
366
|
-
}, /*#__PURE__*/React.createElement("span", null,
|
|
406
|
+
}, /*#__PURE__*/React.createElement("span", null, formatMessage({
|
|
407
|
+
id: 'selected'
|
|
408
|
+
}), ":"), /*#__PURE__*/React.createElement("span", null, isSelectedAll ? selectedAllValue.label : typeof unit === 'function' ? unit(value.length) : value.length)), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
367
409
|
checked: isSelectedAll,
|
|
368
410
|
onChange: e => {
|
|
369
411
|
const checked = e.target.checked;
|
|
@@ -373,22 +415,26 @@ const SelectedAll = () => {
|
|
|
373
415
|
setValue([selectedAllValue]);
|
|
374
416
|
}
|
|
375
417
|
}
|
|
376
|
-
},
|
|
377
|
-
|
|
418
|
+
}, formatMessage({
|
|
419
|
+
id: 'selectAll'
|
|
420
|
+
}))));
|
|
421
|
+
});
|
|
378
422
|
const computedIsSelectAll = (value, selectedAllValue, valueKey = 'value') => {
|
|
379
423
|
return (value == null ? void 0 : value.length) === 1 && get(value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
|
|
380
424
|
};
|
|
381
425
|
|
|
382
426
|
var style$2 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
|
|
383
427
|
|
|
384
|
-
const SelectedTagList = () => {
|
|
428
|
+
const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
429
|
+
const {
|
|
430
|
+
formatMessage
|
|
431
|
+
} = useIntl();
|
|
385
432
|
const {
|
|
386
433
|
props,
|
|
387
434
|
value,
|
|
388
435
|
onRemove
|
|
389
436
|
} = useContext();
|
|
390
437
|
const {
|
|
391
|
-
locale,
|
|
392
438
|
single,
|
|
393
439
|
maxLength,
|
|
394
440
|
labelKey,
|
|
@@ -399,7 +445,9 @@ const SelectedTagList = () => {
|
|
|
399
445
|
gap: 8
|
|
400
446
|
}, /*#__PURE__*/React.createElement("div", {
|
|
401
447
|
className: style$2['label']
|
|
402
|
-
},
|
|
448
|
+
}, formatMessage({
|
|
449
|
+
id: 'selected'
|
|
450
|
+
}), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
403
451
|
className: style$2['tag-container']
|
|
404
452
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
405
453
|
gap: 8,
|
|
@@ -419,9 +467,9 @@ const SelectedTagList = () => {
|
|
|
419
467
|
className: style$2['tag-inner']
|
|
420
468
|
}, item[labelKey]));
|
|
421
469
|
}))));
|
|
422
|
-
};
|
|
470
|
+
});
|
|
423
471
|
|
|
424
|
-
var style$1 = {"list":"_IsXdU","is-popup":"_-dvpa","default-list":"_QD1Mz","is-selected-all":"_M-mOy","default-list-item":"_KtOsz","is-selected":"_TQhBB","single-checked":"_2rUrh","is-disabled":"_NbwX5","selected-all":"_vN2Fx","selected-tag":"_6oITk","select-search":"_iAH9D","select-list-item-description":"_TCkeJ"};
|
|
472
|
+
var style$1 = {"list":"_IsXdU","is-popup":"_-dvpa","default-list":"_QD1Mz","is-selected-all":"_M-mOy","default-list-item":"_KtOsz","is-selected":"_TQhBB","single-checked":"_2rUrh","is-disabled":"_NbwX5","selected-all":"_vN2Fx","selected-tag":"_6oITk","select-search":"_iAH9D","select-list-item-description":"_TCkeJ","footer":"_v3f23"};
|
|
425
473
|
|
|
426
474
|
const _excluded = ["children"];
|
|
427
475
|
const SelectList = forwardRef((_ref, ref) => {
|
|
@@ -429,6 +477,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
429
477
|
children
|
|
430
478
|
} = _ref,
|
|
431
479
|
p = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
480
|
+
const fetchListRef = useRef(null);
|
|
432
481
|
const props = Object.assign({}, {
|
|
433
482
|
renderItemContent: ({
|
|
434
483
|
item,
|
|
@@ -522,9 +571,11 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
522
571
|
props,
|
|
523
572
|
value,
|
|
524
573
|
searchProps,
|
|
525
|
-
setSearchProps
|
|
574
|
+
setSearchProps,
|
|
575
|
+
onOpenChange
|
|
526
576
|
} = targetProps;
|
|
527
577
|
const {
|
|
578
|
+
footer,
|
|
528
579
|
isPopup,
|
|
529
580
|
getSearchProps,
|
|
530
581
|
getSearchCallback,
|
|
@@ -586,7 +637,8 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
586
637
|
pageData: options
|
|
587
638
|
};
|
|
588
639
|
}
|
|
589
|
-
} : api)
|
|
640
|
+
} : api),
|
|
641
|
+
ref: fetchListRef
|
|
590
642
|
}), fetchProps => {
|
|
591
643
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
592
644
|
return renderList(Object.assign({}, fetchProps, targetProps, {
|
|
@@ -606,14 +658,27 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
606
658
|
}
|
|
607
659
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
608
660
|
vertical: true
|
|
609
|
-
}, components.search, components.selectedAll, components.fetchList,
|
|
661
|
+
}, components.search, components.selectedAll, components.fetchList, footer && /*#__PURE__*/React.createElement("div", {
|
|
662
|
+
className: classnames(style$1['footer'], 'select-list-footer')
|
|
663
|
+
}, typeof footer === 'function' ? footer({
|
|
664
|
+
reload: () => {
|
|
665
|
+
fetchListRef.current && fetchListRef.current.reload();
|
|
666
|
+
},
|
|
667
|
+
close: () => {
|
|
668
|
+
onOpenChange(false);
|
|
669
|
+
}
|
|
670
|
+
}) : footer), components.selectedTag);
|
|
610
671
|
});
|
|
611
672
|
});
|
|
612
673
|
|
|
613
|
-
var style = {"list":"_DrEYJ","is-popup":"_KgWTX","header":"_Vmbrg","col":"_dJmfs","body":"_704J1","is-selected-all":"_qU5zU","is-selected":"_MzyWg","is-disabled":"_5luTv","right-options":"_UXi-g","no-padding-btn":"_iaCir","tag":"_JkYqS","tag-inner":"_VZlBL","single-checked":"_Eiz-u","select-search":"_temy6","tags-search":"_7phL2","descriptions":"_ttNK9","descriptions-col-label":"_xU-i7","descriptions-col-content":"_SvfzQ"};
|
|
674
|
+
var style = {"list":"_DrEYJ","is-popup":"_KgWTX","header":"_Vmbrg","col":"_dJmfs","body":"_704J1","is-selected-all":"_qU5zU","is-selected":"_MzyWg","is-disabled":"_5luTv","right-options":"_UXi-g","no-padding-btn":"_iaCir","tag":"_JkYqS","tag-inner":"_VZlBL","single-checked":"_Eiz-u","select-search":"_temy6","tags-search":"_7phL2","descriptions":"_ttNK9","descriptions-col-label":"_xU-i7","descriptions-col-content":"_SvfzQ","footer":"_lISfA"};
|
|
614
675
|
|
|
615
|
-
const SelectTableList = forwardRef((p, ref) => {
|
|
676
|
+
const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
|
|
677
|
+
const {
|
|
678
|
+
formatMessage
|
|
679
|
+
} = useIntl();
|
|
616
680
|
const [tagSearchText, setTagSearchText] = useState('');
|
|
681
|
+
const fetchListRef = useRef();
|
|
617
682
|
const props = Object.assign({}, {
|
|
618
683
|
overlayWidth: '600px',
|
|
619
684
|
filterRender: contextProps => {
|
|
@@ -675,6 +740,7 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
675
740
|
onOpenChange
|
|
676
741
|
} = targetProps;
|
|
677
742
|
const {
|
|
743
|
+
footer,
|
|
678
744
|
filterRender,
|
|
679
745
|
columns,
|
|
680
746
|
options,
|
|
@@ -683,7 +749,6 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
683
749
|
api,
|
|
684
750
|
selectedAllValue,
|
|
685
751
|
isPopup,
|
|
686
|
-
locale,
|
|
687
752
|
single,
|
|
688
753
|
maxLength,
|
|
689
754
|
getSearchProps,
|
|
@@ -694,6 +759,16 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
694
759
|
searchProps
|
|
695
760
|
} = props;
|
|
696
761
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
762
|
+
const footerEl = footer && /*#__PURE__*/React.createElement("div", {
|
|
763
|
+
className: classnames(style['footer'], 'select-table-footer')
|
|
764
|
+
}, typeof footer === 'function' ? footer({
|
|
765
|
+
reload: () => {
|
|
766
|
+
fetchListRef.current && fetchListRef.current.reload();
|
|
767
|
+
},
|
|
768
|
+
close: () => {
|
|
769
|
+
onOpenChange(false);
|
|
770
|
+
}
|
|
771
|
+
}) : footer);
|
|
697
772
|
return /*#__PURE__*/React.createElement(Row, {
|
|
698
773
|
wrap: false,
|
|
699
774
|
ref: bodyRef
|
|
@@ -761,7 +836,8 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
761
836
|
pageData: options
|
|
762
837
|
};
|
|
763
838
|
}
|
|
764
|
-
} : api)
|
|
839
|
+
} : api),
|
|
840
|
+
ref: fetchListRef
|
|
765
841
|
}), fetchProps => {
|
|
766
842
|
const {
|
|
767
843
|
list
|
|
@@ -819,7 +895,7 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
819
895
|
className: classnames(style['col'], style['single-checked'], 'select-table-list-col')
|
|
820
896
|
}, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
|
|
821
897
|
});
|
|
822
|
-
})), !single && /*#__PURE__*/React.createElement(Col, {
|
|
898
|
+
}), single && footerEl), !single && /*#__PURE__*/React.createElement(Col, {
|
|
823
899
|
className: classnames(style['right-options'], {
|
|
824
900
|
'is-popup': isPopup
|
|
825
901
|
}),
|
|
@@ -836,7 +912,9 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
836
912
|
wrap: false,
|
|
837
913
|
justify: 'space-between',
|
|
838
914
|
align: 'middle'
|
|
839
|
-
}, /*#__PURE__*/React.createElement(Col, null,
|
|
915
|
+
}, /*#__PURE__*/React.createElement(Col, null, formatMessage({
|
|
916
|
+
id: 'selected'
|
|
917
|
+
}), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
|
|
840
918
|
className: style['no-padding-btn'],
|
|
841
919
|
type: "link",
|
|
842
920
|
onClick: () => {
|
|
@@ -877,9 +955,9 @@ const SelectTableList = forwardRef((p, ref) => {
|
|
|
877
955
|
}, /*#__PURE__*/React.createElement("span", {
|
|
878
956
|
className: style['tag-inner']
|
|
879
957
|
}, item[labelKey])));
|
|
880
|
-
})))));
|
|
958
|
+
}))), footerEl));
|
|
881
959
|
});
|
|
882
|
-
});
|
|
960
|
+
}));
|
|
883
961
|
|
|
884
962
|
export { SelectInput, SelectTableList, SelectedAll, SelectedTagList, SelectList as default };
|
|
885
963
|
//# sourceMappingURL=index.modern.js.map
|