Skip to content

Commit

Permalink
#51 ActionSheet 的 menus 和 actions 增加支持传入自定义 className
Browse files Browse the repository at this point in the history
  • Loading branch information
progrape committed Apr 25, 2016
1 parent a09719a commit 42bf8f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/actionsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ class App extends React.Component {
show: false,
menus: [{
label: '拍照',
className: 'customClassName',
onClick: ()=>{

}
}, {
label: '从手机相册中选择',
className: 'customClassName',
onClick: ()=>{

}
}],
actions: [{
label: '取消',
className: 'customClassName',
onClick: this.hide.bind(this)
}]
};
Expand Down
18 changes: 10 additions & 8 deletions src/components/actionsheet/actionsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,28 @@ export default class ActionSheet extends React.Component {

_renderMenuItem() {
return this.props.menus.map((menu, idx) => {
const {label, ...others} = menu;
const className = classNames({
weui_actionsheet_cell: true
const {label, className, ...others} = menu;
const cls = classNames({
weui_actionsheet_cell: true,
[className]: className
});

return (
<div key={idx} {...others} className={className}>{label}</div>
<div key={idx} {...others} className={cls}>{label}</div>
);
});
}

_renderActions() {
return this.props.actions.map((action, idx) => {
const {label, ...others} = action;
const className = classNames({
weui_actionsheet_cell: true
const {label, className, ...others} = action;
const cls = classNames({
weui_actionsheet_cell: true,
[className]: className
});

return (
<div key={idx} {...others} className={className}>{label}</div>
<div key={idx} {...others} className={cls}>{label}</div>
);
});
}
Expand Down
17 changes: 12 additions & 5 deletions test/actionsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ describe('<ActionSheet></ActionSheet>', ()=> {
[undefined, null, true, false].map((show) => {
describe(`<ActionSheet></ActionSheet>`, ()=> {
const menus = [{
label: '拍照'
label: '拍照',
className: 'customClassName1'
}, {
label: '从相册中选取'
label: '从相册中选取',
className: 'customClassName2'
}];
const actions = [{
label: '取消'
label: '取消',
className: 'customClassName'
}, {
label: '确定'
}];
Expand Down Expand Up @@ -67,7 +70,9 @@ describe('<ActionSheet></ActionSheet>', ()=> {
assert(menuItems.length === menus.length);

menuItems.map((menuItem, index)=> {
assert(menuItem.text() === menus[index].label);
const menu = menus[index];
assert(menuItem.text() === menu.label);
menu.className && assert(menuItem.hasClass(menu.className));
});
});

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

actionItems.map((actionItem, index)=> {
assert(actionItem.text() === actions[index].label);
const action = actions[index];
assert(actionItem.text() === action.label);
action.className && assert(actionItem.hasClass(action.className));
});
});
});
Expand Down

1 comment on commit 42bf8f3

@p2227
Copy link

@p2227 p2227 commented on 42bf8f3 May 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最终还是加入了~~

Please sign in to comment.