From 8a362e4d043d501a86b50dade9c4a8eafd10f808 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 16 Feb 2017 12:40:12 -0700 Subject: [PATCH] Rollback on table partials to fix mounting/unmounting issues --- README.md | 69 ++++----------- src/index.js | 154 ++++++++++++--------------------- stories/FunctionalRendering.js | 86 +----------------- 3 files changed, 76 insertions(+), 233 deletions(-) diff --git a/README.md b/README.md index b085861..f523273 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ const data = [{ const columns = [{ header: 'Name', - accessor: 'name' // String-based value accessors! + accessor: 'name' // String-based value accessors! }, { header: 'Age', accessor: 'age', @@ -607,56 +607,21 @@ Possibly one of the coolest features of React-Table is its ability to expose int The function you pass will be called with the following items: - Fully-resolved state of the table -- The standard table component (including individual partials as properties of this component) +- A function that returns the standard table component - The instance of the component You can then return any JSX or react you want! This turns out to be perfect for: -- Reordering the internal components of the table - Accessing the internal state of the table without a `ref` - Decorating the table or extending it with your own UI - Building your own custom display logic -Custom pagination order: -```javascript - - {(state, { - Root, - Table, - HeaderGroups, - Headers, - Rows, - Footers, - Pagination, - NoData, - Loading - }, instance) => { - return ( - - - - - - - -
- - -
- ) - }} -
-``` - Accessing internal state and wrapping with more UI: ```javascript - {(state, Table, instance) => { + {(state, makeTable, instance) => { return (
state.allVisibleColumns === {JSON.stringify(state.allVisibleColumns, null, 4)}
- + {makeTable()} ) }} @@ -683,18 +648,20 @@ Though we confidently stand by the markup and architecture behind it, `react-tab // Change the global default import { ReactTableDefaults } from 'react-table' Object.assign(ReactTableDefaults, { - TableComponent: Component, - TheadComponent: Component, - TbodyComponent: Component, - TrGroupComponent: Component, - TrComponent: Component, - ThComponent: Component, - TdComponent: Component, - PaginationComponent: Component, - PreviousComponent: Component, - NextComponent: Component, - LoadingComponent: Component, - ExpanderComponent: Component + TableComponent: component, + TheadComponent: component, + TbodyComponent: component, + TrGroupComponent: component, + TrComponent: component, + ThComponent: component + TdComponent: component, + TfootComponent: component, + ExpanderComponent: component, + PaginationComponent: component, + PreviousComponent: undefined, + NextComponent: undefined, + LoadingComponent: component, + NoDataComponent: component, }) // Or change per instance diff --git a/src/index.js b/src/index.js index c3dbdf8..0fb4dbd 100644 --- a/src/index.js +++ b/src/index.js @@ -709,110 +709,66 @@ export default React.createClass({ const loadingProps = getLoadingProps(finalState, undefined, undefined, this) const noDataProps = getNoDataProps(finalState, undefined, undefined, this) - const Root = ({children}) => { - return ( -
- {children} -
- ) - } - - const Table = ({children}) => ( - - {children} - - ) - - const HeaderGroups = () => hasHeaderGroups ? makeHeaderGroups() : null - const Headers = () => makeHeaders() - const Rows = ({children}) => ( - ( +
- {pageRows.map((d, i) => makePageRow(d, i))} - {padRows.map(makePadRow)} - + + {hasHeaderGroups ? makeHeaderGroups() : null} + {makeHeaders()} + + {pageRows.map((d, i) => makePageRow(d, i))} + {padRows.map(makePadRow)} + + {hasColumnFooter ? makeColumnFooters() : null} + + {showPagination ? ( + + ) : null} + + {_.normalizeComponent(noDataText)} + + +
) - const Footers = () => hasColumnFooter ? makeColumnFooters() : null - - const Pagination = () => showPagination ? ( - - ) : null - - const NoData = () => !pageRows.length ? ( - - {_.normalizeComponent(noDataText)} - - ) : null - - const Loading = () => ( - - ) - - const StandardTable = () => ( - -
- - - - -
- - - - - ) - - Object.assign(StandardTable, { - Root, - Table, - HeaderGroups, - Headers, - Rows, - Footers, - Pagination, - NoData, - Loading - }) - // childProps are optionally passed to a function-as-a-child - return children ? children(finalState, StandardTable, this) : + return children ? children(finalState, makeTable, this) : makeTable() } }) diff --git a/stories/FunctionalRendering.js b/stories/FunctionalRendering.js index cf52b65..0c49dac 100644 --- a/stories/FunctionalRendering.js +++ b/stories/FunctionalRendering.js @@ -60,16 +60,13 @@ export default () => { return (
Functional rendering simply means that you have all of the building blocks to render your own React Table however you'd like. -
-
- Whether it's completely custom, or even just rearranging the order of the table's elements, this is how you can do it.



- Pagination at the top using partials: + Decorating the standard table output

@@ -78,84 +75,7 @@ export default () => { data={data} columns={columns} > - {(state, { - Root, - Table, - HeaderGroups, - Headers, - Rows, - Footers, - Pagination, - NoData, - Loading - }, instance) => { - return ( - - - - - - - -
- - -
- ) - }} - -
- - {() => ` -import ReactTable from 'react-table' - -return ( - - {(state, { - Root, - Table, - HeaderGroups, - Headers, - Rows, - Footers, - Pagination, - NoData, - Loading - }, instance) => { - return ( - - - - - - - -
- - -
- ) - }} -
-) - `}
- -
-
- - Wrapping the standard table output -
-
- -
- - {(state, Table, instance) => { + {(state, makeTable, instance) => { return (
state.allVisibleColumns === {JSON.stringify(state.allVisibleColumns, null, 4)}
- + {makeTable()} ) }}