Skip to content

Commit 61cebf5

Browse files
committed
merge from develop (#77)
* #58, patched searchbar, add iconSize for toast #62, change weui dependency to 0.4.1 (#63) * update `weui` version * update react version and move to peerDependencies (#66) 1. react 升级到 v15,并且引入了新的版本规范。 @see https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html 2. 不同版本的 react 会冲突,把依赖写到 peerDependencies 更合适一点。参考其他 react 相关的库,如 react-redux. * fix extra comma in package.json * 修复 package.son 依赖 1. 补充依赖 jsdom 2. npm 对依赖 history 顺序做了调整 * #68 Cell* 增加支持传入自定义 className * #51 ActionSheet 的 menus 和 actions 增加支持传入自定义 className
1 parent a2e2a87 commit 61cebf5

File tree

19 files changed

+174
-86
lines changed

19 files changed

+174
-86
lines changed

docs/actionsheet.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ class App extends React.Component {
2626
show: false,
2727
menus: [{
2828
label: '拍照',
29+
className: 'customClassName',
2930
onClick: ()=>{
3031

3132
}
3233
}, {
3334
label: '从手机相册中选择',
35+
className: 'customClassName',
3436
onClick: ()=>{
3537

3638
}
3739
}],
3840
actions: [{
3941
label: '取消',
42+
className: 'customClassName',
4043
onClick: this.hide.bind(this)
4144
}]
4245
};

docs/toast.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
属性 | 类型 | 默认值 | 可选值 | 备注
77
-----|------|--------|-------|------|
88
icon|string|toast|所有icon|
9+
iconSize|string|'small'|small, large| icon size
910
show|bool|false|| 是否显示
1011

1112
示例:

example/pages/toast/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export default class ToastDemo extends React.Component {
1313
state = {
1414
showToast: false,
1515
showLoading: false,
16+
showCustom: false,
1617
toastTimer: null,
17-
loadingTimer: null
18+
loadingTimer: null,
19+
customTimer: null
1820
};
1921

2022
componentWillUnmount() {
@@ -26,7 +28,13 @@ export default class ToastDemo extends React.Component {
2628
return (
2729
<Page className="toast" title="Toast" spacing>
2830
<Button onClick={this.showToast.bind(this)}>Toast</Button>
31+
<Button onClick={this.showCustom.bind(this)}>Custom Toast</Button>
2932
<Button onClick={this.showLoading.bind(this)}>Loading</Button>
33+
<Toast
34+
show={this.state.showCustom}
35+
icon="waiting_circle"
36+
iconSize="large"
37+
>waiting...</Toast>
3038
<Toast show={this.state.showToast}>完成</Toast>
3139
<Toast icon="loading" show={this.state.showLoading}>正在加载中...</Toast>
3240
</Page>
@@ -48,4 +56,12 @@ export default class ToastDemo extends React.Component {
4856
this.setState({showLoading: false});
4957
}, 2000);
5058
}
59+
60+
showCustom() {
61+
this.setState({showCustom: true});
62+
63+
this.state.customTimer = setTimeout(()=> {
64+
this.setState({showCustom: false});
65+
}, 2000);
66+
}
5167
};

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
},
3333
"homepage": "https://github.com/weui/react-weui",
3434
"dependencies": {
35-
"classnames": "^2.2.0",
36-
"react": "^0.14.2"
35+
"classnames": "^2.2.0"
3736
},
3837
"devDependencies": {
3938
"autoprefixer": "^6.3.5",
@@ -47,8 +46,10 @@
4746
"eslint-plugin-react": "^3.11.3",
4847
"extract-text-webpack-plugin": "^1.0.1",
4948
"file-loader": "^0.8.5",
49+
"history": "^1.17.0",
5050
"html-webpack-plugin": "^2.14.0",
5151
"istanbul": "^0.4.1",
52+
"jsdom": "^8.4.0",
5253
"less": "^2.5.3",
5354
"less-loader": "^2.2.1",
5455
"mocha": "^2.3.4",
@@ -57,7 +58,6 @@
5758
"react-addons-css-transition-group": "^0.14.7",
5859
"react-addons-test-utils": "^0.14.3",
5960
"react-dom": "^0.14.2",
60-
"history": "^1.17.0",
6161
"react-router": "^1.0.2",
6262
"rimraf": "^2.4.3",
6363
"sinon": "^1.17.2",
@@ -66,6 +66,9 @@
6666
"url-loader": "^0.5.7",
6767
"webpack": "^1.12.2",
6868
"webpack-dev-server": "^1.12.1",
69-
"weui": "^0.4.0"
69+
"weui": "^0.4.1"
70+
},
71+
"peerDependencies": {
72+
"react": "^0.14.2 || ^15.0.1"
7073
}
7174
}

src/components/actionsheet/actionsheet.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,28 @@ export default class ActionSheet extends React.Component {
4848

4949
_renderMenuItem() {
5050
return this.props.menus.map((menu, idx) => {
51-
const {label, ...others} = menu;
52-
const className = classNames({
53-
weui_actionsheet_cell: true
51+
const {label, className, ...others} = menu;
52+
const cls = classNames({
53+
weui_actionsheet_cell: true,
54+
[className]: className
5455
});
5556

5657
return (
57-
<div key={idx} {...others} className={className}>{label}</div>
58+
<div key={idx} {...others} className={cls}>{label}</div>
5859
);
5960
});
6061
}
6162

6263
_renderActions() {
6364
return this.props.actions.map((action, idx) => {
64-
const {label, ...others} = action;
65-
const className = classNames({
66-
weui_actionsheet_cell: true
65+
const {label, className, ...others} = action;
66+
const cls = classNames({
67+
weui_actionsheet_cell: true,
68+
[className]: className
6769
});
6870

6971
return (
70-
<div key={idx} {...others} className={className}>{label}</div>
72+
<div key={idx} {...others} className={cls}>{label}</div>
7173
);
7274
});
7375
}

src/components/cell/cell_body.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import classNames from 'classnames';
99

1010
export default class CellBody extends React.Component {
1111
render() {
12-
const {children, ...others} = this.props;
13-
const className = classNames({
12+
const {className, children, ...others} = this.props;
13+
const cls = classNames({
1414
weui_cell_bd: true,
15-
weui_cell_primary: true
15+
weui_cell_primary: true,
16+
[className]: className
1617
});
1718

1819
return (
19-
<div className={className} {...others}>{children}</div>
20+
<div className={cls} {...others}>{children}</div>
2021
);
2122
}
2223
};

src/components/cell/cell_footer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import classNames from 'classnames';
99

1010
export default class CellFooter extends React.Component {
1111
render() {
12-
const {children, ...others} = this.props;
13-
const className = classNames({
14-
weui_cell_ft: true
12+
const {className, children, ...others} = this.props;
13+
const cls = classNames({
14+
weui_cell_ft: true,
15+
[className]: className
1516
});
1617

1718
return (
18-
<div className={className} {...others}>{children}</div>
19+
<div className={cls} {...others}>{children}</div>
1920
);
2021
}
2122
};

src/components/cell/cell_header.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import classNames from 'classnames';
99

1010
export default class CellHeader extends React.Component {
1111
render() {
12-
const {children, ...others} = this.props;
13-
const className = classNames({
14-
weui_cell_hd: true
12+
const {className, children, ...others} = this.props;
13+
const cls = classNames({
14+
weui_cell_hd: true,
15+
[className]: className
1516
});
1617

1718
return (
18-
<div className={className} {...others}>{children}</div>
19+
<div className={cls} {...others}>{children}</div>
1920
);
2021
}
2122
};

src/components/cell/cells_tips.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import classNames from 'classnames';
99

1010
export default class CellsTips extends React.Component {
1111
render() {
12-
const {children, ...others} = this.props;
13-
const className = classNames({
14-
weui_cells_tips: true
12+
const {className, children, ...others} = this.props;
13+
const cls = classNames({
14+
weui_cells_tips: true,
15+
[className]: className
1516
});
1617

1718
return (
18-
<div className={className} {...others}>{children}</div>
19+
<div className={cls} {...others}>{children}</div>
1920
);
2021
}
2122
};

src/components/cell/cells_title.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import classNames from 'classnames';
99

1010
export default class CellsTitle extends React.Component {
1111
render() {
12-
const {children, ...others} = this.props;
13-
const className = classNames({
14-
weui_cells_title: true
12+
const {className, children, ...others} = this.props;
13+
const cls = classNames({
14+
weui_cells_title: true,
15+
[className]: className
1516
});
1617

1718
return (
18-
<div className={className} {...others}>{children}</div>
19+
<div className={cls} {...others}>{children}</div>
1920
);
2021
}
2122
};

src/components/searchbar/searchbar.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ class SearchBar extends React.Component {
7272
onChange={this.changeHandle.bind(this)}
7373
value={this.state.text}
7474
/>
75-
<a className='weui_icon_clear' onMouseDown={this.clearHandle.bind(this)}/>
75+
{/*React will not trigger onMouseDown when not onClick presented*/}
76+
<a
77+
className='weui_icon_clear'
78+
onClick={e=>e/*issues #59*/}
79+
onMouseDown={this.clearHandle.bind(this)}
80+
/>
7681
</div>
7782
<label
7883
className='weui_search_text'

src/components/toast/toast.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ import Icon from '../icon/index';
1313
class Toast extends React.Component {
1414
static propTypes = {
1515
icon: React.PropTypes.string,
16+
iconSize: React.PropTypes.string,
1617
show: React.PropTypes.bool
1718
};
1819

1920
static defaultProps = {
2021
icon: 'toast',
21-
show: false
22+
show: false,
2223
};
2324

2425
render() {
25-
const {icon, show, children} = this.props;
26+
const {icon, show, children, iconSize} = this.props;
2627

2728
return (
2829
<div className={icon === 'loading' ? 'weui_loading_toast' : ''} style={{display: show ? 'block' : 'none'}}>
2930
<Mask transparent={true}/>
3031
<div className="weui_toast">
31-
<Icon value={icon}/>
32+
<Icon value={icon} size={iconSize}/>
3233
<p className="weui_toast_content">{children}</p>
3334
</div>
3435
</div>

test/actionsheet.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ describe('<ActionSheet></ActionSheet>', ()=> {
1616
[undefined, null, true, false].map((show) => {
1717
describe(`<ActionSheet></ActionSheet>`, ()=> {
1818
const menus = [{
19-
label: '拍照'
19+
label: '拍照',
20+
className: 'customClassName1'
2021
}, {
21-
label: '从相册中选取'
22+
label: '从相册中选取',
23+
className: 'customClassName2'
2224
}];
2325
const actions = [{
24-
label: '取消'
26+
label: '取消',
27+
className: 'customClassName'
2528
}, {
2629
label: '确定'
2730
}];
@@ -67,7 +70,9 @@ describe('<ActionSheet></ActionSheet>', ()=> {
6770
assert(menuItems.length === menus.length);
6871

6972
menuItems.map((menuItem, index)=> {
70-
assert(menuItem.text() === menus[index].label);
73+
const menu = menus[index];
74+
assert(menuItem.text() === menu.label);
75+
menu.className && assert(menuItem.hasClass(menu.className));
7176
});
7277
});
7378

@@ -76,7 +81,9 @@ describe('<ActionSheet></ActionSheet>', ()=> {
7681
assert(actionItems.length === actions.length);
7782

7883
actionItems.map((actionItem, index)=> {
79-
assert(actionItem.text() === actions[index].label);
84+
const action = actions[index];
85+
assert(actionItem.text() === action.label);
86+
action.className && assert(actionItem.hasClass(action.className));
8087
});
8188
});
8289
});

test/cell_body.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ describe('<CellBody></CellBody>', ()=> {
1515

1616
['cell body wording', <img src="http://mmrb.github.io/avatar/jf.jpg" />, <div><h2 className="title">文章标题</h2><p className="desc">文章描述</p></div>].map((child)=>{
1717
describe(`<CellBody>${child}</CellBody>`, ()=>{
18+
const customClassName = 'customClassName1 customClassName2';
1819
const wrapper = shallow(
19-
<CellBody>{child}</CellBody>
20+
<CellBody className={customClassName}>{child}</CellBody>
2021
);
2122

2223
it(`should render <CellBody></CellBody> component `, ()=>{
@@ -27,6 +28,10 @@ describe('<CellBody></CellBody>', ()=> {
2728
assert(wrapper.hasClass(`weui_cell_bd`));
2829
});
2930

31+
it(`should have custom class name ${customClassName}`, ()=> {
32+
assert(wrapper.hasClass(customClassName));
33+
});
34+
3035
it(`should have child ${child}`, ()=>{
3136
assert(wrapper.contains(child));
3237
});

test/cell_footer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ describe('<CellFooter></CellFooter>', ()=> {
1515

1616
['cell footer wording', <img src="http://mmrb.github.io/avatar/bear.jpg" />].map((child)=>{
1717
describe(`<CellFooter>${child}</CellFooter>`, ()=>{
18+
const customClassName = 'customClassName1 customClassName2';
1819
const wrapper = shallow(
19-
<CellFooter>{child}</CellFooter>
20+
<CellFooter className={customClassName}>{child}</CellFooter>
2021
);
2122

2223
it(`should render <CellFooter></CellFooter> component `, ()=>{
@@ -27,6 +28,10 @@ describe('<CellFooter></CellFooter>', ()=> {
2728
assert(wrapper.hasClass(`weui_cell_ft`));
2829
});
2930

31+
it(`should have custom class name ${customClassName}`, ()=> {
32+
assert(wrapper.hasClass(customClassName));
33+
});
34+
3035
it(`should have child ${child}`, ()=>{
3136
assert(wrapper.contains(child));
3237
});

test/cell_header.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ describe('<CellHeader></CellHeader>', ()=> {
1515

1616
['cell header wording', <img src="http://mmrb.github.io/avatar/jf.jpg" />, <p>cell header wording</p>].map((child)=>{
1717
describe(`<CellHeader>${child}</CellHeader>`, ()=>{
18+
const customClassName = 'customClassName1 customClassName2';
1819
const wrapper = shallow(
19-
<CellHeader>{child}</CellHeader>
20+
<CellHeader className={customClassName}>{child}</CellHeader>
2021
);
2122

2223
it(`should render <CellHeader></CellHeader> component `, ()=>{
@@ -27,6 +28,10 @@ describe('<CellHeader></CellHeader>', ()=> {
2728
assert(wrapper.hasClass(`weui_cell_hd`));
2829
});
2930

31+
it(`should have custom class name ${customClassName}`, ()=> {
32+
assert(wrapper.hasClass(customClassName));
33+
});
34+
3035
it(`should have child ${child}`, ()=>{
3136
assert(wrapper.contains(child));
3237
});

0 commit comments

Comments
 (0)