From a1d67a9992884c0eb4b1838296a7cf432f463ed2 Mon Sep 17 00:00:00 2001 From: ES Date: Fri, 12 Jul 2019 09:54:23 +0530 Subject: [PATCH 1/4] Allow custom class names for most of the components --- demo/src/schema/basic.js | 2 +- demo/src/schema/normalized.js | 9 ++++++++- src/components/Body.js | 22 ++++++++++++++-------- src/components/Button.js | 4 ++-- src/components/Columns.js | 14 +++++++++----- src/components/Editable.js | 10 ++++++++-- src/components/Filters.js | 15 +++++++++++---- src/components/Header.js | 14 ++++++++++---- src/components/Limiter.js | 6 +++--- src/components/MassActions.js | 19 ++++++++++++++----- src/components/Pages.js | 21 ++++++++++++++------- src/components/Print.js | 5 +++-- src/components/Renderer/Body/Actions.js | 9 +++++---- src/components/ResetFilters.js | 5 +++-- src/components/ResultCount.js | 4 ++-- src/components/Table.js | 8 +++----- src/createTable.js | 4 ++-- 17 files changed, 112 insertions(+), 59 deletions(-) diff --git a/demo/src/schema/basic.js b/demo/src/schema/basic.js index 8a56741..2f8da49 100644 --- a/demo/src/schema/basic.js +++ b/demo/src/schema/basic.js @@ -327,7 +327,7 @@ export default { type: 'action', name: 'edit', label: 'Edit', - htmlClass: 'btn btn-secondary', + className: 'btn btn-secondary', thunk: ( config ) => ( dispatch, getState ) => { console.log('edit', config, getState()); } diff --git a/demo/src/schema/normalized.js b/demo/src/schema/normalized.js index 9bf5414..a2cea06 100644 --- a/demo/src/schema/normalized.js +++ b/demo/src/schema/normalized.js @@ -77,6 +77,12 @@ export default { // // } // // } // }, + // Table: { + // className: 'new-table-class' + // }, + Header: { + className: 'new-header-class' + }, ResultCount: { styles: { display: 'flex', @@ -217,6 +223,7 @@ export default { // styles: {} }, Table: { + className: 'new-table-class', styles: { // table: { // background: '#000', @@ -344,7 +351,7 @@ export default { type: 'action', name: 'edit', label: 'Edit', - htmlClass: 'btn btn-secondary', + className: 'btn btn-secondary', thunk: ( config ) => ( dispatch, getState ) => { console.log('edit', config, getState()); } diff --git a/src/components/Body.js b/src/components/Body.js index 7f6201c..0eaef17 100644 --- a/src/components/Body.js +++ b/src/components/Body.js @@ -12,14 +12,14 @@ import { createSelector } from 'reselect'; const addElementResizeEventListener = require('element-resize-event'); const removeElementResizeEventListener = require('element-resize-event').unbind; -const renderCol = (rowIndex, primaryKey, schema, styles, column, index) => { +const renderCol = (rowIndex, primaryKey, schema, styles, colClassName, column, index) => { const { textAlign, name, type } = column; const ColRenderer = getRenderer(column, Renderers); return (
@@ -34,10 +34,10 @@ const renderCol = (rowIndex, primaryKey, schema, styles, column, index) => { ); }; -const renderRow = (columns, rowHeight, styles, primaryKey, schema, rowIndex, top) => ( +const renderRow = (columns, rowHeight, styles, primaryKey, schema, rowClassName, colClassName, rowIndex, top) => ( - { renderCol.bind(this, rowIndex, primaryKey, schema, styles) } + { renderCol.bind(this, rowIndex, primaryKey, schema, styles, colClassName) } ); -const Body = React.forwardRef(({ top: startTop = 0 }, ref) => { +const Body = React.forwardRef(({ top: startTop = 0, config }, ref) => { const { columns, action, @@ -68,6 +68,12 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => { } } = useContext(ConfigContext); + const { + className = 'table-body', + rowClassName = 'rdt-table-row', + colClassName = 'rdt-table-col' + } = config; + const itemCount = useSelector(getData(tableData => (tableData.items || []).length)); const isPrinting = useSelector(getData(tableData => !!tableData.isPrinting)); @@ -120,7 +126,7 @@ const Body = React.forwardRef(({ top: startTop = 0 }, ref) => { return ( { range={ range } rowHeight={ rowHeight } > - { renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema) } + { renderRow.bind(this, columns, rowHeight, styles, primaryKey, schema, rowClassName, colClassName) } ); }); diff --git a/src/components/Button.js b/src/components/Button.js index 56a7e2f..d07f20d 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -4,10 +4,10 @@ import ConfigContext from '../context'; const Button = ({ config }) => { const { thunk } = useContext(ConfigContext); - const { thunk: cb, label, name, styles = {} } = config; + const { thunk: cb, label, name, styles = {}, className = 'rdt-toolbar-btn' } = config; return ( diff --git a/src/components/Columns.js b/src/components/Columns.js index b7d1b61..b15471f 100644 --- a/src/components/Columns.js +++ b/src/components/Columns.js @@ -10,7 +10,11 @@ const Columns = ({ open, toggle, config: { - styles = {} + styles = {}, + className = 'rdt-toolbar-columns', + btnClassName = 'rdt-toolbar-button', + menuClassName = 'rdt-toolbar-menu', + menuItemClassName = 'rdt-toolbar-item', } }) => { const { @@ -20,15 +24,15 @@ const Columns = ({ } = useContext(ConfigContext); const visibleColumnIds = useSelector(getData(({ visibleColumnIds }) => visibleColumnIds)) || []; return ( - - -