@gm-pc/react 1.28.0-beta.0 → 1.28.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/more_select/base.tsx +12 -15
- package/src/component/more_select/more_select.tsx +6 -0
- package/src/component/more_select/style.less +4 -0
- package/src/component/more_select/types.ts +11 -0
- package/src/component/switch/style.less +4 -0
- package/src/component/switch/switch.tsx +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/react",
|
|
3
|
-
"version": "1.28.0-beta.
|
|
3
|
+
"version": "1.28.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.28.0-beta.
|
|
27
|
+
"@gm-pc/locales": "^1.28.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": "8e9f3a00a9da2a0d800dafeb65f37d737f84be75"
|
|
52
52
|
}
|
|
@@ -20,8 +20,8 @@ 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
|
-
import { Checkbox
|
|
24
|
-
|
|
23
|
+
import { Checkbox } from '../checkbox'
|
|
24
|
+
import { Switch } from '../switch'
|
|
25
25
|
interface MoreSelectBaseState {
|
|
26
26
|
searchValue: string
|
|
27
27
|
loading: boolean
|
|
@@ -46,7 +46,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
46
46
|
loading: false,
|
|
47
47
|
willActiveIndex: this.props.isKeyboard ? 0 : null,
|
|
48
48
|
isCheckedAll: false,
|
|
49
|
-
isFilterDelete:
|
|
49
|
+
isFilterDelete: true,
|
|
50
50
|
displayCount: 0,
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -71,15 +71,14 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
componentDidMount() {
|
|
74
|
-
const { maxTagCount } = this.props
|
|
74
|
+
const { maxTagCount, tagItemWidth = 80, omittedTagWidth = 45 } = this.props
|
|
75
75
|
if (maxTagCount === 'responsive' && this._selectionRef.current) {
|
|
76
76
|
// HACK: 首次计算
|
|
77
77
|
setTimeout(() => {
|
|
78
78
|
if (this._selectionRef.current) {
|
|
79
79
|
const { width } = this._selectionRef.current.getBoundingClientRect()
|
|
80
|
-
const omittedTagWidth = 50 // for "+N..."
|
|
81
80
|
const availableWidth = width - omittedTagWidth
|
|
82
|
-
const newDisplayCount = Math.floor(availableWidth /
|
|
81
|
+
const newDisplayCount = Math.floor(availableWidth / tagItemWidth)
|
|
83
82
|
if (this.state.displayCount !== newDisplayCount) {
|
|
84
83
|
this.setState({ displayCount: newDisplayCount > 0 ? newDisplayCount : 0 })
|
|
85
84
|
}
|
|
@@ -90,12 +89,11 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
90
89
|
for (const entry of entries) {
|
|
91
90
|
const { width } = entry.contentRect
|
|
92
91
|
// Estimate item width, let's say 80px.
|
|
93
|
-
const omittedTagWidth = 50 // for "+N..."
|
|
94
92
|
const availableWidth = width - omittedTagWidth
|
|
95
|
-
const newDisplayCount = Math.floor(availableWidth /
|
|
93
|
+
const newDisplayCount = Math.floor(availableWidth / tagItemWidth)
|
|
96
94
|
|
|
97
95
|
if (this.state.displayCount !== newDisplayCount) {
|
|
98
|
-
this.setState({ displayCount: newDisplayCount
|
|
96
|
+
this.setState({ displayCount: newDisplayCount })
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
})
|
|
@@ -300,9 +298,8 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
300
298
|
return (
|
|
301
299
|
<Flex
|
|
302
300
|
justifyBetween
|
|
303
|
-
className='tw-p-[8px]'
|
|
301
|
+
className='tw-p-[8px] gm-more-select-default-bottom'
|
|
304
302
|
alignCenter
|
|
305
|
-
style={{ borderTop: '1px solid #aeaeae' }}
|
|
306
303
|
>
|
|
307
304
|
{isShowCheckedAll && (
|
|
308
305
|
<Checkbox
|
|
@@ -323,14 +320,15 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
323
320
|
}
|
|
324
321
|
}}
|
|
325
322
|
>
|
|
326
|
-
全选
|
|
323
|
+
全选({availableData.length})
|
|
327
324
|
</Checkbox>
|
|
328
325
|
)}
|
|
329
326
|
{isShowDeletedSwitch && (
|
|
330
327
|
<Flex alignCenter>
|
|
331
328
|
<Flex row>
|
|
332
329
|
<Switch
|
|
333
|
-
|
|
330
|
+
size='small'
|
|
331
|
+
style={{ width: 32 }}
|
|
334
332
|
checked={isFilterDelete}
|
|
335
333
|
onChange={(open) => {
|
|
336
334
|
this.setState({
|
|
@@ -347,7 +345,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
347
345
|
}}
|
|
348
346
|
/>
|
|
349
347
|
</Flex>
|
|
350
|
-
<span className='gm-margin-left-5'
|
|
348
|
+
<span className='gm-margin-left-5'>过滤已删除数据</span>
|
|
351
349
|
</Flex>
|
|
352
350
|
)}
|
|
353
351
|
</Flex>
|
|
@@ -464,7 +462,6 @@ class MoreSelectBase<V extends string | number = string> extends Component<
|
|
|
464
462
|
children,
|
|
465
463
|
maxTagCount,
|
|
466
464
|
maxTagPlaceholder,
|
|
467
|
-
isRenderDefaultBottom = false,
|
|
468
465
|
} = this.props
|
|
469
466
|
|
|
470
467
|
// 处理 maxTagCount 逻辑
|
|
@@ -12,6 +12,12 @@ 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,
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
private _moreSelectBaseRef = createRef<MoreSelectBase>()
|
|
@@ -73,6 +73,17 @@ interface MoreSelectCommonProps<V extends string | number = string> {
|
|
|
73
73
|
omittedValues: MoreSelectDataItem<V>[],
|
|
74
74
|
omittedCount: number
|
|
75
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
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
interface MoreSelectBaseProps<V extends string | number = string>
|
|
@@ -11,6 +11,7 @@ interface SwitchProps {
|
|
|
11
11
|
onChange?(checked: boolean): void
|
|
12
12
|
className?: string
|
|
13
13
|
style?: CSSProperties
|
|
14
|
+
size?: 'small' | 'middle'
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
interface SwitchState {
|
|
@@ -26,10 +27,11 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
26
27
|
on: '',
|
|
27
28
|
off: '',
|
|
28
29
|
onChange: _.noop,
|
|
30
|
+
size: 'middle',
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
readonly state: SwitchState = {
|
|
32
|
-
checked: this.props.checked,
|
|
34
|
+
checked: !!this.props.checked,
|
|
33
35
|
labelWidth: null,
|
|
34
36
|
isReady: false,
|
|
35
37
|
}
|
|
@@ -53,7 +55,7 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
53
55
|
UNSAFE_componentWillReceiveProps(nextProps: Readonly<SwitchProps>) {
|
|
54
56
|
if ('checked' in nextProps) {
|
|
55
57
|
this.setState({
|
|
56
|
-
checked: nextProps.checked,
|
|
58
|
+
checked: !!nextProps.checked,
|
|
57
59
|
})
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -82,6 +84,7 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
82
84
|
disabled,
|
|
83
85
|
on,
|
|
84
86
|
off,
|
|
87
|
+
size,
|
|
85
88
|
...rest
|
|
86
89
|
} = this.props
|
|
87
90
|
|
|
@@ -101,8 +104,9 @@ class Switch extends Component<SwitchProps, SwitchState> {
|
|
|
101
104
|
ref={this._inputOffRef}
|
|
102
105
|
className={classNames('gm-switch gm-switch-' + type, className, {
|
|
103
106
|
disabled,
|
|
107
|
+
[`gm-switch-${size}`]: size,
|
|
104
108
|
})}
|
|
105
|
-
style={style}
|
|
109
|
+
style={style as any}
|
|
106
110
|
data-attr={this.state.labelWidth}
|
|
107
111
|
disabled={disabled}
|
|
108
112
|
type='checkbox'
|