@gm-pc/react 1.27.4-beta.3 → 1.27.5-beta.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/react",
3
- "version": "1.27.4-beta.3",
3
+ "version": "1.27.5-beta.0",
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.4-beta.3",
27
+ "@gm-pc/locales": "^1.27.5-beta.0",
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": "65e074c3ee9385378ee89111a24aaaef74f74038"
51
+ "gitHead": "62f3bf16794e2d1778f97dc45c342746b9ea53f9"
52
52
  }
@@ -22,10 +22,11 @@ import { findDOMNode } from 'react-dom'
22
22
  import { ConfigConsumer, ConfigProvider, ConfigProviderProps } from '../config_provider'
23
23
 
24
24
  interface MoreSelectBaseState {
25
- searchValue: string
25
+ searchValue: string | undefined
26
26
  loading: boolean
27
27
  /* keyboard 默认第一个位置 */
28
28
  willActiveIndex: number | null
29
+ isOpen: boolean
29
30
  }
30
31
 
31
32
  // @todo keydown item disabled
@@ -38,9 +39,10 @@ class MoreSelectBase<V extends string | number = string> extends Component<
38
39
  static renderListFilterPinYin = renderListFilterPinYin
39
40
 
40
41
  readonly state: MoreSelectBaseState = {
41
- searchValue: '',
42
+ searchValue: (undefined as unknown) as string,
42
43
  loading: false,
43
44
  willActiveIndex: this.props.isKeyboard ? 0 : null,
45
+ isOpen: false,
44
46
  }
45
47
 
46
48
  private _isUnmounted = false
@@ -133,6 +135,10 @@ class MoreSelectBase<V extends string | number = string> extends Component<
133
135
  const searchValue = event.target.value
134
136
  this.setState({ searchValue })
135
137
  this._debounceDoSearch(searchValue)
138
+ if (this.props.isSameAntd) {
139
+ // eslint-disable-next-line no-unused-expressions
140
+ this._popoverRef.current?.apiDoSetActive(true)
141
+ }
136
142
  setTimeout(() => {
137
143
  // eslint-disable-next-line no-unused-expressions
138
144
  isInitSearch && this._inputRef.current?.select()
@@ -232,18 +238,34 @@ class MoreSelectBase<V extends string | number = string> extends Component<
232
238
  )
233
239
  }
234
240
 
241
+ private _renderSearchInput = () => {
242
+ const { searchPlaceholder } = this.props
243
+ const { searchValue } = this.state
244
+ return (
245
+ <div className='gm-more-select-popup-input'>
246
+ <Input
247
+ ref={this._inputRef}
248
+ autoFocus
249
+ value={searchValue}
250
+ onChange={this._handleChange}
251
+ placeholder={searchPlaceholder}
252
+ />
253
+ </div>
254
+ )
255
+ }
256
+
235
257
  private _renderList = (config: ConfigProviderProps): ReactNode => {
236
258
  const {
237
259
  selected = [],
238
260
  multiple,
239
261
  isGroupList,
240
262
  renderListItem,
241
- searchPlaceholder,
242
263
  listHeight,
243
264
  popupClassName,
244
265
  renderCustomizedBottom,
266
+ isSameAntd = false,
245
267
  } = this.props
246
- const { loading, searchValue, willActiveIndex } = this.state
268
+ const { loading, willActiveIndex } = this.state
247
269
  const filterData = this._getFilterData()
248
270
  return (
249
271
  <ConfigProvider {...config}>
@@ -251,15 +273,7 @@ class MoreSelectBase<V extends string | number = string> extends Component<
251
273
  className={classNames('gm-more-select-popup', popupClassName)}
252
274
  onKeyDown={this._handlePopupKeyDown}
253
275
  >
254
- <div className='gm-more-select-popup-input'>
255
- <Input
256
- ref={this._inputRef}
257
- autoFocus
258
- value={searchValue}
259
- onChange={this._handleChange}
260
- placeholder={searchPlaceholder}
261
- />
262
- </div>
276
+ {isSameAntd ? null : this._renderSearchInput()}
263
277
  <div style={{ height: listHeight }}>
264
278
  {loading && (
265
279
  <Flex alignCenter justifyCenter className='gm-bg gm-padding-5'>
@@ -299,7 +313,16 @@ class MoreSelectBase<V extends string | number = string> extends Component<
299
313
  }
300
314
 
301
315
  private _handlePopoverVisibleChange = (active: boolean) => {
302
- if (active && this.props.searchOnActive) {
316
+ if (this.props.isSameAntd) {
317
+ this.setState({
318
+ isOpen: active,
319
+ })
320
+ if (!this.props.multiple && !active) {
321
+ this.setState({ searchValue: undefined })
322
+ }
323
+ }
324
+
325
+ if (active && this.props.searchOnActive && !this.props.isSameAntd) {
303
326
  const searchValue = localStorage.getItem('_GM-PC_MORESELECT_SEARCHVALUE')
304
327
  if (searchValue) {
305
328
  this.setState({ searchValue })
@@ -325,7 +348,11 @@ class MoreSelectBase<V extends string | number = string> extends Component<
325
348
  style,
326
349
  popoverType,
327
350
  children,
351
+ searchPlaceholder,
352
+ isSameAntd = false,
328
353
  } = this.props
354
+ const { searchValue } = this.state
355
+
329
356
  return (
330
357
  <ConfigConsumer>
331
358
  {(config) => (
@@ -346,7 +373,9 @@ class MoreSelectBase<V extends string | number = string> extends Component<
346
373
  ref={this._popoverRef}
347
374
  type={popoverType}
348
375
  popup={() => this._renderList(config)}
349
- disabled={disabled}
376
+ disabled={
377
+ disabled || (!isSameAntd ? false : this.state.searchValue === undefined)
378
+ }
350
379
  isInPopup={isInPopup}
351
380
  onVisibleChange={this._handlePopoverVisibleChange}
352
381
  >
@@ -355,13 +384,17 @@ class MoreSelectBase<V extends string | number = string> extends Component<
355
384
  ref={this._selectionRef}
356
385
  tabIndex={0}
357
386
  wrap
358
- className='gm-more-select-selected'
387
+ className={classNames({
388
+ 'gm-more-select-selected': true,
389
+ 'gm-more-select-selected-antd': isSameAntd,
390
+ })}
359
391
  >
360
392
  {selected.length !== 0 ? (
361
393
  selected.map((item) => (
362
394
  <Flex
363
395
  key={item.value as any}
364
396
  className='gm-more-select-selected-item'
397
+ alignCenter
365
398
  >
366
399
  <Popover
367
400
  disabled={!this.props.isKeyboard}
@@ -369,7 +402,23 @@ class MoreSelectBase<V extends string | number = string> extends Component<
369
402
  popup={<div className='gm-padding-10'>{item.text}</div>}
370
403
  >
371
404
  <Flex flex column>
372
- {renderSelected!(item)}
405
+ {isSameAntd ? (
406
+ <div className='gm-more-select-popup-input'>
407
+ <Input
408
+ ref={this._inputRef}
409
+ value={
410
+ !this.state.isOpen
411
+ ? renderSelected!(item)
412
+ : searchValue
413
+ }
414
+ onChange={this._handleChange}
415
+ placeholder={searchPlaceholder}
416
+ className='gm-more-select-popup-input-no-border'
417
+ />
418
+ </div>
419
+ ) : (
420
+ renderSelected!(item)
421
+ )}
373
422
  </Flex>
374
423
  </Popover>
375
424
  {multiple ? (
@@ -393,7 +442,20 @@ class MoreSelectBase<V extends string | number = string> extends Component<
393
442
  ))
394
443
  ) : (
395
444
  // 加多个 &nbsp; 避免对齐问题,有文本才有对齐
396
- <div className='gm-text-placeholder'>{placeholder}&nbsp; </div>
445
+ <>
446
+ {isSameAntd ? (
447
+ <Input
448
+ ref={this._inputRef}
449
+ value={searchValue}
450
+ onChange={this._handleChange}
451
+ placeholder={searchPlaceholder}
452
+ className='gm-more-select-popup-input-no-border'
453
+ />
454
+ ) : (
455
+ <div className='gm-text-placeholder'>{placeholder}&nbsp; </div>
456
+ )}
457
+ </>
458
+ //
397
459
  )}
398
460
  </Flex>
399
461
  )}
@@ -14,10 +14,15 @@
14
14
  }
15
15
  }
16
16
 
17
+ .gm-more-select-selected-antd {
18
+ padding: 0 12px;
19
+ }
20
+
17
21
  .gm-more-select-clear-btn {
18
22
  position: absolute;
19
- right: 5px;
20
- top: 7px;
23
+ right: 4px;
24
+ top: 50%;
25
+ transform: translateY(-50%);
21
26
  cursor: pointer;
22
27
  color: var(--gm-color-desc);
23
28
  }
@@ -70,3 +75,10 @@
70
75
  }
71
76
  }
72
77
  }
78
+
79
+ .gm-more-select-popup-input-no-border {
80
+ border: none !important;
81
+ border-radius: 0 !important;
82
+ padding: 0 !important;
83
+ box-shadow: none !important;
84
+ }
@@ -80,6 +80,8 @@ interface MoreSelectBaseProps<V extends string | number = string>
80
80
  ): MoreSelectGroupDataItem<V>[]
81
81
  /** 是否在active的时候搜索,订单业务相关,searchValue放在localstorage */
82
82
  searchOnActive?: boolean
83
+ /** 是否用select */
84
+ isSameAntd?: boolean
83
85
  }
84
86
 
85
87
  type MoreSelectData<V extends string | number = string> =