@sheinoutmobile/shineoutmobile 1.8.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.
Potentially problematic release.
This version of @sheinoutmobile/shineoutmobile might be problematic. Click here for more details.
- package/.eslintignore +20 -0
- package/.eslintrc +8 -0
- package/.gitlab-ci.yml +53 -0
- package/.yarnrc +1 -0
- package/CHANGELOG.md +8 -0
- package/README.md +14 -0
- package/build.config.js +6 -0
- package/doc.config.js +16 -0
- package/lib/index.esm.js +5414 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/package.json +47 -0
- package/src/component/button/button.jsx +83 -0
- package/src/component/button/index.jsx +3 -0
- package/src/component/button/style.less +132 -0
- package/src/component/cell/cell.jsx +71 -0
- package/src/component/cell/index.jsx +3 -0
- package/src/component/cell/style.less +86 -0
- package/src/component/cell-group/cell-group.jsx +26 -0
- package/src/component/cell-group/index.jsx +3 -0
- package/src/component/cell-group/style.less +22 -0
- package/src/component/checkbox/checkbox.jsx +92 -0
- package/src/component/checkbox/index.js +3 -0
- package/src/component/checkbox/kind/checkbox-button.jsx +41 -0
- package/src/component/checkbox/style.less +49 -0
- package/src/component/dialog/dialog.jsx +58 -0
- package/src/component/dialog/index.js +3 -0
- package/src/component/dialog/kind/dialog-alert.jsx +22 -0
- package/src/component/dialog/kind/dialog-confirm.jsx +54 -0
- package/src/component/dialog/style.less +80 -0
- package/src/component/drawer/drawer.jsx +151 -0
- package/src/component/drawer/index.jsx +3 -0
- package/src/component/drawer/js/tools.js +1 -0
- package/src/component/drawer/style.less +17 -0
- package/src/component/field/field.jsx +49 -0
- package/src/component/field/index.js +3 -0
- package/src/component/icon/icon.jsx +55 -0
- package/src/component/icon/index.jsx +19 -0
- package/src/component/icon/style.less +9 -0
- package/src/component/icons/index.js +3 -0
- package/src/component/icons/mrp.js +3 -0
- package/src/component/image-previewer/image-previewer.jsx +54 -0
- package/src/component/image-previewer/index.js +3 -0
- package/src/component/index-sort-list/group.jsx +49 -0
- package/src/component/index-sort-list/index-bar.jsx +34 -0
- package/src/component/index-sort-list/index.js +3 -0
- package/src/component/index-sort-list/js/rules.js +14 -0
- package/src/component/index-sort-list/js/sort-rule.js +41 -0
- package/src/component/index-sort-list/list.jsx +110 -0
- package/src/component/index-sort-list/style.less +109 -0
- package/src/component/input/index.js +3 -0
- package/src/component/input/input.jsx +285 -0
- package/src/component/input/style.less +77 -0
- package/src/component/list-view/index.js +3 -0
- package/src/component/list-view/jsx/empty.jsx +23 -0
- package/src/component/list-view/list-view.jsx +165 -0
- package/src/component/list-view/style.less +79 -0
- package/src/component/loading/index.js +3 -0
- package/src/component/loading/loading.jsx +97 -0
- package/src/component/loading/styles.less +128 -0
- package/src/component/multiple-selector/index.jsx +3 -0
- package/src/component/multiple-selector/item.jsx +23 -0
- package/src/component/multiple-selector/multiple-selector.jsx +116 -0
- package/src/component/multiple-selector/selector.jsx +41 -0
- package/src/component/multiple-selector/style.less +78 -0
- package/src/component/notice-bar/index.jsx +3 -0
- package/src/component/notice-bar/notice-bar.jsx +86 -0
- package/src/component/notice-bar/style.less +72 -0
- package/src/component/notify/index.js +37 -0
- package/src/component/notify/notify.jsx +125 -0
- package/src/component/notify/style.less +48 -0
- package/src/component/picker/drawPicker.jsx +110 -0
- package/src/component/picker/index.js +3 -0
- package/src/component/picker/picker.jsx +380 -0
- package/src/component/picker/pickerItem.jsx +31 -0
- package/src/component/picker/style.less +80 -0
- package/src/component/pull-refresh/index.js +3 -0
- package/src/component/pull-refresh/pull-refresh.jsx +46 -0
- package/src/component/search-bar/index.jsx +3 -0
- package/src/component/search-bar/search-bar.jsx +97 -0
- package/src/component/search-bar/style.less +52 -0
- package/src/component/sign/index.jsx +3 -0
- package/src/component/sign/sign.jsx +33 -0
- package/src/component/sign/style.less +56 -0
- package/src/component/sort-item/index.jsx +3 -0
- package/src/component/sort-item/sort-item.jsx +52 -0
- package/src/component/sort-item/style.less +52 -0
- package/src/component/subscript/index.js +3 -0
- package/src/component/subscript/style.less +63 -0
- package/src/component/subscript/subscript.jsx +77 -0
- package/src/component/tab/index.jsx +6 -0
- package/src/component/tab/nav-child.jsx +63 -0
- package/src/component/tab/panel.jsx +22 -0
- package/src/component/tab/style.less +87 -0
- package/src/component/tab/tab.jsx +195 -0
- package/src/component/tag/index.jsx +3 -0
- package/src/component/tag/style.less +56 -0
- package/src/component/tag/tag.jsx +52 -0
- package/src/component/toast/content.jsx +31 -0
- package/src/component/toast/index.js +3 -0
- package/src/component/toast/style.less +50 -0
- package/src/component/toast/toast.jsx +62 -0
- package/src/component/touchable/index.js +3 -0
- package/src/component/touchable/style.less +33 -0
- package/src/component/touchable/touchable.jsx +43 -0
- package/src/component/uploader/index.jsx +445 -0
- package/src/component/uploader/js/get-image-base64.js +31 -0
- package/src/component/uploader/js/get-image-detail.js +26 -0
- package/src/component/uploader/js/index.js +77 -0
- package/src/component/uploader/js/merge-class-name.js +14 -0
- package/src/component/uploader/js/old-compress-function.js +64 -0
- package/src/component/uploader/js/request.js +62 -0
- package/src/component/uploader/js/tools.js +115 -0
- package/src/component/uploader/jsx/config.jsx +36 -0
- package/src/component/uploader/jsx/img-preview.jsx +41 -0
- package/src/component/uploader/jsx/thumbnails.jsx +27 -0
- package/src/component/uploader/styles/index.less +158 -0
- package/src/index.js +1 -0
- package/src/index.jsx +64 -0
- package/src/styles/color.less +51 -0
- package/src/styles/font.less +14 -0
- package/src/styles/format-theme.less +27 -0
- package/src/styles/index.less +26 -0
- package/src/styles/spacing.less +3 -0
- package/src/styles/var.less +3 -0
- package/src/tools/create-body-container.js +47 -0
- package/src/tools/limit-body-scroll.js +17 -0
- package/src/tools/limit-document-scroll.js +12 -0
- package/src/tools/merge-class-name.js +14 -0
- package/src/tools/object-key-check.js +3 -0
- package/src/tools/pinyin.js +6 -0
- package/src/tools/proptypes.js +51 -0
- package/src/tools/style.less +14 -0
- package/test/cases/case-button01.assert.js +6 -0
- package/test/cases/case-button01.source.jsx +28 -0
- package/test/cases/case-checkbox01.assert.js +6 -0
- package/test/cases/case-checkbox01.source.jsx +20 -0
- package/test/cases/case-dialog01.assert.js +6 -0
- package/test/cases/case-dialog01.source.jsx +45 -0
- package/test/cases/case-drawer01.assert.js +6 -0
- package/test/cases/case-drawer01.source.jsx +85 -0
- package/test/cases/case-icons01.assert.js +6 -0
- package/test/cases/case-icons01.source.jsx +25 -0
- package/test/cases/case-indexSortList01.assert.js +6 -0
- package/test/cases/case-indexSortList01.source.jsx +74 -0
- package/test/cases/case-input01.assert.js +6 -0
- package/test/cases/case-input01.source.jsx +24 -0
- package/test/cases/case-listView01.assert.js +6 -0
- package/test/cases/case-listView01.source.jsx +64 -0
- package/test/cases/case-multiplePicker01.assert.js +6 -0
- package/test/cases/case-multiplePicker01.source.jsx +60 -0
- package/test/cases/case-multipleSelector01.assert.js +6 -0
- package/test/cases/case-multipleSelector01.source.jsx +49 -0
- package/test/cases/case-noticebar01.assert.js +6 -0
- package/test/cases/case-noticebar01.source.jsx +21 -0
- package/test/cases/case-picker01.assert.js +6 -0
- package/test/cases/case-picker01.source.jsx +61 -0
- package/test/cases/case-refresh01.assert.js +6 -0
- package/test/cases/case-refresh01.source.jsx +33 -0
- package/test/cases/case-sign01.assert.js +6 -0
- package/test/cases/case-sign01.source.jsx +21 -0
- package/test/cases/case-subscript01.assert.js +6 -0
- package/test/cases/case-subscript01.source.jsx +30 -0
- package/test/cases/case-tab01.assert.js +6 -0
- package/test/cases/case-tab01.source.jsx +51 -0
- package/test/cases/case-toast01.assert.js +6 -0
- package/test/cases/case-toast01.source.jsx +32 -0
- package/test/cases/case-uploader01.assert.js +6 -0
- package/test/cases/case-uploader01.source.jsx +45 -0
- package/test.config.js +25 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import pinyin from '../../../tools/pinyin';
|
|
2
|
+
|
|
3
|
+
const getFirstString = str => (str ? str[0] : '#');
|
|
4
|
+
|
|
5
|
+
// 默认按传入汉字首字的首字母
|
|
6
|
+
const pinyinRule = item => (
|
|
7
|
+
pinyin(getFirstString(item.label), { style: pinyin.STYLE_FIRST_LETTER })[0][0].toLocaleUpperCase()
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
const pinyinSort = (a, b) => (a.title > b.title ? 0 : -1);
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
pinyinRule, pinyinSort,
|
|
14
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { pinyinRule, pinyinSort } from './rules';
|
|
2
|
+
|
|
3
|
+
const ruleConfig = {
|
|
4
|
+
pinyin: pinyinRule,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const sortConfig = {
|
|
8
|
+
pinyin: pinyinSort,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// 根据规则处理data
|
|
12
|
+
export default (data = [], rule, sort) => {
|
|
13
|
+
const resultData = [];
|
|
14
|
+
let ruleFunc = null;
|
|
15
|
+
let sortFunc = sort;
|
|
16
|
+
|
|
17
|
+
if (typeof rule === 'function') {
|
|
18
|
+
ruleFunc = rule;
|
|
19
|
+
} else if (typeof rule === 'string') {
|
|
20
|
+
ruleFunc = ruleConfig[rule];
|
|
21
|
+
sortFunc = sortConfig[rule];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!ruleFunc) {
|
|
25
|
+
console.error(`错误的sortRule传参,请确保传入规则无误!${rule}`);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
data.forEach((d) => {
|
|
30
|
+
const index = ruleFunc(d);
|
|
31
|
+
if (resultData.find(r => r.title === index)) {
|
|
32
|
+
resultData.find(r => r.title === index).data.push(d);
|
|
33
|
+
} else {
|
|
34
|
+
resultData.push({ title: index, data: [d] });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (typeof sortFunc === 'function') resultData.sort(sortFunc);
|
|
39
|
+
|
|
40
|
+
return resultData;
|
|
41
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { Component, createRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from './style.less';
|
|
4
|
+
import { getProps } from '../../tools/proptypes';
|
|
5
|
+
import mergeClassName from '../../tools/merge-class-name';
|
|
6
|
+
import sortByRules from './js/sort-rule';
|
|
7
|
+
|
|
8
|
+
import Group from './group';
|
|
9
|
+
import IndexBar from './index-bar';
|
|
10
|
+
|
|
11
|
+
const name = 'sm-index-list';
|
|
12
|
+
|
|
13
|
+
// 通过目标节点距离容器的高度(offsetTop)、目标节点自身高度(offsetHeight)、容齐的滚动距离(scrollTop)
|
|
14
|
+
// 来判断该节点是否处于「头部超出容器可视范围」而「尾部还未超出容器可视范围」
|
|
15
|
+
const findIndex = (current, scrollTop) => (
|
|
16
|
+
current
|
|
17
|
+
&& scrollTop - current.offsetTop > 0
|
|
18
|
+
&& scrollTop - current.offsetTop < current.offsetHeight
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
class List extends Component {
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props);
|
|
24
|
+
this.window = createRef();
|
|
25
|
+
this.state = {
|
|
26
|
+
scrollTop: 0,
|
|
27
|
+
index: null,
|
|
28
|
+
};
|
|
29
|
+
this.windowScroll = this.windowScroll.bind(this);
|
|
30
|
+
this.indexClick = this.indexClick.bind(this);
|
|
31
|
+
this.groupRefs = {}; // 存储所有Group组件内部最外延的节点的ref
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// componentDidMount() {
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
sort() {
|
|
38
|
+
const { data, rule } = this.props;
|
|
39
|
+
let resultData = data;
|
|
40
|
+
const resultIndexList = [];
|
|
41
|
+
|
|
42
|
+
if (rule) resultData = sortByRules(data, rule);
|
|
43
|
+
|
|
44
|
+
resultData.forEach(d => resultIndexList.push(d.title));
|
|
45
|
+
return { data: resultData, indexList: resultIndexList };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 滚动的时候,会判断到底滚到来哪个Group的范围,并把index设置该Group的的title
|
|
49
|
+
windowScroll(e) {
|
|
50
|
+
const { scrollTop } = e.target;
|
|
51
|
+
Object.keys(this.groupRefs).forEach((title) => {
|
|
52
|
+
if (findIndex(this.groupRefs[title], scrollTop)) this.setState({ index: title });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
indexClick(index) {
|
|
57
|
+
const { current } = this.window;
|
|
58
|
+
if (this.groupRefs[index].offsetTop < current.height) { // 如果点击的索引(index)在底部且小于容器的高度,那设定滚动到最底即可
|
|
59
|
+
current.scrollTop = current.scrollHeight - current.clientHeight;
|
|
60
|
+
} else {
|
|
61
|
+
current.scrollTop = this.groupRefs[index].offsetTop;
|
|
62
|
+
this.setState({ index });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
render() {
|
|
67
|
+
const { select, empty, render } = this.props;
|
|
68
|
+
const { scrollTop, index } = this.state;
|
|
69
|
+
const { data, indexList } = this.sort();
|
|
70
|
+
return (
|
|
71
|
+
<div className={mergeClassName([styles[name]])}>
|
|
72
|
+
<div
|
|
73
|
+
ref={this.window}
|
|
74
|
+
className={styles[`${name}-window`]}
|
|
75
|
+
onScroll={this.windowScroll}
|
|
76
|
+
>
|
|
77
|
+
{
|
|
78
|
+
data.map(d => (
|
|
79
|
+
<Group
|
|
80
|
+
{...d}
|
|
81
|
+
render={render}
|
|
82
|
+
scrollTop={scrollTop}
|
|
83
|
+
click={select}
|
|
84
|
+
index={index}
|
|
85
|
+
ref={(el) => {
|
|
86
|
+
this.groupRefs[d.title] = el;
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
))
|
|
90
|
+
}
|
|
91
|
+
{
|
|
92
|
+
(!data || data.length === 0)
|
|
93
|
+
&& (typeof empty === 'string' ? <div className={styles[`${name}-window-empty`]}>{empty}</div> : empty)
|
|
94
|
+
}
|
|
95
|
+
</div>
|
|
96
|
+
<IndexBar index={index} indexList={indexList} click={this.indexClick} />
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
List.propTypes = {
|
|
103
|
+
...getProps(PropTypes, 'className', 'select', 'empty'),
|
|
104
|
+
data: PropTypes.arrayOf(PropTypes.object),
|
|
105
|
+
rule: PropTypes.oneOf(['pinyin', PropTypes.func]), // 分类规则
|
|
106
|
+
sort: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), // 排序规则
|
|
107
|
+
render: PropTypes.func, // item自定义渲染
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default List;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
@import "../../styles/color";
|
|
2
|
+
@import "../../styles/format-theme";
|
|
3
|
+
|
|
4
|
+
.sm-index-list{
|
|
5
|
+
height: 100%;
|
|
6
|
+
position: relative;
|
|
7
|
+
|
|
8
|
+
&-window{
|
|
9
|
+
height: 100%;
|
|
10
|
+
overflow: auto;
|
|
11
|
+
-webkit-overflow-scrolling: touch;
|
|
12
|
+
|
|
13
|
+
&-empty{
|
|
14
|
+
height: 100%;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
|
|
19
|
+
color: @gray-darker;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&-group{
|
|
24
|
+
&-fix{
|
|
25
|
+
width: 100%;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 0;
|
|
28
|
+
|
|
29
|
+
color: @green;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&-title{
|
|
33
|
+
line-height: @index-list-title-line-height;
|
|
34
|
+
padding: 0 @index-list-title-padding;
|
|
35
|
+
margin: 0;
|
|
36
|
+
|
|
37
|
+
background: @background-color;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&-content{
|
|
41
|
+
padding: 0;
|
|
42
|
+
margin: 0;
|
|
43
|
+
|
|
44
|
+
li:active{
|
|
45
|
+
background-color: @active-color;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&-cell{
|
|
49
|
+
padding: 0 @index-list-title-padding;
|
|
50
|
+
|
|
51
|
+
list-style: none;
|
|
52
|
+
|
|
53
|
+
&-text{
|
|
54
|
+
display: inline-block;
|
|
55
|
+
width: 100%;
|
|
56
|
+
line-height: 16px;
|
|
57
|
+
padding: 12px 0;
|
|
58
|
+
|
|
59
|
+
border-bottom: 1px solid #ebedf0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&-render{
|
|
63
|
+
display: inline-block;
|
|
64
|
+
width: 100%;
|
|
65
|
+
|
|
66
|
+
border-bottom: 1px solid #ebedf0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
li:last-child{
|
|
71
|
+
text{
|
|
72
|
+
border-bottom: none;
|
|
73
|
+
}
|
|
74
|
+
> span{
|
|
75
|
+
border-bottom: none;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&-bar{
|
|
82
|
+
min-height: 100px;
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
justify-content: space-evenly;
|
|
86
|
+
|
|
87
|
+
position: absolute;
|
|
88
|
+
right: 0;
|
|
89
|
+
top: 50%;
|
|
90
|
+
transform: translateY(-50%);
|
|
91
|
+
|
|
92
|
+
padding: 0;
|
|
93
|
+
margin: 0;
|
|
94
|
+
|
|
95
|
+
li{
|
|
96
|
+
line-height: 14px;
|
|
97
|
+
|
|
98
|
+
list-style: none;
|
|
99
|
+
padding: 0 4px 0 16px;
|
|
100
|
+
|
|
101
|
+
font-size: 12px;
|
|
102
|
+
font-weight: 500;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&-active{
|
|
106
|
+
color: @green;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import React, {Component} from 'react';
|
|
2
|
+
import styles from './style.less';
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import mergeClassName from '../../tools/merge-class-name';
|
|
5
|
+
|
|
6
|
+
class Input extends Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
const value = typeof props.value === 'undefined' ? props.defaultValue : props.value;
|
|
10
|
+
this.state = {
|
|
11
|
+
iValue: value,
|
|
12
|
+
focused: false,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
componentDidMount() {
|
|
17
|
+
this.weChatInputBug();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
componentWillReceiveProps(nextProps){
|
|
21
|
+
if(this.props.value !== nextProps.value) {
|
|
22
|
+
this.adjustSize();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
isWeiXinAndIos() {
|
|
27
|
+
const ua = `${window.navigator.userAgent.toLowerCase()}`;
|
|
28
|
+
const isWeixin = /MicroMessenger/i.test(ua);
|
|
29
|
+
const isIos = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua);
|
|
30
|
+
return isWeixin && isIos;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
weChatInputBug() { // 解决微信键盘收起页面不回弹的问题
|
|
34
|
+
let myFunction;
|
|
35
|
+
const isWXAndIos = this.isWeiXinAndIos();
|
|
36
|
+
if (isWXAndIos) {
|
|
37
|
+
document.body.addEventListener('focusin', () => {
|
|
38
|
+
clearTimeout(myFunction);
|
|
39
|
+
});
|
|
40
|
+
document.body.addEventListener('focusout', () => {
|
|
41
|
+
clearTimeout(myFunction);
|
|
42
|
+
myFunction = setTimeout(() => {
|
|
43
|
+
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
|
|
44
|
+
}, 200);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bindRef = (el) => {
|
|
50
|
+
this.ref = el
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
invalidNumber = (value) => {
|
|
54
|
+
const { digits, type, positive } = this.props;
|
|
55
|
+
if (type !== 'number') return false;
|
|
56
|
+
|
|
57
|
+
let reg = positive ? '^\\d*' : '^-?\\d*';
|
|
58
|
+
if (digits === undefined) {
|
|
59
|
+
reg += '\\.?\\d*'
|
|
60
|
+
} else if (digits > 0) {
|
|
61
|
+
reg += `\\.?\\d{0,${digits}}`
|
|
62
|
+
}
|
|
63
|
+
reg += '$';
|
|
64
|
+
return !new RegExp(reg).test(value);
|
|
65
|
+
}
|
|
66
|
+
invalidEmoji = (value) => {
|
|
67
|
+
const reg = /(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/g
|
|
68
|
+
return reg.test(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
adjustSize = () => {
|
|
72
|
+
const input = this.ref;
|
|
73
|
+
const { type, autoSize } = this.props;
|
|
74
|
+
if (!(type === 'textarea' && autoSize) || !input) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log('input', input)
|
|
78
|
+
input.style.height = 'auto';
|
|
79
|
+
|
|
80
|
+
let height = input.scrollHeight;
|
|
81
|
+
if (typeof autoSize === 'object') {
|
|
82
|
+
const { maxHeight, minHeight } = autoSize;
|
|
83
|
+
if (maxHeight) {
|
|
84
|
+
height = Math.min(height, maxHeight);
|
|
85
|
+
}
|
|
86
|
+
if (minHeight) {
|
|
87
|
+
height = Math.max(height, minHeight);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (height) {
|
|
92
|
+
input.style.height = height + 'px';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getValue() {
|
|
97
|
+
const { iValue } = this.state;
|
|
98
|
+
const { value } = this.props;
|
|
99
|
+
return typeof value === 'undefined' ? iValue : value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
handleClear = (e) => {
|
|
103
|
+
e.preventDefault(); // not blur
|
|
104
|
+
e.target.value = '';
|
|
105
|
+
this.handleChange(e, true);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
handleFocus = (e) => {
|
|
109
|
+
const { onFocus } = this.props;
|
|
110
|
+
this.setState({
|
|
111
|
+
focused: true
|
|
112
|
+
});
|
|
113
|
+
if (onFocus instanceof Function) {
|
|
114
|
+
onFocus(e);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
handleBlur = (e) => {
|
|
119
|
+
const { onBlur } = this.props;
|
|
120
|
+
|
|
121
|
+
this.setState({
|
|
122
|
+
focused: false
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (onBlur instanceof Function) {
|
|
126
|
+
onBlur(e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
handleChange = (e, clearClick) => {
|
|
131
|
+
if (clearClick) {
|
|
132
|
+
this.ref.focus()
|
|
133
|
+
}
|
|
134
|
+
const { value, onChange } = this.props;
|
|
135
|
+
if (e.target && this.invalidNumber(e.target.value)) return;
|
|
136
|
+
if (e.target && this.invalidEmoji(e.target.value)) return;
|
|
137
|
+
if (typeof value === 'undefined') {
|
|
138
|
+
this.setState({
|
|
139
|
+
iValue: e.target.value
|
|
140
|
+
}, this.adjustSize);
|
|
141
|
+
}
|
|
142
|
+
if (onChange instanceof Function) {
|
|
143
|
+
onChange(e);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
renderWordLimit() {
|
|
148
|
+
const { showWordLimit, maxLength, type } = this.props;
|
|
149
|
+
if (showWordLimit && maxLength && type === 'textarea') {
|
|
150
|
+
return (
|
|
151
|
+
<div class={styles['word-limit']}>
|
|
152
|
+
{this.getValue().length}/{maxLength}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
render() {
|
|
158
|
+
const {
|
|
159
|
+
focused,
|
|
160
|
+
} = this.state;
|
|
161
|
+
|
|
162
|
+
const {
|
|
163
|
+
style,
|
|
164
|
+
className,
|
|
165
|
+
type,
|
|
166
|
+
value,
|
|
167
|
+
defaultValue,
|
|
168
|
+
align,
|
|
169
|
+
readonly,
|
|
170
|
+
disabled,
|
|
171
|
+
border,
|
|
172
|
+
clearable,
|
|
173
|
+
placeholder,
|
|
174
|
+
maxLength,
|
|
175
|
+
showWordLimit,
|
|
176
|
+
onChange,
|
|
177
|
+
autoSize,
|
|
178
|
+
positive,
|
|
179
|
+
emoji,
|
|
180
|
+
placeholderStyle,
|
|
181
|
+
...otherProps
|
|
182
|
+
} = this.props;
|
|
183
|
+
|
|
184
|
+
const isArea = type === 'textarea';
|
|
185
|
+
const val = this.getValue();
|
|
186
|
+
|
|
187
|
+
const inputProps = {
|
|
188
|
+
ref: this.bindRef,
|
|
189
|
+
type: type === 'password' ? type : 'text',
|
|
190
|
+
className: mergeClassName([
|
|
191
|
+
styles.input,
|
|
192
|
+
styles['input-not-border'],
|
|
193
|
+
styles[`input-placeholder-${placeholderStyle}`],
|
|
194
|
+
]),
|
|
195
|
+
style: {
|
|
196
|
+
textAlign: align,
|
|
197
|
+
},
|
|
198
|
+
readOnly: readonly,
|
|
199
|
+
disabled: disabled,
|
|
200
|
+
placeholder: placeholder,
|
|
201
|
+
maxLength: maxLength,
|
|
202
|
+
...otherProps,
|
|
203
|
+
onFocus: this.handleFocus,
|
|
204
|
+
onBlur: this.handleBlur,
|
|
205
|
+
onChange: this.handleChange,
|
|
206
|
+
value: val,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const component = isArea
|
|
210
|
+
? <textarea {...inputProps} />
|
|
211
|
+
: <input {...inputProps} />;
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div
|
|
215
|
+
style={style}
|
|
216
|
+
className={
|
|
217
|
+
mergeClassName([
|
|
218
|
+
styles['input-wrap'],
|
|
219
|
+
!border && styles['input-not-border'],
|
|
220
|
+
isArea ? styles['input-wrap-column'] : styles['input-wrap-row'],
|
|
221
|
+
isArea && styles['input-textarea'],
|
|
222
|
+
className,
|
|
223
|
+
])
|
|
224
|
+
}
|
|
225
|
+
>
|
|
226
|
+
{component}
|
|
227
|
+
{
|
|
228
|
+
clearable && !isArea && (
|
|
229
|
+
<div
|
|
230
|
+
style={{
|
|
231
|
+
visibility: focused && val ? 'visible' : 'hidden'
|
|
232
|
+
}}
|
|
233
|
+
className={styles['clearable']}
|
|
234
|
+
onMouseDown={this.handleClear}
|
|
235
|
+
/>
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
{this.renderWordLimit()}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
Input.propTypes = {
|
|
245
|
+
style: PropTypes.object,
|
|
246
|
+
className: PropTypes.string,
|
|
247
|
+
type: PropTypes.oneOf(['text', 'number', 'password', 'textarea', 'tel']),
|
|
248
|
+
defaultValue: PropTypes.string,
|
|
249
|
+
value: PropTypes.string,
|
|
250
|
+
align: PropTypes.oneOf(['left', 'center', 'right']),
|
|
251
|
+
readonly: PropTypes.bool,
|
|
252
|
+
disabled: PropTypes.bool,
|
|
253
|
+
border: PropTypes.bool,
|
|
254
|
+
placeholder: PropTypes.string,
|
|
255
|
+
placeholderStyle: PropTypes.oneOfType(['light', 'default']),
|
|
256
|
+
clearable: PropTypes.bool,
|
|
257
|
+
maxLength: PropTypes.number,
|
|
258
|
+
autoSize: PropTypes.oneOfType([
|
|
259
|
+
PropTypes.bool,
|
|
260
|
+
PropTypes.shape({ width: PropTypes.number, height: PropTypes.number })
|
|
261
|
+
]),
|
|
262
|
+
showWordLimit: PropTypes.bool,
|
|
263
|
+
digits: PropTypes.number,
|
|
264
|
+
positive: PropTypes.bool,
|
|
265
|
+
rows: PropTypes.number,
|
|
266
|
+
onChange: PropTypes.func,
|
|
267
|
+
emoji: PropTypes.bool,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
Input.defaultProps = {
|
|
271
|
+
type: 'text',
|
|
272
|
+
defaultValue: '',
|
|
273
|
+
align: 'left',
|
|
274
|
+
readonly: false,
|
|
275
|
+
disabled: false,
|
|
276
|
+
border: false,
|
|
277
|
+
rows: 1,
|
|
278
|
+
showWordLimit: false,
|
|
279
|
+
autoSize: true,
|
|
280
|
+
positive: false,
|
|
281
|
+
emoji: false,
|
|
282
|
+
placeholderStyle: 'default',
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export default Input;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
@import "../../styles/var";
|
|
2
|
+
|
|
3
|
+
.input-wrap {
|
|
4
|
+
display: flex;
|
|
5
|
+
//flex: 1;
|
|
6
|
+
//width: 100%;
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
border: 1px solid @border-color;
|
|
9
|
+
border-radius: 2%;
|
|
10
|
+
padding: 2px 4px;
|
|
11
|
+
|
|
12
|
+
&-row {
|
|
13
|
+
flex-direction: row;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&-column {
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
}
|
|
19
|
+
> input {
|
|
20
|
+
flex: 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.input {
|
|
25
|
+
display: block;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
min-width: 0;
|
|
28
|
+
margin: 0;
|
|
29
|
+
padding: 0;
|
|
30
|
+
color: @text-color;
|
|
31
|
+
text-align: left;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
resize: none;
|
|
34
|
+
font-size: @size-normal;
|
|
35
|
+
|
|
36
|
+
&-placeholder{
|
|
37
|
+
&-default::placeholder{
|
|
38
|
+
color: @text-color-min;
|
|
39
|
+
}
|
|
40
|
+
&-light::placeholder{
|
|
41
|
+
line-height: 14px;
|
|
42
|
+
font-size: 12px;
|
|
43
|
+
color: @text-color-light;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.input + .clearable {
|
|
49
|
+
width: 16px;
|
|
50
|
+
height: 16px;
|
|
51
|
+
background-color: #ccc;
|
|
52
|
+
background-repeat: no-repeat;
|
|
53
|
+
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg fill='%23fff' viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3C/svg%3E");
|
|
54
|
+
background-size: 16px auto;
|
|
55
|
+
background-position: 1.5px 1.5px;
|
|
56
|
+
border-radius: 50%;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
margin-left: 4px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.input-not-border {
|
|
62
|
+
border: 0;
|
|
63
|
+
outline: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.word-limit {
|
|
67
|
+
margin-top: 4px;
|
|
68
|
+
color: #7d7e80;
|
|
69
|
+
font-size: 12px;
|
|
70
|
+
line-height: 16px;
|
|
71
|
+
text-align: right;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.input-textarea{
|
|
75
|
+
padding: 10px;
|
|
76
|
+
border-radius: @radius;
|
|
77
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from '../style.less';
|
|
4
|
+
import mergeClassName from '../../../tools/merge-class-name';
|
|
5
|
+
import Icons from '../../icons';
|
|
6
|
+
|
|
7
|
+
const Empty = ({ text, size }) => (
|
|
8
|
+
<div className={styles.empty}>
|
|
9
|
+
<Icons name="nodata" className={mergeClassName([styles['empty-icon'], styles[`empty-size-${size}`]])} />
|
|
10
|
+
<text>{text}</text>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
// size
|
|
14
|
+
Empty.propTypes = {
|
|
15
|
+
text: PropTypes.node,
|
|
16
|
+
size: PropTypes.oneOf(['small', 'default', 'large']),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Empty.defaultProps = {
|
|
20
|
+
text: '暂无数据',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default Empty;
|