Skip to content

Commit 9bd16a8

Browse files
committed
Init
1 parent 01862fc commit 9bd16a8

28 files changed

+15341
-10548
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/node_modules
2+
/lib
3+
/cjs
4+
/esm
5+
/dist

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

.prettierrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 100,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": true,
14+
"singleQuote": false,
15+
"tabWidth": 4,
16+
"trailingComma": "es5",
17+
"useTabs": true
18+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 react-widget
3+
Copyright (c) 2020 react-widget-select
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 24 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,35 @@
1-
# react-widget-select
1+
# select
2+
3+
Select组件
24

35
## 安装
6+
47
`npm install --save react-widget-select`
58

6-
## API
79

8-
```html
9-
<Select>
10-
<Option value="lucy">lucy</Option>
11-
</Select>
10+
## 使用
11+
12+
13+
14+
```js
15+
16+
```
17+
18+
### Interfaces
19+
20+
```ts
21+
1222
```
1323

14-
```html
15-
<Select options={[{label:lucy, value: lucy}]}>
16-
</Select>
24+
### defaultProps
25+
1726
```
27+
28+
```
29+
30+
31+
### 基础样式
1832

19-
### Select props
20-
21-
| 参数 | 说明 | 类型 | 默认值 |
22-
| --- | --- | --- | --- |
23-
| prefixCls | 组件CSS样式前缀 | string | rw-select |
24-
| className | 组件className属性 | string | - |
25-
| style | 组件style属性 | React.CSSProperties | - |
26-
| tabIndex | 组件tabIndex属性 | number | - |
27-
| options | 组件数据 | Array\<Option> | false |
28-
| inline | 内联组件 | boolean | true |
29-
| emptyLabel | 下拉框无内容时显示 | ReactNode | no data. |
30-
| searchComponent | 自定义搜索输入框组件 | ReactNode | input |
31-
| valueField | 设置取值字段 | string | value |
32-
| labelField | 设置显示字段 | string | label |
33-
| childrenField | 设置子节点字段 | string | children |
34-
| labelInValue | 是否把每个选项的 label 包装到 value 中,会把 Select 的 value 类型从 `string` 变为 `{key: string, label: ReactNode}` 的格式 | boolean | false |
35-
| allowClear | 支持清除 | boolean | false |
36-
| autoFocus | 默认获取焦点 | boolean | false |
37-
| defaultValue | 指定默认选中的条目 | string|number | - |
38-
| value | 指定默认选中的条目 `受控` | string|number | - |
39-
| disabled | 是否禁用 | boolean | false |
40-
| readOnly | 是否只读 | boolean | false |
41-
| placeholder | 选择框默认文字 | string | - |
42-
| showArrow | 是否显示下拉小箭头 | boolean | true |
43-
| showSearch | 显示下拉框的搜索输入框 | boolean | false |
44-
| optionFilterField | 搜索时过滤对应的 option 属性 | string | label |
45-
| filterOption | 是否根据输入项进行筛选。当其为一个函数时,会接收 `searchText` `option` 两个参数,当 `option` 符合筛选条件时,应返回 `true`,反之则返回 `false`| boolean or function(inputValue, option) | true |
46-
| dropdownClassName | 下拉菜单的 className 属性 | string | - |
47-
| dropdownMatchSelectWidth | 下拉菜单和选择器同宽 | boolean | true |
48-
| dropdownStyle | 下拉菜单的 style 属性 | object | - |
49-
| dropdownProps | 下拉菜单扩展属性,参考`ListBox` | object | - |
50-
| placement | dropdown出现位置<`PlacementType`> | string | bottomLeft |
51-
| offset | dropdown位置偏移量 | Array<number> | [0, 0] |
52-
| popupClassName | dropdown弹出层的className属性 | string | - |
53-
| popupRootComponent | dropdown弹出层自定义组件类型 | ReactNode | div |
54-
| getPopupContainer | popup渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域。 | Function(triggerNode) | () => document.body |
55-
| destroyPopupOnHide | dropdown隐藏时删除DOM节点 | boolean | true |
56-
| defaultOpen | 是否默认展开下拉菜单 | boolean | - |
57-
| open | 是否展开下拉菜单`受控` | boolean | - |
58-
| onResizeToHideDropDown | 浏览器大小改变时隐藏下拉框 | boolean | true |
59-
| onScrollToHideDropDown | 浏览器触发滚动时隐藏下拉框 | boolean | false |
60-
| renderValue | 自定义渲染被选中的选项 | (menu: ReactNode, option: Option) => ReactNode | - |
61-
| renderMenu | 自定义下拉框内容 | (menu: ReactNode, props) => ReactNode | - |
62-
| renderMenuItem | 自定义下拉选项内容 | (label:React.Node, option:Option) => ReactNode | - |
63-
| renderMenuGroupTitle | 自定义下拉分组标题内容 | (label:React.Node, option:Option) => ReactNode | - |
64-
| onBlur | 失去焦点的时回调 | function | - |
65-
| onFocus | 获得焦点时回调 | function | - |
66-
| onChange | 选中 option 时调用此函数 | function(value, option:Option) | - |
67-
| onSearch | 搜索输入框值变化时回调 | function(value: string) | |
68-
| onSelect | 被选中时调用,参数为选中项的 value (或 key) 值 | function(value, option:Option) | - |
69-
| onDropDownVisibleChange | 展开/隐藏下拉菜单的回调 | function(open) | - |
70-
| onMouseEnter | 鼠标移入时回调 | function | - |
71-
| onMouseLeave | 鼠标移出时回调 | function | - |
72-
73-
74-
> 注意,如果发现下拉菜单跟随页面滚动,或者需要在其他弹层中触发 Select,请尝试使用 `getPopupContainer={triggerNode => triggerNode.parentNode}` 将下拉弹层渲染节点固定在触发器的父元素中。
75-
76-
### Select Methods
77-
78-
| 名称 | 说明 |
79-
| --- | --- |
80-
| blur() | 取消焦点 |
81-
| focus() | 获取焦点 |
82-
83-
### Option props
84-
85-
| 参数 | 说明 | 类型 | 默认值 |
86-
| --- | --- | --- | --- |
87-
| disabled | 是否禁用 | boolean | false |
88-
| label | 选中该 Option 后,Select 的 title | ReactNode | - |
89-
| value | 默认根据此属性值进行筛选 | string\|number | - |
90-
91-
### OptGroup props
92-
93-
| 参数 | 说明 | 类型 | 默认值 |
94-
| --- | --- | --- | --- |
95-
| children | 子节点 | Array\<Option> | - |
96-
| label | 组名 | string\|React.Element ||
97-
98-
### PlacementType
33+
```css
9934

10035
```
101-
type PlacementType =
102-
| bottomLeft
103-
| bottomCenter
104-
| bottomRight
105-
| topLeft
106-
| topCenter
107-
| topRight
108-
| leftTop
109-
| leftCenter
110-
| leftBottom
111-
| rightTop
112-
| rightCenter
113-
| rightBottom
114-
| centerCenter
115-
116-
```

babel.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = api => {
2+
const isTest = api.env("test");
3+
if (!isTest) return {};
4+
5+
return {
6+
presets: [
7+
[
8+
"babel-preset-packez",
9+
{
10+
modules: "cjs",
11+
},
12+
],
13+
],
14+
};
15+
};

examples/Demo.js

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
import React, { Component } from 'react';
2-
import DemoList from './DemoList';
1+
import React, { Component } from "react";
2+
import DemoList from "./DemoList";
33

44
export default class Demo extends Component {
5+
state = {
6+
current: DemoList[0],
7+
};
58

6-
state = {
7-
current: DemoList[0]
8-
}
9+
onDemoChange(item, e) {
10+
this.setState({
11+
current: item,
12+
});
13+
}
914

10-
onDemoChange(item, e) {
11-
this.setState({
12-
current: item
13-
});
14-
}
15-
16-
render() {
17-
const { current } = this.state;
18-
return (
19-
<div className="container">
20-
<div className="slider">
21-
{
22-
DemoList.map((item, i) => {
23-
return (
24-
<div
25-
className={current === item ? 'active' : ''}
26-
onClick={this.onDemoChange.bind(this, item)}
27-
>
28-
{item.label}
29-
</div>
30-
);
31-
})
32-
}
33-
</div>
34-
<div className="content">
35-
{current ? <current.component /> : null}
36-
</div>
37-
</div>
38-
)
39-
}
40-
}
15+
render() {
16+
const { current } = this.state;
17+
return (
18+
<div className="container">
19+
<div className="slider">
20+
{DemoList.map((item, i) => {
21+
return (
22+
<div
23+
key={i}
24+
className={current === item ? "active" : ""}
25+
onClick={this.onDemoChange.bind(this, item)}
26+
>
27+
{item.label}
28+
</div>
29+
);
30+
})}
31+
</div>
32+
<div className="content">{current ? <current.component /> : null}</div>
33+
</div>
34+
);
35+
}
36+
}

examples/DemoList.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import Demo1 from './demos/demo1';
2-
import Demo2 from './demos/Demo2';
3-
import Demo3 from './demos/Demo3';
1+
import Demo1 from "./demos/demo1";
2+
// import Demo2 from './demos/Demo2';
3+
// import Demo3 from './demos/Demo3';
44
// import Demo4 from './demos/Demo4';
55

66
export default [
7-
{
8-
label: '基本功能',
9-
component: Demo1
10-
},
11-
{
12-
label: 'renderMenu',
13-
component: Demo2
14-
},
15-
{
16-
label: '远程搜索',
17-
component: Demo3
18-
},
19-
// {
20-
// label: 'fixed',
21-
// component: Demo4
22-
// }
23-
]
7+
{
8+
label: "基本功能",
9+
component: Demo1,
10+
},
11+
// {
12+
// label: 'fixed',
13+
// component: Demo4
14+
// }
15+
];

0 commit comments

Comments
 (0)