From cb409a1f04467132002735f56e7a93e07d8b3147 Mon Sep 17 00:00:00 2001 From: Yury Orlov Date: Wed, 22 Nov 2017 13:53:50 +0300 Subject: [PATCH] refactor(react-grid): replace render functions with components in Grid (#486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGES:   The Grid's `rootTemplate`, `headerPlaceholderTemplate`, and `footerPlaceholderTemplate` properties have been replaced with `rootComponent`, `headerPlaceholderComponent`, and `footerPlaceholderComponent`. This also means that they accept components instead of render functions. Find more details here: https://github.com/DevExpress/devextreme-reactive/issues/496   The `headerTemplate`, `bodyTemplate`, and `footerTemplate` properties have been replaced with the `children` property in `rootTemplate`. --- .../dx-react-grid-bootstrap3/src/grid.jsx | 6 +- .../src/templates/layout.jsx | 35 ++++++----- .../dx-react-grid-material-ui/src/grid.jsx | 10 +--- .../src/templates/layout.jsx | 37 ++++++------ packages/dx-react-grid/docs/reference/grid.md | 32 +++++----- packages/dx-react-grid/src/grid.jsx | 28 ++++----- packages/dx-react-grid/src/grid.test.jsx | 6 +- .../dx-react-grid/src/plugins/grid-core.jsx | 46 +++++++------- .../src/plugins/grid-core.test.jsx | 60 +++++-------------- 9 files changed, 113 insertions(+), 147 deletions(-) diff --git a/packages/dx-react-grid-bootstrap3/src/grid.jsx b/packages/dx-react-grid-bootstrap3/src/grid.jsx index 37a741baaf..19bbf9ea36 100644 --- a/packages/dx-react-grid-bootstrap3/src/grid.jsx +++ b/packages/dx-react-grid-bootstrap3/src/grid.jsx @@ -5,9 +5,9 @@ import { Root, Header, Footer } from './templates/layout'; export const Grid = ({ children, ...props }) => ( {children} diff --git a/packages/dx-react-grid-bootstrap3/src/templates/layout.jsx b/packages/dx-react-grid-bootstrap3/src/templates/layout.jsx index f50e2d24ad..6d115c6c7a 100644 --- a/packages/dx-react-grid-bootstrap3/src/templates/layout.jsx +++ b/packages/dx-react-grid-bootstrap3/src/templates/layout.jsx @@ -1,42 +1,47 @@ import React from 'react'; import PropTypes from 'prop-types'; -export const Root = ({ - headerTemplate, - bodyTemplate, - footerTemplate, -}) => ( +export const Root = ({ children }) => (
- {headerTemplate()} - {bodyTemplate()} - {footerTemplate()} + {children}
); Root.propTypes = { - headerTemplate: PropTypes.func.isRequired, - bodyTemplate: PropTypes.func.isRequired, - footerTemplate: PropTypes.func.isRequired, + children: PropTypes.oneOfType([ + PropTypes.node, + PropTypes.arrayOf(PropTypes.node), + ]), +}; + +Root.defaultProps = { + children: undefined, }; export const Header = ({ children }) => children &&
{children}
; Header.propTypes = { - children: PropTypes.node, + children: PropTypes.oneOfType([ + PropTypes.node, + PropTypes.arrayOf(PropTypes.node), + ]), }; Header.defaultProps = { - children: null, + children: undefined, }; export const Footer = ({ children }) => children &&
{children}
; Footer.propTypes = { - children: PropTypes.node, + children: PropTypes.oneOfType([ + PropTypes.node, + PropTypes.arrayOf(PropTypes.node), + ]), }; Footer.defaultProps = { - children: null, + children: undefined, }; diff --git a/packages/dx-react-grid-material-ui/src/grid.jsx b/packages/dx-react-grid-material-ui/src/grid.jsx index c74d59cbf8..19bbf9ea36 100644 --- a/packages/dx-react-grid-material-ui/src/grid.jsx +++ b/packages/dx-react-grid-material-ui/src/grid.jsx @@ -3,15 +3,11 @@ import PropTypes from 'prop-types'; import { Grid as GridBase } from '@devexpress/dx-react-grid'; import { Root, Header, Footer } from './templates/layout'; -const rootTemplate = props => ; -const headerPlaceholderTemplate = props =>
; -const footerPlaceholderTemplate = props =>