Skip to content

Commit

Permalink
#15 Cells允许传入自定义className
Browse files Browse the repository at this point in the history
  • Loading branch information
progrape committed Dec 23, 2015
1 parent 4ce2744 commit 862d987
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/components/cell/cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import classNames from 'classnames';

export default class Cells extends React.Component {
render() {
const {children, access, radio, checkbox, form, ...others} = this.props;
const className = classNames({
const {children, className, access, radio, checkbox, form, ...others} = this.props;
const cls = classNames({
weui_cells: true,
weui_cells_access: access,
weui_cells_form: form
weui_cells_form: form,
[className]: className
});

return (
<div className={className} {...others}>{children}</div>
<div className={cls} {...others}>{children}</div>
);
}
};
17 changes: 11 additions & 6 deletions test/cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ const {Cells, Cell, CellHeader, CellBody, CellFooter} = WeUI;
describe('<Cells></Cells>', ()=> {

[true, false].map((access) => {
describe(`<Cells access="${access}"></Cells>`, ()=>{
describe(`<Cells access="${access}"></Cells>`, ()=> {
const child = <Cell><CellHeader>header</CellHeader><CellBody>body</CellBody><CellFooter>footer</CellFooter></Cell>;
const customClassName = 'customClassName1 customClassName2';
const wrapper = shallow(
<Cells access={access}>{child}</Cells>
<Cells access={access} className={customClassName}>{child}</Cells>
);

it(`should render <Cells></Cells> component `, ()=>{
it(`should render <Cells></Cells> component `, ()=> {
assert(wrapper.instance() instanceof Cells);
});

it(`should have 'weui_cells' class name`, ()=>{
it(`should have 'weui_cells' class name`, ()=> {
assert(wrapper.hasClass(`weui_cells`));
});

it(`should have 'weui_cells_access' when access attribute is true`, ()=>{
it(`should have custom class name ${customClassName}`, ()=> {
assert(wrapper.hasClass(customClassName));
});

it(`should have 'weui_cells_access' when access attribute is true`, ()=> {
if (access) {
assert(wrapper.hasClass(`weui_cells_access`));
}
});

it(`should have child typeof Cell`, ()=>{
it(`should have child typeof Cell`, ()=> {
assert(wrapper.find(Cell).html() === shallow(child).html());
});
});
Expand Down

0 comments on commit 862d987

Please # to comment.