Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell* 和 ActionSheet 的 menu/action 支持传入自定义 className #71

Merged
merged 2 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 5 additions & 4 deletions src/components/cell/cell_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import classNames from 'classnames';

export default class CellBody extends React.Component {
render() {
const {children, ...others} = this.props;
const className = classNames({
const {className, children, ...others} = this.props;
const cls = classNames({
weui_cell_bd: true,
weui_cell_primary: true
weui_cell_primary: true,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
9 changes: 5 additions & 4 deletions src/components/cell/cell_footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import classNames from 'classnames';

export default class CellFooter extends React.Component {
render() {
const {children, ...others} = this.props;
const className = classNames({
weui_cell_ft: true
const {className, children, ...others} = this.props;
const cls = classNames({
weui_cell_ft: true,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
9 changes: 5 additions & 4 deletions src/components/cell/cell_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import classNames from 'classnames';

export default class CellHeader extends React.Component {
render() {
const {children, ...others} = this.props;
const className = classNames({
weui_cell_hd: true
const {className, children, ...others} = this.props;
const cls = classNames({
weui_cell_hd: true,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
9 changes: 5 additions & 4 deletions src/components/cell/cells_tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import classNames from 'classnames';

export default class CellsTips extends React.Component {
render() {
const {children, ...others} = this.props;
const className = classNames({
weui_cells_tips: true
const {className, children, ...others} = this.props;
const cls = classNames({
weui_cells_tips: true,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
9 changes: 5 additions & 4 deletions src/components/cell/cells_title.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import classNames from 'classnames';

export default class CellsTitle extends React.Component {
render() {
const {children, ...others} = this.props;
const className = classNames({
weui_cells_title: true
const {className, children, ...others} = this.props;
const cls = classNames({
weui_cells_title: true,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
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
7 changes: 6 additions & 1 deletion test/cell_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('<CellBody></CellBody>', ()=> {

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

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

it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have child ${child}`, ()=>{
assert(wrapper.contains(child));
});
Expand Down
7 changes: 6 additions & 1 deletion test/cell_footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('<CellFooter></CellFooter>', ()=> {

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

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

it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have child ${child}`, ()=>{
assert(wrapper.contains(child));
});
Expand Down
7 changes: 6 additions & 1 deletion test/cell_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('<CellHeader></CellHeader>', ()=> {

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

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

it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have child ${child}`, ()=>{
assert(wrapper.contains(child));
});
Expand Down
7 changes: 6 additions & 1 deletion test/cells_tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const {CellsTips} = WeUI;
describe('<CellsTips></CellsTips>', ()=> {

const text = `cells tips wording`;
const customClassName = 'customClassName1 customClassName2';
const wrapper = shallow(
<CellsTips>{text}</CellsTips>
<CellsTips className={customClassName}>{text}</CellsTips>
);

it(`should render <CellsTips></CellsTips> component `, ()=>{
Expand All @@ -26,6 +27,10 @@ describe('<CellsTips></CellsTips>', ()=> {
assert(wrapper.hasClass(`weui_cells_tips`));
});

it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have text ${text}`, ()=>{
assert(wrapper.text() === text);
});
Expand Down
7 changes: 6 additions & 1 deletion test/cells_title.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const {CellsTitle} = WeUI;
describe('<CellsTitle></CellsTitle>', ()=> {

const text = `cells tips wording`;
const customClassName = 'customClassName1 customClassName2';
const wrapper = shallow(
<CellsTitle>{text}</CellsTitle>
<CellsTitle className={customClassName}>{text}</CellsTitle>
);

it(`should render <CellsTitle></CellsTitle> component `, ()=>{
Expand All @@ -26,6 +27,10 @@ describe('<CellsTitle></CellsTitle>', ()=> {
assert(wrapper.hasClass(`weui_cells_title`));
});

it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have text ${text}`, ()=>{
assert(wrapper.text() === text);
});
Expand Down