-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
wangkailang
commented
Aug 28, 2019
•
edited
Loading
edited
- 支持 VirtualSelectBox 组件
Codecov Report
@@ Coverage Diff @@
## master #65 +/- ##
==========================================
+ Coverage 78.07% 81.34% +3.26%
==========================================
Files 30 33 +3
Lines 967 1131 +164
Branches 201 234 +33
==========================================
+ Hits 755 920 +165
+ Misses 210 208 -2
- Partials 2 3 +1
Continue to review full report at Codecov.
|
Deploy preview for wizard-ui ready! Built with commit 6466fd2 |
'data-action'?: string; | ||
} | string; | ||
export type DropdownButtonMenuItem = | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块儿是格式化出来的吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的
src/utils/elastic-query.ts
Outdated
*/ | ||
function toStr(arr: ArrType[]) { | ||
if (!(arr instanceof Array)) return ''; | ||
const forward: any[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type ValueType = string | number;
type ArrType = {
type: string;
value: ValueType;
}
...
const forward: ValueType[] = [];
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import VirtualSelectBox from './index'; | ||
import getMockDatas from '../../../stories/utils/getMockDatas'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里在 components 里引用了 stories 里面的东西,stories 里面也需要引用 components 中的组件,所以类似 mock data 这种 components 和 stories 里面的都需要使用的方法是不是单独出来,让两个模块都引用这个更好些?
src/interface.tsx
Outdated
query: Query; | ||
} | ||
|
||
export interface VirtualSelectBoxProps extends VirtualSelectBoxDefaultProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以使用泛型来为约束 item 类型
export interface VirtualSelectBoxItem {
id?: number;
}
export interface VirtualSelectBoxProps<T> extends VirtualSelectBoxDefaultProps {
fetchData: (isReloading: boolean, query: Query, search?: string) => Promise<{
query: Query;
items: T[];
totalCount: number;
error?: string;
}>;
item?: T;
className?: string;
clear?: boolean;
onSelect?: (i: T) => void;
formatOption?: (item: T) => T;
}
export interface VirtualSelectBoxState<T> {
search: string;
items: T[];
query: Query;
isFetching: boolean;
totalCount: number;
isOpen: boolean;
isReloading: boolean;
error?: string;
}
组件定义
class VirtualSelectBox<T extends VirtualSelectBoxItem> extends React.Component<VirtualSelectBoxProps<T>, VirtualSelectBoxState<T>> {}
调用
type Data = { id?: number; name: string };
<VirtualSelectBox<Data>
item={{ id: 1, name: `${resName}-1` }}
fetchData={fetchDatas}
onSelect={noOp}
clear
/>
为了解决 clear 时调用 onSelect({}) 报错,我们可以添加一个可选的默认值属性,类型也是 T,在 clear 时将默认值传入,也可以更方便的定制化
VirtualList 也可以这么修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
666 呀,这种用法听实用的,也比较灵活,根据这个做个调整:
- 在
VirtualList
上补充VirtualItem
代替VirtualSelectBoxItem
,并支持 string 类型; VirtualSelectBoxDefaultProps
增加defaultItem
指定为泛类型,解决onSelect({})
的问题。
…al-select-box * 'master' of github.com:xsky-fe/wizard-ui: Release 0.2.0 feat: Add InputDropdown. (#64) # Conflicts: # src/interface.tsx