@gm-pc/react 1.28.0-beta.2 → 1.29.0-beta.2
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/package.json +3 -3
- package/src/component/loading/types.ts +1 -1
- package/src/component/more_select/base.tsx +41 -227
- package/src/component/more_select/more_select.tsx +0 -10
- package/src/component/more_select/stories.tsx +0 -92
- package/src/component/more_select/style.less +0 -4
- package/src/component/more_select/types.ts +3 -33
- package/src/component/nav/nav.tsx +3 -0
- package/src/component/nav/types.ts +1 -0
- package/src/component/switch/style.less +0 -4
- package/src/component/switch/switch.tsx +3 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.0-beta.2",
|
|
4
4
|
"description": "观麦前端基础组件库",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-pc#readme",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@gm-common/hooks": "^2.10.0",
|
|
26
26
|
"@gm-common/tool": "^2.10.0",
|
|
27
|
-
"@gm-pc/locales": "^1.
|
|
27
|
+
"@gm-pc/locales": "^1.29.0-beta.2",
|
|
28
28
|
"big.js": "^6.0.1",
|
|
29
29
|
"classnames": "^2.2.5",
|
|
30
30
|
"lodash": "^4.17.19",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-router-dom": "^5.2.0",
|
|
49
49
|
"react-window": "^1.8.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "71157a29a2684a64359ea15e50eb43d64cee12f5"
|
|
52
52
|
}
|
|
@@ -20,16 +20,12 @@ import { getLocale } from '@gm-pc/locales'
|
|
|
20
20
|
import { ListBase } from '../list'
|
|
21
21
|
import { findDOMNode } from 'react-dom'
|
|
22
22
|
import { ConfigConsumer, ConfigProvider, ConfigProviderProps } from '../config_provider'
|
|
23
|
-
|
|
24
|
-
import { Switch } from '../switch'
|
|
23
|
+
|
|
25
24
|
interface MoreSelectBaseState {
|
|
26
25
|
searchValue: string
|
|
27
26
|
loading: boolean
|
|
28
27
|
/* keyboard 默认第一个位置 */
|
|
29
28
|
willActiveIndex: number | null
|
|
30
|
-
isCheckedAll: boolean
|
|
31
|
-
isFilterDelete: boolean
|
|
32
|
-
displayCount: number
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
// @todo keydown item disabled
|
|
@@ -45,9 +41,6 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
45
41
|
searchValue: '',
|
|
46
42
|
loading: false,
|
|
47
43
|
willActiveIndex: this.props.isKeyboard ? 0 : null,
|
|
48
|
-
isCheckedAll: false,
|
|
49
|
-
isFilterDelete: true,
|
|
50
|
-
displayCount: 0,
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
private _isUnmounted = false
|
|
@@ -55,7 +48,6 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
55
48
|
private _selectionRef = createRef<HTMLDivElement>()
|
|
56
49
|
private _popoverRef = createRef<Popover>()
|
|
57
50
|
private _inputRef = createRef<HTMLInputElement>()
|
|
58
|
-
private _resizeObserver: ResizeObserver | null = null
|
|
59
51
|
|
|
60
52
|
private _filterData: MoreSelectGroupDataItem<V>[] | undefined
|
|
61
53
|
|
|
@@ -70,42 +62,8 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
70
62
|
}
|
|
71
63
|
}
|
|
72
64
|
|
|
73
|
-
componentDidMount() {
|
|
74
|
-
const { maxTagCount, tagItemWidth = 80, omittedTagWidth = 45 } = this.props
|
|
75
|
-
if (maxTagCount === 'responsive' && this._selectionRef.current) {
|
|
76
|
-
// HACK: 首次计算
|
|
77
|
-
setTimeout(() => {
|
|
78
|
-
if (this._selectionRef.current) {
|
|
79
|
-
const { width } = this._selectionRef.current.getBoundingClientRect()
|
|
80
|
-
const availableWidth = width - omittedTagWidth
|
|
81
|
-
const newDisplayCount = Math.floor(availableWidth / tagItemWidth)
|
|
82
|
-
if (this.state.displayCount !== newDisplayCount) {
|
|
83
|
-
this.setState({ displayCount: newDisplayCount > 0 ? newDisplayCount : 0 })
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}, 0)
|
|
87
|
-
|
|
88
|
-
this._resizeObserver = new ResizeObserver((entries) => {
|
|
89
|
-
for (const entry of entries) {
|
|
90
|
-
const { width } = entry.contentRect
|
|
91
|
-
// Estimate item width, let's say 80px.
|
|
92
|
-
const availableWidth = width - omittedTagWidth
|
|
93
|
-
const newDisplayCount = Math.floor(availableWidth / tagItemWidth)
|
|
94
|
-
|
|
95
|
-
if (this.state.displayCount !== newDisplayCount) {
|
|
96
|
-
this.setState({ displayCount: newDisplayCount })
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
this._resizeObserver.observe(this._selectionRef.current)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
65
|
componentWillUnmount() {
|
|
105
|
-
this._isUnmounted =
|
|
106
|
-
if (this._resizeObserver) {
|
|
107
|
-
this._resizeObserver.disconnect()
|
|
108
|
-
}
|
|
66
|
+
this._isUnmounted = false
|
|
109
67
|
}
|
|
110
68
|
|
|
111
69
|
public apiDoFocus = (): void => {
|
|
@@ -208,7 +166,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
208
166
|
onSelect(willSelected)
|
|
209
167
|
}
|
|
210
168
|
|
|
211
|
-
private _handlePopupKeyDown = (event: KeyboardEvent
|
|
169
|
+
private _handlePopupKeyDown = (event: KeyboardEvent): void => {
|
|
212
170
|
const { onKeyDown } = this.props
|
|
213
171
|
let willActiveIndex = this.state.willActiveIndex as number
|
|
214
172
|
if (!onKeyDown) {
|
|
@@ -274,84 +232,6 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
274
232
|
)
|
|
275
233
|
}
|
|
276
234
|
|
|
277
|
-
renderBottom = () => {
|
|
278
|
-
const {
|
|
279
|
-
selected = [],
|
|
280
|
-
isShowDeletedSwitch = true,
|
|
281
|
-
isShowCheckedAll = true,
|
|
282
|
-
} = this.props
|
|
283
|
-
const { isCheckedAll, isFilterDelete } = this.state
|
|
284
|
-
const flatFilterData = this._getFlatFilterData()
|
|
285
|
-
|
|
286
|
-
// 根据过滤状态决定是否过滤已删除商品
|
|
287
|
-
const availableData = isFilterDelete
|
|
288
|
-
? flatFilterData.filter((item) => !item.deleted)
|
|
289
|
-
: flatFilterData
|
|
290
|
-
|
|
291
|
-
// 检查是否所有可用数据都被选中
|
|
292
|
-
const allSelected =
|
|
293
|
-
availableData.length > 0 &&
|
|
294
|
-
availableData.every((item) =>
|
|
295
|
-
selected.some((selectedItem) => selectedItem.value === item.value)
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
return (
|
|
299
|
-
<Flex
|
|
300
|
-
justifyBetween
|
|
301
|
-
className='tw-p-[8px] gm-more-select-default-bottom'
|
|
302
|
-
alignCenter
|
|
303
|
-
>
|
|
304
|
-
{isShowCheckedAll && (
|
|
305
|
-
<Checkbox
|
|
306
|
-
checked={allSelected}
|
|
307
|
-
onChange={(e) => {
|
|
308
|
-
const isChecked = e.target.checked
|
|
309
|
-
this.setState({
|
|
310
|
-
isCheckedAll: isChecked,
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
if (isChecked) {
|
|
314
|
-
// 全选当前过滤后的可用数据
|
|
315
|
-
const valuesToSelect = availableData.map((item) => item.value)
|
|
316
|
-
this._handleSelect(valuesToSelect)
|
|
317
|
-
} else {
|
|
318
|
-
// 取消全选
|
|
319
|
-
this._handleSelect([])
|
|
320
|
-
}
|
|
321
|
-
}}
|
|
322
|
-
>
|
|
323
|
-
全选({availableData.length})
|
|
324
|
-
</Checkbox>
|
|
325
|
-
)}
|
|
326
|
-
{isShowDeletedSwitch && (
|
|
327
|
-
<Flex alignCenter>
|
|
328
|
-
<Flex row>
|
|
329
|
-
<Switch
|
|
330
|
-
size='small'
|
|
331
|
-
style={{ width: 32 }}
|
|
332
|
-
checked={isFilterDelete}
|
|
333
|
-
onChange={(open) => {
|
|
334
|
-
this.setState({
|
|
335
|
-
isFilterDelete: open,
|
|
336
|
-
})
|
|
337
|
-
if (isCheckedAll) {
|
|
338
|
-
const newAvailableData = open
|
|
339
|
-
? flatFilterData.filter((item) => !item.deleted)
|
|
340
|
-
: flatFilterData
|
|
341
|
-
|
|
342
|
-
const valuesToSelect = newAvailableData.map((item) => item.value)
|
|
343
|
-
this._handleSelect(valuesToSelect)
|
|
344
|
-
}
|
|
345
|
-
}}
|
|
346
|
-
/>
|
|
347
|
-
</Flex>
|
|
348
|
-
<span className='gm-margin-left-5'>过滤已删除数据</span>
|
|
349
|
-
</Flex>
|
|
350
|
-
)}
|
|
351
|
-
</Flex>
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
235
|
private _renderList = (config: ConfigProviderProps): ReactNode => {
|
|
356
236
|
const {
|
|
357
237
|
selected = [],
|
|
@@ -362,21 +242,9 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
362
242
|
listHeight,
|
|
363
243
|
popupClassName,
|
|
364
244
|
renderCustomizedBottom,
|
|
365
|
-
isRenderDefaultBottom = false,
|
|
366
245
|
} = this.props
|
|
367
|
-
const { loading, searchValue, willActiveIndex
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// 如果开启了过滤已删除商品功能,需要过滤掉已删除的商品
|
|
371
|
-
if (isFilterDelete) {
|
|
372
|
-
filterData = filterData
|
|
373
|
-
.map((group) => ({
|
|
374
|
-
...group,
|
|
375
|
-
children: group.children.filter((item) => !item.deleted),
|
|
376
|
-
}))
|
|
377
|
-
.filter((group) => group.children.length > 0)
|
|
378
|
-
}
|
|
379
|
-
|
|
246
|
+
const { loading, searchValue, willActiveIndex } = this.state
|
|
247
|
+
const filterData = this._getFilterData()
|
|
380
248
|
return (
|
|
381
249
|
<ConfigProvider {...config}>
|
|
382
250
|
<div
|
|
@@ -416,11 +284,8 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
416
284
|
</div>
|
|
417
285
|
{!loading &&
|
|
418
286
|
!!filterData.length &&
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
: isRenderDefaultBottom
|
|
422
|
-
? this.renderBottom()
|
|
423
|
-
: null)}
|
|
287
|
+
renderCustomizedBottom &&
|
|
288
|
+
renderCustomizedBottom(this._popoverRef)}
|
|
424
289
|
</div>
|
|
425
290
|
</ConfigProvider>
|
|
426
291
|
)
|
|
@@ -460,90 +325,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
460
325
|
style,
|
|
461
326
|
popoverType,
|
|
462
327
|
children,
|
|
463
|
-
maxTagCount,
|
|
464
|
-
maxTagPlaceholder,
|
|
465
328
|
} = this.props
|
|
466
|
-
|
|
467
|
-
// 处理 maxTagCount 逻辑
|
|
468
|
-
const renderSelectedItems = () => {
|
|
469
|
-
if (!multiple || !maxTagCount || selected.length === 0) {
|
|
470
|
-
return selected.map((item) => (
|
|
471
|
-
<Flex key={item.value as any} className='gm-more-select-selected-item'>
|
|
472
|
-
<Popover
|
|
473
|
-
disabled={!this.props.isKeyboard}
|
|
474
|
-
type='hover'
|
|
475
|
-
popup={<div className='gm-padding-10'>{item.text}</div>}
|
|
476
|
-
>
|
|
477
|
-
<Flex flex column>
|
|
478
|
-
{renderSelected!(item)}
|
|
479
|
-
</Flex>
|
|
480
|
-
</Popover>
|
|
481
|
-
{multiple ? (
|
|
482
|
-
<SVGRemove
|
|
483
|
-
className='gm-cursor gm-more-select-clear-btn'
|
|
484
|
-
onClick={disabled ? _.noop : this._handleClear.bind(this, item)}
|
|
485
|
-
/>
|
|
486
|
-
) : (
|
|
487
|
-
!disabledClose && ( // 是否不限时清除按钮,仅单选可用
|
|
488
|
-
<SVGCloseCircle
|
|
489
|
-
onClick={disabled ? _.noop : this._handleClear.bind(this, item)}
|
|
490
|
-
className='gm-cursor gm-more-select-clear-btn'
|
|
491
|
-
/>
|
|
492
|
-
)
|
|
493
|
-
)}
|
|
494
|
-
</Flex>
|
|
495
|
-
))
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
// 处理 maxTagCount 逻辑
|
|
499
|
-
const isResponsive = maxTagCount === 'responsive'
|
|
500
|
-
let displayCount: number
|
|
501
|
-
|
|
502
|
-
if (isResponsive) {
|
|
503
|
-
displayCount = this.state.displayCount
|
|
504
|
-
} else {
|
|
505
|
-
displayCount = maxTagCount as number
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
const itemsToShow = selected.slice(0, displayCount)
|
|
509
|
-
const omittedItems = selected.slice(displayCount)
|
|
510
|
-
const omittedCount = selected.length - displayCount
|
|
511
|
-
|
|
512
|
-
return (
|
|
513
|
-
<>
|
|
514
|
-
{itemsToShow.map((item) => (
|
|
515
|
-
<Flex key={item.value as any} className='gm-more-select-selected-item'>
|
|
516
|
-
<Popover
|
|
517
|
-
disabled={!this.props.isKeyboard}
|
|
518
|
-
type='hover'
|
|
519
|
-
popup={<div className='gm-padding-10'>{item.text}</div>}
|
|
520
|
-
>
|
|
521
|
-
<Flex flex column>
|
|
522
|
-
{renderSelected!(item)}
|
|
523
|
-
</Flex>
|
|
524
|
-
</Popover>
|
|
525
|
-
<SVGRemove
|
|
526
|
-
className='gm-cursor gm-more-select-clear-btn'
|
|
527
|
-
onClick={disabled ? _.noop : this._handleClear.bind(this, item)}
|
|
528
|
-
/>
|
|
529
|
-
</Flex>
|
|
530
|
-
))}
|
|
531
|
-
{omittedCount > 0 && (
|
|
532
|
-
<Flex
|
|
533
|
-
key='omitted'
|
|
534
|
-
className='gm-more-select-selected-item gm-more-select-omitted-item'
|
|
535
|
-
>
|
|
536
|
-
{maxTagPlaceholder ? (
|
|
537
|
-
maxTagPlaceholder(omittedItems, omittedCount)
|
|
538
|
-
) : (
|
|
539
|
-
<span className='gm-more-select-omitted-count'>+{omittedCount}...</span>
|
|
540
|
-
)}
|
|
541
|
-
</Flex>
|
|
542
|
-
)}
|
|
543
|
-
</>
|
|
544
|
-
)
|
|
545
|
-
}
|
|
546
|
-
|
|
547
329
|
return (
|
|
548
330
|
<ConfigConsumer>
|
|
549
331
|
{(config) => (
|
|
@@ -558,7 +340,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
558
340
|
},
|
|
559
341
|
className
|
|
560
342
|
)}
|
|
561
|
-
style={style
|
|
343
|
+
style={style}
|
|
562
344
|
>
|
|
563
345
|
<Popover
|
|
564
346
|
ref={this._popoverRef}
|
|
@@ -576,7 +358,39 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
576
358
|
className='gm-more-select-selected'
|
|
577
359
|
>
|
|
578
360
|
{selected.length !== 0 ? (
|
|
579
|
-
|
|
361
|
+
selected.map((item) => (
|
|
362
|
+
<Flex
|
|
363
|
+
key={item.value as any}
|
|
364
|
+
className='gm-more-select-selected-item'
|
|
365
|
+
>
|
|
366
|
+
<Popover
|
|
367
|
+
disabled={!this.props.isKeyboard}
|
|
368
|
+
type='hover'
|
|
369
|
+
popup={<div className='gm-padding-10'>{item.text}</div>}
|
|
370
|
+
>
|
|
371
|
+
<Flex flex column>
|
|
372
|
+
{renderSelected!(item)}
|
|
373
|
+
</Flex>
|
|
374
|
+
</Popover>
|
|
375
|
+
{multiple ? (
|
|
376
|
+
<SVGRemove
|
|
377
|
+
className='gm-cursor gm-more-select-clear-btn'
|
|
378
|
+
onClick={
|
|
379
|
+
disabled ? _.noop : this._handleClear.bind(this, item)
|
|
380
|
+
}
|
|
381
|
+
/>
|
|
382
|
+
) : (
|
|
383
|
+
!disabledClose && ( // 是否不限时清除按钮,仅单选可用
|
|
384
|
+
<SVGCloseCircle
|
|
385
|
+
onClick={
|
|
386
|
+
disabled ? _.noop : this._handleClear.bind(this, item)
|
|
387
|
+
}
|
|
388
|
+
className='gm-cursor gm-more-select-clear-btn'
|
|
389
|
+
/>
|
|
390
|
+
)
|
|
391
|
+
)}
|
|
392
|
+
</Flex>
|
|
393
|
+
))
|
|
580
394
|
) : (
|
|
581
395
|
// 加多个 避免对齐问题,有文本才有对齐
|
|
582
396
|
<div className='gm-text-placeholder'>{placeholder} </div>
|
|
@@ -12,12 +12,6 @@ class MoreSelect<V = any> extends Component<MoreSelectProps<V>> {
|
|
|
12
12
|
renderListFilterType: 'default',
|
|
13
13
|
popoverType: 'focus',
|
|
14
14
|
onKeyDown: _.noop,
|
|
15
|
-
/** 是否展示全选以及过滤已删除商品 */
|
|
16
|
-
isRenderDefaultBottom: false,
|
|
17
|
-
/** 是否展示已删除商品 */
|
|
18
|
-
isShowDeletedSwitch: true,
|
|
19
|
-
/** 是否展示全选 */
|
|
20
|
-
isShowCheckedAll: true,
|
|
21
15
|
}
|
|
22
16
|
|
|
23
17
|
private _moreSelectBaseRef = createRef<MoreSelectBase>()
|
|
@@ -91,8 +85,6 @@ class MoreSelect<V = any> extends Component<MoreSelectProps<V>> {
|
|
|
91
85
|
onSearch,
|
|
92
86
|
onClick,
|
|
93
87
|
renderListFilter,
|
|
94
|
-
maxTagCount,
|
|
95
|
-
maxTagPlaceholder,
|
|
96
88
|
...rest
|
|
97
89
|
} = this.props
|
|
98
90
|
let tempSelect = selected as MoreSelectDataItem<V>[]
|
|
@@ -137,8 +129,6 @@ class MoreSelect<V = any> extends Component<MoreSelectProps<V>> {
|
|
|
137
129
|
isGroupList={isGroupList}
|
|
138
130
|
onSearch={onSearch && this._handleSearch}
|
|
139
131
|
renderListFilter={renderListFilter && this._renderListFilter}
|
|
140
|
-
maxTagCount={maxTagCount}
|
|
141
|
-
maxTagPlaceholder={maxTagPlaceholder}
|
|
142
132
|
/>
|
|
143
133
|
)
|
|
144
134
|
}
|
|
@@ -318,98 +318,6 @@ export const ComMoreSelectWithIsGroupListMultiple = () => (
|
|
|
318
318
|
/>
|
|
319
319
|
)
|
|
320
320
|
|
|
321
|
-
export const ComMoreSelectWithMaxTagCount = () => {
|
|
322
|
-
// 创建一个包含多个选项的数据集
|
|
323
|
-
const manyOptions = [
|
|
324
|
-
{ value: 1, text: '选项1' },
|
|
325
|
-
{ value: 2, text: '选项2' },
|
|
326
|
-
{ value: 3, text: '选项3' },
|
|
327
|
-
{ value: 4, text: '选项4' },
|
|
328
|
-
{ value: 5, text: '选项5' },
|
|
329
|
-
{ value: 6, text: '选项6' },
|
|
330
|
-
{ value: 7, text: '选项7' },
|
|
331
|
-
{ value: 8, text: '选项8' },
|
|
332
|
-
]
|
|
333
|
-
|
|
334
|
-
// 预选多个选项
|
|
335
|
-
const preSelected = manyOptions.slice(0, 6)
|
|
336
|
-
|
|
337
|
-
return (
|
|
338
|
-
<div style={{ width: '300px' }}>
|
|
339
|
-
<h3>maxTagCount 示例</h3>
|
|
340
|
-
|
|
341
|
-
<div style={{ marginBottom: '20px' }}>
|
|
342
|
-
<h4>不使用 maxTagCount(显示所有选项)</h4>
|
|
343
|
-
<MoreSelect<number>
|
|
344
|
-
multiple
|
|
345
|
-
data={manyOptions}
|
|
346
|
-
selected={preSelected}
|
|
347
|
-
onSelect={(selected) => {
|
|
348
|
-
console.log('不限制显示数量:', selected)
|
|
349
|
-
}}
|
|
350
|
-
/>
|
|
351
|
-
</div>
|
|
352
|
-
|
|
353
|
-
<div style={{ marginBottom: '20px' }}>
|
|
354
|
-
<h4>maxTagCount={2}(最多显示2个选项)</h4>
|
|
355
|
-
<MoreSelect<number>
|
|
356
|
-
multiple
|
|
357
|
-
maxTagCount={2}
|
|
358
|
-
data={manyOptions}
|
|
359
|
-
selected={preSelected}
|
|
360
|
-
onSelect={(selected) => {
|
|
361
|
-
console.log('最多显示2个:', selected)
|
|
362
|
-
}}
|
|
363
|
-
/>
|
|
364
|
-
</div>
|
|
365
|
-
|
|
366
|
-
<div style={{ marginBottom: '20px' }}>
|
|
367
|
-
<h4>maxTagCount={3}(最多显示3个选项)</h4>
|
|
368
|
-
<MoreSelect<number>
|
|
369
|
-
multiple
|
|
370
|
-
maxTagCount={3}
|
|
371
|
-
data={manyOptions}
|
|
372
|
-
selected={preSelected}
|
|
373
|
-
onSelect={(selected) => {
|
|
374
|
-
console.log('最多显示3个:', selected)
|
|
375
|
-
}}
|
|
376
|
-
/>
|
|
377
|
-
</div>
|
|
378
|
-
|
|
379
|
-
<div style={{ marginBottom: '20px' }}>
|
|
380
|
-
<h4>maxTagCount=responsive(响应式模式)</h4>
|
|
381
|
-
<MoreSelect<number>
|
|
382
|
-
multiple
|
|
383
|
-
maxTagCount='responsive'
|
|
384
|
-
data={manyOptions}
|
|
385
|
-
selected={preSelected}
|
|
386
|
-
onSelect={(selected) => {
|
|
387
|
-
console.log('响应式模式:', selected)
|
|
388
|
-
}}
|
|
389
|
-
/>
|
|
390
|
-
</div>
|
|
391
|
-
|
|
392
|
-
<div style={{ marginBottom: '20px' }}>
|
|
393
|
-
<h4>自定义 maxTagPlaceholder</h4>
|
|
394
|
-
<MoreSelect<number>
|
|
395
|
-
multiple
|
|
396
|
-
maxTagCount={2}
|
|
397
|
-
maxTagPlaceholder={(omittedValues, omittedCount) => (
|
|
398
|
-
<span style={{ color: '#1890ff', fontWeight: 'bold' }}>
|
|
399
|
-
还有{omittedCount}项未显示
|
|
400
|
-
</span>
|
|
401
|
-
)}
|
|
402
|
-
data={manyOptions}
|
|
403
|
-
selected={preSelected}
|
|
404
|
-
onSelect={(selected) => {
|
|
405
|
-
console.log('自定义占位符:', selected)
|
|
406
|
-
}}
|
|
407
|
-
/>
|
|
408
|
-
</div>
|
|
409
|
-
</div>
|
|
410
|
-
)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
321
|
export default {
|
|
414
322
|
title: '表单/MoreSelect',
|
|
415
323
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { Popover } from '@gm-pc/react'
|
|
1
2
|
import { CSSProperties, ReactNode, KeyboardEvent } from 'react'
|
|
2
|
-
import { Popover } from '../popover'
|
|
3
3
|
|
|
4
4
|
/** 普通的数据格式 */
|
|
5
5
|
interface MoreSelectDataItem<V extends string | number = string> {
|
|
6
6
|
value: V
|
|
7
7
|
text: string
|
|
8
8
|
disabled?: boolean
|
|
9
|
-
/** 是否已删除 */
|
|
10
|
-
deleted?: boolean
|
|
11
9
|
[key: string]: any
|
|
12
10
|
}
|
|
13
11
|
|
|
@@ -38,13 +36,10 @@ interface MoreSelectCommonProps<V extends string | number = string> {
|
|
|
38
36
|
renderListItem?(value: MoreSelectDataItem<V>, index: number): ReactNode
|
|
39
37
|
|
|
40
38
|
/** 自定义popup底部渲染 */
|
|
41
|
-
renderCustomizedBottom?(
|
|
42
|
-
ref: React.RefObject<Popover>,
|
|
43
|
-
defaultBottom: () => ReactNode
|
|
44
|
-
): ReactNode
|
|
39
|
+
renderCustomizedBottom?(ref: React.RefObject<Popover>): ReactNode
|
|
45
40
|
|
|
46
41
|
/**
|
|
47
|
-
*
|
|
42
|
+
* 自定义“空状态”渲染
|
|
48
43
|
*
|
|
49
44
|
* 若函数返回 undefined 则使用默认的空状态
|
|
50
45
|
*/
|
|
@@ -65,25 +60,6 @@ interface MoreSelectCommonProps<V extends string | number = string> {
|
|
|
65
60
|
/** 目前为了 keyboard */
|
|
66
61
|
isKeyboard?: boolean
|
|
67
62
|
onKeyDown?(event: KeyboardEvent): void
|
|
68
|
-
|
|
69
|
-
/** 最多显示的选中项数量,超出部分会折叠 */
|
|
70
|
-
maxTagCount?: number | 'responsive'
|
|
71
|
-
/** 自定义超出 maxTagCount 时显示的内容 */
|
|
72
|
-
maxTagPlaceholder?: (
|
|
73
|
-
omittedValues: MoreSelectDataItem<V>[],
|
|
74
|
-
omittedCount: number
|
|
75
|
-
) => ReactNode
|
|
76
|
-
|
|
77
|
-
/** 是否展示全选以及过滤已删除商品 */
|
|
78
|
-
isRenderDefaultBottom?: boolean
|
|
79
|
-
/** 是否展示已删除商品 */
|
|
80
|
-
isShowDeletedSwitch?: boolean
|
|
81
|
-
/** 是否展示全选 */
|
|
82
|
-
isShowCheckedAll?: boolean
|
|
83
|
-
/** 当设置 maxTagCount 的时候的宽度, 根据这个去计算显示内容 */
|
|
84
|
-
tagItemWidth?: number
|
|
85
|
-
/** +N 显示的宽度 */
|
|
86
|
-
omittedTagWidth?: number
|
|
87
63
|
}
|
|
88
64
|
|
|
89
65
|
interface MoreSelectBaseProps<V extends string | number = string>
|
|
@@ -104,12 +80,6 @@ interface MoreSelectBaseProps<V extends string | number = string>
|
|
|
104
80
|
): MoreSelectGroupDataItem<V>[]
|
|
105
81
|
/** 是否在active的时候搜索,订单业务相关,searchValue放在localstorage */
|
|
106
82
|
searchOnActive?: boolean
|
|
107
|
-
/** 是否展示全选以及过滤已删除商品 */
|
|
108
|
-
isRenderDefaultBottom?: boolean
|
|
109
|
-
/** 是否展示已删除商品 */
|
|
110
|
-
isShowDeletedSwitch?: boolean
|
|
111
|
-
/** 是否展示全选 */
|
|
112
|
-
isShowCheckedAll?: boolean
|
|
113
83
|
}
|
|
114
84
|
|
|
115
85
|
type MoreSelectData<V extends string | number = string> =
|
|
@@ -13,6 +13,7 @@ const Nav: FC<NavProps> = ({
|
|
|
13
13
|
onPushCreate,
|
|
14
14
|
showActive,
|
|
15
15
|
other,
|
|
16
|
+
otherFirst,
|
|
16
17
|
className,
|
|
17
18
|
style,
|
|
18
19
|
footerImage,
|
|
@@ -78,6 +79,8 @@ const Nav: FC<NavProps> = ({
|
|
|
78
79
|
>
|
|
79
80
|
<div className='gm-nav-logo'>{logo}</div>
|
|
80
81
|
<Flex flex column className='gm-nav-content'>
|
|
82
|
+
{otherFirst}
|
|
83
|
+
|
|
81
84
|
{data.map((one) => (
|
|
82
85
|
<NavItem
|
|
83
86
|
key={one.link}
|
|
@@ -11,7 +11,6 @@ interface SwitchProps {
|
|
|
11
11
|
onChange?(checked: boolean): void
|
|
12
12
|
className?: string
|
|
13
13
|
style?: CSSProperties
|
|
14
|
-
size?: 'small' | 'middle'
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
interface SwitchState {
|
|
@@ -27,11 +26,10 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
27
26
|
on: '',
|
|
28
27
|
off: '',
|
|
29
28
|
onChange: _.noop,
|
|
30
|
-
size: 'middle',
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
readonly state: SwitchState = {
|
|
34
|
-
checked:
|
|
32
|
+
checked: this.props.checked,
|
|
35
33
|
labelWidth: null,
|
|
36
34
|
isReady: false,
|
|
37
35
|
}
|
|
@@ -55,7 +53,7 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
55
53
|
UNSAFE_componentWillReceiveProps(nextProps: Readonly<SwitchProps>) {
|
|
56
54
|
if ('checked' in nextProps) {
|
|
57
55
|
this.setState({
|
|
58
|
-
checked:
|
|
56
|
+
checked: nextProps.checked,
|
|
59
57
|
})
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -84,7 +82,6 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
84
82
|
disabled,
|
|
85
83
|
on,
|
|
86
84
|
off,
|
|
87
|
-
size,
|
|
88
85
|
...rest
|
|
89
86
|
} = this.props
|
|
90
87
|
|
|
@@ -104,9 +101,8 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
104
101
|
ref={this._inputOffRef}
|
|
105
102
|
className={classNames('gm-switch gm-switch-' + type, className, {
|
|
106
103
|
disabled,
|
|
107
|
-
[`gm-switch-${size}`]: size,
|
|
108
104
|
})}
|
|
109
|
-
style={style
|
|
105
|
+
style={style}
|
|
110
106
|
data-attr={this.state.labelWidth}
|
|
111
107
|
disabled={disabled}
|
|
112
108
|
type='checkbox'
|