Skip to content

Commit

Permalink
#68 Cell* 增加支持传入自定义 className
Browse files Browse the repository at this point in the history
  • Loading branch information
progrape committed Apr 25, 2016
1 parent 4a577ad commit a09719a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 25 deletions.
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>
);
}
};
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

0 comments on commit a09719a

Please sign in to comment.