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

feat(react-grid): add components for the Grid plugin #553

Merged
merged 8 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions packages/dx-react-grid-bootstrap3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"rollup-plugin-node-resolve": "^3.0.0"
},
"dependencies": {
"classnames": "^2.2.5",
"prop-types": "^15.6.0"
},
"peerDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/dx-react-grid-bootstrap3/src/grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const Grid = ({ children, ...props }) => (
</GridBase>
);

Grid.Root = Root;
Grid.HeaderPlaceholder = Header;
Grid.FooterPlaceholder = Footer;

Grid.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
Expand Down
32 changes: 26 additions & 6 deletions packages/dx-react-grid-bootstrap3/src/templates/layout.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

export const Root = ({ children }) => (
<div className="panel panel-default">
export const Root = ({ children, className, ...restProps }) => (
<div className={classNames('panel panel-default', className)}{...restProps}>
{children}
</div>
);
Expand All @@ -12,36 +13,55 @@ Root.propTypes = {
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
className: PropTypes.string,
};

Root.defaultProps = {
children: undefined,
className: undefined,
};

export const Header = ({ children }) =>
children && <div className="panel-heading" style={{ paddingBottom: '5px' }}>{children}</div>;
export const Header = ({
children, className,
style, ...restProps
}) => !!children && (
<div
className={classNames('panel-heading', className)}
style={{ paddingBottom: '5px', ...style }}
{...restProps}
>
{children}
</div>
);

Header.propTypes = {
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
className: PropTypes.string,
style: PropTypes.object,
};

Header.defaultProps = {
children: undefined,
className: undefined,
style: null,
};

export const Footer = ({ children }) =>
children && <div className="panel-footer">{children}</div>;
export const Footer = ({ children, className, ...restProps }) =>
!!children &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Why !!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SergeyAlexeev Because if don't pass children to the FooterPlaceholder my application broken with an exception.

<div className={classNames('panel-footer', className)} {...restProps}>{children}</div>;

Footer.propTypes = {
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
className: PropTypes.string,
};

Footer.defaultProps = {
children: undefined,
className: undefined,
};
104 changes: 104 additions & 0 deletions packages/dx-react-grid-bootstrap3/src/templates/layout.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Root, Header, Footer } from './layout';

describe('Layout', () => {
const children = <div />;

describe('Root', () => {
it('should pass className to the root element', () => {
const tree = shallow((
<Root className="custom-class" />
));

expect(tree.is('.custom-class'))
.toBeTruthy();
expect(tree.is('.panel-default'))
.toBeTruthy();
});

it('should pass rest props to the root element', () => {
const tree = shallow((
<Root data={{ a: 1 }} />
));

expect(tree.props().data)
.toMatchObject({ a: 1 });
});
});

describe('Header', () => {
it('should pass className to the root element', () => {
const tree = shallow((
<Header
className="custom-class"
data={{ a: 1 }}
>
{children}
</Header>
));

expect(tree.is('.custom-class'))
.toBeTruthy();
expect(tree.is('.panel-heading'))
.toBeTruthy();
});

it('should combine style on the root element', () => {
const tree = shallow((
<Header
style={{ color: 'red' }}
>
{children}
</Header>
));

expect(tree.props().style)
.toMatchObject({ paddingBottom: '5px', color: 'red' });
});

it('should pass rest props to the root element', () => {
const tree = shallow((
<Header
data={{ a: 1 }}
>
{children}
</Header>
));

expect(tree.props().data)
.toMatchObject({ a: 1 });
});
});

describe('Footer', () => {
it('should pass className to the root element', () => {
const tree = shallow((
<Footer
data={{ a: 1 }}
className="custom-class"
>
{children}
</Footer>
));

expect(tree.is('.custom-class'))
.toBeTruthy();
expect(tree.is('.panel-footer'))
.toBeTruthy();
});

it('should pass rest props to the root element', () => {
const tree = shallow((
<Footer
data={{ a: 1 }}
>
{children}
</Footer>
));

expect(tree.props().data)
.toMatchObject({ a: 1 });
});
});
});
4 changes: 4 additions & 0 deletions packages/dx-react-grid-material-ui/src/grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const Grid = ({ children, ...props }) => (
</GridBase>
);

Grid.Root = Root;
Grid.HeaderPlaceholder = Header;
Grid.FooterPlaceholder = Footer;

Grid.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
Expand Down
25 changes: 19 additions & 6 deletions packages/dx-react-grid-material-ui/src/templates/layout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from 'material-ui/styles';

const styles = theme => ({
Expand All @@ -14,8 +15,8 @@ const styles = theme => ({
},
});

export const Root = ({ children }) => (
<div>{children}</div>
export const Root = ({ children, ...restProps }) => (
<div {...restProps}>{children}</div>
);

Root.propTypes = {
Expand All @@ -29,36 +30,48 @@ Root.defaultProps = {
children: undefined,
};

const HeaderBase = ({ children, classes }) =>
children && <div className={classes.headingPanel}>{children}</div>;
const HeaderBase = ({
children, classes,
className, ...restProps
}) =>
!!children &&
<div className={classNames(classes.headingPanel, className)} {...restProps}>{children}</div>;

HeaderBase.propTypes = {
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
classes: PropTypes.object.isRequired,
className: PropTypes.string,
};

HeaderBase.defaultProps = {
children: undefined,
className: undefined,
};

export const Header = withStyles(styles, { name: 'GridLayout' })(HeaderBase);

const FooterBase = ({ children, classes }) =>
children && <div className={classes.footerPanel}>{children}</div>;
const FooterBase = ({
children, classes,
className, ...restProps
}) =>
!!children &&
<div className={classNames(classes.footerPanel, className)} {...restProps}>{children}</div>;

FooterBase.propTypes = {
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
classes: PropTypes.object.isRequired,
className: PropTypes.string,
};

FooterBase.defaultProps = {
children: undefined,
className: undefined,
};

export const Footer = withStyles(styles, { name: 'GridLayout' })(FooterBase);
Loading