@kne/super-select 0.1.36 → 0.1.38
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 +155 -2
- package/dist/index.css +771 -16
- package/dist/index.css.map +1 -1
- package/dist/index.js +692 -235
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +635 -186
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +3 -1
- package/dist/locale/en-US.js.map +1 -1
- package/dist/locale/en-US.modern.js +3 -1
- package/dist/locale/en-US.modern.js.map +1 -1
- package/dist/locale/zh-CN.js +3 -1
- package/dist/locale/zh-CN.js.map +1 -1
- package/dist/locale/zh-CN.modern.js +3 -1
- package/dist/locale/zh-CN.modern.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -564,12 +564,12 @@ render(<BaseExample />);
|
|
|
564
564
|
```
|
|
565
565
|
|
|
566
566
|
- SelectTableList 表格选择
|
|
567
|
-
-
|
|
567
|
+
- 表格形式的选择组件,适合复杂数据的展示和选择,支持自定义列、搜索、单选/多选、renderMobile 自定义移动端卡片等
|
|
568
568
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
569
569
|
|
|
570
570
|
```jsx
|
|
571
571
|
const { SelectTableList } = _SuperSelect;
|
|
572
|
-
const { Space, Button, Flex, Divider, Tag, Avatar, Switch } = antd;
|
|
572
|
+
const { Space, Button, Flex, Divider, Tag, Avatar, Switch, Checkbox } = antd;
|
|
573
573
|
const { useState } = React;
|
|
574
574
|
|
|
575
575
|
// 模拟员工数据
|
|
@@ -870,6 +870,142 @@ const DirectRenderExample = () => {
|
|
|
870
870
|
);
|
|
871
871
|
};
|
|
872
872
|
|
|
873
|
+
const EmployeeMobileCard = ({ item, checked, disabled, onToggle }) => {
|
|
874
|
+
const statusColor = item.status === 'active' ? 'success' : 'default';
|
|
875
|
+
const statusText = item.status === 'active' ? '在职' : '停用';
|
|
876
|
+
|
|
877
|
+
return (
|
|
878
|
+
<div
|
|
879
|
+
onClick={() => {
|
|
880
|
+
if (!disabled) {
|
|
881
|
+
onToggle();
|
|
882
|
+
}
|
|
883
|
+
}}
|
|
884
|
+
style={{
|
|
885
|
+
display: 'flex',
|
|
886
|
+
alignItems: 'flex-start',
|
|
887
|
+
gap: 12,
|
|
888
|
+
padding: '12px 16px',
|
|
889
|
+
background: checked ? 'var(--primary-color-1, #e6f4ff)' : '#fff',
|
|
890
|
+
border: `1px solid ${checked ? 'var(--primary-color-2, #91caff)' : '#f0f0f0'}`,
|
|
891
|
+
borderRadius: 12,
|
|
892
|
+
boxSizing: 'border-box',
|
|
893
|
+
cursor: disabled ? 'not-allowed' : 'pointer'
|
|
894
|
+
}}
|
|
895
|
+
>
|
|
896
|
+
<Checkbox
|
|
897
|
+
checked={checked}
|
|
898
|
+
disabled={disabled}
|
|
899
|
+
onClick={e => e.stopPropagation()}
|
|
900
|
+
onChange={onToggle}
|
|
901
|
+
style={{ marginTop: 2, flexShrink: 0 }}
|
|
902
|
+
/>
|
|
903
|
+
<div style={{ flex: 1, minWidth: 0 }}>
|
|
904
|
+
{/* 主信息:姓名 + 状态 */}
|
|
905
|
+
<Flex justify="space-between" align="center" gap={8} style={{ marginBottom: 6 }}>
|
|
906
|
+
<Flex align="center" gap={8} style={{ flex: 1, minWidth: 0 }}>
|
|
907
|
+
<Avatar size="small" style={{ backgroundColor: '#1677ff', flexShrink: 0 }}>
|
|
908
|
+
{item.name.slice(-2)}
|
|
909
|
+
</Avatar>
|
|
910
|
+
<span
|
|
911
|
+
style={{
|
|
912
|
+
fontSize: 16,
|
|
913
|
+
fontWeight: 600,
|
|
914
|
+
color: 'rgba(0,0,0,0.88)',
|
|
915
|
+
lineHeight: '22px',
|
|
916
|
+
overflow: 'hidden',
|
|
917
|
+
textOverflow: 'ellipsis',
|
|
918
|
+
whiteSpace: 'nowrap'
|
|
919
|
+
}}
|
|
920
|
+
>
|
|
921
|
+
{item.name}
|
|
922
|
+
</span>
|
|
923
|
+
</Flex>
|
|
924
|
+
<Tag color={statusColor} style={{ margin: 0, flexShrink: 0 }}>
|
|
925
|
+
{statusText}
|
|
926
|
+
</Tag>
|
|
927
|
+
</Flex>
|
|
928
|
+
{/* 次要信息:部门 · 职位 */}
|
|
929
|
+
<div style={{ fontSize: 13, color: 'rgba(0,0,0,0.65)', lineHeight: '20px', marginBottom: 4 }}>
|
|
930
|
+
{item.department}
|
|
931
|
+
<span style={{ margin: '0 6px', color: 'rgba(0,0,0,0.25)' }}>·</span>
|
|
932
|
+
{item.position}
|
|
933
|
+
</div>
|
|
934
|
+
{/* 辅助信息:邮箱 / 入职日期 */}
|
|
935
|
+
<div style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)', lineHeight: '18px' }}>
|
|
936
|
+
{item.email}
|
|
937
|
+
<span style={{ margin: '0 6px', color: 'rgba(0,0,0,0.25)' }}>·</span>
|
|
938
|
+
入职 {item.joinDate}
|
|
939
|
+
</div>
|
|
940
|
+
</div>
|
|
941
|
+
</div>
|
|
942
|
+
);
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// 自定义移动端卡片:突出主 / 次 / 辅层次
|
|
946
|
+
const CustomMobileCardExample = ({ isPopup }) => {
|
|
947
|
+
const [value, setValue] = useState([]);
|
|
948
|
+
|
|
949
|
+
return (
|
|
950
|
+
<Flex vertical gap={8}>
|
|
951
|
+
<span>自定义移动端卡片(renderMobile):</span>
|
|
952
|
+
<div style={{ color: '#666', fontSize: 12, lineHeight: 1.6 }}>
|
|
953
|
+
仅移动端生效。主信息为大号姓名,次要为部门/职位,辅助为邮箱与入职日期。桌面端仍为普通表格。
|
|
954
|
+
</div>
|
|
955
|
+
<SelectTableList
|
|
956
|
+
options={employeeOptions}
|
|
957
|
+
columns={employeeColumns}
|
|
958
|
+
valueKey="id"
|
|
959
|
+
labelKey="name"
|
|
960
|
+
value={value}
|
|
961
|
+
onChange={setValue}
|
|
962
|
+
isPopup={isPopup}
|
|
963
|
+
placeholder="请选择员工"
|
|
964
|
+
getSearchCallback={({ searchText }, item) => {
|
|
965
|
+
if (!searchText) return true;
|
|
966
|
+
const keyword = searchText.toLowerCase();
|
|
967
|
+
return (
|
|
968
|
+
item.name.toLowerCase().includes(keyword) ||
|
|
969
|
+
item.email.toLowerCase().includes(keyword) ||
|
|
970
|
+
item.department.toLowerCase().includes(keyword)
|
|
971
|
+
);
|
|
972
|
+
}}
|
|
973
|
+
style={{ width: 600 }}
|
|
974
|
+
renderMobile={({ list, value: selected, setValue: setSelected, props: selectProps, isSelectedAll }) => (
|
|
975
|
+
<Flex vertical gap={12} style={{ padding: '0 0 12px' }}>
|
|
976
|
+
{list.map(item => {
|
|
977
|
+
const isChecked = selected.some(target => target.id === item.id);
|
|
978
|
+
return (
|
|
979
|
+
<EmployeeMobileCard
|
|
980
|
+
key={item.id}
|
|
981
|
+
item={item}
|
|
982
|
+
checked={(isSelectedAll && !item.disabled) || isChecked}
|
|
983
|
+
disabled={isSelectedAll || item.disabled}
|
|
984
|
+
onToggle={() => {
|
|
985
|
+
if (item.disabled || isSelectedAll) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (selectProps.single) {
|
|
989
|
+
setSelected([item]);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
setSelected(prev =>
|
|
993
|
+
isChecked ? prev.filter(target => target.id !== item.id) : [...prev, item]
|
|
994
|
+
);
|
|
995
|
+
}}
|
|
996
|
+
/>
|
|
997
|
+
);
|
|
998
|
+
})}
|
|
999
|
+
</Flex>
|
|
1000
|
+
)}
|
|
1001
|
+
/>
|
|
1002
|
+
{value.length > 0 && (
|
|
1003
|
+
<div>已选 {value.length} 人:{value.map(item => item.name).join('、')}</div>
|
|
1004
|
+
)}
|
|
1005
|
+
</Flex>
|
|
1006
|
+
);
|
|
1007
|
+
};
|
|
1008
|
+
|
|
873
1009
|
const BaseExample = () => {
|
|
874
1010
|
const [isPopup, setIsPopup] = useState(true);
|
|
875
1011
|
|
|
@@ -898,6 +1034,8 @@ const BaseExample = () => {
|
|
|
898
1034
|
<Divider />
|
|
899
1035
|
<CustomFooterExample isPopup={isPopup} />
|
|
900
1036
|
<Divider />
|
|
1037
|
+
<CustomMobileCardExample isPopup={isPopup} />
|
|
1038
|
+
<Divider />
|
|
901
1039
|
<DirectRenderExample />
|
|
902
1040
|
</Flex>
|
|
903
1041
|
);
|
|
@@ -2141,6 +2279,21 @@ render(<BaseExample />);
|
|
|
2141
2279
|
| rowStyle | 行自定义样式 | object | - |
|
|
2142
2280
|
| headerClassName | 表头自定义类名 | string | - |
|
|
2143
2281
|
| headerStyle | 表头自定义样式 | object | - |
|
|
2282
|
+
| renderMobile | 移动端自定义卡片渲染;为 `false` 时关闭移动端卡片;为 function 时接管列表区渲染(仅移动端),参数含 `list` / `value` / `setValue` / `renderBody` 等 | boolean \| function | 默认卡片 List |
|
|
2283
|
+
|
|
2284
|
+
```jsx
|
|
2285
|
+
<SelectTableList
|
|
2286
|
+
columns={columns}
|
|
2287
|
+
options={options}
|
|
2288
|
+
renderMobile={({ list, value, setValue, isSelectedAll }) => (
|
|
2289
|
+
<Flex vertical gap={12}>
|
|
2290
|
+
{list.map(item => (
|
|
2291
|
+
<CustomCard key={item.id} item={item} /* ... */ />
|
|
2292
|
+
))}
|
|
2293
|
+
</Flex>
|
|
2294
|
+
)}
|
|
2295
|
+
/>
|
|
2296
|
+
```
|
|
2144
2297
|
|
|
2145
2298
|
##### columns 配置项
|
|
2146
2299
|
|