@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,195 @@
|
|
|
1
|
+
import React, { Children, PureComponent, createRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from './style.less';
|
|
4
|
+
import NavChild from './nav-child';
|
|
5
|
+
|
|
6
|
+
import mergeClassName from '../../tools/merge-class-name';
|
|
7
|
+
import checkKey from '../../tools/object-key-check';
|
|
8
|
+
import Panel from './panel';
|
|
9
|
+
|
|
10
|
+
const extraWidth = 2; // 文字宽度两边额外的宽度
|
|
11
|
+
|
|
12
|
+
class Tab extends PureComponent {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.state = { $active: null };
|
|
16
|
+
this.navChildRef = {};
|
|
17
|
+
this.line = createRef();
|
|
18
|
+
this.nav = createRef();
|
|
19
|
+
this.setActive = this.setActive.bind(this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
componentDidMount() {
|
|
23
|
+
const { active, defaultActive, children } = this.props;
|
|
24
|
+
const realActive = active
|
|
25
|
+
|| defaultActive
|
|
26
|
+
|| Children.toArray(children).find(ch => checkKey(ch.props, 'name')).props.name;
|
|
27
|
+
|
|
28
|
+
this.setActive(realActive, true);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
componentDidUpdate() {
|
|
32
|
+
const { $active } = this.state;
|
|
33
|
+
const { active = $active, autoWidth } = this.props;
|
|
34
|
+
|
|
35
|
+
const { width, translateX } = this.setLineStyle(active);
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
this.line.current.style.width === width
|
|
39
|
+
&& this.line.current.style.transform === translateX
|
|
40
|
+
) return;
|
|
41
|
+
|
|
42
|
+
// 如果配置了自适应宽度,则需要调整tabs容器来让被激活的tab居中
|
|
43
|
+
if (autoWidth) this.setTabsTransform(active);
|
|
44
|
+
|
|
45
|
+
this.line.current.style.width = width;
|
|
46
|
+
this.line.current.style.transform = translateX;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 激活对应的tab页头, notNotice代表是否需要触发onchange
|
|
50
|
+
setActive(name, notNotice) {
|
|
51
|
+
const { onChange } = this.props;
|
|
52
|
+
|
|
53
|
+
this.setState({ $active: name });
|
|
54
|
+
|
|
55
|
+
if (!notNotice && typeof onChange === 'function') onChange(name);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 设置下划线的位置
|
|
59
|
+
setLineStyle(active) {
|
|
60
|
+
if (!this.navChildRef[active]) return {};
|
|
61
|
+
|
|
62
|
+
const textEl = this.navChildRef[active].text.current;
|
|
63
|
+
const childEl = this.navChildRef[active].navChild.current;
|
|
64
|
+
|
|
65
|
+
const { clientWidth, offsetLeft } = textEl; // 下划线的宽度
|
|
66
|
+
const offsetLeftN = childEl.offsetLeft; // 下划线的位置
|
|
67
|
+
|
|
68
|
+
return Object.assign({}, { // lineStyle
|
|
69
|
+
width: `${clientWidth + (2 * extraWidth)}px`,
|
|
70
|
+
translateX: `translateX(${offsetLeftN + offsetLeft - extraWidth}px)`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 当tab标题总长度超过容器长度时,设置容器的transform来保证被选中的tab居中
|
|
75
|
+
setTabsTransform(active) {
|
|
76
|
+
if (!this.navChildRef[active]) return;
|
|
77
|
+
|
|
78
|
+
const childEl = this.navChildRef[active].navChild.current; // 当前选中的tab
|
|
79
|
+
|
|
80
|
+
let totalWidth = 0; // 所有的tab的总长度
|
|
81
|
+
Object.keys(this.navChildRef).forEach((key) => {
|
|
82
|
+
totalWidth += this.navChildRef[key].navChild.current.clientWidth;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const navWidth = this.nav.current.clientWidth;
|
|
86
|
+
const maxOffset = totalWidth - navWidth; // 最大偏移量
|
|
87
|
+
let offset = childEl.offsetLeft - (navWidth / 2) + (childEl.clientWidth / 2); // 需要偏移量
|
|
88
|
+
|
|
89
|
+
if (offset < 0) offset = 0;
|
|
90
|
+
if (offset > maxOffset) offset = maxOffset;
|
|
91
|
+
|
|
92
|
+
// this.nav.current.style.transform = `translateX(${-offset}px)`;
|
|
93
|
+
this.nav.current.scrollLeft = offset;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
createHeader() {
|
|
97
|
+
const { $active } = this.state;
|
|
98
|
+
const { active = $active, children, color, autoWidth } = this.props;
|
|
99
|
+
|
|
100
|
+
const tabs = [];
|
|
101
|
+
Children.toArray(children).forEach((child) => {
|
|
102
|
+
if (!child || !child.type) return;
|
|
103
|
+
|
|
104
|
+
if (checkKey(child.props, 'name')) {
|
|
105
|
+
const { name, width, tab } = child.props;
|
|
106
|
+
const nav = (
|
|
107
|
+
<NavChild
|
|
108
|
+
ref={(el) => {
|
|
109
|
+
this.navChildRef[name] = el;
|
|
110
|
+
}}
|
|
111
|
+
tab={tab}
|
|
112
|
+
name={name}
|
|
113
|
+
active={active}
|
|
114
|
+
onClick={this.setActive}
|
|
115
|
+
color={color}
|
|
116
|
+
width={width || `${100 / Children.toArray(children).length}%`}
|
|
117
|
+
autoWidth={autoWidth}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
tabs.push(nav);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (tabs.length === 0) return null;
|
|
125
|
+
|
|
126
|
+
return tabs;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
createContent() {
|
|
130
|
+
const { $active } = this.state;
|
|
131
|
+
const { active = $active, children } = this.props;
|
|
132
|
+
|
|
133
|
+
const contents = [];
|
|
134
|
+
Children.toArray(children).forEach((child) => {
|
|
135
|
+
if (!child || !child.type) return;
|
|
136
|
+
|
|
137
|
+
if (checkKey(child.props, 'name')) {
|
|
138
|
+
const { name, className } = child.props;
|
|
139
|
+
const content = (
|
|
140
|
+
<div className={mergeClassName([active !== name && styles['sm-none'], className])}>
|
|
141
|
+
{child.props.children}
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
contents.push(content);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (contents.length === 0) return null;
|
|
149
|
+
|
|
150
|
+
return contents;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
render() {
|
|
154
|
+
const { tabClassName, contentClassName, contentStyle, color, border, autoWidth } = this.props;
|
|
155
|
+
|
|
156
|
+
const tabs = this.createHeader();
|
|
157
|
+
const contents = this.createContent();
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className={tabClassName}>
|
|
161
|
+
<div className={mergeClassName([
|
|
162
|
+
styles['sm-tabs'],
|
|
163
|
+
border && styles['sm-tabs-border'],
|
|
164
|
+
])}
|
|
165
|
+
>
|
|
166
|
+
<div ref={this.nav} className={mergeClassName([styles['sm-tabs-nav'], autoWidth && styles['sm-tabs-nav-scroll']])}>
|
|
167
|
+
{tabs}
|
|
168
|
+
<div ref={this.line} className={mergeClassName([styles['sm-tabs-line'], styles[`sm-tabs-line-${color}`]])} />
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
<div className={contentClassName} style={contentStyle}>{contents}</div>
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
Tab.propTypes = {
|
|
178
|
+
defaultActive: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
179
|
+
active: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
180
|
+
children: PropTypes.instanceOf(Panel),
|
|
181
|
+
onChange: PropTypes.func,
|
|
182
|
+
tabClassName: PropTypes.string,
|
|
183
|
+
contentClassName: PropTypes.string,
|
|
184
|
+
contentStyle: PropTypes.objectOf(PropTypes.any),
|
|
185
|
+
color: PropTypes.oneOf(['blue', 'red']),
|
|
186
|
+
autoWidth: PropTypes.bool,
|
|
187
|
+
border: PropTypes.bool,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
Tab.defaultProps = {
|
|
191
|
+
autoWidth: false,
|
|
192
|
+
border: true,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default Tab;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
@import "../../styles/color";
|
|
2
|
+
|
|
3
|
+
.tag-default {
|
|
4
|
+
display: inline-block;
|
|
5
|
+
padding: 2px 5px;
|
|
6
|
+
border-radius: 2px;
|
|
7
|
+
text-align: center;
|
|
8
|
+
font-size: 12px;
|
|
9
|
+
|
|
10
|
+
&-green {
|
|
11
|
+
background: #DCFAEA;
|
|
12
|
+
color: @green;
|
|
13
|
+
}
|
|
14
|
+
&-red {
|
|
15
|
+
background: #FFECEB;
|
|
16
|
+
color: @red;
|
|
17
|
+
}
|
|
18
|
+
&-blue {
|
|
19
|
+
background: #EBF5FF;
|
|
20
|
+
color: @blue;
|
|
21
|
+
}
|
|
22
|
+
&-purple {
|
|
23
|
+
background: #EBE6FF;
|
|
24
|
+
color: #8C68FE;
|
|
25
|
+
}
|
|
26
|
+
&-fuchsia {
|
|
27
|
+
background: #FEEBFF;
|
|
28
|
+
color: #B530FF;
|
|
29
|
+
}
|
|
30
|
+
&-yellow {
|
|
31
|
+
background: #FFFBEB;
|
|
32
|
+
color: #E6A117;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.tag-plain {
|
|
37
|
+
display: inline-block;
|
|
38
|
+
padding: 4px 10px;
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
text-align: center;
|
|
41
|
+
border: 1px solid;
|
|
42
|
+
font-size: 12px;
|
|
43
|
+
|
|
44
|
+
&-pink{
|
|
45
|
+
border-color: #FDD3D0;
|
|
46
|
+
color: #FB9088;
|
|
47
|
+
}
|
|
48
|
+
&-yellow{
|
|
49
|
+
border-color: #F6DDA1;
|
|
50
|
+
color: #E9AB17;
|
|
51
|
+
}
|
|
52
|
+
&-green{
|
|
53
|
+
border-color: #DCFAEA;
|
|
54
|
+
color: @green;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
6
|
+
const Tag = (args) => {
|
|
7
|
+
const {
|
|
8
|
+
style,
|
|
9
|
+
className,
|
|
10
|
+
plain,
|
|
11
|
+
text,
|
|
12
|
+
children,
|
|
13
|
+
color,
|
|
14
|
+
textColor,
|
|
15
|
+
...other
|
|
16
|
+
} = args;
|
|
17
|
+
const plainText = plain ? 'plain' : 'default';
|
|
18
|
+
return (
|
|
19
|
+
<span
|
|
20
|
+
className={
|
|
21
|
+
mergeClassName([
|
|
22
|
+
styles[`tag-${plainText}`],
|
|
23
|
+
styles[`tag-${plainText}-${color}`],
|
|
24
|
+
className,
|
|
25
|
+
])
|
|
26
|
+
}
|
|
27
|
+
style={{
|
|
28
|
+
...(color ? plain ? { borderColor: color } : { background: color } : {}),
|
|
29
|
+
...(textColor ? { color: textColor } : {}),
|
|
30
|
+
...style,
|
|
31
|
+
}}
|
|
32
|
+
{...other}
|
|
33
|
+
>
|
|
34
|
+
{ text || children }
|
|
35
|
+
</span>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Tag.propTypes = {
|
|
40
|
+
style: PropTypes.object,
|
|
41
|
+
className: PropTypes.string,
|
|
42
|
+
text: PropTypes.node,
|
|
43
|
+
children: PropTypes.node,
|
|
44
|
+
plain: PropTypes.bool,
|
|
45
|
+
color: PropTypes.string,
|
|
46
|
+
textColor: PropTypes.string,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Tag.defaultProps = {
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default Tag;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from './style.less';
|
|
4
|
+
import Icon from '../icons';
|
|
5
|
+
import mergeClassName from '../../tools/merge-class-name';
|
|
6
|
+
|
|
7
|
+
const Content = ({ children, cover, icon }) => (
|
|
8
|
+
<div className={mergeClassName([styles.cover, cover && styles['cover-background']])}>
|
|
9
|
+
<div className={styles['sm-toast-content']}>
|
|
10
|
+
{
|
|
11
|
+
icon
|
|
12
|
+
? (
|
|
13
|
+
<Icon
|
|
14
|
+
className={mergeClassName([styles['sm-toast-content-icon'], styles[`sm-toast-content-icon-${icon}`]])}
|
|
15
|
+
name={icon}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
: null
|
|
19
|
+
}
|
|
20
|
+
<span className={styles['sm-toast-content-text']}>{children}</span>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
Content.propTypes = {
|
|
26
|
+
children: PropTypes.node,
|
|
27
|
+
cover: PropTypes.bool,
|
|
28
|
+
icon: PropTypes.string,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default Content;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@import "../../styles/index";
|
|
2
|
+
@import "../../styles/color";
|
|
3
|
+
|
|
4
|
+
.cover{
|
|
5
|
+
|
|
6
|
+
&-background{
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
background: rgba(0, 0, 0, 0.25);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.sm-toast{
|
|
14
|
+
&-content{
|
|
15
|
+
.sm-position-center;
|
|
16
|
+
min-width: 100px;
|
|
17
|
+
max-width: 60%;
|
|
18
|
+
min-height: 100px;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
align-items: center;
|
|
22
|
+
|
|
23
|
+
padding: 15px 20px;
|
|
24
|
+
|
|
25
|
+
border-radius: 8px;
|
|
26
|
+
background: rgba(0, 0, 0, 0.65);
|
|
27
|
+
color: @white;
|
|
28
|
+
text-align: center;
|
|
29
|
+
|
|
30
|
+
&-icon{
|
|
31
|
+
font-size: 2.5em;
|
|
32
|
+
margin-bottom: 12px;
|
|
33
|
+
|
|
34
|
+
//&-success{
|
|
35
|
+
// color: @green;
|
|
36
|
+
//}
|
|
37
|
+
//&-fail{
|
|
38
|
+
// color: @red;
|
|
39
|
+
//}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&-text{
|
|
43
|
+
//.sm-ellipsis;
|
|
44
|
+
max-width: 100%;
|
|
45
|
+
display: inline-block;
|
|
46
|
+
|
|
47
|
+
margin: auto;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDom from 'react-dom';
|
|
3
|
+
import Container from '../../tools/create-body-container';
|
|
4
|
+
|
|
5
|
+
import Content from './content';
|
|
6
|
+
|
|
7
|
+
let timeout = null;
|
|
8
|
+
|
|
9
|
+
// 负责挂在节点和移除节点
|
|
10
|
+
class Dom {
|
|
11
|
+
constructor(delay) {
|
|
12
|
+
this.container = new Container('toast');
|
|
13
|
+
this.containerEl = this.container.getEl();
|
|
14
|
+
this.delay = delay || 2;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
render(el, delay) {
|
|
18
|
+
if (timeout) {
|
|
19
|
+
ReactDom.unmountComponentAtNode(this.containerEl);
|
|
20
|
+
clearTimeout(timeout);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.containerEl.style.visibility = 'visible';
|
|
24
|
+
this.containerEl.addEventListener('click', () => this.destroy());
|
|
25
|
+
|
|
26
|
+
ReactDom.render(el, this.containerEl);
|
|
27
|
+
|
|
28
|
+
timeout = setTimeout(() => this.destroy(this.containerEl), (delay || this.delay) * 1000);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
destroy() {
|
|
32
|
+
this.containerEl.style.visibility = 'hidden';
|
|
33
|
+
ReactDom.unmountComponentAtNode(this.containerEl);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class Toast {
|
|
38
|
+
constructor(delay) {
|
|
39
|
+
this.dom = new Dom(delay);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
info(text, delay) {
|
|
43
|
+
this.dom.render(<Content>{text}</Content>, delay);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
success(text, delay) {
|
|
47
|
+
const el = (
|
|
48
|
+
<Content icon="success">{text}</Content>
|
|
49
|
+
);
|
|
50
|
+
this.dom.render(el, delay);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fail(text, delay) {
|
|
54
|
+
this.dom.render(<Content icon="fail">{text}</Content>, delay);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
loading(text, delay) {
|
|
58
|
+
this.dom.render(<Content cover>{text}</Content>, delay);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default new Toast();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@import "../../styles/color";
|
|
2
|
+
|
|
3
|
+
.touchable {
|
|
4
|
+
display: inline-block;
|
|
5
|
+
position: relative;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
padding: 0;
|
|
8
|
+
margin: 0;
|
|
9
|
+
border: none;
|
|
10
|
+
outline: none;
|
|
11
|
+
background-color: transparent;
|
|
12
|
+
-webkit-appearance: none;
|
|
13
|
+
-webkit-text-size-adjust: 100%;
|
|
14
|
+
|
|
15
|
+
&::before {
|
|
16
|
+
position: absolute;
|
|
17
|
+
top: 50%;
|
|
18
|
+
left: 50%;
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 100%;
|
|
21
|
+
background-color: #000000;
|
|
22
|
+
border-color: #000000;
|
|
23
|
+
border-radius: inherit;
|
|
24
|
+
-webkit-transform: translate(-50%, -50%);
|
|
25
|
+
transform: translate(-50%, -50%);
|
|
26
|
+
opacity: 0;
|
|
27
|
+
content: ' ';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:active::before {
|
|
31
|
+
opacity: .1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from './style.less';
|
|
4
|
+
import mergeClassName from '../../tools/merge-class-name';
|
|
5
|
+
|
|
6
|
+
class Touchable extends PureComponent {
|
|
7
|
+
render() {
|
|
8
|
+
const {
|
|
9
|
+
className,
|
|
10
|
+
disabled,
|
|
11
|
+
children,
|
|
12
|
+
...otherProps
|
|
13
|
+
} = this.props;
|
|
14
|
+
|
|
15
|
+
const finallyClassName = mergeClassName([
|
|
16
|
+
styles.touchable,
|
|
17
|
+
className,
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
className={finallyClassName}
|
|
24
|
+
disabled={disabled}
|
|
25
|
+
{...otherProps}
|
|
26
|
+
>
|
|
27
|
+
{children}
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Touchable.propTypes = {
|
|
34
|
+
children: PropTypes.node,
|
|
35
|
+
disabled: PropTypes.bool,
|
|
36
|
+
onClick: PropTypes.func,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Touchable.defaultProps = {
|
|
40
|
+
disabled: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default Touchable;
|